ArmNN
 22.05
MockProfilingConnection Class Reference

#include <ProfilingMocks.hpp>

Inheritance diagram for MockProfilingConnection:

Public Types

enum  PacketType {
  StreamMetaData, ConnectionAcknowledge, CounterDirectory, ReqCounterDirectory,
  PeriodicCounterSelection, PerJobCounterSelection, TimelineMessageDirectory, PeriodicCounterCapture,
  ActivateTimelineReporting, DeactivateTimelineReporting, Unknown
}
 

Public Member Functions

 MockProfilingConnection ()
 
bool IsOpen () const override
 
void Close () override
 
bool WritePacket (const unsigned char *buffer, uint32_t length) override
 
long CheckForPacket (const std::pair< PacketType, uint32_t > packetInfo)
 
bool WritePacket (arm::pipe::Packet &&packet)
 
arm::pipe::Packet ReadPacket (uint32_t timeout) override
 
unsigned long GetWrittenDataSize ()
 
void Clear ()
 

Detailed Description

Definition at line 39 of file ProfilingMocks.hpp.

Member Enumeration Documentation

◆ PacketType

enum PacketType
strong
Enumerator
StreamMetaData 
ConnectionAcknowledge 
CounterDirectory 
ReqCounterDirectory 
PeriodicCounterSelection 
PerJobCounterSelection 
TimelineMessageDirectory 
PeriodicCounterCapture 
ActivateTimelineReporting 
DeactivateTimelineReporting 
Unknown 

Definition at line 48 of file ProfilingMocks.hpp.

49  {
50  StreamMetaData,
51  ConnectionAcknowledge,
52  CounterDirectory,
53  ReqCounterDirectory,
54  PeriodicCounterSelection,
55  PerJobCounterSelection,
56  TimelineMessageDirectory,
57  PeriodicCounterCapture,
58  ActivateTimelineReporting,
59  DeactivateTimelineReporting,
60  Unknown
61  };

Constructor & Destructor Documentation

◆ MockProfilingConnection()

Definition at line 42 of file ProfilingMocks.hpp.

43  : m_IsOpen(true)
44  , m_WrittenData()
45  , m_Packet()
46  {}

Member Function Documentation

◆ CheckForPacket()

long CheckForPacket ( const std::pair< PacketType, uint32_t >  packetInfo)
inline

Definition at line 112 of file ProfilingMocks.hpp.

Referenced by SwapProfilingConnectionFactoryHelper::WaitForPacketsSent().

113  {
114  std::lock_guard<std::mutex> lock(m_Mutex);
115 
116  if(packetInfo.second != 0)
117  {
118  return static_cast<long>(std::count(m_WrittenData.begin(), m_WrittenData.end(), packetInfo));
119  }
120  else
121  {
122  return static_cast<long>(std::count_if(m_WrittenData.begin(), m_WrittenData.end(),
123  [&packetInfo](const std::pair<PacketType, uint32_t> pair) { return packetInfo.first == pair.first; }));
124  }
125  }

◆ Clear()

void Clear ( )
inline

Definition at line 152 of file ProfilingMocks.hpp.

153  {
154  std::lock_guard<std::mutex> lock(m_Mutex);
155 
156  m_WrittenData.clear();
157  }

◆ Close()

void Close ( )
inlineoverride

Definition at line 70 of file ProfilingMocks.hpp.

71  {
72  std::lock_guard<std::mutex> lock(m_Mutex);
73 
74  m_IsOpen = false;
75  }

◆ GetWrittenDataSize()

unsigned long GetWrittenDataSize ( )
inline

Definition at line 145 of file ProfilingMocks.hpp.

146  {
147  std::lock_guard<std::mutex> lock(m_Mutex);
148 
149  return static_cast<unsigned long>(m_WrittenData.size());
150  }

◆ IsOpen()

bool IsOpen ( ) const
inlineoverride

Definition at line 63 of file ProfilingMocks.hpp.

64  {
65  std::lock_guard<std::mutex> lock(m_Mutex);
66 
67  return m_IsOpen;
68  }

◆ ReadPacket()

arm::pipe::Packet ReadPacket ( uint32_t  timeout)
inlineoverride

Definition at line 135 of file ProfilingMocks.hpp.

References armnn::IgnoreUnused().

136  {
137  arm::pipe::IgnoreUnused(timeout);
138 
139  // Simulate a delay in the reading process. The default timeout is way too long.
140  std::this_thread::sleep_for(std::chrono::milliseconds(5));
141  std::lock_guard<std::mutex> lock(m_Mutex);
142  return std::move(m_Packet);
143  }
void IgnoreUnused(Ts &&...)

◆ WritePacket() [1/2]

bool WritePacket ( const unsigned char *  buffer,
uint32_t  length 
)
inlineoverride

Definition at line 77 of file ProfilingMocks.hpp.

References MockProfilingConnection::PeriodicCounterCapture, MockProfilingConnection::TimelineMessageDirectory, and MockProfilingConnection::Unknown.

78  {
79  if (buffer == nullptr || length == 0)
80  {
81  return false;
82  }
83 
84  uint32_t header = ReadUint32(buffer, 0);
85 
86  uint32_t packetFamily = (header >> 26);
87  uint32_t packetId = ((header >> 16) & 1023);
88 
89  PacketType packetType;
90 
91  switch (packetFamily)
92  {
93  case 0:
94  packetType = packetId < 8 ? PacketType(packetId) : PacketType::Unknown;
95  break;
96  case 1:
97  packetType = packetId == 0 ? PacketType::TimelineMessageDirectory : PacketType::Unknown;
98  break;
99  case 3:
100  packetType = packetId == 0 ? PacketType::PeriodicCounterCapture : PacketType::Unknown;
101  break;
102  default:
103  packetType = PacketType::Unknown;
104  }
105 
106  std::lock_guard<std::mutex> lock(m_Mutex);
107 
108  m_WrittenData.push_back({ packetType, length });
109  return true;
110  }
MockProfilingConnection::PacketType PacketType

◆ WritePacket() [2/2]

bool WritePacket ( arm::pipe::Packet &&  packet)
inline

Definition at line 127 of file ProfilingMocks.hpp.

128  {
129  std::lock_guard<std::mutex> lock(m_Mutex);
130 
131  m_Packet = std::move(packet);
132  return true;
133  }

The documentation for this class was generated from the following file: