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 | // |
| 5 | #include "CounterIdMap.hpp" |
Jim Flynn | f9db3ef | 2022-03-08 21:23:44 +0000 | [diff] [blame] | 6 | |
| 7 | #include <common/include/ProfilingException.hpp> |
| 8 | |
Jim Flynn | 8e0c7a6 | 2020-01-30 14:10:55 +0000 | [diff] [blame] | 9 | #include <map> |
David Monahan | de80307 | 2020-01-30 12:44:23 +0000 | [diff] [blame] | 10 | |
Cathal Corbett | 5aa9fd7 | 2022-02-25 15:33:28 +0000 | [diff] [blame] | 11 | namespace arm |
David Monahan | de80307 | 2020-01-30 12:44:23 +0000 | [diff] [blame] | 12 | { |
Cathal Corbett | 5aa9fd7 | 2022-02-25 15:33:28 +0000 | [diff] [blame] | 13 | namespace pipe |
David Monahan | de80307 | 2020-01-30 12:44:23 +0000 | [diff] [blame] | 14 | { |
| 15 | |
| 16 | void CounterIdMap::RegisterMapping(uint16_t globalCounterId, |
| 17 | uint16_t backendCounterId, |
Cathal Corbett | 6f07372 | 2022-03-04 12:11:09 +0000 | [diff] [blame] | 18 | const std::string& backendId) |
David Monahan | de80307 | 2020-01-30 12:44:23 +0000 | [diff] [blame] | 19 | { |
Cathal Corbett | 6f07372 | 2022-03-04 12:11:09 +0000 | [diff] [blame] | 20 | std::pair<uint16_t, std::string> backendIdPair(backendCounterId, backendId); |
David Monahan | de80307 | 2020-01-30 12:44:23 +0000 | [diff] [blame] | 21 | m_GlobalCounterIdMap[globalCounterId] = backendIdPair; |
| 22 | m_BackendCounterIdMap[backendIdPair] = globalCounterId; |
| 23 | } |
| 24 | |
Jim Flynn | 9789702 | 2020-02-02 12:52:59 +0000 | [diff] [blame] | 25 | void CounterIdMap::Reset() |
| 26 | { |
| 27 | m_GlobalCounterIdMap.clear(); |
| 28 | m_BackendCounterIdMap.clear(); |
| 29 | } |
| 30 | |
Cathal Corbett | 6f07372 | 2022-03-04 12:11:09 +0000 | [diff] [blame] | 31 | uint16_t CounterIdMap::GetGlobalId(uint16_t backendCounterId, const std::string& backendId) const |
David Monahan | de80307 | 2020-01-30 12:44:23 +0000 | [diff] [blame] | 32 | { |
Cathal Corbett | 6f07372 | 2022-03-04 12:11:09 +0000 | [diff] [blame] | 33 | std::pair<uint16_t, std::string> backendIdPair(backendCounterId, backendId); |
David Monahan | de80307 | 2020-01-30 12:44:23 +0000 | [diff] [blame] | 34 | auto it = m_BackendCounterIdMap.find(backendIdPair); |
| 35 | if (it == m_BackendCounterIdMap.end()) |
| 36 | { |
| 37 | std::stringstream ss; |
| 38 | ss << "No Backend Counter [" << backendIdPair.second << ":" << backendIdPair.first << "] registered"; |
Jim Flynn | f9db3ef | 2022-03-08 21:23:44 +0000 | [diff] [blame] | 39 | throw arm::pipe::ProfilingException(ss.str()); |
David Monahan | de80307 | 2020-01-30 12:44:23 +0000 | [diff] [blame] | 40 | } |
| 41 | return it->second; |
| 42 | } |
| 43 | |
Cathal Corbett | 6f07372 | 2022-03-04 12:11:09 +0000 | [diff] [blame] | 44 | 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] | 45 | { |
| 46 | auto it = m_GlobalCounterIdMap.find(globalCounterId); |
| 47 | if (it == m_GlobalCounterIdMap.end()) |
| 48 | { |
| 49 | std::stringstream ss; |
| 50 | ss << "No Global Counter ID [" << globalCounterId << "] registered"; |
Jim Flynn | f9db3ef | 2022-03-08 21:23:44 +0000 | [diff] [blame] | 51 | throw arm::pipe::ProfilingException(ss.str()); |
David Monahan | de80307 | 2020-01-30 12:44:23 +0000 | [diff] [blame] | 52 | } |
| 53 | return it->second; |
| 54 | } |
| 55 | |
Cathal Corbett | 5aa9fd7 | 2022-02-25 15:33:28 +0000 | [diff] [blame] | 56 | } // namespace pipe |
| 57 | } // namespace arm |