ArmNN
 22.05
ProfilingTestUtils.hpp
Go to the documentation of this file.
1 //
2 // Copyright © 2019 Arm Ltd and Contributors. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5 
6 #pragma once
7 
8 #include "Runtime.hpp"
9 
10 #include <client/src/BufferManager.hpp>
11 #include <client/src/ProfilingService.hpp>
12 #include <client/src/ProfilingUtils.hpp>
13 
14 
16 
17 #include <common/include/Optional.hpp>
18 #include <common/include/ProfilingGuid.hpp>
19 
20 using namespace armnn;
21 using namespace arm::pipe;
22 
23 const static uint32_t bodyHeaderSize = 6;
24 
26 
27 /// Returns a vector of CpuRef, CpuAcc or GpuAcc backends if they where registered
28 std::vector<BackendId> GetSuitableBackendRegistered();
29 
30 inline unsigned int OffsetToNextWord(unsigned int numberOfBytes);
31 
32 void VerifyTimelineHeaderBinary(const unsigned char* readableData,
33  unsigned int& offset,
34  uint32_t packetDataLength);
35 
36 ProfilingGuid VerifyTimelineLabelBinaryPacketData(arm::pipe::Optional<ProfilingGuid> guid,
37  const std::string& label,
38  const unsigned char* readableData,
39  unsigned int& offset);
40 
41 void VerifyTimelineEventClassBinaryPacketData(ProfilingGuid guid,
42  ProfilingGuid nameGuid,
43  const unsigned char* readableData,
44  unsigned int& offset);
45 
46 void VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType relationshipType,
47  arm::pipe::Optional<ProfilingGuid> relationshipGuid,
48  arm::pipe::Optional<ProfilingGuid> headGuid,
49  arm::pipe::Optional<ProfilingGuid> tailGuid,
50  arm::pipe::Optional<ProfilingGuid> attributeGuid,
51  const unsigned char* readableData,
52  unsigned int& offset);
53 
54 ProfilingGuid VerifyTimelineEntityBinaryPacketData(arm::pipe::Optional<ProfilingGuid> guid,
55  const unsigned char* readableData,
56  unsigned int& offset);
57 
58 ProfilingGuid VerifyTimelineEventBinaryPacket(arm::pipe::Optional<uint64_t> timestamp,
59  arm::pipe::Optional<int> threadId,
60  arm::pipe::Optional<ProfilingGuid> eventGuid,
61  const unsigned char* readableData,
62  unsigned int& offset);
63 
65 
66 bool CompareOutput(std::vector<std::string> output, std::vector<std::string> expectedOutput);
67 
68 namespace arm
69 {
70 
71 namespace pipe
72 {
73 
74 class ProfilingServiceRuntimeHelper : public ProfilingService
75 {
76 public:
77  ProfilingServiceRuntimeHelper(uint16_t maxGlobalCounterId,
78  IInitialiseProfilingService& initialiser,
79  arm::pipe::IProfilingService& profilingService)
80  : ProfilingService(maxGlobalCounterId,
81  initialiser,
82  arm::pipe::ARMNN_SOFTWARE_INFO,
83  arm::pipe::ARMNN_SOFTWARE_VERSION,
84  arm::pipe::ARMNN_HARDWARE_VERSION),
85  m_ProfilingService(profilingService) {}
86  ~ProfilingServiceRuntimeHelper() = default;
87 
88  BufferManager& GetProfilingBufferManager()
89  {
90  return GetBufferManager(static_cast<arm::pipe::ProfilingService&>(m_ProfilingService));
91  }
92  arm::pipe::IProfilingService& m_ProfilingService;
93 
94  void ForceTransitionToState(ProfilingState newState)
95  {
96  TransitionToState(static_cast<arm::pipe::ProfilingService&>(m_ProfilingService), newState);
97  }
98 };
99 
100 struct LogLevelSwapper
101 {
102 public:
103  LogLevelSwapper(arm::pipe::LogSeverity severity)
104  {
105  // Set the new log level
106  arm::pipe::ConfigureLogging(true, true, severity);
107  }
108  ~LogLevelSwapper()
109  {
110  // The default log level for unit tests is "Fatal"
111  arm::pipe::ConfigureLogging(true, true, arm::pipe::LogSeverity::Fatal);
112  }
113 };
114 
116 {
117 public:
118  StreamRedirector(std::ostream& stream, std::streambuf* newStreamBuffer)
119  : m_Stream(stream)
120  , m_BackupBuffer(m_Stream.rdbuf(newStreamBuffer))
121  {}
122 
123  ~StreamRedirector() { CancelRedirect(); }
124 
126  {
127  // Only cancel the redirect once.
128  if (m_BackupBuffer != nullptr )
129  {
130  m_Stream.rdbuf(m_BackupBuffer);
131  m_BackupBuffer = nullptr;
132  }
133  }
134 
135 private:
136  std::ostream& m_Stream;
137  std::streambuf* m_BackupBuffer;
138 };
139 
140 } // namespace pipe
141 
142 } // namespace arm
ProfilingGuid VerifyTimelineEventBinaryPacket(arm::pipe::Optional< uint64_t > timestamp, arm::pipe::Optional< int > threadId, arm::pipe::Optional< ProfilingGuid > eventGuid, const unsigned char *readableData, unsigned int &offset)
void ConfigureLogging(bool printToStandardOutput, bool printToDebugOutput, LogSeverity severity)
Configures the logging behaviour of the ARMNN library.
Definition: Utils.cpp:18
ProfilingGuid VerifyTimelineEntityBinaryPacketData(arm::pipe::Optional< ProfilingGuid > guid, const unsigned char *readableData, unsigned int &offset)
unsigned int OffsetToNextWord(unsigned int numberOfBytes)
uint32_t GetStreamMetaDataPacketSize()
void VerifyPostOptimisationStructureTestImpl(armnn::BackendId backendId)
arm::pipe::IInitialiseProfilingService IInitialiseProfilingService
Definition: Runtime.hpp:28
Copyright (c) 2021 ARM Limited and Contributors.
StreamRedirector(std::ostream &stream, std::streambuf *newStreamBuffer)
void VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType relationshipType, arm::pipe::Optional< ProfilingGuid > relationshipGuid, arm::pipe::Optional< ProfilingGuid > headGuid, arm::pipe::Optional< ProfilingGuid > tailGuid, arm::pipe::Optional< ProfilingGuid > attributeGuid, const unsigned char *readableData, unsigned int &offset)
std::vector< BackendId > GetSuitableBackendRegistered()
Returns a vector of CpuRef, CpuAcc or GpuAcc backends if they where registered.
bool CompareOutput(std::vector< std::string > output, std::vector< std::string > expectedOutput)
void VerifyTimelineHeaderBinary(const unsigned char *readableData, unsigned int &offset, uint32_t packetDataLength)
ProfilingGuid VerifyTimelineLabelBinaryPacketData(arm::pipe::Optional< ProfilingGuid > guid, const std::string &label, const unsigned char *readableData, unsigned int &offset)
void ForceTransitionToState(ProfilingState newState)
LogSeverity
Definition: Utils.hpp:14
arm::pipe::IProfilingService & m_ProfilingService
ProfilingServiceRuntimeHelper(uint16_t maxGlobalCounterId, IInitialiseProfilingService &initialiser, arm::pipe::IProfilingService &profilingService)
void VerifyTimelineEventClassBinaryPacketData(ProfilingGuid guid, ProfilingGuid nameGuid, const unsigned char *readableData, unsigned int &offset)