Narumol Prangnawarat | df31cfe | 2019-11-22 11:26:06 +0000 | [diff] [blame] | 1 | // |
Jim Flynn | 6398a98 | 2020-05-27 17:05:21 +0100 | [diff] [blame] | 2 | // Copyright © 2019 Arm Ltd and Contributors. All rights reserved. |
Narumol Prangnawarat | df31cfe | 2019-11-22 11:26:06 +0000 | [diff] [blame] | 3 | // SPDX-License-Identifier: MIT |
| 4 | // |
| 5 | |
| 6 | #pragma once |
| 7 | |
| 8 | #include "ProfilingUtils.hpp" |
Keith Davis | 33ed221 | 2020-03-30 10:43:41 +0100 | [diff] [blame] | 9 | #include "Runtime.hpp" |
Narumol Prangnawarat | df31cfe | 2019-11-22 11:26:06 +0000 | [diff] [blame] | 10 | |
Narumol Prangnawarat | df31cfe | 2019-11-22 11:26:06 +0000 | [diff] [blame] | 11 | #include <BufferManager.hpp> |
| 12 | #include <ProfilingService.hpp> |
| 13 | |
Jim Flynn | decd08b | 2022-03-13 22:35:46 +0000 | [diff] [blame^] | 14 | #include <common/include/Optional.hpp> |
Nikhil Raj | 77fe76b | 2021-06-09 14:55:32 +0100 | [diff] [blame] | 15 | #include <common/include/ProfilingGuid.hpp> |
| 16 | |
Narumol Prangnawarat | df31cfe | 2019-11-22 11:26:06 +0000 | [diff] [blame] | 17 | using namespace armnn; |
Cathal Corbett | 5aa9fd7 | 2022-02-25 15:33:28 +0000 | [diff] [blame] | 18 | using namespace arm::pipe; |
Narumol Prangnawarat | df31cfe | 2019-11-22 11:26:06 +0000 | [diff] [blame] | 19 | |
Finn Williams | 985fecf | 2020-04-30 11:06:43 +0100 | [diff] [blame] | 20 | const static uint32_t bodyHeaderSize = 6; |
| 21 | |
Finn Williams | a0de056 | 2020-04-22 12:27:37 +0100 | [diff] [blame] | 22 | uint32_t GetStreamMetaDataPacketSize(); |
| 23 | |
Jan Eilers | f78c767 | 2020-07-01 18:09:39 +0100 | [diff] [blame] | 24 | /// Returns a vector of CpuRef, CpuAcc or GpuAcc backends if they where registered |
| 25 | std::vector<BackendId> GetSuitableBackendRegistered(); |
| 26 | |
Narumol Prangnawarat | df31cfe | 2019-11-22 11:26:06 +0000 | [diff] [blame] | 27 | inline unsigned int OffsetToNextWord(unsigned int numberOfBytes); |
| 28 | |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 29 | void VerifyTimelineHeaderBinary(const unsigned char* readableData, |
| 30 | unsigned int& offset, |
| 31 | uint32_t packetDataLength); |
Narumol Prangnawarat | df31cfe | 2019-11-22 11:26:06 +0000 | [diff] [blame] | 32 | |
Jim Flynn | decd08b | 2022-03-13 22:35:46 +0000 | [diff] [blame^] | 33 | ProfilingGuid VerifyTimelineLabelBinaryPacketData(arm::pipe::Optional<ProfilingGuid> guid, |
Jim Flynn | 6398a98 | 2020-05-27 17:05:21 +0100 | [diff] [blame] | 34 | const std::string& label, |
| 35 | const unsigned char* readableData, |
| 36 | unsigned int& offset); |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 37 | |
| 38 | void VerifyTimelineEventClassBinaryPacketData(ProfilingGuid guid, |
Jim Flynn | 1892d21 | 2020-05-26 21:10:49 +0100 | [diff] [blame] | 39 | ProfilingGuid nameGuid, |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 40 | const unsigned char* readableData, |
| 41 | unsigned int& offset); |
| 42 | |
| 43 | void VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType relationshipType, |
Jim Flynn | decd08b | 2022-03-13 22:35:46 +0000 | [diff] [blame^] | 44 | arm::pipe::Optional<ProfilingGuid> relationshipGuid, |
| 45 | arm::pipe::Optional<ProfilingGuid> headGuid, |
| 46 | arm::pipe::Optional<ProfilingGuid> tailGuid, |
| 47 | arm::pipe::Optional<ProfilingGuid> attributeGuid, |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 48 | const unsigned char* readableData, |
| 49 | unsigned int& offset); |
| 50 | |
Jim Flynn | decd08b | 2022-03-13 22:35:46 +0000 | [diff] [blame^] | 51 | ProfilingGuid VerifyTimelineEntityBinaryPacketData(arm::pipe::Optional<ProfilingGuid> guid, |
Jim Flynn | 6398a98 | 2020-05-27 17:05:21 +0100 | [diff] [blame] | 52 | const unsigned char* readableData, |
| 53 | unsigned int& offset); |
Narumol Prangnawarat | df31cfe | 2019-11-22 11:26:06 +0000 | [diff] [blame] | 54 | |
Jim Flynn | decd08b | 2022-03-13 22:35:46 +0000 | [diff] [blame^] | 55 | ProfilingGuid VerifyTimelineEventBinaryPacket(arm::pipe::Optional<uint64_t> timestamp, |
| 56 | arm::pipe::Optional<int> threadId, |
| 57 | arm::pipe::Optional<ProfilingGuid> eventGuid, |
Jim Flynn | 6398a98 | 2020-05-27 17:05:21 +0100 | [diff] [blame] | 58 | const unsigned char* readableData, |
| 59 | unsigned int& offset); |
Narumol Prangnawarat | df31cfe | 2019-11-22 11:26:06 +0000 | [diff] [blame] | 60 | |
| 61 | void VerifyPostOptimisationStructureTestImpl(armnn::BackendId backendId); |
| 62 | |
Jim Flynn | 6398a98 | 2020-05-27 17:05:21 +0100 | [diff] [blame] | 63 | bool CompareOutput(std::vector<std::string> output, std::vector<std::string> expectedOutput); |
| 64 | |
Cathal Corbett | 5aa9fd7 | 2022-02-25 15:33:28 +0000 | [diff] [blame] | 65 | namespace arm |
Narumol Prangnawarat | df31cfe | 2019-11-22 11:26:06 +0000 | [diff] [blame] | 66 | { |
| 67 | |
Cathal Corbett | 5aa9fd7 | 2022-02-25 15:33:28 +0000 | [diff] [blame] | 68 | namespace pipe |
Narumol Prangnawarat | df31cfe | 2019-11-22 11:26:06 +0000 | [diff] [blame] | 69 | { |
| 70 | |
| 71 | class ProfilingServiceRuntimeHelper : public ProfilingService |
| 72 | { |
| 73 | public: |
Jim Flynn | 3443025 | 2022-03-04 15:03:58 +0000 | [diff] [blame] | 74 | ProfilingServiceRuntimeHelper(uint16_t maxGlobalCounterId, |
| 75 | IInitialiseProfilingService& initialiser, |
| 76 | arm::pipe::IProfilingService& profilingService) |
| 77 | : ProfilingService(maxGlobalCounterId, initialiser), m_ProfilingService(profilingService) {} |
Narumol Prangnawarat | df31cfe | 2019-11-22 11:26:06 +0000 | [diff] [blame] | 78 | ~ProfilingServiceRuntimeHelper() = default; |
| 79 | |
| 80 | BufferManager& GetProfilingBufferManager() |
| 81 | { |
Jim Flynn | 3443025 | 2022-03-04 15:03:58 +0000 | [diff] [blame] | 82 | return GetBufferManager(static_cast<arm::pipe::ProfilingService&>(m_ProfilingService)); |
Narumol Prangnawarat | df31cfe | 2019-11-22 11:26:06 +0000 | [diff] [blame] | 83 | } |
Jim Flynn | 3443025 | 2022-03-04 15:03:58 +0000 | [diff] [blame] | 84 | arm::pipe::IProfilingService& m_ProfilingService; |
Keith Davis | 33ed221 | 2020-03-30 10:43:41 +0100 | [diff] [blame] | 85 | |
| 86 | void ForceTransitionToState(ProfilingState newState) |
| 87 | { |
Jim Flynn | 3443025 | 2022-03-04 15:03:58 +0000 | [diff] [blame] | 88 | TransitionToState(static_cast<arm::pipe::ProfilingService&>(m_ProfilingService), newState); |
Keith Davis | 33ed221 | 2020-03-30 10:43:41 +0100 | [diff] [blame] | 89 | } |
Narumol Prangnawarat | df31cfe | 2019-11-22 11:26:06 +0000 | [diff] [blame] | 90 | }; |
| 91 | |
Jim Flynn | 6c9f17d | 2022-03-10 23:13:01 +0000 | [diff] [blame] | 92 | struct LogLevelSwapper |
| 93 | { |
| 94 | public: |
| 95 | LogLevelSwapper(arm::pipe::LogSeverity severity) |
| 96 | { |
| 97 | // Set the new log level |
| 98 | arm::pipe::ConfigureLogging(true, true, severity); |
| 99 | } |
| 100 | ~LogLevelSwapper() |
| 101 | { |
| 102 | // The default log level for unit tests is "Fatal" |
| 103 | arm::pipe::ConfigureLogging(true, true, arm::pipe::LogSeverity::Fatal); |
| 104 | } |
| 105 | }; |
| 106 | |
| 107 | struct StreamRedirector |
| 108 | { |
| 109 | public: |
| 110 | StreamRedirector(std::ostream& stream, std::streambuf* newStreamBuffer) |
| 111 | : m_Stream(stream) |
| 112 | , m_BackupBuffer(m_Stream.rdbuf(newStreamBuffer)) |
| 113 | {} |
| 114 | |
| 115 | ~StreamRedirector() { CancelRedirect(); } |
| 116 | |
| 117 | void CancelRedirect() |
| 118 | { |
| 119 | // Only cancel the redirect once. |
| 120 | if (m_BackupBuffer != nullptr ) |
| 121 | { |
| 122 | m_Stream.rdbuf(m_BackupBuffer); |
| 123 | m_BackupBuffer = nullptr; |
| 124 | } |
| 125 | } |
| 126 | |
| 127 | private: |
| 128 | std::ostream& m_Stream; |
| 129 | std::streambuf* m_BackupBuffer; |
| 130 | }; |
| 131 | |
Cathal Corbett | 5aa9fd7 | 2022-02-25 15:33:28 +0000 | [diff] [blame] | 132 | } // namespace pipe |
Narumol Prangnawarat | df31cfe | 2019-11-22 11:26:06 +0000 | [diff] [blame] | 133 | |
Cathal Corbett | 5aa9fd7 | 2022-02-25 15:33:28 +0000 | [diff] [blame] | 134 | } // namespace arm |