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 | |
Francis Murtagh | fcb8ef6 | 2019-09-20 15:40:09 +0100 | [diff] [blame] | 14 | #include <atomic> |
Francis Murtagh | fcb8ef6 | 2019-09-20 15:40:09 +0100 | [diff] [blame] | 15 | #include <mutex> |
| 16 | #include <thread> |
| 17 | |
| 18 | namespace armnn |
| 19 | { |
| 20 | |
| 21 | namespace profiling |
| 22 | { |
| 23 | |
| 24 | class PeriodicCounterCapture final : public IPeriodicCounterCapture |
| 25 | { |
| 26 | public: |
Matteo Martincigh | e0e6efc | 2019-10-04 17:17:42 +0100 | [diff] [blame] | 27 | PeriodicCounterCapture(const Holder& data, ISendCounterPacket& packet, const IReadCounterValues& readCounterValue) |
| 28 | : m_CaptureDataHolder(data) |
| 29 | , m_IsRunning(false) |
| 30 | , m_KeepRunning(false) |
| 31 | , m_ReadCounterValues(readCounterValue) |
| 32 | , m_SendCounterPacket(packet) |
| 33 | {} |
| 34 | ~PeriodicCounterCapture() { Stop(); } |
Francis Murtagh | fcb8ef6 | 2019-09-20 15:40:09 +0100 | [diff] [blame] | 35 | |
| 36 | void Start() override; |
Matteo Martincigh | e0e6efc | 2019-10-04 17:17:42 +0100 | [diff] [blame] | 37 | void Stop() override; |
Finn Williams | f4d59a6 | 2019-10-14 15:55:18 +0100 | [diff] [blame] | 38 | bool IsRunning() const { return m_IsRunning; } |
Francis Murtagh | fcb8ef6 | 2019-09-20 15:40:09 +0100 | [diff] [blame] | 39 | |
| 40 | private: |
| 41 | CaptureData ReadCaptureData(); |
Matteo Martincigh | e0e6efc | 2019-10-04 17:17:42 +0100 | [diff] [blame] | 42 | void Capture(const IReadCounterValues& readCounterValues); |
Francis Murtagh | fcb8ef6 | 2019-09-20 15:40:09 +0100 | [diff] [blame] | 43 | |
Matteo Martincigh | e0e6efc | 2019-10-04 17:17:42 +0100 | [diff] [blame] | 44 | const Holder& m_CaptureDataHolder; |
Finn Williams | f4d59a6 | 2019-10-14 15:55:18 +0100 | [diff] [blame] | 45 | bool m_IsRunning; |
Matteo Martincigh | e0e6efc | 2019-10-04 17:17:42 +0100 | [diff] [blame] | 46 | std::atomic<bool> m_KeepRunning; |
| 47 | std::thread m_PeriodCaptureThread; |
| 48 | const IReadCounterValues& m_ReadCounterValues; |
| 49 | ISendCounterPacket& m_SendCounterPacket; |
Francis Murtagh | fcb8ef6 | 2019-09-20 15:40:09 +0100 | [diff] [blame] | 50 | }; |
| 51 | |
| 52 | } // namespace profiling |
| 53 | |
| 54 | } // namespace armnn |