xref: /aosp_15_r20/external/armnn/profiling/client/src/CounterIdMap.cpp (revision 89c4ff92f2867872bb9e2354d150bf0c8c502810)
1 //
2 // Copyright © 2020 Arm Ltd. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5 
6 #include <client/include/CounterIdMap.hpp>
7 
8 #include <common/include/ProfilingException.hpp>
9 
10 #include <map>
11 
12 namespace arm
13 {
14 namespace pipe
15 {
16 
RegisterMapping(uint16_t globalCounterId,uint16_t backendCounterId,const std::string & backendId)17 void CounterIdMap::RegisterMapping(uint16_t globalCounterId,
18                                    uint16_t backendCounterId,
19                                    const std::string& backendId)
20 {
21     std::pair<uint16_t, std::string> backendIdPair(backendCounterId, backendId);
22     m_GlobalCounterIdMap[globalCounterId] = backendIdPair;
23     m_BackendCounterIdMap[backendIdPair] = globalCounterId;
24 }
25 
Reset()26 void CounterIdMap::Reset()
27 {
28     m_GlobalCounterIdMap.clear();
29     m_BackendCounterIdMap.clear();
30 }
31 
GetGlobalId(uint16_t backendCounterId,const std::string & backendId) const32 uint16_t CounterIdMap::GetGlobalId(uint16_t backendCounterId, const std::string& backendId) const
33 {
34     std::pair<uint16_t, std::string> backendIdPair(backendCounterId, backendId);
35     auto it = m_BackendCounterIdMap.find(backendIdPair);
36     if (it == m_BackendCounterIdMap.end())
37     {
38         std::stringstream ss;
39         ss << "No Backend Counter [" << backendIdPair.second << ":" << backendIdPair.first << "] registered";
40         throw arm::pipe::ProfilingException(ss.str());
41     }
42     return it->second;
43 }
44 
GetBackendId(uint16_t globalCounterId) const45 const std::pair<uint16_t, std::string>& CounterIdMap::GetBackendId(uint16_t globalCounterId) const
46 {
47     auto it = m_GlobalCounterIdMap.find(globalCounterId);
48     if (it == m_GlobalCounterIdMap.end())
49     {
50         std::stringstream ss;
51         ss << "No Global Counter ID [" << globalCounterId << "] registered";
52         throw arm::pipe::ProfilingException(ss.str());
53     }
54     return it->second;
55 }
56 
57 }    // namespace pipe
58 }    // namespace arm
59