blob: 0926879f678fa0b16d4d447a214451d63b2edcb5 [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{
James Conroy2dcd3fe2020-02-06 18:34:52 +000018 return std::make_unique<RegisterBackendCounters>(RegisterBackendCounters(currentMaxGlobalCounterID, m_BackendId));
Colm Donelan1aff3932020-02-05 17:48:59 +000019}
20
21std::unique_ptr<ISendTimelinePacket> BackendProfiling::GetSendTimelinePacket()
22{
23 return m_ProfilingService.GetSendTimelinePacket();
24}
25
26IProfilingGuidGenerator& BackendProfiling::GetProfilingGuidGenerator()
27{
28 // The profiling service is our Guid Generator.
29 return m_ProfilingService;
30}
31
Jim Flynn64063552020-02-14 10:18:08 +000032void BackendProfiling::ReportCounters(const std::vector<Timestamp>& timestamps)
33{
34 for (const auto timestampInfo : timestamps)
35 {
36 std::vector<CounterValue> backendCounterValues = timestampInfo.counterValues;
37 for_each(backendCounterValues.begin(), backendCounterValues.end(), [&](CounterValue& backendCounterValue)
38 {
39 // translate the counterId to globalCounterId
40 backendCounterValue.counterId = m_ProfilingService.GetCounterMappings().GetGlobalId(
41 backendCounterValue.counterId, m_BackendId);
42 });
43
44 // Send Periodic Counter Capture Packet for the Timestamp
45 m_ProfilingService.GetSendCounterPacket().SendPeriodicCounterCapturePacket(
46 timestampInfo.timestamp, backendCounterValues);
47 }
48}
49
James Conroy2dcd3fe2020-02-06 18:34:52 +000050CounterStatus BackendProfiling::GetCounterStatus(uint16_t backendCounterId)
Colm Donelan1aff3932020-02-05 17:48:59 +000051{
James Conroy2dcd3fe2020-02-06 18:34:52 +000052 uint16_t globalCounterId = m_ProfilingService.GetCounterMappings().GetGlobalId(backendCounterId, m_BackendId);
53 CaptureData captureData = m_ProfilingService.GetCaptureData();
54
55 CounterStatus counterStatus(backendCounterId, globalCounterId, false, 0);
56
57 if (captureData.IsCounterIdInCaptureData(globalCounterId))
58 {
59 counterStatus.m_Enabled = true;
60 counterStatus.m_SamplingRateInMicroseconds = captureData.GetCapturePeriod();
61 }
62
63 return counterStatus;
Colm Donelan1aff3932020-02-05 17:48:59 +000064}
65
66std::vector<CounterStatus> BackendProfiling::GetActiveCounters()
67{
James Conroy2dcd3fe2020-02-06 18:34:52 +000068 CaptureData captureData = m_ProfilingService.GetCaptureData();
69
70 const std::vector<uint16_t>& globalCounterIds = captureData.GetCounterIds();
71 std::vector<CounterStatus> activeCounterIds;
72
73 for (auto globalCounterId : globalCounterIds) {
74 // Get pair of local counterId and backendId using globalCounterId
75 const std::pair<uint16_t, armnn::BackendId>& backendCounterIdPair =
76 ProfilingService::Instance().GetCounterMappings().GetBackendId(globalCounterId);
77 if (backendCounterIdPair.second == m_BackendId)
78 {
79 activeCounterIds.emplace_back(backendCounterIdPair.first,
80 globalCounterId,
81 true,
82 captureData.GetCapturePeriod());
83 }
84 }
85
86 return activeCounterIds;
Colm Donelan1aff3932020-02-05 17:48:59 +000087}
88
89bool BackendProfiling::IsProfilingEnabled() const
90{
91 return m_ProfilingService.IsProfilingEnabled();
92}
93
94} // namespace profiling
95} // namespace armnn