From bf74e673fcc1adae0881d8d5f3afea56de30cd61 Mon Sep 17 00:00:00 2001 From: Sergey Yagovtsev Date: Mon, 26 Sep 2016 23:23:38 +0300 Subject: [PATCH] Move getCurrentTime function in separate header --- src/CMakeLists.txt | 1 + src/block.cpp | 1 + src/current_time.h | 62 +++++++++++++++++++++++++++++++++++++++++ src/profile_manager.cpp | 1 + src/profile_manager.h | 30 -------------------- 5 files changed, 65 insertions(+), 30 deletions(-) create mode 100644 src/current_time.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 133797d..87be249 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -16,6 +16,7 @@ set(H_FILES profile_manager.h spin_lock.h event_trace_win.h + current_time.h ) set(SOURCES diff --git a/src/block.cpp b/src/block.cpp index 373de61..7eb4cdc 100644 --- a/src/block.cpp +++ b/src/block.cpp @@ -25,6 +25,7 @@ ************************************************************************/ #include "profile_manager.h" +#include "current_time.h" using namespace profiler; diff --git a/src/current_time.h b/src/current_time.h new file mode 100644 index 0000000..718fb36 --- /dev/null +++ b/src/current_time.h @@ -0,0 +1,62 @@ +/** +Lightweight profiler library for c++ +Copyright(C) 2016 Sergey Yagovtsev, Victor Zarubkin + +This program is free software : you can redistribute it and / or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program.If not, see . +**/ + +#ifndef EASY_______CURRENT_TIME_H_____ +#define EASY_______CURRENT_TIME_H_____ + +#include "profiler/profiler.h" + +#ifdef _WIN32 +#include +#else +#include +#include +#endif + +static inline profiler::timestamp_t getCurrentTime() +{ +#ifdef _WIN32 + //see https://msdn.microsoft.com/library/windows/desktop/dn553408(v=vs.85).aspx + LARGE_INTEGER elapsedMicroseconds; + if (!QueryPerformanceCounter(&elapsedMicroseconds)) + return 0; + return (profiler::timestamp_t)elapsedMicroseconds.QuadPart; +#else + +#if (defined(__GNUC__) || defined(__ICC)) + + #if defined(__i386__) + unsigned long long t; + __asm__ __volatile__("rdtsc" : "=A"(t)); + return t; + #elif defined(__x86_64__) + unsigned int hi, lo; + __asm__ __volatile__("rdtsc" : "=a" (lo), "=d" (hi)); + return ((uint64_t)hi << 32) | lo; + #endif + +#else + return std::chrono::time_point_cast(std::chrono::system_clock::now()).time_since_epoch().count(); +#define USE_STD_CHRONO +#endif + +#endif +} + + +#endif // EASY_______CURRENT_TIME_H_____ diff --git a/src/profile_manager.cpp b/src/profile_manager.cpp index d2fe565..b15628a 100644 --- a/src/profile_manager.cpp +++ b/src/profile_manager.cpp @@ -31,6 +31,7 @@ #include "profiler/easy_net.h" #include "profiler/easy_socket.h" #include "event_trace_win.h" +#include "current_time.h" ////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////// diff --git a/src/profile_manager.h b/src/profile_manager.h index 5060546..61bbe18 100644 --- a/src/profile_manager.h +++ b/src/profile_manager.h @@ -54,36 +54,6 @@ inline uint32_t getCurrentThreadId() #endif } -static inline profiler::timestamp_t getCurrentTime() -{ -#ifdef _WIN32 - //see https://msdn.microsoft.com/library/windows/desktop/dn553408(v=vs.85).aspx - LARGE_INTEGER elapsedMicroseconds; - if (!QueryPerformanceCounter(&elapsedMicroseconds)) - return 0; - return (profiler::timestamp_t)elapsedMicroseconds.QuadPart; -#else - -#if (defined(__GNUC__) || defined(__ICC)) - - #if defined(__i386__) - unsigned long long t; - __asm__ __volatile__("rdtsc" : "=A"(t)); - return t; - #elif defined(__x86_64__) - unsigned int hi, lo; - __asm__ __volatile__("rdtsc" : "=a" (lo), "=d" (hi)); - return ((uint64_t)hi << 32) | lo; - #endif - -#else - return std::chrono::time_point_cast(std::chrono::system_clock::now()).time_since_epoch().count(); -#define USE_STD_CHRONO -#endif - -#endif -} - namespace profiler { class SerializedBlock;