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" |
Francis Murtagh | fcb8ef6 | 2019-09-20 15:40:09 +0100 | [diff] [blame] | 9 | #include "SendCounterPacket.hpp" |
| 10 | |
Jim Flynn | 2776183 | 2022-03-20 21:52:17 +0000 | [diff] [blame] | 11 | #include <client/include/CounterIdMap.hpp> |
| 12 | #include <client/include/Holder.hpp> |
| 13 | #include <client/include/ICounterValues.hpp> |
| 14 | |
| 15 | #include <client/include/backends/IBackendProfilingContext.hpp> |
Nikhil Raj | 7dcc697 | 2021-04-30 15:44:24 +0100 | [diff] [blame] | 16 | |
| 17 | #include <common/include/Packet.hpp> |
| 18 | |
Francis Murtagh | fcb8ef6 | 2019-09-20 15:40:09 +0100 | [diff] [blame] | 19 | #include <atomic> |
Jim Flynn | e195a04 | 2022-04-12 17:19:28 +0100 | [diff] [blame] | 20 | |
| 21 | #if !defined(ARMNN_DISABLE_THREADS) |
Francis Murtagh | fcb8ef6 | 2019-09-20 15:40:09 +0100 | [diff] [blame] | 22 | #include <mutex> |
| 23 | #include <thread> |
Jim Flynn | e195a04 | 2022-04-12 17:19:28 +0100 | [diff] [blame] | 24 | #endif |
Francis Murtagh | fcb8ef6 | 2019-09-20 15:40:09 +0100 | [diff] [blame] | 25 | |
Cathal Corbett | 5aa9fd7 | 2022-02-25 15:33:28 +0000 | [diff] [blame] | 26 | namespace arm |
Francis Murtagh | fcb8ef6 | 2019-09-20 15:40:09 +0100 | [diff] [blame] | 27 | { |
| 28 | |
Cathal Corbett | 5aa9fd7 | 2022-02-25 15:33:28 +0000 | [diff] [blame] | 29 | namespace pipe |
Francis Murtagh | fcb8ef6 | 2019-09-20 15:40:09 +0100 | [diff] [blame] | 30 | { |
| 31 | |
| 32 | class PeriodicCounterCapture final : public IPeriodicCounterCapture |
| 33 | { |
| 34 | public: |
Finn Williams | 032bc74 | 2020-02-12 11:02:34 +0000 | [diff] [blame] | 35 | PeriodicCounterCapture(const Holder& data, |
| 36 | ISendCounterPacket& packet, |
Finn Williams | f3fcf32 | 2020-05-11 14:38:02 +0100 | [diff] [blame] | 37 | IReadCounterValues& readCounterValue, |
Finn Williams | 032bc74 | 2020-02-12 11:02:34 +0000 | [diff] [blame] | 38 | const ICounterMappings& counterIdMap, |
Cathal Corbett | 6f07372 | 2022-03-04 12:11:09 +0000 | [diff] [blame] | 39 | const std::unordered_map<std::string, |
Jim Flynn | e195a04 | 2022-04-12 17:19:28 +0100 | [diff] [blame] | 40 | std::shared_ptr<IBackendProfilingContext>>& backendProfilingContexts) |
Finn Williams | 032bc74 | 2020-02-12 11:02:34 +0000 | [diff] [blame] | 41 | : m_CaptureDataHolder(data) |
| 42 | , m_IsRunning(false) |
| 43 | , m_KeepRunning(false) |
| 44 | , m_ReadCounterValues(readCounterValue) |
| 45 | , m_SendCounterPacket(packet) |
| 46 | , m_CounterIdMap(counterIdMap) |
Finn Williams | fe5a24b | 2020-04-09 16:05:28 +0100 | [diff] [blame] | 47 | , m_BackendProfilingContexts(backendProfilingContexts) |
Matteo Martincigh | e0e6efc | 2019-10-04 17:17:42 +0100 | [diff] [blame] | 48 | {} |
| 49 | ~PeriodicCounterCapture() { Stop(); } |
Francis Murtagh | fcb8ef6 | 2019-09-20 15:40:09 +0100 | [diff] [blame] | 50 | |
| 51 | void Start() override; |
Matteo Martincigh | e0e6efc | 2019-10-04 17:17:42 +0100 | [diff] [blame] | 52 | void Stop() override; |
Finn Williams | f4d59a6 | 2019-10-14 15:55:18 +0100 | [diff] [blame] | 53 | bool IsRunning() const { return m_IsRunning; } |
Francis Murtagh | fcb8ef6 | 2019-09-20 15:40:09 +0100 | [diff] [blame] | 54 | |
| 55 | private: |
| 56 | CaptureData ReadCaptureData(); |
Finn Williams | f3fcf32 | 2020-05-11 14:38:02 +0100 | [diff] [blame] | 57 | void Capture(IReadCounterValues& readCounterValues); |
Finn Williams | 032bc74 | 2020-02-12 11:02:34 +0000 | [diff] [blame] | 58 | void DispatchPeriodicCounterCapturePacket( |
Cathal Corbett | 6f07372 | 2022-03-04 12:11:09 +0000 | [diff] [blame] | 59 | const std::string& backendId, const std::vector<Timestamp>& timestampValues); |
Francis Murtagh | fcb8ef6 | 2019-09-20 15:40:09 +0100 | [diff] [blame] | 60 | |
Matteo Martincigh | e0e6efc | 2019-10-04 17:17:42 +0100 | [diff] [blame] | 61 | const Holder& m_CaptureDataHolder; |
Finn Williams | f4d59a6 | 2019-10-14 15:55:18 +0100 | [diff] [blame] | 62 | bool m_IsRunning; |
Matteo Martincigh | e0e6efc | 2019-10-04 17:17:42 +0100 | [diff] [blame] | 63 | std::atomic<bool> m_KeepRunning; |
Jim Flynn | e195a04 | 2022-04-12 17:19:28 +0100 | [diff] [blame] | 64 | #if !defined(ARMNN_DISABLE_THREADS) |
Matteo Martincigh | e0e6efc | 2019-10-04 17:17:42 +0100 | [diff] [blame] | 65 | std::thread m_PeriodCaptureThread; |
Jim Flynn | e195a04 | 2022-04-12 17:19:28 +0100 | [diff] [blame] | 66 | #endif |
Finn Williams | f3fcf32 | 2020-05-11 14:38:02 +0100 | [diff] [blame] | 67 | IReadCounterValues& m_ReadCounterValues; |
Matteo Martincigh | e0e6efc | 2019-10-04 17:17:42 +0100 | [diff] [blame] | 68 | ISendCounterPacket& m_SendCounterPacket; |
Finn Williams | 032bc74 | 2020-02-12 11:02:34 +0000 | [diff] [blame] | 69 | const ICounterMappings& m_CounterIdMap; |
Cathal Corbett | 6f07372 | 2022-03-04 12:11:09 +0000 | [diff] [blame] | 70 | const std::unordered_map<std::string, |
Cathal Corbett | 5aa9fd7 | 2022-02-25 15:33:28 +0000 | [diff] [blame] | 71 | std::shared_ptr<IBackendProfilingContext>>& m_BackendProfilingContexts; |
Francis Murtagh | fcb8ef6 | 2019-09-20 15:40:09 +0100 | [diff] [blame] | 72 | }; |
| 73 | |
Cathal Corbett | 5aa9fd7 | 2022-02-25 15:33:28 +0000 | [diff] [blame] | 74 | } // namespace pipe |
Francis Murtagh | fcb8ef6 | 2019-09-20 15:40:09 +0100 | [diff] [blame] | 75 | |
Cathal Corbett | 5aa9fd7 | 2022-02-25 15:33:28 +0000 | [diff] [blame] | 76 | } // namespace arm |