From e9e1878cb94e45ba71303a8ceda5bc523997fde4 Mon Sep 17 00:00:00 2001 From: Aron Virginas-Tar Date: Fri, 7 Jun 2019 16:55:07 +0100 Subject: IVGCVSW-3253 Refactor MonotonicClockRaw in WallClockTimer Signed-off-by: Aron Virginas-Tar Change-Id: I759aaeff4e543c36047698716bd99bac4e4092d3 --- src/armnn/WallClockTimer.hpp | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/src/armnn/WallClockTimer.hpp b/src/armnn/WallClockTimer.hpp index 197ad7d1b7..ff17d79e92 100644 --- a/src/armnn/WallClockTimer.hpp +++ b/src/armnn/WallClockTimer.hpp @@ -11,25 +11,27 @@ namespace armnn { -// Clock class that uses the same timestamp function as the Mali DDK where possible. -class monotonic_clock_raw { +#if defined(CLOCK_MONOTONIC_RAW) && defined(__unix__) +#define USE_CLOCK_MONOTONIC_RAW 1 +#else +#define USE_CLOCK_MONOTONIC_RAW 0 +#endif + +#if USE_CLOCK_MONOTONIC_RAW +class MonotonicClockRaw +{ public: - using duration = std::chrono::nanoseconds; - using time_point = std::chrono::time_point; + using duration = std::chrono::nanoseconds; + using time_point = std::chrono::time_point; - static std::chrono::time_point now() noexcept + static std::chrono::time_point now() noexcept { -#if defined(__unix__) timespec ts; clock_gettime(CLOCK_MONOTONIC_RAW, &ts); return time_point(std::chrono::nanoseconds(ts.tv_sec * 1000000000 + ts.tv_nsec)); -#else - // On other platforms we have to make do with the standard C++ API, which may not exactly match - // the Mali DDK. - return std::chrono::time_point(); -#endif } }; +#endif // Implementation of an instrument to measure elapsed wall-clock time in microseconds. class WallClockTimer : public Instrument @@ -51,8 +53,8 @@ public: // Get the recorded measurements std::vector GetMeasurements() const override; -#if defined(CLOCK_MONOTONIC_RAW) - using clock = monotonic_clock_raw; +#if USE_CLOCK_MONOTONIC_RAW + using clock = MonotonicClockRaw; #else using clock = std::chrono::steady_clock; #endif -- cgit v1.2.1