telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 1 | // |
| 2 | // Copyright © 2017 Arm Ltd. All rights reserved. |
David Beck | ecb56cd | 2018-09-05 12:52:57 +0100 | [diff] [blame] | 3 | // SPDX-License-Identifier: MIT |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 4 | // |
| 5 | |
| 6 | #pragma once |
| 7 | |
| 8 | #include "Instrument.hpp" |
| 9 | #include <chrono> |
| 10 | |
| 11 | namespace armnn |
| 12 | { |
| 13 | |
| 14 | // Clock class that uses the same timestamp function as the Mali DDK. |
| 15 | class monotonic_clock_raw { |
| 16 | public: |
| 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 Drozd | 2d9dd36 | 2018-09-27 11:53:34 +0100 | [diff] [blame] | 28 | // Implementation of an instrument to measure elapsed wall-clock time in microseconds. |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 29 | class WallClockTimer : public Instrument |
| 30 | { |
| 31 | public: |
| 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 | |
| 58 | private: |
| 59 | clock::time_point m_Start; |
| 60 | clock::time_point m_Stop; |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 61 | }; |
| 62 | |
| 63 | } //namespace armnn |