David Monahan | de80307 | 2020-01-30 12:44:23 +0000 | [diff] [blame] | 1 | // |
| 2 | // Copyright © 2020 Arm Ltd. All rights reserved. |
| 3 | // SPDX-License-Identifier: MIT |
| 4 | // |
Jim Flynn | 2776183 | 2022-03-20 21:52:17 +0000 | [diff] [blame] | 5 | |
| 6 | #include <client/include/CounterIdMap.hpp> |
Jim Flynn | f9db3ef | 2022-03-08 21:23:44 +0000 | [diff] [blame] | 7 | |
| 8 | #include <common/include/ProfilingException.hpp> |
| 9 | |
Jim Flynn | 8e0c7a6 | 2020-01-30 14:10:55 +0000 | [diff] [blame] | 10 | #include <map> |
David Monahan | de80307 | 2020-01-30 12:44:23 +0000 | [diff] [blame] | 11 | |
Cathal Corbett | 5aa9fd7 | 2022-02-25 15:33:28 +0000 | [diff] [blame] | 12 | namespace arm |
David Monahan | de80307 | 2020-01-30 12:44:23 +0000 | [diff] [blame] | 13 | { |
Cathal Corbett | 5aa9fd7 | 2022-02-25 15:33:28 +0000 | [diff] [blame] | 14 | namespace pipe |
David Monahan | de80307 | 2020-01-30 12:44:23 +0000 | [diff] [blame] | 15 | { |
| 16 | |
| 17 | void CounterIdMap::RegisterMapping(uint16_t globalCounterId, |
| 18 | uint16_t backendCounterId, |
Cathal Corbett | 6f07372 | 2022-03-04 12:11:09 +0000 | [diff] [blame] | 19 | const std::string& backendId) |
David Monahan | de80307 | 2020-01-30 12:44:23 +0000 | [diff] [blame] | 20 | { |
Cathal Corbett | 6f07372 | 2022-03-04 12:11:09 +0000 | [diff] [blame] | 21 | std::pair<uint16_t, std::string> backendIdPair(backendCounterId, backendId); |
David Monahan | de80307 | 2020-01-30 12:44:23 +0000 | [diff] [blame] | 22 | m_GlobalCounterIdMap[globalCounterId] = backendIdPair; |
| 23 | m_BackendCounterIdMap[backendIdPair] = globalCounterId; |
| 24 | } |
| 25 | |
Jim Flynn | 9789702 | 2020-02-02 12:52:59 +0000 | [diff] [blame] | 26 | void CounterIdMap::Reset() |
| 27 | { |
| 28 | m_GlobalCounterIdMap.clear(); |
| 29 | m_BackendCounterIdMap.clear(); |
| 30 | } |
| 31 | |
Cathal Corbett | 6f07372 | 2022-03-04 12:11:09 +0000 | [diff] [blame] | 32 | uint16_t CounterIdMap::GetGlobalId(uint16_t backendCounterId, const std::string& backendId) const |
David Monahan | de80307 | 2020-01-30 12:44:23 +0000 | [diff] [blame] | 33 | { |
Cathal Corbett | 6f07372 | 2022-03-04 12:11:09 +0000 | [diff] [blame] | 34 | std::pair<uint16_t, std::string> backendIdPair(backendCounterId, backendId); |
David Monahan | de80307 | 2020-01-30 12:44:23 +0000 | [diff] [blame] | 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"; |
Jim Flynn | f9db3ef | 2022-03-08 21:23:44 +0000 | [diff] [blame] | 40 | throw arm::pipe::ProfilingException(ss.str()); |
David Monahan | de80307 | 2020-01-30 12:44:23 +0000 | [diff] [blame] | 41 | } |
| 42 | return it->second; |
| 43 | } |
| 44 | |
Cathal Corbett | 6f07372 | 2022-03-04 12:11:09 +0000 | [diff] [blame] | 45 | const std::pair<uint16_t, std::string>& CounterIdMap::GetBackendId(uint16_t globalCounterId) const |
David Monahan | de80307 | 2020-01-30 12:44:23 +0000 | [diff] [blame] | 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"; |
Jim Flynn | f9db3ef | 2022-03-08 21:23:44 +0000 | [diff] [blame] | 52 | throw arm::pipe::ProfilingException(ss.str()); |
David Monahan | de80307 | 2020-01-30 12:44:23 +0000 | [diff] [blame] | 53 | } |
| 54 | return it->second; |
| 55 | } |
| 56 | |
Cathal Corbett | 5aa9fd7 | 2022-02-25 15:33:28 +0000 | [diff] [blame] | 57 | } // namespace pipe |
| 58 | } // namespace arm |