diff options
author | telsoa01 <telmo.soares@arm.com> | 2018-08-31 09:22:23 +0100 |
---|---|---|
committer | telsoa01 <telmo.soares@arm.com> | 2018-08-31 09:22:23 +0100 |
commit | c577f2c6a3b4ddb6ba87a882723c53a248afbeba (patch) | |
tree | bd7d4c148df27f8be6649d313efb24f536b7cf34 /src/armnn/WallClockTimer.hpp | |
parent | 4c7098bfeab1ffe1cdc77f6c15548d3e73274746 (diff) | |
download | armnn-c577f2c6a3b4ddb6ba87a882723c53a248afbeba.tar.gz |
Release 18.08
Diffstat (limited to 'src/armnn/WallClockTimer.hpp')
-rw-r--r-- | src/armnn/WallClockTimer.hpp | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/src/armnn/WallClockTimer.hpp b/src/armnn/WallClockTimer.hpp new file mode 100644 index 0000000000..84b46da8a2 --- /dev/null +++ b/src/armnn/WallClockTimer.hpp @@ -0,0 +1,63 @@ +// +// Copyright © 2017 Arm Ltd. All rights reserved. +// See LICENSE file in the project root for full license information. +// + +#pragma once + +#include "Instrument.hpp" +#include <chrono> + +namespace armnn +{ + +// Clock class that uses the same timestamp function as the Mali DDK. +class monotonic_clock_raw { +public: + using duration = std::chrono::nanoseconds; + using time_point = std::chrono::time_point<monotonic_clock_raw, duration>; + + static std::chrono::time_point<monotonic_clock_raw, std::chrono::nanoseconds> now() noexcept + { + timespec ts; + clock_gettime(CLOCK_MONOTONIC_RAW, &ts); + return time_point(std::chrono::nanoseconds(ts.tv_sec*1000000000 + ts.tv_nsec)); + } +}; + +// Implementation of an instrument to measure elapsed wall-clock time in milliseconds. +class WallClockTimer : public Instrument +{ +public: + // Construct a Wall Clock Timer + WallClockTimer() = default; + ~WallClockTimer() = default; + + // Start the Wall clock timer + void Start() override; + + // Stop the Wall clock timer + void Stop() override; + + // Get the name of the timer + const char* GetName() const override; + + // Get the recorded measurements + std::vector<Measurement> GetMeasurements() const override; + +#if defined(CLOCK_MONOTONIC_RAW) + using clock = monotonic_clock_raw; +#else + using clock = std::chrono::steady_clock; +#endif + + static const std::string WALL_CLOCK_TIME; + static const std::string WALL_CLOCK_TIME_START; + static const std::string WALL_CLOCK_TIME_STOP; + +private: + clock::time_point m_Start; + clock::time_point m_Stop; +}; + +} //namespace armnn |