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 | { |
James Conroy | 2dcd3fe | 2020-02-06 18:34:52 +0000 | [diff] [blame] | 18 | return std::make_unique<RegisterBackendCounters>(RegisterBackendCounters(currentMaxGlobalCounterID, m_BackendId)); |
Colm Donelan | 1aff393 | 2020-02-05 17:48:59 +0000 | [diff] [blame] | 19 | } |
| 20 | |
| 21 | std::unique_ptr<ISendTimelinePacket> BackendProfiling::GetSendTimelinePacket() |
| 22 | { |
| 23 | return m_ProfilingService.GetSendTimelinePacket(); |
| 24 | } |
| 25 | |
| 26 | IProfilingGuidGenerator& BackendProfiling::GetProfilingGuidGenerator() |
| 27 | { |
| 28 | // The profiling service is our Guid Generator. |
| 29 | return m_ProfilingService; |
| 30 | } |
| 31 | |
James Conroy | 2dcd3fe | 2020-02-06 18:34:52 +0000 | [diff] [blame] | 32 | CounterStatus BackendProfiling::GetCounterStatus(uint16_t backendCounterId) |
Colm Donelan | 1aff393 | 2020-02-05 17:48:59 +0000 | [diff] [blame] | 33 | { |
James Conroy | 2dcd3fe | 2020-02-06 18:34:52 +0000 | [diff] [blame] | 34 | uint16_t globalCounterId = m_ProfilingService.GetCounterMappings().GetGlobalId(backendCounterId, m_BackendId); |
| 35 | CaptureData captureData = m_ProfilingService.GetCaptureData(); |
| 36 | |
| 37 | CounterStatus counterStatus(backendCounterId, globalCounterId, false, 0); |
| 38 | |
| 39 | if (captureData.IsCounterIdInCaptureData(globalCounterId)) |
| 40 | { |
| 41 | counterStatus.m_Enabled = true; |
| 42 | counterStatus.m_SamplingRateInMicroseconds = captureData.GetCapturePeriod(); |
| 43 | } |
| 44 | |
| 45 | return counterStatus; |
Colm Donelan | 1aff393 | 2020-02-05 17:48:59 +0000 | [diff] [blame] | 46 | } |
| 47 | |
| 48 | std::vector<CounterStatus> BackendProfiling::GetActiveCounters() |
| 49 | { |
James Conroy | 2dcd3fe | 2020-02-06 18:34:52 +0000 | [diff] [blame] | 50 | CaptureData captureData = m_ProfilingService.GetCaptureData(); |
| 51 | |
| 52 | const std::vector<uint16_t>& globalCounterIds = captureData.GetCounterIds(); |
| 53 | std::vector<CounterStatus> activeCounterIds; |
| 54 | |
| 55 | for (auto globalCounterId : globalCounterIds) { |
| 56 | // Get pair of local counterId and backendId using globalCounterId |
| 57 | const std::pair<uint16_t, armnn::BackendId>& backendCounterIdPair = |
| 58 | ProfilingService::Instance().GetCounterMappings().GetBackendId(globalCounterId); |
| 59 | if (backendCounterIdPair.second == m_BackendId) |
| 60 | { |
| 61 | activeCounterIds.emplace_back(backendCounterIdPair.first, |
| 62 | globalCounterId, |
| 63 | true, |
| 64 | captureData.GetCapturePeriod()); |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | return activeCounterIds; |
Colm Donelan | 1aff393 | 2020-02-05 17:48:59 +0000 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | bool BackendProfiling::IsProfilingEnabled() const |
| 72 | { |
| 73 | return m_ProfilingService.IsProfilingEnabled(); |
| 74 | } |
| 75 | |
| 76 | } // namespace profiling |
| 77 | } // namespace armnn |