blob: cb637c3974ee3690c164150f247f10c3e6e0d821 [file] [log] [blame]
David Monahande803072020-01-30 12:44:23 +00001//
2// Copyright © 2020 Arm Ltd. All rights reserved.
3// SPDX-License-Identifier: MIT
4//
Jim Flynn27761832022-03-20 21:52:17 +00005
6#include <client/include/CounterIdMap.hpp>
Jim Flynnf9db3ef2022-03-08 21:23:44 +00007
8#include <common/include/ProfilingException.hpp>
9
Jim Flynn8e0c7a62020-01-30 14:10:55 +000010#include <map>
David Monahande803072020-01-30 12:44:23 +000011
Cathal Corbett5aa9fd72022-02-25 15:33:28 +000012namespace arm
David Monahande803072020-01-30 12:44:23 +000013{
Cathal Corbett5aa9fd72022-02-25 15:33:28 +000014namespace pipe
David Monahande803072020-01-30 12:44:23 +000015{
16
17void CounterIdMap::RegisterMapping(uint16_t globalCounterId,
18 uint16_t backendCounterId,
Cathal Corbett6f073722022-03-04 12:11:09 +000019 const std::string& backendId)
David Monahande803072020-01-30 12:44:23 +000020{
Cathal Corbett6f073722022-03-04 12:11:09 +000021 std::pair<uint16_t, std::string> backendIdPair(backendCounterId, backendId);
David Monahande803072020-01-30 12:44:23 +000022 m_GlobalCounterIdMap[globalCounterId] = backendIdPair;
23 m_BackendCounterIdMap[backendIdPair] = globalCounterId;
24}
25
Jim Flynn97897022020-02-02 12:52:59 +000026void CounterIdMap::Reset()
27{
28 m_GlobalCounterIdMap.clear();
29 m_BackendCounterIdMap.clear();
30}
31
Cathal Corbett6f073722022-03-04 12:11:09 +000032uint16_t CounterIdMap::GetGlobalId(uint16_t backendCounterId, const std::string& backendId) const
David Monahande803072020-01-30 12:44:23 +000033{
Cathal Corbett6f073722022-03-04 12:11:09 +000034 std::pair<uint16_t, std::string> backendIdPair(backendCounterId, backendId);
David Monahande803072020-01-30 12:44:23 +000035 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";
Jim Flynnf9db3ef2022-03-08 21:23:44 +000040 throw arm::pipe::ProfilingException(ss.str());
David Monahande803072020-01-30 12:44:23 +000041 }
42 return it->second;
43}
44
Cathal Corbett6f073722022-03-04 12:11:09 +000045const std::pair<uint16_t, std::string>& CounterIdMap::GetBackendId(uint16_t globalCounterId) const
David Monahande803072020-01-30 12:44:23 +000046{
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";
Jim Flynnf9db3ef2022-03-08 21:23:44 +000052 throw arm::pipe::ProfilingException(ss.str());
David Monahande803072020-01-30 12:44:23 +000053 }
54 return it->second;
55}
56
Cathal Corbett5aa9fd72022-02-25 15:33:28 +000057} // namespace pipe
58} // namespace arm