From 70e4e4382e4a9dba90c555cf6612c727aee99c4b Mon Sep 17 00:00:00 2001 From: moneromooo-monero Date: Sun, 11 Mar 2018 11:17:29 +0000 Subject: [PATCH] perf_timer: add a way to get and reset the current time --- src/common/perf_timer.cpp | 16 ++++++++++++++++ src/common/perf_timer.h | 4 ++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/common/perf_timer.cpp b/src/common/perf_timer.cpp index d287949ba..fc51dc7f7 100644 --- a/src/common/perf_timer.cpp +++ b/src/common/perf_timer.cpp @@ -165,4 +165,20 @@ void PerformanceTimer::resume() paused = false; } +void PerformanceTimer::reset() +{ + if (paused) + ticks = 0; + else + ticks = get_tick_count(); +} + +uint64_t PerformanceTimer::value() const +{ + uint64_t v = ticks; + if (!paused) + v = get_tick_count() - v; + return ticks_to_ns(v); +} + } diff --git a/src/common/perf_timer.h b/src/common/perf_timer.h index 267f94161..d859cf576 100644 --- a/src/common/perf_timer.h +++ b/src/common/perf_timer.h @@ -51,8 +51,8 @@ public: ~PerformanceTimer(); void pause(); void resume(); - - uint64_t value() const { return ticks; } + void reset(); + uint64_t value() const; protected: uint64_t ticks;