ArmNN
 20.08
FileOnlyProfilingConnection Class Reference

#include <FileOnlyProfilingConnection.hpp>

Inheritance diagram for FileOnlyProfilingConnection:
IProfilingConnection IInternalProfilingConnection

Public Member Functions

 FileOnlyProfilingConnection (const Runtime::CreationOptions::ExternalProfilingOptions &options)
 
 ~FileOnlyProfilingConnection () override
 
bool IsOpen () const override
 
void Close () override
 
bool WritePacket (const unsigned char *buffer, uint32_t length) override
 
arm::pipe::Packet ReadPacket (uint32_t timeout) override
 
void SetEndianess (const TargetEndianness &endianness) override
 
void ReturnPacket (arm::pipe::Packet &packet) override
 
- Public Member Functions inherited from IProfilingConnection
virtual ~IProfilingConnection ()
 
- Public Member Functions inherited from IInternalProfilingConnection
virtual ~IInternalProfilingConnection ()
 

Detailed Description

Definition at line 50 of file FileOnlyProfilingConnection.hpp.

Constructor & Destructor Documentation

◆ FileOnlyProfilingConnection()

FileOnlyProfilingConnection ( const Runtime::CreationOptions::ExternalProfilingOptions &  options)
inlineexplicit

Definition at line 53 of file FileOnlyProfilingConnection.hpp.

54  : m_Options(options)
55  , m_Endianness(TargetEndianness::LeWire) // Set a sensible default.
56  // StreamMetaDataProcessor will set a real value.
57  , m_IsRunning(false)
58  , m_KeepRunning(false)
59  , m_Timeout(1000)
60  {
61  // add the StreamMetaDataProcessor
62  auto streamMetaDataProcessor = std::make_shared<StreamMetaDataProcessor>(this);
63  AddLocalPacketHandler(streamMetaDataProcessor);
64  // and any additional ones added by the users
65  for (const ILocalPacketHandlerSharedPtr& localPacketHandler : options.m_LocalPacketHandlers)
66  {
67  AddLocalPacketHandler(localPacketHandler);
68  }
69  if (!m_PacketHandlers.empty())
70  {
71  StartProcessingThread();
72  }
73  // NOTE: could add timeout to the external profiling options
74  };
std::shared_ptr< ILocalPacketHandler > ILocalPacketHandlerSharedPtr

◆ ~FileOnlyProfilingConnection()

Definition at line 74 of file FileOnlyProfilingConnection.cpp.

75 {
76  try
77  {
78  Close();
79  }
80  catch (...)
81  {
82  // do nothing
83  }
84 }

Member Function Documentation

◆ Close()

void Close ( )
overridevirtual

Implements IInternalProfilingConnection.

Definition at line 92 of file FileOnlyProfilingConnection.cpp.

93 {
94  // Dump any unread packets out of the queue.
95  size_t initialSize = m_PacketQueue.size();
96  for (size_t i = 0; i < initialSize; ++i)
97  {
98  m_PacketQueue.pop();
99  }
100  // dispose of the processing thread
101  m_KeepRunning.store(false);
102  if (m_LocalHandlersThread.joinable())
103  {
104  // make sure the thread wakes up and sees it has to stop
105  m_ConditionPacketReadable.notify_one();
106  m_LocalHandlersThread.join();
107  }
108 }

◆ IsOpen()

bool IsOpen ( ) const
overridevirtual

Implements IProfilingConnection.

Definition at line 86 of file FileOnlyProfilingConnection.cpp.

87 {
88  // This type of connection is always open.
89  return true;
90 }

◆ ReadPacket()

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

Implements IProfilingConnection.

Definition at line 127 of file FileOnlyProfilingConnection.cpp.

128 {
129  std::unique_lock<std::mutex> lck(m_PacketAvailableMutex);
130 
131  // Here we are using m_PacketQueue.empty() as a predicate variable
132  // The conditional variable will wait until packetQueue is not empty or until a timeout
133  if (!m_ConditionPacketAvailable.wait_for(lck,
134  std::chrono::milliseconds(timeout),
135  [&]{return !m_PacketQueue.empty();}))
136  {
137  arm::pipe::Packet empty;
138  return empty;
139  }
140 
141  arm::pipe::Packet returnedPacket = std::move(m_PacketQueue.front());
142  m_PacketQueue.pop();
143  return returnedPacket;
144 }

◆ ReturnPacket()

void ReturnPacket ( arm::pipe::Packet &  packet)
overridevirtual

Implements IInternalProfilingConnection.

Definition at line 118 of file FileOnlyProfilingConnection.cpp.

Referenced by StreamMetaDataProcessor::HandlePacket().

119 {
120  {
121  std::lock_guard<std::mutex> lck(m_PacketAvailableMutex);
122  m_PacketQueue.push(std::move(packet));
123  }
124  m_ConditionPacketAvailable.notify_one();
125 }

◆ SetEndianess()

void SetEndianess ( const TargetEndianness endianness)
inlineoverridevirtual

Implements IInternalProfilingConnection.

Definition at line 88 of file FileOnlyProfilingConnection.hpp.

Referenced by StreamMetaDataProcessor::HandlePacket().

89  {
90  m_Endianness = endianness;
91  }

◆ WritePacket()

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

Implements IProfilingConnection.

Definition at line 110 of file FileOnlyProfilingConnection.cpp.

References ARMNN_ASSERT, and armnn::profiling::ReceivePacket().

111 {
112  ARMNN_ASSERT(buffer);
113  arm::pipe::Packet packet = ReceivePacket(buffer, length);
114  ForwardPacketToHandlers(packet);
115  return true;
116 }
arm::pipe::Packet ReceivePacket(const unsigned char *buffer, uint32_t length)
#define ARMNN_ASSERT(COND)
Definition: Assert.hpp:14

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