blob: 88cbb4d50de75e61d7584bfc3ffbaf0768b88562 [file] [log] [blame]
telsoa01c577f2c2018-08-31 09:22:23 +01001//
2// Copyright © 2017 Arm Ltd. All rights reserved.
David Beckecb56cd2018-09-05 12:52:57 +01003// SPDX-License-Identifier: MIT
telsoa01c577f2c2018-08-31 09:22:23 +01004//
5
6#pragma once
7
8#include "Instrument.hpp"
9#include <chrono>
10
11namespace armnn
12{
13
14// Clock class that uses the same timestamp function as the Mali DDK.
15class monotonic_clock_raw {
16public:
17 using duration = std::chrono::nanoseconds;
18 using time_point = std::chrono::time_point<monotonic_clock_raw, duration>;
19
20 static std::chrono::time_point<monotonic_clock_raw, std::chrono::nanoseconds> now() noexcept
21 {
22 timespec ts;
23 clock_gettime(CLOCK_MONOTONIC_RAW, &ts);
24 return time_point(std::chrono::nanoseconds(ts.tv_sec*1000000000 + ts.tv_nsec));
25 }
26};
27
Nina Drozd2d9dd362018-09-27 11:53:34 +010028// Implementation of an instrument to measure elapsed wall-clock time in microseconds.
telsoa01c577f2c2018-08-31 09:22:23 +010029class WallClockTimer : public Instrument
30{
31public:
32 // Construct a Wall Clock Timer
33 WallClockTimer() = default;
34 ~WallClockTimer() = default;
35
36 // Start the Wall clock timer
37 void Start() override;
38
39 // Stop the Wall clock timer
40 void Stop() override;
41
42 // Get the name of the timer
43 const char* GetName() const override;
44
45 // Get the recorded measurements
46 std::vector<Measurement> GetMeasurements() const override;
47
48#if defined(CLOCK_MONOTONIC_RAW)
49 using clock = monotonic_clock_raw;
50#else
51 using clock = std::chrono::steady_clock;
52#endif
53
54 static const std::string WALL_CLOCK_TIME;
55 static const std::string WALL_CLOCK_TIME_START;
56 static const std::string WALL_CLOCK_TIME_STOP;
57
58private:
59 clock::time_point m_Start;
60 clock::time_point m_Stop;
telsoa01c577f2c2018-08-31 09:22:23 +010061};
62
63} //namespace armnn