Ferran Balaguer | 7388217 | 2019-09-02 16:39:42 +0100 | [diff] [blame] | 1 | // |
Jim Flynn | 83d08a9 | 2020-07-09 13:48:16 +0100 | [diff] [blame] | 2 | // Copyright © 2017 Arm Ltd and Contributors. All rights reserved. |
Ferran Balaguer | 7388217 | 2019-09-02 16:39:42 +0100 | [diff] [blame] | 3 | // SPDX-License-Identifier: MIT |
| 4 | // |
| 5 | |
| 6 | #pragma once |
| 7 | |
Narumol Prangnawarat | 404b275 | 2019-09-24 17:23:16 +0100 | [diff] [blame] | 8 | #include "IBufferManager.hpp" |
Matteo Martincigh | 5d737fb | 2019-10-07 13:05:13 +0100 | [diff] [blame] | 9 | #include "ISendCounterPacket.hpp" |
Narumol Prangnawarat | 0ec068f | 2019-09-30 16:20:20 +0100 | [diff] [blame] | 10 | #include "ProfilingUtils.hpp" |
Matteo Martincigh | 24e8f92 | 2019-09-19 11:57:46 +0100 | [diff] [blame] | 11 | |
Narumol Prangnawarat | 0ec068f | 2019-09-30 16:20:20 +0100 | [diff] [blame] | 12 | #include <type_traits> |
Ferran Balaguer | 7388217 | 2019-09-02 16:39:42 +0100 | [diff] [blame] | 13 | |
Cathal Corbett | 5aa9fd7 | 2022-02-25 15:33:28 +0000 | [diff] [blame] | 14 | namespace arm |
Ferran Balaguer | 7388217 | 2019-09-02 16:39:42 +0100 | [diff] [blame] | 15 | { |
| 16 | |
Cathal Corbett | 5aa9fd7 | 2022-02-25 15:33:28 +0000 | [diff] [blame] | 17 | namespace pipe |
Ferran Balaguer | 7388217 | 2019-09-02 16:39:42 +0100 | [diff] [blame] | 18 | { |
| 19 | |
| 20 | class SendCounterPacket : public ISendCounterPacket |
| 21 | { |
| 22 | public: |
Matteo Martincigh | 5d737fb | 2019-10-07 13:05:13 +0100 | [diff] [blame] | 23 | using CategoryRecord = std::vector<uint32_t>; |
| 24 | using DeviceRecord = std::vector<uint32_t>; |
| 25 | using CounterSetRecord = std::vector<uint32_t>; |
| 26 | using EventRecord = std::vector<uint32_t>; |
Finn Williams | 032bc74 | 2020-02-12 11:02:34 +0000 | [diff] [blame] | 27 | using IndexValuePairsVector = std::vector<CounterValue>; |
Francis Murtagh | 3a16198 | 2019-09-04 15:25:02 +0100 | [diff] [blame] | 28 | |
Jim Flynn | 9c85b41 | 2022-03-16 00:27:43 +0000 | [diff] [blame] | 29 | SendCounterPacket(IBufferManager& buffer, |
| 30 | const std::string& softwareInfo, |
| 31 | const std::string& softwareVersion, |
| 32 | const std::string& hardwareVersion) |
| 33 | : m_BufferManager(buffer), |
| 34 | m_SoftwareInfo(softwareInfo), |
| 35 | m_SoftwareVersion(softwareVersion), |
| 36 | m_HardwareVersion(hardwareVersion) |
Matteo Martincigh | 149528e | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 37 | {} |
Ferran Balaguer | 7388217 | 2019-09-02 16:39:42 +0100 | [diff] [blame] | 38 | |
| 39 | void SendStreamMetaDataPacket() override; |
| 40 | |
Matteo Martincigh | 42f9d9e | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 41 | void SendCounterDirectoryPacket(const ICounterDirectory& counterDirectory) override; |
Ferran Balaguer | 7388217 | 2019-09-02 16:39:42 +0100 | [diff] [blame] | 42 | |
Francis Murtagh | 3a16198 | 2019-09-04 15:25:02 +0100 | [diff] [blame] | 43 | void SendPeriodicCounterCapturePacket(uint64_t timestamp, const IndexValuePairsVector& values) override; |
Ferran Balaguer | 7388217 | 2019-09-02 16:39:42 +0100 | [diff] [blame] | 44 | |
| 45 | void SendPeriodicCounterSelectionPacket(uint32_t capturePeriod, |
| 46 | const std::vector<uint16_t>& selectedCounterIds) override; |
| 47 | |
Ferran Balaguer | 7388217 | 2019-09-02 16:39:42 +0100 | [diff] [blame] | 48 | private: |
Matteo Martincigh | 149528e | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 49 | template <typename ExceptionType> |
| 50 | void CancelOperationAndThrow(const std::string& errorMessage) |
| 51 | { |
Narumol Prangnawarat | 404b275 | 2019-09-24 17:23:16 +0100 | [diff] [blame] | 52 | // Throw a runtime exception with the given error message |
| 53 | throw ExceptionType(errorMessage); |
| 54 | } |
| 55 | |
| 56 | template <typename ExceptionType> |
Matteo Martincigh | 2ffcc41 | 2019-11-05 11:47:40 +0000 | [diff] [blame] | 57 | void CancelOperationAndThrow(IPacketBufferPtr& writerBuffer, const std::string& errorMessage) |
Narumol Prangnawarat | 404b275 | 2019-09-24 17:23:16 +0100 | [diff] [blame] | 58 | { |
Jim Flynn | f9db3ef | 2022-03-08 21:23:44 +0000 | [diff] [blame] | 59 | if (std::is_same<ExceptionType, arm::pipe::BufferExhaustion>::value) |
Narumol Prangnawarat | 0ec068f | 2019-09-30 16:20:20 +0100 | [diff] [blame] | 60 | { |
Sadik Armagan | 3896b47 | 2020-02-10 12:24:15 +0000 | [diff] [blame] | 61 | m_BufferManager.FlushReadList(); |
Narumol Prangnawarat | 0ec068f | 2019-09-30 16:20:20 +0100 | [diff] [blame] | 62 | } |
Matteo Martincigh | 5d737fb | 2019-10-07 13:05:13 +0100 | [diff] [blame] | 63 | |
Narumol Prangnawarat | 404b275 | 2019-09-24 17:23:16 +0100 | [diff] [blame] | 64 | if (writerBuffer != nullptr) |
| 65 | { |
| 66 | // Cancel the operation |
| 67 | m_BufferManager.Release(writerBuffer); |
| 68 | } |
Matteo Martincigh | 149528e | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 69 | |
| 70 | // Throw a runtime exception with the given error message |
| 71 | throw ExceptionType(errorMessage); |
| 72 | } |
| 73 | |
Narumol Prangnawarat | 404b275 | 2019-09-24 17:23:16 +0100 | [diff] [blame] | 74 | IBufferManager& m_BufferManager; |
Matteo Martincigh | 42f9d9e | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 75 | |
| 76 | protected: |
| 77 | // Helper methods, protected for testing |
| 78 | bool CreateCategoryRecord(const CategoryPtr& category, |
| 79 | const Counters& counters, |
| 80 | CategoryRecord& categoryRecord, |
| 81 | std::string& errorMessage); |
| 82 | bool CreateDeviceRecord(const DevicePtr& device, |
| 83 | DeviceRecord& deviceRecord, |
| 84 | std::string& errorMessage); |
| 85 | bool CreateCounterSetRecord(const CounterSetPtr& counterSet, |
| 86 | CounterSetRecord& counterSetRecord, |
| 87 | std::string& errorMessage); |
| 88 | bool CreateEventRecord(const CounterPtr& counter, |
| 89 | EventRecord& eventRecord, |
| 90 | std::string& errorMessage); |
Jim Flynn | 9c85b41 | 2022-03-16 00:27:43 +0000 | [diff] [blame] | 91 | private: |
| 92 | std::string m_SoftwareInfo; |
| 93 | std::string m_SoftwareVersion; |
| 94 | std::string m_HardwareVersion; |
Ferran Balaguer | 7388217 | 2019-09-02 16:39:42 +0100 | [diff] [blame] | 95 | }; |
| 96 | |
Cathal Corbett | 5aa9fd7 | 2022-02-25 15:33:28 +0000 | [diff] [blame] | 97 | } // namespace pipe |
Ferran Balaguer | 7388217 | 2019-09-02 16:39:42 +0100 | [diff] [blame] | 98 | |
Cathal Corbett | 5aa9fd7 | 2022-02-25 15:33:28 +0000 | [diff] [blame] | 99 | } // namespace arm |