ArmNN
 20.05
FileOnlyProfilingConnection Class Reference

#include <FileOnlyProfilingConnection.hpp>

Inheritance diagram for FileOnlyProfilingConnection:
IProfilingConnection

Public Member Functions

 FileOnlyProfilingConnection (const Runtime::CreationOptions::ExternalProfilingOptions &options, const bool quietOp=true)
 
 ~FileOnlyProfilingConnection ()
 
bool IsOpen () const override
 
void Close () override
 
bool WritePacket (const unsigned char *buffer, uint32_t length) override
 
Packet ReadPacket (uint32_t timeout) override
 
- Public Member Functions inherited from IProfilingConnection
virtual ~IProfilingConnection ()
 

Detailed Description

Definition at line 41 of file FileOnlyProfilingConnection.hpp.

Constructor & Destructor Documentation

◆ FileOnlyProfilingConnection()

FileOnlyProfilingConnection ( const Runtime::CreationOptions::ExternalProfilingOptions &  options,
const bool  quietOp = true 
)
inline

Definition at line 44 of file FileOnlyProfilingConnection.hpp.

46  : m_Options(options)
47  , m_QuietOp(quietOp)
48  , m_Endianness(TargetEndianness::LeWire) // Set a sensible default. WaitForStreamMeta will set a real value.
49  , m_IsRunning(false)
50  , m_KeepRunning(false)
51  , m_Timeout(1000)
52  {
53  for (ILocalPacketHandlerSharedPtr localPacketHandler : options.m_LocalPacketHandlers)
54  {
55  AddLocalPacketHandler(localPacketHandler);
56  }
57  if (!options.m_LocalPacketHandlers.empty())
58  {
59  StartProcessingThread();
60  }
61  // NOTE: could add timeout to the external profiling options
62  };
std::shared_ptr< ILocalPacketHandler > ILocalPacketHandlerSharedPtr
armnn::Runtime::CreationOptions::ExternalProfilingOptions options

◆ ~FileOnlyProfilingConnection()

Member Function Documentation

◆ Close()

void Close ( )
overridevirtual

Implements IProfilingConnection.

Definition at line 34 of file FileOnlyProfilingConnection.cpp.

References armnn::profiling::BeWire, armnn::IgnoreUnused(), armnn::profiling::LeWire, armnn::numeric_cast(), armnn::profiling::uint16_t_size, armnn::profiling::uint32_t_size, armnn::profiling::WriteUint16(), and armnn::profiling::WriteUint32().

Referenced by FileOnlyProfilingConnection::ReadPacket(), and FileOnlyProfilingConnection::~FileOnlyProfilingConnection().

35 {
36  // Dump any unread packets out of the queue.
37  size_t initialSize = m_PacketQueue.size();
38  for (size_t i = 0; i < initialSize; ++i)
39  {
40  m_PacketQueue.pop();
41  }
42  // dispose of the processing thread
43  m_KeepRunning.store(false);
44  if (m_LocalHandlersThread.joinable())
45  {
46  // make sure the thread wakes up and sees it has to stop
47  m_ConditionPacketReadable.notify_one();
48  m_LocalHandlersThread.join();
49  }
50 }

◆ IsOpen()

bool IsOpen ( ) const
overridevirtual

Implements IProfilingConnection.

Definition at line 28 of file FileOnlyProfilingConnection.cpp.

29 {
30  // This type of connection is always open.
31  return true;
32 }

◆ ReadPacket()

Packet ReadPacket ( uint32_t  timeout)
overridevirtual

Implements IProfilingConnection.

Definition at line 179 of file FileOnlyProfilingConnection.cpp.

References armnn::profiling::BeWire, FileOnlyProfilingConnection::Close(), armnn::profiling::CounterDirectory, armnn::profiling::StreamMetaData, and armnn::profiling::Unknown.

180 {
181  std::unique_lock<std::mutex> lck(m_PacketAvailableMutex);
182 
183  // Here we are using m_PacketQueue.empty() as a predicate variable
184  // The conditional variable will wait until packetQueue is not empty or until a timeout
185  if(!m_ConditionPacketAvailable.wait_for(lck,
186  std::chrono::milliseconds(timeout),
187  [&]{return !m_PacketQueue.empty();}))
188  {
189  throw armnn::TimeoutException("Thread has timed out as per requested time limit");
190  }
191 
192  Packet returnedPacket = std::move(m_PacketQueue.front());
193  m_PacketQueue.pop();
194  return returnedPacket;
195 }

◆ WritePacket()

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

Implements IProfilingConnection.

Definition at line 123 of file FileOnlyProfilingConnection.cpp.

References ARMNN_ASSERT, armnn::profiling::CounterDirectory, ICounterDirectory::GetCategories(), Version::GetEncodedValue(), armnn::profiling::ReceivePacket(), PacketVersionResolver::ResolvePacketVersion(), and armnn::profiling::StreamMetaData.

124 {
125  ARMNN_ASSERT(buffer);
126  Packet packet = ReceivePacket(buffer, length);
127 
128  // Read Header and determine case
129  uint32_t outgoingHeaderAsWords[2];
130  PackageActivity packageActivity = GetPackageActivity(packet, outgoingHeaderAsWords);
131 
132  switch (packageActivity)
133  {
135  {
136  if (!WaitForStreamMeta(buffer, length))
137  {
138  return EXIT_FAILURE;
139  }
140 
141  SendConnectionAck();
142  break;
143  }
145  {
146  std::unique_ptr<unsigned char[]> uniqueCounterData = std::make_unique<unsigned char[]>(length - 8);
147 
148  std::memcpy(uniqueCounterData.get(), buffer + 8, length - 8);
149 
150  Packet directoryPacket(outgoingHeaderAsWords[0], length - 8, uniqueCounterData);
151 
152  armnn::profiling::PacketVersionResolver packetVersionResolver;
153  DirectoryCaptureCommandHandler directoryCaptureCommandHandler(
154  0, 2, packetVersionResolver.ResolvePacketVersion(0, 2).GetEncodedValue());
155  directoryCaptureCommandHandler.operator()(directoryPacket);
156  const ICounterDirectory& counterDirectory = directoryCaptureCommandHandler.GetCounterDirectory();
157  for (auto& category : counterDirectory.GetCategories())
158  {
159  // Remember we need to translate the Uid's from our CounterDirectory instance to the parent one.
160  std::vector<uint16_t> translatedCounters;
161  for (auto const& copyUid : category->m_Counters)
162  {
163  translatedCounters.emplace_back(directoryCaptureCommandHandler.TranslateUIDCopyToOriginal(copyUid));
164  }
165  m_IdList.insert(std::end(m_IdList), std::begin(translatedCounters), std::end(translatedCounters));
166  }
167  SendCounterSelectionPacket();
168  break;
169  }
170  default:
171  {
172  break;
173  }
174  }
175  ForwardPacketToHandlers(packet);
176  return true;
177 }
Version ResolvePacketVersion(uint32_t familyId, uint32_t packetId) const
#define ARMNN_ASSERT(COND)
Definition: Assert.hpp:14
Packet ReceivePacket(const unsigned char *buffer, uint32_t length)

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