Francis Murtagh | fcb8ef6 | 2019-09-20 15:40:09 +0100 | [diff] [blame] | 1 | // |
| 2 | // Copyright © 2019 Arm Ltd. All rights reserved. |
| 3 | // SPDX-License-Identifier: MIT |
| 4 | // |
| 5 | |
| 6 | #pragma once |
| 7 | |
Francis Murtagh | fcb8ef6 | 2019-09-20 15:40:09 +0100 | [diff] [blame] | 8 | #include "IPeriodicCounterCapture.hpp" |
Matteo Martincigh | e0e6efc | 2019-10-04 17:17:42 +0100 | [diff] [blame^] | 9 | #include "Holder.hpp" |
Francis Murtagh | fcb8ef6 | 2019-09-20 15:40:09 +0100 | [diff] [blame] | 10 | #include "Packet.hpp" |
Francis Murtagh | fcb8ef6 | 2019-09-20 15:40:09 +0100 | [diff] [blame] | 11 | #include "SendCounterPacket.hpp" |
Matteo Martincigh | e0e6efc | 2019-10-04 17:17:42 +0100 | [diff] [blame^] | 12 | #include "ICounterValues.hpp" |
Francis Murtagh | fcb8ef6 | 2019-09-20 15:40:09 +0100 | [diff] [blame] | 13 | |
Matteo Martincigh | e0e6efc | 2019-10-04 17:17:42 +0100 | [diff] [blame^] | 14 | #include <WallClockTimer.hpp> |
Francis Murtagh | fcb8ef6 | 2019-09-20 15:40:09 +0100 | [diff] [blame] | 15 | |
| 16 | #include <atomic> |
| 17 | #include <chrono> |
| 18 | #include <mutex> |
| 19 | #include <thread> |
| 20 | |
| 21 | namespace armnn |
| 22 | { |
| 23 | |
| 24 | namespace profiling |
| 25 | { |
| 26 | |
| 27 | class PeriodicCounterCapture final : public IPeriodicCounterCapture |
| 28 | { |
| 29 | public: |
Matteo Martincigh | e0e6efc | 2019-10-04 17:17:42 +0100 | [diff] [blame^] | 30 | PeriodicCounterCapture(const Holder& data, ISendCounterPacket& packet, const IReadCounterValues& readCounterValue) |
| 31 | : m_CaptureDataHolder(data) |
| 32 | , m_IsRunning(false) |
| 33 | , m_KeepRunning(false) |
| 34 | , m_ReadCounterValues(readCounterValue) |
| 35 | , m_SendCounterPacket(packet) |
| 36 | {} |
| 37 | ~PeriodicCounterCapture() { Stop(); } |
Francis Murtagh | fcb8ef6 | 2019-09-20 15:40:09 +0100 | [diff] [blame] | 38 | |
| 39 | void Start() override; |
Matteo Martincigh | e0e6efc | 2019-10-04 17:17:42 +0100 | [diff] [blame^] | 40 | void Stop() override; |
| 41 | bool IsRunning() const { return m_IsRunning.load(); } |
Francis Murtagh | fcb8ef6 | 2019-09-20 15:40:09 +0100 | [diff] [blame] | 42 | |
| 43 | private: |
| 44 | CaptureData ReadCaptureData(); |
Matteo Martincigh | e0e6efc | 2019-10-04 17:17:42 +0100 | [diff] [blame^] | 45 | void Capture(const IReadCounterValues& readCounterValues); |
Francis Murtagh | fcb8ef6 | 2019-09-20 15:40:09 +0100 | [diff] [blame] | 46 | |
Matteo Martincigh | e0e6efc | 2019-10-04 17:17:42 +0100 | [diff] [blame^] | 47 | const Holder& m_CaptureDataHolder; |
| 48 | std::atomic<bool> m_IsRunning; |
| 49 | std::atomic<bool> m_KeepRunning; |
| 50 | std::thread m_PeriodCaptureThread; |
| 51 | const IReadCounterValues& m_ReadCounterValues; |
| 52 | ISendCounterPacket& m_SendCounterPacket; |
Francis Murtagh | fcb8ef6 | 2019-09-20 15:40:09 +0100 | [diff] [blame] | 53 | }; |
| 54 | |
| 55 | } // namespace profiling |
| 56 | |
| 57 | } // namespace armnn |