ArmNN
 21.02
MockProfilingConnection Class Reference

#include <ProfilingMocks.hpp>

Inheritance diagram for MockProfilingConnection:
IProfilingConnection

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 ()
 
- Public Member Functions inherited from IProfilingConnection
virtual ~IProfilingConnection ()
 

Detailed Description

Definition at line 35 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 44 of file ProfilingMocks.hpp.

45  {
46  StreamMetaData,
47  ConnectionAcknowledge,
48  CounterDirectory,
49  ReqCounterDirectory,
50  PeriodicCounterSelection,
51  PerJobCounterSelection,
52  TimelineMessageDirectory,
53  PeriodicCounterCapture,
54  ActivateTimelineReporting,
55  DeactivateTimelineReporting,
56  Unknown
57  };

Constructor & Destructor Documentation

◆ MockProfilingConnection()

Definition at line 38 of file ProfilingMocks.hpp.

39  : m_IsOpen(true)
40  , m_WrittenData()
41  , m_Packet()
42  {}

Member Function Documentation

◆ CheckForPacket()

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

Definition at line 108 of file ProfilingMocks.hpp.

Referenced by BOOST_AUTO_TEST_CASE(), and SwapProfilingConnectionFactoryHelper::WaitForPacketsSent().

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

◆ Clear()

void Clear ( )
inline

Definition at line 148 of file ProfilingMocks.hpp.

Referenced by BOOST_AUTO_TEST_CASE().

149  {
150  std::lock_guard<std::mutex> lock(m_Mutex);
151 
152  m_WrittenData.clear();
153  }

◆ Close()

void Close ( )
inlineoverridevirtual

Implements IProfilingConnection.

Definition at line 66 of file ProfilingMocks.hpp.

67  {
68  std::lock_guard<std::mutex> lock(m_Mutex);
69 
70  m_IsOpen = false;
71  }

◆ GetWrittenDataSize()

unsigned long GetWrittenDataSize ( )
inline

Definition at line 141 of file ProfilingMocks.hpp.

Referenced by BOOST_AUTO_TEST_CASE().

142  {
143  std::lock_guard<std::mutex> lock(m_Mutex);
144 
145  return static_cast<unsigned long>(m_WrittenData.size());
146  }

◆ IsOpen()

bool IsOpen ( ) const
inlineoverridevirtual

Implements IProfilingConnection.

Definition at line 59 of file ProfilingMocks.hpp.

Referenced by BOOST_AUTO_TEST_CASE().

60  {
61  std::lock_guard<std::mutex> lock(m_Mutex);
62 
63  return m_IsOpen;
64  }

◆ ReadPacket()

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

Implements IProfilingConnection.

Definition at line 131 of file ProfilingMocks.hpp.

References armnn::IgnoreUnused().

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

◆ WritePacket() [1/2]

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

Implements IProfilingConnection.

Definition at line 73 of file ProfilingMocks.hpp.

References MockProfilingConnection::PeriodicCounterCapture, armnn::profiling::ReadUint32(), MockProfilingConnection::TimelineMessageDirectory, and MockProfilingConnection::Unknown.

Referenced by BOOST_AUTO_TEST_CASE().

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

◆ WritePacket() [2/2]

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

Definition at line 123 of file ProfilingMocks.hpp.

124  {
125  std::lock_guard<std::mutex> lock(m_Mutex);
126 
127  m_Packet = std::move(packet);
128  return true;
129  }

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