ArmNN
 21.11
FileOnlyProfilingConnection Class Reference

#include <FileOnlyProfilingConnection.hpp>

Inheritance diagram for FileOnlyProfilingConnection:
IProfilingConnection IInternalProfilingConnection

Public Member Functions

 FileOnlyProfilingConnection (const IRuntime::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()

Definition at line 53 of file FileOnlyProfilingConnection.hpp.

References IRuntime::CreationOptions::ExternalProfilingOptions::m_LocalPacketHandlers.

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 73 of file FileOnlyProfilingConnection.cpp.

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

Member Function Documentation

◆ Close()

void Close ( )
overridevirtual

Implements IInternalProfilingConnection.

Definition at line 91 of file FileOnlyProfilingConnection.cpp.

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

◆ IsOpen()

bool IsOpen ( ) const
overridevirtual

Implements IProfilingConnection.

Definition at line 85 of file FileOnlyProfilingConnection.cpp.

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

◆ ReadPacket()

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

Implements IProfilingConnection.

Definition at line 126 of file FileOnlyProfilingConnection.cpp.

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

◆ ReturnPacket()

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

Implements IInternalProfilingConnection.

Definition at line 117 of file FileOnlyProfilingConnection.cpp.

Referenced by StreamMetaDataProcessor::HandlePacket().

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

◆ 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 109 of file FileOnlyProfilingConnection.cpp.

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

110 {
111  ARMNN_ASSERT(buffer);
112  arm::pipe::Packet packet = ReceivePacket(buffer, length);
113  ForwardPacketToHandlers(packet);
114  return true;
115 }
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: