1 // 2 // Copyright © 2017 Arm Ltd. All rights reserved. 3 // SPDX-License-Identifier: MIT 4 // 5 6 #pragma once 7 8 #include "Instrument.hpp" 9 #include <chrono> 10 #include "DllExport.hpp" 11 12 namespace armnn 13 { 14 15 #if defined(CLOCK_MONOTONIC_RAW) && defined(__unix__) 16 #define USE_CLOCK_MONOTONIC_RAW 1 17 #else 18 #define USE_CLOCK_MONOTONIC_RAW 0 19 #endif 20 21 #if USE_CLOCK_MONOTONIC_RAW 22 class MonotonicClockRaw 23 { 24 public: 25 using duration = std::chrono::nanoseconds; 26 using time_point = std::chrono::time_point<MonotonicClockRaw, duration>; 27 now()28 static std::chrono::time_point<MonotonicClockRaw, std::chrono::nanoseconds> now() noexcept 29 { 30 timespec ts; 31 clock_gettime(CLOCK_MONOTONIC_RAW, &ts); 32 return time_point(std::chrono::nanoseconds(ts.tv_sec * 1000000000 + ts.tv_nsec)); 33 } 34 }; 35 #endif 36 37 // Implementation of an instrument to measure elapsed wall-clock time in microseconds. 38 class WallClockTimer : public Instrument 39 { 40 public: 41 // Construct a Wall Clock Timer 42 WallClockTimer() = default; 43 ~WallClockTimer() = default; 44 45 // Start the Wall clock timer 46 void Start() override; 47 48 // Stop the Wall clock timer 49 void Stop() override; 50 51 // Get the name of the timer 52 const char* GetName() const override; 53 54 // Get the recorded measurements 55 std::vector<Measurement> GetMeasurements() const override; 56 57 #if USE_CLOCK_MONOTONIC_RAW 58 using clock = MonotonicClockRaw; 59 #else 60 using clock = std::chrono::steady_clock; 61 #endif 62 63 ARMNN_DLLEXPORT static const std::string WALL_CLOCK_TIME; 64 static const std::string WALL_CLOCK_TIME_START; 65 static const std::string WALL_CLOCK_TIME_STOP; 66 67 private: 68 clock::time_point m_Start; 69 clock::time_point m_Stop; 70 }; 71 72 } //namespace armnn 73