ArmNN
 24.02
WallClockTimer.hpp
Go to the documentation of this file.
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 
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
armnn::WallClockTimer::WALL_CLOCK_TIME_STOP
static const std::string WALL_CLOCK_TIME_STOP
Definition: WallClockTimer.hpp:65
armnn::WallClockTimer::GetMeasurements
std::vector< Measurement > GetMeasurements() const override
Definition: WallClockTimer.cpp:30
armnn::WallClockTimer::WallClockTimer
WallClockTimer()=default
DllExport.hpp
armnn::WallClockTimer::Stop
void Stop() override
Definition: WallClockTimer.cpp:25
armnn::WallClockTimer::WALL_CLOCK_TIME
static const std::string WALL_CLOCK_TIME
Definition: WallClockTimer.hpp:63
armnn::WallClockTimer::Start
void Start() override
Definition: WallClockTimer.cpp:20
Instrument.hpp
ARMNN_DLLEXPORT
#define ARMNN_DLLEXPORT
Definition: DllExport.hpp:17
armnn::WallClockTimer::~WallClockTimer
~WallClockTimer()=default
armnn::Instrument
Definition: Instrument.hpp:51
armnn
Copyright (c) 2021 ARM Limited and Contributors.
Definition: 01_00_quick_start.dox:6
armnn::WallClockTimer::clock
std::chrono::steady_clock clock
Definition: WallClockTimer.hpp:60
armnn::WallClockTimer::WALL_CLOCK_TIME_START
static const std::string WALL_CLOCK_TIME_START
Definition: WallClockTimer.hpp:64
armnn::WallClockTimer::GetName
const char * GetName() const override
Definition: WallClockTimer.cpp:15
armnn::WallClockTimer
Definition: WallClockTimer.hpp:38