blob: 135174b478b680c56a1a4faa736e151a46e8db57 [file] [log] [blame]
Colm Donelan1aff3932020-02-05 17:48:59 +00001//
2// Copyright © 2020 Arm Ltd. All rights reserved.
3// SPDX-License-Identifier: MIT
4//
5
6#include "BackendProfiling.hpp"
7#include "RegisterBackendCounters.hpp"
8
9namespace armnn
10{
11
12namespace profiling
13{
14
15std::unique_ptr<IRegisterBackendCounters>
16 BackendProfiling::GetCounterRegistrationInterface(uint16_t currentMaxGlobalCounterID)
17{
Sadik Armagan3184c902020-03-18 10:57:30 +000018 return std::make_unique<RegisterBackendCounters>(
19 RegisterBackendCounters(currentMaxGlobalCounterID, m_BackendId, m_ProfilingService));
Colm Donelan1aff3932020-02-05 17:48:59 +000020}
21
22std::unique_ptr<ISendTimelinePacket> BackendProfiling::GetSendTimelinePacket()
23{
24 return m_ProfilingService.GetSendTimelinePacket();
25}
26
27IProfilingGuidGenerator& BackendProfiling::GetProfilingGuidGenerator()
28{
29 // The profiling service is our Guid Generator.
30 return m_ProfilingService;
31}
32
Jim Flynn64063552020-02-14 10:18:08 +000033void BackendProfiling::ReportCounters(const std::vector<Timestamp>& timestamps)
34{
Derek Lambertieac4adb2020-08-25 13:05:59 +010035 for (const auto& timestampInfo : timestamps)
Jim Flynn64063552020-02-14 10:18:08 +000036 {
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 Conroy2dcd3fe2020-02-06 18:34:52 +000051CounterStatus BackendProfiling::GetCounterStatus(uint16_t backendCounterId)
Colm Donelan1aff3932020-02-05 17:48:59 +000052{
James Conroy2dcd3fe2020-02-06 18:34:52 +000053 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 Donelan1aff3932020-02-05 17:48:59 +000065}
66
67std::vector<CounterStatus> BackendProfiling::GetActiveCounters()
68{
James Conroy2dcd3fe2020-02-06 18:34:52 +000069 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 Armagan3184c902020-03-18 10:57:30 +000077 m_ProfilingService.GetCounterMappings().GetBackendId(globalCounterId);
James Conroy2dcd3fe2020-02-06 18:34:52 +000078 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 Donelan1aff3932020-02-05 17:48:59 +000088}
89
90bool BackendProfiling::IsProfilingEnabled() const
91{
92 return m_ProfilingService.IsProfilingEnabled();
93}
94
95} // namespace profiling
96} // namespace armnn