diff options
author | moneromooo-monero <moneromooo-monero@users.noreply.github.com> | 2017-08-01 14:03:18 +0100 |
---|---|---|
committer | moneromooo-monero <moneromooo-monero@users.noreply.github.com> | 2017-08-01 14:03:18 +0100 |
commit | bda8c5983ba41274cca6144f4a1f29b23eaa44a7 (patch) | |
tree | 73272c9766c79e6760025a1a0f16f486cdb50dc8 | |
parent | Merge pull request #2159 (diff) | |
download | monero-bda8c5983ba41274cca6144f4a1f29b23eaa44a7.tar.xz |
epee: add nanosecond timer and pause/restart profiling macros
Nanosecond timer precision won't work on Windows, but we don't
care since I'm using that just for profiling incremental code
paths, but a Windows coder is welcome to add it if there's a way.
Diffstat (limited to '')
-rw-r--r-- | contrib/epee/include/misc_os_dependent.h | 15 | ||||
-rw-r--r-- | contrib/epee/include/profile_tools.h | 7 |
2 files changed, 17 insertions, 5 deletions
diff --git a/contrib/epee/include/misc_os_dependent.h b/contrib/epee/include/misc_os_dependent.h index 806d3e83e..69ded09e5 100644 --- a/contrib/epee/include/misc_os_dependent.h +++ b/contrib/epee/include/misc_os_dependent.h @@ -48,17 +48,17 @@ namespace epee namespace misc_utils { - inline uint64_t get_tick_count() + inline uint64_t get_ns_count() { #if defined(_MSC_VER) - return ::GetTickCount64(); + return ::GetTickCount64() * 1000000; #elif defined(WIN32) static LARGE_INTEGER pcfreq = {0}; LARGE_INTEGER ticks; if (!pcfreq.QuadPart) QueryPerformanceFrequency(&pcfreq); QueryPerformanceCounter(&ticks); - ticks.QuadPart *= 1000; /* we want msec */ + ticks.QuadPart *= 1000000000; /* we want nsec */ return ticks.QuadPart / pcfreq.QuadPart; #elif defined(__MACH__) clock_serv_t cclock; @@ -68,16 +68,21 @@ namespace misc_utils clock_get_time(cclock, &mts); mach_port_deallocate(mach_task_self(), cclock); - return (mts.tv_sec * 1000) + (mts.tv_nsec/1000000); + return (mts.tv_sec * 1000000000) + (mts.tv_nsec); #else struct timespec ts; if(clock_gettime(CLOCK_MONOTONIC, &ts) != 0) { return 0; } - return (ts.tv_sec * 1000) + (ts.tv_nsec/1000000); + return (ts.tv_sec * 1000000000) + (ts.tv_nsec); #endif } + inline uint64_t get_tick_count() + { + return get_ns_count() / 1000000; + } + inline int call_sys_cmd(const std::string& cmd) { diff --git a/contrib/epee/include/profile_tools.h b/contrib/epee/include/profile_tools.h index d3b1e4db4..f285fe48b 100644 --- a/contrib/epee/include/profile_tools.h +++ b/contrib/epee/include/profile_tools.h @@ -57,8 +57,15 @@ namespace epee #define TIME_MEASURE_START(var_name) uint64_t var_name = epee::misc_utils::get_tick_count(); +#define TIME_MEASURE_PAUSE(var_name) var_name = epee::misc_utils::get_tick_count() - var_name; +#define TIME_MEASURE_RESTART(var_name) var_name = epee::misc_utils::get_tick_count() - var_name; #define TIME_MEASURE_FINISH(var_name) var_name = epee::misc_utils::get_tick_count() - var_name; +#define TIME_MEASURE_NS_START(var_name) uint64_t var_name = epee::misc_utils::get_ns_count(); +#define TIME_MEASURE_NS_PAUSE(var_name) var_name = epee::misc_utils::get_ns_count() - var_name; +#define TIME_MEASURE_NS_RESTART(var_name) var_name = epee::misc_utils::get_ns_count() - var_name; +#define TIME_MEASURE_NS_FINISH(var_name) var_name = epee::misc_utils::get_ns_count() - var_name; + namespace profile_tools { struct local_call_account |