Colm Donelan | 1aff393 | 2020-02-05 17:48:59 +0000 | [diff] [blame] | 1 | // |
| 2 | // Copyright © 2020 Arm Ltd. All rights reserved. |
| 3 | // SPDX-License-Identifier: MIT |
| 4 | // |
| 5 | |
| 6 | #include "BackendProfiling.hpp" |
| 7 | #include "RegisterBackendCounters.hpp" |
| 8 | |
| 9 | namespace armnn |
| 10 | { |
| 11 | |
| 12 | namespace profiling |
| 13 | { |
| 14 | |
| 15 | std::unique_ptr<IRegisterBackendCounters> |
| 16 | BackendProfiling::GetCounterRegistrationInterface(uint16_t currentMaxGlobalCounterID) |
| 17 | { |
Sadik Armagan | 3184c90 | 2020-03-18 10:57:30 +0000 | [diff] [blame] | 18 | return std::make_unique<RegisterBackendCounters>( |
| 19 | RegisterBackendCounters(currentMaxGlobalCounterID, m_BackendId, m_ProfilingService)); |
Colm Donelan | 1aff393 | 2020-02-05 17:48:59 +0000 | [diff] [blame] | 20 | } |
| 21 | |
| 22 | std::unique_ptr<ISendTimelinePacket> BackendProfiling::GetSendTimelinePacket() |
| 23 | { |
| 24 | return m_ProfilingService.GetSendTimelinePacket(); |
| 25 | } |
| 26 | |
| 27 | IProfilingGuidGenerator& BackendProfiling::GetProfilingGuidGenerator() |
| 28 | { |
| 29 | // The profiling service is our Guid Generator. |
| 30 | return m_ProfilingService; |
| 31 | } |
| 32 | |
Jim Flynn | 6406355 | 2020-02-14 10:18:08 +0000 | [diff] [blame] | 33 | void BackendProfiling::ReportCounters(const std::vector<Timestamp>& timestamps) |
| 34 | { |
Derek Lamberti | eac4adb | 2020-08-25 13:05:59 +0100 | [diff] [blame] | 35 | for (const auto& timestampInfo : timestamps) |
Jim Flynn | 6406355 | 2020-02-14 10:18:08 +0000 | [diff] [blame] | 36 | { |
| 37 | std::vector<CounterValue> backendCounterValues = timestampInfo.counterValues; |
| 38 | for_each(backendCounterValues.begin(), backendCounterValues.end(), [&](CounterValue& backendCounterValue) |
| 39 | { |
| 40 | // translate the counterId to globalCounterId |
| 41 | backendCounterValue.counterId = m_ProfilingService.GetCounterMappings().GetGlobalId( |
| 42 | backendCounterValue.counterId, m_BackendId); |
| 43 | }); |
| 44 | |
| 45 | // Send Periodic Counter Capture Packet for the Timestamp |
| 46 | m_ProfilingService.GetSendCounterPacket().SendPeriodicCounterCapturePacket( |
| 47 | timestampInfo.timestamp, backendCounterValues); |
| 48 | } |
| 49 | } |
| 50 | |
James Conroy | 2dcd3fe | 2020-02-06 18:34:52 +0000 | [diff] [blame] | 51 | CounterStatus BackendProfiling::GetCounterStatus(uint16_t backendCounterId) |
Colm Donelan | 1aff393 | 2020-02-05 17:48:59 +0000 | [diff] [blame] | 52 | { |
James Conroy | 2dcd3fe | 2020-02-06 18:34:52 +0000 | [diff] [blame] | 53 | uint16_t globalCounterId = m_ProfilingService.GetCounterMappings().GetGlobalId(backendCounterId, m_BackendId); |
| 54 | CaptureData captureData = m_ProfilingService.GetCaptureData(); |
| 55 | |
| 56 | CounterStatus counterStatus(backendCounterId, globalCounterId, false, 0); |
| 57 | |
| 58 | if (captureData.IsCounterIdInCaptureData(globalCounterId)) |
| 59 | { |
| 60 | counterStatus.m_Enabled = true; |
| 61 | counterStatus.m_SamplingRateInMicroseconds = captureData.GetCapturePeriod(); |
| 62 | } |
| 63 | |
| 64 | return counterStatus; |
Colm Donelan | 1aff393 | 2020-02-05 17:48:59 +0000 | [diff] [blame] | 65 | } |
| 66 | |
| 67 | std::vector<CounterStatus> BackendProfiling::GetActiveCounters() |
| 68 | { |
James Conroy | 2dcd3fe | 2020-02-06 18:34:52 +0000 | [diff] [blame] | 69 | CaptureData captureData = m_ProfilingService.GetCaptureData(); |
| 70 | |
| 71 | const std::vector<uint16_t>& globalCounterIds = captureData.GetCounterIds(); |
| 72 | std::vector<CounterStatus> activeCounterIds; |
| 73 | |
| 74 | for (auto globalCounterId : globalCounterIds) { |
| 75 | // Get pair of local counterId and backendId using globalCounterId |
| 76 | const std::pair<uint16_t, armnn::BackendId>& backendCounterIdPair = |
Sadik Armagan | 3184c90 | 2020-03-18 10:57:30 +0000 | [diff] [blame] | 77 | m_ProfilingService.GetCounterMappings().GetBackendId(globalCounterId); |
James Conroy | 2dcd3fe | 2020-02-06 18:34:52 +0000 | [diff] [blame] | 78 | if (backendCounterIdPair.second == m_BackendId) |
| 79 | { |
| 80 | activeCounterIds.emplace_back(backendCounterIdPair.first, |
| 81 | globalCounterId, |
| 82 | true, |
| 83 | captureData.GetCapturePeriod()); |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | return activeCounterIds; |
Colm Donelan | 1aff393 | 2020-02-05 17:48:59 +0000 | [diff] [blame] | 88 | } |
| 89 | |
| 90 | bool BackendProfiling::IsProfilingEnabled() const |
| 91 | { |
| 92 | return m_ProfilingService.IsProfilingEnabled(); |
| 93 | } |
| 94 | |
| 95 | } // namespace profiling |
| 96 | } // namespace armnn |