ArmNN
 20.08
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 36 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 45 of file ProfilingMocks.hpp.

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

Constructor & Destructor Documentation

◆ MockProfilingConnection()

Definition at line 39 of file ProfilingMocks.hpp.

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

Member Function Documentation

◆ CheckForPacket()

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

Definition at line 109 of file ProfilingMocks.hpp.

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

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

◆ Clear()

void Clear ( )
inline

Definition at line 149 of file ProfilingMocks.hpp.

Referenced by BOOST_AUTO_TEST_CASE().

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

◆ Close()

void Close ( )
inlineoverridevirtual

Implements IProfilingConnection.

Definition at line 67 of file ProfilingMocks.hpp.

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

◆ GetWrittenDataSize()

unsigned long GetWrittenDataSize ( )
inline

Definition at line 142 of file ProfilingMocks.hpp.

Referenced by BOOST_AUTO_TEST_CASE().

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

◆ IsOpen()

bool IsOpen ( ) const
inlineoverridevirtual

Implements IProfilingConnection.

Definition at line 60 of file ProfilingMocks.hpp.

Referenced by BOOST_AUTO_TEST_CASE().

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

◆ ReadPacket()

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

Implements IProfilingConnection.

Definition at line 132 of file ProfilingMocks.hpp.

References armnn::IgnoreUnused().

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

◆ WritePacket() [1/2]

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

Implements IProfilingConnection.

Definition at line 74 of file ProfilingMocks.hpp.

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

Referenced by BOOST_AUTO_TEST_CASE().

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

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

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