1 //
2 // Copyright © 2020 Arm Ltd. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5
6 #include "BackendProfiling.hpp"
7 #include <client/src/RegisterBackendCounters.hpp>
8
9 namespace arm
10 {
11
12 namespace pipe
13 {
14
15 std::unique_ptr<IRegisterBackendCounters>
GetCounterRegistrationInterface(uint16_t currentMaxGlobalCounterID)16 BackendProfiling::GetCounterRegistrationInterface(uint16_t currentMaxGlobalCounterID)
17 {
18 return std::make_unique<RegisterBackendCounters>(
19 RegisterBackendCounters(currentMaxGlobalCounterID, m_BackendId, m_ProfilingService));
20 }
21
GetSendTimelinePacket()22 std::unique_ptr<ISendTimelinePacket> BackendProfiling::GetSendTimelinePacket()
23 {
24 return m_ProfilingService.GetSendTimelinePacket();
25 }
26
GetProfilingGuidGenerator()27 IProfilingGuidGenerator& BackendProfiling::GetProfilingGuidGenerator()
28 {
29 // The profiling service is our Guid Generator.
30 return m_ProfilingService;
31 }
32
ReportCounters(const std::vector<Timestamp> & timestamps)33 void BackendProfiling::ReportCounters(const std::vector<Timestamp>& timestamps)
34 {
35 for (const auto& timestampInfo : timestamps)
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
GetCounterStatus(uint16_t backendCounterId)51 CounterStatus BackendProfiling::GetCounterStatus(uint16_t backendCounterId)
52 {
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;
65 }
66
GetActiveCounters()67 std::vector<CounterStatus> BackendProfiling::GetActiveCounters()
68 {
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, std::string>& backendCounterIdPair =
77 m_ProfilingService.GetCounterMappings().GetBackendId(globalCounterId);
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;
88 }
89
IsProfilingEnabled() const90 bool BackendProfiling::IsProfilingEnabled() const
91 {
92 return m_ProfilingService.IsProfilingEnabled();
93 }
94
95 } // namespace pipe
96
97 } // namespace arm
98