blob: 884fb3f2ff112c0f7198c3662a2dc72698d7dd0a [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
James Conroy2dcd3fe2020-02-06 18:34:52 +000032CounterStatus BackendProfiling::GetCounterStatus(uint16_t backendCounterId)
Colm Donelan1aff3932020-02-05 17:48:59 +000033{
James Conroy2dcd3fe2020-02-06 18:34:52 +000034 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 Donelan1aff3932020-02-05 17:48:59 +000046}
47
48std::vector<CounterStatus> BackendProfiling::GetActiveCounters()
49{
James Conroy2dcd3fe2020-02-06 18:34:52 +000050 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 Donelan1aff3932020-02-05 17:48:59 +000069}
70
71bool BackendProfiling::IsProfilingEnabled() const
72{
73 return m_ProfilingService.IsProfilingEnabled();
74}
75
76} // namespace profiling
77} // namespace armnn