ArmNN
 20.02
BackendProfiling.cpp
Go to the documentation of this file.
1 //
2 // Copyright © 2020 Arm Ltd. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5 
6 #include "BackendProfiling.hpp"
8 
9 namespace armnn
10 {
11 
12 namespace profiling
13 {
14 
15 std::unique_ptr<IRegisterBackendCounters>
16  BackendProfiling::GetCounterRegistrationInterface(uint16_t currentMaxGlobalCounterID)
17 {
18  return std::make_unique<RegisterBackendCounters>(RegisterBackendCounters(currentMaxGlobalCounterID, m_BackendId));
19 }
20 
21 std::unique_ptr<ISendTimelinePacket> BackendProfiling::GetSendTimelinePacket()
22 {
23  return m_ProfilingService.GetSendTimelinePacket();
24 }
25 
27 {
28  // The profiling service is our Guid Generator.
29  return m_ProfilingService;
30 }
31 
32 void 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
46  timestampInfo.timestamp, backendCounterValues);
47  }
48 }
49 
51 {
52  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;
64 }
65 
66 std::vector<CounterStatus> BackendProfiling::GetActiveCounters()
67 {
68  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 =
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;
87 }
88 
90 {
91  return m_ProfilingService.IsProfilingEnabled();
92 }
93 
94 } // namespace profiling
95 } // namespace armnn
static ProfilingService & Instance()
virtual std::unique_ptr< ISendTimelinePacket > GetSendTimelinePacket() const =0
virtual CaptureData GetCaptureData()=0
std::vector< CounterStatus > GetActiveCounters() override
const std::vector< uint16_t > & GetCounterIds() const
Definition: Holder.cpp:49
void ReportCounters(const std::vector< Timestamp > &) override
std::unique_ptr< IRegisterBackendCounters > GetCounterRegistrationInterface(uint16_t currentMaxGlobalCounterID) override
Copyright (c) 2020 ARM Limited.
bool IsProfilingEnabled() const override
virtual const ICounterMappings & GetCounterMappings() const =0
CounterStatus GetCounterStatus(uint16_t backendCounterId) override
uint32_t GetCapturePeriod() const
Definition: Holder.cpp:44
IProfilingGuidGenerator & GetProfilingGuidGenerator() override
std::unique_ptr< ISendTimelinePacket > GetSendTimelinePacket() override
const ICounterMappings & GetCounterMappings() const override
virtual bool IsProfilingEnabled() const =0
virtual void SendPeriodicCounterCapturePacket(uint64_t timestamp, const IndexValuePairsVector &values)=0
Create and write a PeriodicCounterCapturePacket from the parameters to the buffer.
bool IsCounterIdInCaptureData(uint16_t counterId)
Definition: Holder.cpp:61
virtual const std::pair< uint16_t, armnn::BackendId > & GetBackendId(uint16_t globalCounterId) const =0
virtual ISendCounterPacket & GetSendCounterPacket()=0
virtual uint16_t GetGlobalId(uint16_t backendCounterId, const armnn::BackendId &backendId) const =0