ArmNN
 21.02
TestTimelinePacketHandler Class Reference

#include <TestTimelinePacketHandler.hpp>

Inheritance diagram for TestTimelinePacketHandler:
ILocalPacketHandler

Public Member Functions

 TestTimelinePacketHandler ()
 
virtual std::vector< uint32_t > GetHeadersAccepted () override
 
virtual void HandlePacket (const arm::pipe::Packet &packet) override
 process the packet More...
 
void Stop ()
 
void WaitOnInferenceCompletion (unsigned int timeout)
 
void SetInferenceComplete ()
 
const TimelineModelGetTimelineModel () const
 
virtual void SetConnection (IInternalProfilingConnection *profilingConnection) override
 Set a profiling connection on the handler. More...
 
- Public Member Functions inherited from ILocalPacketHandler
virtual ~ILocalPacketHandler ()
 

Detailed Description

Definition at line 46 of file TestTimelinePacketHandler.hpp.

Constructor & Destructor Documentation

◆ TestTimelinePacketHandler()

Definition at line 49 of file TestTimelinePacketHandler.hpp.

49  :
50  m_Connection(nullptr),
51  m_InferenceCompleted(false),
52  m_DirectoryHeader(CreateTimelinePacketHeader(1, 0, 0, 0, 0, 0).first),
53  m_MessageHeader(CreateTimelinePacketHeader(1, 0, 1, 0, 0, 0).first),
54  m_MessageDecoder(m_TimelineModel),
55  m_Decoder(1, 1, 0, m_MessageDecoder),
56  m_DirectoryDecoder(1, 0, 0, m_Decoder, true)
57  { m_MessageDecoder.SetPacketHandler(this); }
std::pair< uint32_t, uint32_t > CreateTimelinePacketHeader(uint32_t packetFamily, uint32_t packetClass, uint32_t packetType, uint32_t streamId, uint32_t sequenceNumbered, uint32_t dataLength)
Creates a timeline packet header.
void SetPacketHandler(TestTimelinePacketHandler *packetHandler)

Member Function Documentation

◆ GetHeadersAccepted()

std::vector< uint32_t > GetHeadersAccepted ( )
overridevirtual
Returns
lists the headers of the packets that this handler accepts only these packets will get sent to this handler. If this function returns an empty list then ALL packets will be sent to the PacketHandler i.e. a universal handler.

Implements ILocalPacketHandler.

Definition at line 19 of file TestTimelinePacketHandler.cpp.

20 {
21  std::vector<uint32_t> headers;
22  headers.push_back(m_DirectoryHeader); // message directory
23  headers.push_back(m_MessageHeader); // message
24  return headers;
25 }

◆ GetTimelineModel()

const TimelineModel& GetTimelineModel ( ) const
inline

Definition at line 68 of file TestTimelinePacketHandler.hpp.

68 {return m_TimelineModel;}

◆ HandlePacket()

void HandlePacket ( const arm::pipe::Packet &  packet)
overridevirtual

process the packet

Implements ILocalPacketHandler.

Definition at line 27 of file TestTimelinePacketHandler.cpp.

28 {
29  if (packet.GetHeader() == m_DirectoryHeader)
30  {
31  ProcessDirectoryPacket(packet);
32  }
33  else if (packet.GetHeader() == m_MessageHeader)
34  {
35  ProcessMessagePacket(packet);
36  }
37  else
38  {
39  std::stringstream ss;
40  ss << "Received a packet with unknown header [" << packet.GetHeader() << "]";
41  throw armnn::Exception(ss.str());
42  }
43 }
Base class for all ArmNN exceptions so that users can filter to just those.
Definition: Exceptions.hpp:46

◆ SetConnection()

virtual void SetConnection ( IInternalProfilingConnection profilingConnection)
inlineoverridevirtual

Set a profiling connection on the handler.

Only need to implement this function if the handler will be writing data back to the profiled application.

Reimplemented from ILocalPacketHandler.

Definition at line 70 of file TestTimelinePacketHandler.hpp.

71  {
72  m_Connection = profilingConnection;
73  }

◆ SetInferenceComplete()

void SetInferenceComplete ( )

Definition at line 70 of file TestTimelinePacketHandler.cpp.

71 {
72  { // only lock when we are updating the inference completed variable
73  std::unique_lock<std::mutex> lck(m_InferenceCompletedMutex);
74  m_InferenceCompleted = true;
75  }
76  m_InferenceCompletedConditionVariable.notify_one();
77 }

◆ Stop()

void Stop ( )

Definition at line 45 of file TestTimelinePacketHandler.cpp.

References IInternalProfilingConnection::Close().

46 {
47  m_Connection->Close();
48 }

◆ WaitOnInferenceCompletion()

void WaitOnInferenceCompletion ( unsigned int  timeout)

Definition at line 50 of file TestTimelinePacketHandler.cpp.

51 {
52  std::unique_lock<std::mutex> lck(m_InferenceCompletedMutex);
53 
54  auto start = std::chrono::high_resolution_clock::now();
55  // Here we we will go back to sleep after a spurious wake up if
56  // m_InferenceCompleted is not yet true.
57  if (!m_InferenceCompletedConditionVariable.wait_for(lck,
58  std::chrono::milliseconds(timeout),
59  [&]{return m_InferenceCompleted == true;}))
60  {
61  auto finish = std::chrono::high_resolution_clock::now();
62  std::chrono::duration<double, std::milli> elapsed = finish - start;
63  std::stringstream ss;
64  ss << "Timed out waiting on inference completion for " << elapsed.count() << " ms";
65  throw armnn::TimeoutException(ss.str());
66  }
67  return;
68 }

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