ArmNN
 22.02
armnn::profiling Namespace Reference

Classes

class  ActivateTimelineReportingCommandHandler
 
class  BackendProfiling
 
class  BufferExhaustion
 
class  BufferManager
 
class  CaptureData
 
class  Category
 
class  CommandHandler
 
class  Connection
 
class  ConnectionAcknowledgedCommandHandler
 
class  Counter
 
class  CounterDirectory
 
struct  CounterDirectoryEventRecord
 
class  CounterIdMap
 
class  CounterSet
 
struct  CounterStatus
 
struct  CounterValue
 
class  DeactivateTimelineReportingCommandHandler
 
class  Device
 
class  DirectoryCaptureCommandHandler
 
class  Entity
 
class  EventClassObj
 
class  EventObj
 
class  FileOnlyProfilingConnection
 
class  Holder
 
class  IBackendProfiling
 
class  IBackendProfilingContext
 
class  IBufferManager
 
class  IConsumer
 
class  ICounterDirectory
 
class  ICounterMappings
 
class  ICounterRegistry
 
class  IInternalProfilingConnection
 
class  ILocalPacketHandler
 
class  INotifyBackends
 
class  IPacketBuffer
 
class  IPeriodicCounterCapture
 
class  IProfilingConnection
 
class  IProfilingConnectionFactory
 
class  IProfilingService
 
class  IProfilingServiceStatus
 
class  IReadCounterValues
 
class  IReadOnlyPacketBuffer
 
class  IReadWriteCounterValues
 
class  IRegisterBackendCounters
 
class  IRegisterCounterMapping
 
class  IReportStructure
 
class  ISendCounterPacket
 
class  ISendThread
 
class  ISendTimelinePacket
 
class  IWriteCounterValues
 
struct  LogLevelSwapper
 
class  MockBufferManager
 
class  MockCounterDirectory
 
class  MockPacketBuffer
 
class  MockProfilingConnection
 
class  MockProfilingConnectionFactory
 
class  MockProfilingService
 
class  MockProfilingServiceStatus
 
class  MockSendCounterPacket
 
class  MockStreamCounterBuffer
 
struct  ModelRelationship
 
class  NullProfilingConnection
 
class  PacketBuffer
 
class  PeriodicCounterCapture
 
class  PeriodicCounterSelectionCommandHandler
 
class  PerJobCounterSelectionCommandHandler
 
class  PrintPacketHeaderHandler
 
class  ProfilingConnectionDumpToFileDecorator
 
class  ProfilingConnectionFactory
 
class  ProfilingService
 
class  ProfilingServiceRuntimeHelper
 
class  ProfilingStateMachine
 
class  RegisterBackendCounters
 
class  RequestCounterDirectoryCommandHandler
 
class  RequestCountersPacketHandler
 
class  SendCounterPacket
 
class  SendCounterPacketTest
 
class  SendThread
 
class  SendTimelinePacket
 
class  SocketProfilingConnection
 
class  StreamMetaDataProcessor
 
struct  StreamRedirector
 
class  SwapProfilingConnectionFactoryHelper
 
class  TestFunctorA
 
class  TestFunctorB
 
class  TestFunctorC
 
class  TestProfilingConnectionArmnnError
 
class  TestProfilingConnectionBadAckPacket
 
class  TestProfilingConnectionBase
 
class  TestProfilingConnectionTimeoutError
 
class  TestTimelinePacketHandler
 
class  TimelineMessageDecoder
 
class  TimelineModel
 
class  TimelinePacketWriterFactory
 
class  TimelineUtilityMethods
 
struct  Timestamp
 

Typedefs

using IBackendProfilingContextUniquePtr = std::unique_ptr< IBackendProfilingContext >
 
using ILocalPacketHandlerPtr = std::unique_ptr< ILocalPacketHandler >
 
using ILocalPacketHandlerSharedPtr = std::shared_ptr< ILocalPacketHandler >
 
using CategoryPtr = std::unique_ptr< Category >
 
using DevicePtr = std::unique_ptr< Device >
 
using CounterSetPtr = std::unique_ptr< CounterSet >
 
using CounterPtr = std::shared_ptr< Counter >
 
using Categories = std::unordered_set< CategoryPtr >
 
using Devices = std::unordered_map< uint16_t, DevicePtr >
 
using CounterSets = std::unordered_map< uint16_t, CounterSetPtr >
 
using Counters = std::unordered_map< uint16_t, CounterPtr >
 
using CategoriesIt = Categories::const_iterator
 
using DevicesIt = Devices::const_iterator
 
using CounterSetsIt = CounterSets::const_iterator
 
using CountersIt = Counters::const_iterator
 
using IPacketBufferPtr = std::unique_ptr< IPacketBuffer >
 
using LabelMap = std::map< uint64_t, arm::pipe::ITimelineDecoder::Label >
 
using Attribute = std::pair< std::string, std::string >
 
using Attributes = std::map< std::string, Attribute >
 
using Entities = std::map< uint64_t, Entity >
 
using Relationships = std::map< uint64_t, ModelRelationship >
 
using EventClasses = std::map< uint64_t, EventClassObj >
 
using Events = std::map< uint64_t, EventObj >
 

Enumerations

enum  TargetEndianness { BeWire, LeWire }
 
enum  ProfilingRelationshipType { RetentionLink, ExecutionLink, DataLink, LabelLink }
 
enum  ProfilingState { Uninitialised, NotConnected, WaitingForAck, Active }
 
enum  TimelinePacketStatus { Ok, Error, BufferExhaustion }
 

Functions

constexpr char const * GetProfilingStateName (ProfilingState state)
 
uint16_t GetNextUid (bool peekOnly)
 
std::vector< uint16_t > GetNextCounterUids (uint16_t firstUid, uint16_t cores)
 
void WriteBytes (const IPacketBufferPtr &packetBuffer, unsigned int offset, const void *value, unsigned int valueSize)
 
uint32_t ConstructHeader (uint32_t packetFamily, uint32_t packetId)
 
uint32_t ConstructHeader (uint32_t packetFamily, uint32_t packetClass, uint32_t packetType)
 
void WriteUint64 (const std::unique_ptr< IPacketBuffer > &packetBuffer, unsigned int offset, uint64_t value)
 
void WriteUint32 (const IPacketBufferPtr &packetBuffer, unsigned int offset, uint32_t value)
 
void WriteUint16 (const IPacketBufferPtr &packetBuffer, unsigned int offset, uint16_t value)
 
void WriteUint8 (const IPacketBufferPtr &packetBuffer, unsigned int offset, uint8_t value)
 
void WriteBytes (unsigned char *buffer, unsigned int offset, const void *value, unsigned int valueSize)
 
void WriteUint64 (unsigned char *buffer, unsigned int offset, uint64_t value)
 
void WriteUint32 (unsigned char *buffer, unsigned int offset, uint32_t value)
 
void WriteUint16 (unsigned char *buffer, unsigned int offset, uint16_t value)
 
void WriteUint8 (unsigned char *buffer, unsigned int offset, uint8_t value)
 
void ReadBytes (const IPacketBufferPtr &packetBuffer, unsigned int offset, unsigned int valueSize, uint8_t outValue[])
 
uint64_t ReadUint64 (const IPacketBufferPtr &packetBuffer, unsigned int offset)
 
uint32_t ReadUint32 (const IPacketBufferPtr &packetBuffer, unsigned int offset)
 
uint16_t ReadUint16 (const IPacketBufferPtr &packetBuffer, unsigned int offset)
 
uint8_t ReadUint8 (const IPacketBufferPtr &packetBuffer, unsigned int offset)
 
void ReadBytes (const unsigned char *buffer, unsigned int offset, unsigned int valueSize, uint8_t outValue[])
 
uint64_t ReadUint64 (const unsigned char *buffer, unsigned int offset)
 
uint32_t ReadUint32 (const unsigned char *buffer, unsigned int offset)
 
uint16_t ReadUint16 (const unsigned char *buffer, unsigned int offset)
 
uint8_t ReadUint8 (const unsigned char *buffer, unsigned int offset)
 
std::string GetSoftwareInfo ()
 
std::string GetHardwareVersion ()
 
std::string GetSoftwareVersion ()
 
std::string GetProcessName ()
 
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. More...
 
std::pair< uint32_t, uint32_t > CreateTimelineMessagePacketHeader (unsigned int dataLength)
 Creates a packet header for the timeline messages: More...
 
TimelinePacketStatus WriteTimelineLabelBinaryPacket (uint64_t profilingGuid, const std::string &label, unsigned char *buffer, unsigned int remainingBufferSize, unsigned int &numberOfBytesWritten)
 
TimelinePacketStatus WriteTimelineEntityBinary (uint64_t profilingGuid, unsigned char *buffer, unsigned int remainingBufferSize, unsigned int &numberOfBytesWritten)
 
TimelinePacketStatus WriteTimelineRelationshipBinary (ProfilingRelationshipType relationshipType, uint64_t relationshipGuid, uint64_t headGuid, uint64_t tailGuid, uint64_t attributeGuid, unsigned char *buffer, unsigned int remainingBufferSize, unsigned int &numberOfBytesWritten)
 
TimelinePacketStatus WriteTimelineMessageDirectoryPackage (unsigned char *buffer, unsigned int remainingBufferSize, unsigned int &numberOfBytesWritten)
 
TimelinePacketStatus WriteTimelineEventClassBinary (uint64_t profilingGuid, uint64_t nameGuid, unsigned char *buffer, unsigned int remainingBufferSize, unsigned int &numberOfBytesWritten)
 
TimelinePacketStatus WriteTimelineEventBinary (uint64_t timestamp, int threadId, uint64_t profilingGuid, unsigned char *buffer, unsigned int remainingBufferSize, unsigned int &numberOfBytesWritten)
 
std::string CentreAlignFormatting (const std::string &stringToPass, const int spacingWidth)
 
void PrintDeviceDetails (const std::pair< const unsigned short, std::unique_ptr< Device >> &devicePair)
 
void PrintCounterSetDetails (const std::pair< const unsigned short, std::unique_ptr< CounterSet >> &counterSetPair)
 
void PrintCounterDetails (std::shared_ptr< Counter > &counter)
 
void PrintCategoryDetails (const std::unique_ptr< Category > &category, std::unordered_map< unsigned short, std::shared_ptr< Counter >> counterMap)
 
void PrintCounterDirectory (ICounterDirectory &counterDirectory)
 
uint64_t GetTimestamp ()
 
arm::pipe::Packet ReceivePacket (const unsigned char *buffer, uint32_t length)
 
void WriteBytes (const IPacketBuffer &packetBuffer, unsigned int offset, const void *value, unsigned int valueSize)
 
void WriteUint64 (const IPacketBufferPtr &packetBuffer, unsigned int offset, uint64_t value)
 
std::vector< std::string > GetModelDescription (const TimelineModel &model)
 
std::string GetEntityDescription (const Entity &entity)
 
std::string GetChildDescription (Entity *entity)
 
std::string GetConnectionDescription (const Connection &connection)
 
std::string GetExecutionDescription (Entity *execution)
 
std::string GetEventDescription (EventObj *event)
 

Variables

uint32_t uint16_t_size = sizeof(uint16_t)
 
uint32_t uint32_t_size = sizeof(uint32_t)
 
constexpr unsigned int ThreadIdSize = sizeof(int)
 

Typedef Documentation

◆ Attribute

using Attribute = std::pair<std::string, std::string>

Definition at line 21 of file TimelineModel.hpp.

◆ Attributes

using Attributes = std::map<std::string, Attribute>

Definition at line 22 of file TimelineModel.hpp.

◆ Categories

using Categories = std::unordered_set<CategoryPtr>

Definition at line 35 of file ICounterDirectory.hpp.

◆ CategoriesIt

using CategoriesIt = Categories::const_iterator

Definition at line 41 of file ICounterDirectory.hpp.

◆ CategoryPtr

using CategoryPtr = std::unique_ptr<Category>

Definition at line 29 of file ICounterDirectory.hpp.

◆ CounterPtr

using CounterPtr = std::shared_ptr<Counter>

Definition at line 32 of file ICounterDirectory.hpp.

◆ Counters

using Counters = std::unordered_map<uint16_t, CounterPtr>

Definition at line 38 of file ICounterDirectory.hpp.

◆ CounterSetPtr

using CounterSetPtr = std::unique_ptr<CounterSet>

Definition at line 31 of file ICounterDirectory.hpp.

◆ CounterSets

using CounterSets = std::unordered_map<uint16_t, CounterSetPtr>

Definition at line 37 of file ICounterDirectory.hpp.

◆ CounterSetsIt

using CounterSetsIt = CounterSets::const_iterator

Definition at line 43 of file ICounterDirectory.hpp.

◆ CountersIt

using CountersIt = Counters::const_iterator

Definition at line 44 of file ICounterDirectory.hpp.

◆ DevicePtr

using DevicePtr = std::unique_ptr<Device>

Definition at line 30 of file ICounterDirectory.hpp.

◆ Devices

using Devices = std::unordered_map<uint16_t, DevicePtr>

Definition at line 36 of file ICounterDirectory.hpp.

◆ DevicesIt

using DevicesIt = Devices::const_iterator

Definition at line 42 of file ICounterDirectory.hpp.

◆ Entities

using Entities = std::map<uint64_t, Entity>

Definition at line 136 of file TimelineModel.hpp.

◆ EventClasses

using EventClasses = std::map<uint64_t, EventClassObj>

Definition at line 144 of file TimelineModel.hpp.

◆ Events

using Events = std::map<uint64_t, EventObj>

Definition at line 145 of file TimelineModel.hpp.

◆ IBackendProfilingContextUniquePtr

Definition at line 28 of file IBackendProfilingContext.hpp.

◆ ILocalPacketHandlerPtr

using ILocalPacketHandlerPtr = std::unique_ptr<ILocalPacketHandler>

Definition at line 73 of file ILocalPacketHandler.hpp.

◆ ILocalPacketHandlerSharedPtr

Definition at line 74 of file ILocalPacketHandler.hpp.

◆ IPacketBufferPtr

using IPacketBufferPtr = std::unique_ptr<IPacketBuffer>

Definition at line 44 of file IPacketBuffer.hpp.

◆ LabelMap

using LabelMap = std::map<uint64_t, arm::pipe::ITimelineDecoder::Label>

Definition at line 20 of file TimelineModel.hpp.

◆ Relationships

using Relationships = std::map<uint64_t, ModelRelationship>

Definition at line 143 of file TimelineModel.hpp.

Enumeration Type Documentation

◆ ProfilingRelationshipType

Enumerator
RetentionLink 
ExecutionLink 

Head retains(parents) Tail.

DataLink 

Head execution start depends on Tail execution completion.

LabelLink 

Head uses data of Tail.

Head uses label Tail (Tail MUST be a guid of a label).

Definition at line 18 of file ISendTimelinePacket.hpp.

19 {
20  RetentionLink, /// Head retains(parents) Tail
21  ExecutionLink, /// Head execution start depends on Tail execution completion
22  DataLink, /// Head uses data of Tail
23  LabelLink /// Head uses label Tail (Tail MUST be a guid of a label).
24 };
Head execution start depends on Tail execution completion.

◆ ProfilingState

◆ TargetEndianness

enum TargetEndianness
strong
Enumerator
BeWire 
LeWire 

Definition at line 30 of file ILocalPacketHandler.hpp.

◆ TimelinePacketStatus

Function Documentation

◆ CentreAlignFormatting()

std::string CentreAlignFormatting ( const std::string &  stringToPass,
const int  spacingWidth 
)

◆ ConstructHeader() [1/2]

uint32_t ConstructHeader ( uint32_t  packetFamily,
uint32_t  packetId 
)

Definition at line 100 of file ProfilingUtils.cpp.

Referenced by SendCounterPacket::SendStreamMetaDataPacket(), and TEST_SUITE().

102 {
103  return (( packetFamily & 0x0000003F ) << 26 )|
104  (( packetId & 0x000003FF ) << 16 );
105 }

◆ ConstructHeader() [2/2]

uint32_t ConstructHeader ( uint32_t  packetFamily,
uint32_t  packetClass,
uint32_t  packetType 
)

Definition at line 107 of file ProfilingUtils.cpp.

108 {
109  return ((packetFamily & 0x0000003F) << 26) |
110  ((packetClass & 0x0000007F) << 19) |
111  ((packetType & 0x00000007) << 16);
112 }

◆ CreateTimelineMessagePacketHeader()

std::pair<uint32_t, uint32_t> armnn::profiling::CreateTimelineMessagePacketHeader ( unsigned int  dataLength)

Creates a packet header for the timeline messages:

  • declareLabel
  • declareEntity
  • declareEventClass
  • declareRelationship
  • declareEvent
Parameters
dataLengthThe length of the message body in bytes
Returns
Pair of uint32_t containing word0 and word1 of the header

Definition at line 303 of file ProfilingUtils.cpp.

References CreateTimelinePacketHeader().

304 {
305  return CreateTimelinePacketHeader(1, // Packet family
306  0, // Packet class
307  1, // Packet type
308  0, // Stream id
309  0, // Sequence number
310  dataLength); // Data length
311 }
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.

◆ CreateTimelinePacketHeader()

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.

packetFamiliy Timeline Packet Family packetClass Timeline Packet Class packetType Timeline Packet Type streamId Stream identifier seqeunceNumbered When non-zero the 4 bytes following the header is a u32 sequence number dataLength Unsigned 24-bit integer. Length of data, in bytes. Zero is permitted

Returns
Pair of uint32_t containing word0 and word1 of the header

Definition at line 263 of file ProfilingUtils.cpp.

Referenced by SendTimelinePacket::Commit(), CreateTimelineMessagePacketHeader(), and WriteTimelineMessageDirectoryPackage().

269 {
270  // Packet header word 0:
271  // 26:31 [6] packet_family: timeline Packet Family, value 0b000001
272  // 19:25 [7] packet_class: packet class
273  // 16:18 [3] packet_type: packet type
274  // 8:15 [8] reserved: all zeros
275  // 0:7 [8] stream_id: stream identifier
276  uint32_t packetHeaderWord0 = ((packetFamily & 0x0000003F) << 26) |
277  ((packetClass & 0x0000007F) << 19) |
278  ((packetType & 0x00000007) << 16) |
279  ((streamId & 0x00000007) << 0);
280 
281  // Packet header word 1:
282  // 25:31 [7] reserved: all zeros
283  // 24 [1] sequence_numbered: when non-zero the 4 bytes following the header is a u32 sequence number
284  // 0:23 [24] data_length: unsigned 24-bit integer. Length of data, in bytes. Zero is permitted
285  uint32_t packetHeaderWord1 = ((sequenceNumbered & 0x00000001) << 24) |
286  ((dataLength & 0x00FFFFFF) << 0);
287 
288  return std::make_pair(packetHeaderWord0, packetHeaderWord1);
289 }

◆ GetChildDescription()

std::string GetChildDescription ( Entity entity)

Definition at line 374 of file TimelineModel.cpp.

References GetEntityDescription().

Referenced by TimelineModel::GetEventClasses(), and GetModelDescription().

375 {
376  std::stringstream ss;
377  ss << " child: " << GetEntityDescription(*entity);
378  return ss.str();
379 }
std::string GetEntityDescription(const Entity &entity)

◆ GetConnectionDescription()

std::string GetConnectionDescription ( const Connection connection)

Definition at line 381 of file TimelineModel.cpp.

References Connection::GetGuid(), Entity::GetGuid(), Connection::GetHead(), and Connection::GetTail().

Referenced by TimelineModel::GetEventClasses(), and GetModelDescription().

382 {
383  std::stringstream ss;
384  ss << " connection [" << connection.GetGuid() << "] from entity [";
385  ss << connection.GetHead()->GetGuid() << "] to entity [" << connection.GetTail()->GetGuid() << "]";
386  return ss.str();
387 }

◆ GetEntityDescription()

std::string GetEntityDescription ( const Entity entity)

Definition at line 357 of file TimelineModel.cpp.

References Entity::GetAttributes(), and Entity::GetGuid().

Referenced by GetChildDescription(), TimelineModel::GetEventClasses(), GetExecutionDescription(), and GetModelDescription().

358 {
359  std::stringstream ss;
360  ss << "Entity [" << entity.GetGuid() << "]";
361  for (auto& attributeEntry : entity.GetAttributes())
362  {
363  if (profiling::LabelsAndEventClasses::PROCESS_ID_LABEL == attributeEntry.second.first)
364  {
365  ss << " " << attributeEntry.second.first << " = [processId]";
366  }
367  else {
368  ss << " " << attributeEntry.second.first << " = " << attributeEntry.second.second;
369  }
370  }
371  return ss.str();
372 }

◆ GetEventDescription()

std::string GetEventDescription ( EventObj event)

Definition at line 396 of file TimelineModel.cpp.

Referenced by TimelineModel::GetEventClasses(), and GetModelDescription().

397 {
398  std::stringstream ss;
399  ss << " event: [" << event->GetGuid() << "] class [" << event->GetEventClass() << "]";
400  return ss.str();
401 }

◆ GetExecutionDescription()

std::string GetExecutionDescription ( Entity execution)

Definition at line 389 of file TimelineModel.cpp.

References GetEntityDescription().

Referenced by TimelineModel::GetEventClasses(), and GetModelDescription().

390 {
391  std::stringstream ss;
392  ss << " execution: " << GetEntityDescription(*execution);
393  return ss.str();
394 }
std::string GetEntityDescription(const Entity &entity)

◆ GetHardwareVersion()

std::string GetHardwareVersion ( )

Definition at line 232 of file ProfilingUtils.cpp.

Referenced by GetStreamMetaDataPacketSize(), SendCounterPacket::SendStreamMetaDataPacket(), and TEST_SUITE().

233 {
234  return std::string();
235 }

◆ GetModelDescription()

std::vector< std::string > GetModelDescription ( const TimelineModel model)

Definition at line 330 of file TimelineModel.cpp.

References GetChildDescription(), GetConnectionDescription(), TimelineModel::GetEntities(), GetEntityDescription(), GetEventDescription(), and GetExecutionDescription().

Referenced by TimelineModel::GetEventClasses(), and TEST_SUITE().

331 {
332  std::vector<std::string> desc;
333  for (auto& entry : model.GetEntities())
334  {
335  auto& entity = entry.second;
336  desc.push_back(GetEntityDescription(entity));
337  for (auto& connection : entity.GetConnections())
338  {
339  desc.push_back(GetConnectionDescription(connection));
340  }
341  for (auto child : entity.GetChildren())
342  {
343  desc.push_back(GetChildDescription(child));
344  }
345  for (auto execution : entity.GetExecutions())
346  {
347  desc.push_back(GetExecutionDescription(execution));
348  }
349  for (auto event : entity.GetEvents())
350  {
351  desc.push_back(GetEventDescription(event));
352  }
353  }
354  return desc;
355 }
std::string GetConnectionDescription(const Connection &connection)
std::string GetExecutionDescription(Entity *execution)
std::string GetEntityDescription(const Entity &entity)
std::string GetEventDescription(EventObj *event)
std::string GetChildDescription(Entity *entity)

◆ GetNextCounterUids()

std::vector< uint16_t > GetNextCounterUids ( uint16_t  firstUid,
uint16_t  cores 
)

Definition at line 78 of file ProfilingUtils.cpp.

Referenced by CounterDirectory::RegisterCounter(), MockCounterDirectory::RegisterCounter(), and TEST_SUITE().

79 {
80  // Check that it is possible to generate the next counter UID without causing an overflow (throws in case of error)
81  ThrowIfCantGenerateNextUid(firstUid, cores);
82 
83  // Get the next counter UIDs
84  size_t counterUidsSize = cores == 0 ? 1 : cores;
85  std::vector<uint16_t> counterUids(counterUidsSize, 0);
86  for (size_t i = 0; i < counterUidsSize; i++)
87  {
88  counterUids[i] = firstUid++;
89  }
90  return counterUids;
91 }

◆ GetNextUid()

uint16_t GetNextUid ( bool  peekOnly)

Definition at line 58 of file ProfilingUtils.cpp.

Referenced by CounterDirectory::RegisterCounterSet(), MockCounterDirectory::RegisterCounterSet(), CounterDirectory::RegisterDevice(), MockCounterDirectory::RegisterDevice(), and TEST_SUITE().

59 {
60  // The UID used for profiling objects and events. The first valid UID is 1, as 0 is a reserved value
61  static uint16_t uid = 1;
62 
63  // Check that it is possible to generate the next UID without causing an overflow (throws in case of error)
64  ThrowIfCantGenerateNextUid(uid);
65 
66  if (peekOnly)
67  {
68  // Peek only
69  return uid;
70  }
71  else
72  {
73  // Get the next UID
74  return uid++;
75  }
76 }

◆ GetProcessName()

std::string GetProcessName ( )

Definition at line 243 of file ProfilingUtils.cpp.

Referenced by GetStreamMetaDataPacketSize(), SendCounterPacket::SendStreamMetaDataPacket(), and TEST_SUITE().

244 {
245  std::ifstream comm("/proc/self/comm");
246  std::string name;
247  getline(comm, name);
248  return name;
249 }

◆ GetProfilingStateName()

constexpr char const* armnn::profiling::GetProfilingStateName ( ProfilingState  state)

Definition at line 59 of file ProfilingStateMachine.hpp.

References Active, NotConnected, Uninitialised, and WaitingForAck.

Referenced by PerJobCounterSelectionCommandHandler::operator()(), DeactivateTimelineReportingCommandHandler::operator()(), RequestCounterDirectoryCommandHandler::operator()(), ActivateTimelineReportingCommandHandler::operator()(), ConnectionAcknowledgedCommandHandler::operator()(), and PeriodicCounterSelectionCommandHandler::operator()().

60 {
61  switch (state)
62  {
63  case ProfilingState::Uninitialised: return "Uninitialised";
64  case ProfilingState::NotConnected: return "NotConnected";
65  case ProfilingState::WaitingForAck: return "WaitingForAck";
66  case ProfilingState::Active: return "Active";
67  default: return "Unknown";
68  }
69 }

◆ GetSoftwareInfo()

std::string GetSoftwareInfo ( )

Definition at line 227 of file ProfilingUtils.cpp.

Referenced by GetStreamMetaDataPacketSize(), SendCounterPacket::SendStreamMetaDataPacket(), and TEST_SUITE().

228 {
229  return std::string("ArmNN");
230 }

◆ GetSoftwareVersion()

std::string GetSoftwareVersion ( )

Definition at line 237 of file ProfilingUtils.cpp.

References ARMNN_MAJOR_VERSION, and ARMNN_MINOR_VERSION.

Referenced by GetStreamMetaDataPacketSize(), SendCounterPacket::SendStreamMetaDataPacket(), and TEST_SUITE().

238 {
239  std::string result = "Armnn " + std::to_string(ARMNN_MAJOR_VERSION) + "." + std::to_string(ARMNN_MINOR_VERSION);
240  return result;
241 }
#define ARMNN_MINOR_VERSION
Definition: Version.hpp:14
#define ARMNN_MAJOR_VERSION
Definition: Version.hpp:13

◆ GetTimestamp()

uint64_t GetTimestamp ( )

Definition at line 904 of file ProfilingUtils.cpp.

Referenced by TimelineUtilityMethods::RecordEvent(), and PeriodicCounterCapture::Stop().

905 {
906 #if USE_CLOCK_MONOTONIC_RAW
907  using clock = MonotonicClockRaw;
908 #else
909  using clock = std::chrono::steady_clock;
910 #endif
911 
912  // Take a timestamp
913  auto timestamp = std::chrono::duration_cast<std::chrono::nanoseconds>(clock::now().time_since_epoch());
914 
915  return static_cast<uint64_t>(timestamp.count());
916 }

◆ PrintCategoryDetails()

void armnn::profiling::PrintCategoryDetails ( const std::unique_ptr< Category > &  category,
std::unordered_map< unsigned short, std::shared_ptr< Counter >>  counterMap 
)

Definition at line 794 of file ProfilingUtils.cpp.

References CentreAlignFormatting(), and PrintCounterDetails().

Referenced by PrintCounterDirectory().

796 {
797  std::string categoryBody;
798  std::string categoryHeader;
799 
800  categoryHeader.append(CentreAlignFormatting("Name", 20));
801  categoryHeader.append(" | ");
802  categoryHeader.append(CentreAlignFormatting("Event Count", 14));
803  categoryHeader.append("\n");
804 
805  categoryBody.append(CentreAlignFormatting(category->m_Name, 20));
806  categoryBody.append(" | ");
807  categoryBody.append(CentreAlignFormatting(std::to_string(category->m_Counters.size()), 14));
808 
809  std::cout << "\n" << "\n";
810  std::cout << CentreAlignFormatting("CATEGORY", static_cast<int>(categoryHeader.size()));
811  std::cout << "\n";
812  std::cout << std::string(categoryHeader.size(), '=') << "\n";
813 
814  std::cout << categoryHeader;
815 
816  std::cout << std::string(categoryBody.size(), '-') << "\n";
817 
818  std::cout << categoryBody;
819 
820  std::string counterHeader;
821 
822  counterHeader.append(CentreAlignFormatting("Counter Name", 20));
823  counterHeader.append(" | ");
824  counterHeader.append(CentreAlignFormatting("Description", 50));
825  counterHeader.append(" | ");
826  counterHeader.append(CentreAlignFormatting("Units", 14));
827  counterHeader.append(" | ");
828  counterHeader.append(CentreAlignFormatting("UID", 6));
829  counterHeader.append(" | ");
830  counterHeader.append(CentreAlignFormatting("Max UID", 10));
831  counterHeader.append(" | ");
832  counterHeader.append(CentreAlignFormatting("Class", 8));
833  counterHeader.append(" | ");
834  counterHeader.append(CentreAlignFormatting("Interpolation", 14));
835  counterHeader.append(" | ");
836  counterHeader.append(CentreAlignFormatting("Multiplier", 20));
837  counterHeader.append(" | ");
838  counterHeader.append(CentreAlignFormatting("Counter set UID", 16));
839  counterHeader.append(" | ");
840  counterHeader.append(CentreAlignFormatting("Device UID", 14));
841  counterHeader.append("\n");
842 
843  std::cout << "\n" << "\n";
844  std::cout << CentreAlignFormatting("EVENTS IN CATEGORY: " + category->m_Name,
845  static_cast<int>(counterHeader.size()));
846  std::cout << "\n";
847  std::cout << std::string(counterHeader.size(), '=') << "\n";
848  std::cout << counterHeader;
849  for (auto& it: category->m_Counters) {
850  auto search = counterMap.find(it);
851  if(search != counterMap.end()) {
852  PrintCounterDetails(search->second);
853  }
854  }
855 }
void PrintCounterDetails(std::shared_ptr< Counter > &counter)
std::string CentreAlignFormatting(const std::string &stringToPass, const int spacingWidth)

◆ PrintCounterDetails()

void armnn::profiling::PrintCounterDetails ( std::shared_ptr< Counter > &  counter)

Definition at line 763 of file ProfilingUtils.cpp.

References CentreAlignFormatting().

Referenced by PrintCategoryDetails().

764 {
765  std::string body;
766 
767  body.append(CentreAlignFormatting(counter->m_Name, 20));
768  body.append(" | ");
769  body.append(CentreAlignFormatting(counter->m_Description, 50));
770  body.append(" | ");
771  body.append(CentreAlignFormatting(counter->m_Units, 14));
772  body.append(" | ");
773  body.append(CentreAlignFormatting(std::to_string(counter->m_Uid), 6));
774  body.append(" | ");
775  body.append(CentreAlignFormatting(std::to_string(counter->m_MaxCounterUid), 10));
776  body.append(" | ");
777  body.append(CentreAlignFormatting(std::to_string(counter->m_Class), 8));
778  body.append(" | ");
779  body.append(CentreAlignFormatting(std::to_string(counter->m_Interpolation), 14));
780  body.append(" | ");
781  body.append(CentreAlignFormatting(std::to_string(counter->m_Multiplier), 20));
782  body.append(" | ");
783  body.append(CentreAlignFormatting(std::to_string(counter->m_CounterSetUid), 16));
784  body.append(" | ");
785  body.append(CentreAlignFormatting(std::to_string(counter->m_DeviceUid), 14));
786 
787  body.append("\n");
788 
789  std::cout << std::string(body.size(), '-') << "\n";
790 
791  std::cout << body;
792 }
std::string CentreAlignFormatting(const std::string &stringToPass, const int spacingWidth)

◆ PrintCounterDirectory()

void PrintCounterDirectory ( ICounterDirectory counterDirectory)

Definition at line 857 of file ProfilingUtils.cpp.

References CentreAlignFormatting(), ICounterDirectory::GetCategories(), ICounterDirectory::GetCounters(), ICounterDirectory::GetCounterSets(), ICounterDirectory::GetDevices(), PrintCategoryDetails(), PrintCounterSetDetails(), and PrintDeviceDetails().

Referenced by DirectoryCaptureCommandHandler::operator()().

858 {
859  std::string devicesHeader;
860 
861  devicesHeader.append(CentreAlignFormatting("Device name", 20));
862  devicesHeader.append(" | ");
863  devicesHeader.append(CentreAlignFormatting("UID", 13));
864  devicesHeader.append(" | ");
865  devicesHeader.append(CentreAlignFormatting("Cores", 10));
866  devicesHeader.append("\n");
867 
868  std::cout << "\n" << "\n";
869  std::cout << CentreAlignFormatting("DEVICES", static_cast<int>(devicesHeader.size()));
870  std::cout << "\n";
871  std::cout << std::string(devicesHeader.size(), '=') << "\n";
872  std::cout << devicesHeader;
873  for (auto& it: counterDirectory.GetDevices()) {
874  PrintDeviceDetails(it);
875  }
876 
877  std::string counterSetHeader;
878 
879  counterSetHeader.append(CentreAlignFormatting("Counter set name", 20));
880  counterSetHeader.append(" | ");
881  counterSetHeader.append(CentreAlignFormatting("UID", 13));
882  counterSetHeader.append(" | ");
883  counterSetHeader.append(CentreAlignFormatting("Count", 10));
884  counterSetHeader.append("\n");
885 
886  std::cout << "\n" << "\n";
887  std::cout << CentreAlignFormatting("COUNTER SETS", static_cast<int>(counterSetHeader.size()));
888  std::cout << "\n";
889  std::cout << std::string(counterSetHeader.size(), '=') << "\n";
890 
891  std::cout << counterSetHeader;
892 
893  for (auto& it: counterDirectory.GetCounterSets()) {
895  }
896 
897  auto counters = counterDirectory.GetCounters();
898  for (auto& it: counterDirectory.GetCategories()) {
899  PrintCategoryDetails(it, counters);
900  }
901  std::cout << "\n";
902 }
void PrintDeviceDetails(const std::pair< const unsigned short, std::unique_ptr< Device >> &devicePair)
void PrintCategoryDetails(const std::unique_ptr< Category > &category, std::unordered_map< unsigned short, std::shared_ptr< Counter >> counterMap)
void PrintCounterSetDetails(const std::pair< const unsigned short, std::unique_ptr< CounterSet >> &counterSetPair)
std::string CentreAlignFormatting(const std::string &stringToPass, const int spacingWidth)

◆ PrintCounterSetDetails()

void armnn::profiling::PrintCounterSetDetails ( const std::pair< const unsigned short, std::unique_ptr< CounterSet >> &  counterSetPair)

Definition at line 747 of file ProfilingUtils.cpp.

References CentreAlignFormatting().

Referenced by PrintCounterDirectory().

748 {
749  std::string body;
750 
751  body.append(CentreAlignFormatting(counterSetPair.second->m_Name, 20));
752  body.append(" | ");
753  body.append(CentreAlignFormatting(std::to_string(counterSetPair.first), 13));
754  body.append(" | ");
755  body.append(CentreAlignFormatting(std::to_string(counterSetPair.second->m_Count), 10));
756  body.append("\n");
757 
758  std::cout << std::string(body.size(), '-') << "\n";
759 
760  std::cout<< body;
761 }
std::string CentreAlignFormatting(const std::string &stringToPass, const int spacingWidth)

◆ PrintDeviceDetails()

void armnn::profiling::PrintDeviceDetails ( const std::pair< const unsigned short, std::unique_ptr< Device >> &  devicePair)

Definition at line 732 of file ProfilingUtils.cpp.

References CentreAlignFormatting().

Referenced by PrintCounterDirectory().

733 {
734  std::string body;
735 
736  body.append(CentreAlignFormatting(devicePair.second->m_Name, 20));
737  body.append(" | ");
738  body.append(CentreAlignFormatting(std::to_string(devicePair.first), 13));
739  body.append(" | ");
740  body.append(CentreAlignFormatting(std::to_string(devicePair.second->m_Cores), 10));
741  body.append("\n");
742 
743  std::cout << std::string(body.size(), '-') << "\n";
744  std::cout<< body;
745 }
std::string CentreAlignFormatting(const std::string &stringToPass, const int spacingWidth)

◆ ReadBytes() [1/2]

void ReadBytes ( const IPacketBufferPtr packetBuffer,
unsigned int  offset,
unsigned int  valueSize,
uint8_t  outValue[] 
)

Definition at line 167 of file ProfilingUtils.cpp.

References ARMNN_ASSERT.

Referenced by TEST_SUITE(), and VerifyTimelineEventBinaryPacket().

168 {
169  ARMNN_ASSERT(packetBuffer);
170 
171  ReadBytes(packetBuffer->GetReadableData(), offset, valueSize, outValue);
172 }
void ReadBytes(const unsigned char *buffer, unsigned int offset, unsigned int valueSize, uint8_t outValue[])
#define ARMNN_ASSERT(COND)
Definition: Assert.hpp:14

◆ ReadBytes() [2/2]

void ReadBytes ( const unsigned char *  buffer,
unsigned int  offset,
unsigned int  valueSize,
uint8_t  outValue[] 
)

Definition at line 202 of file ProfilingUtils.cpp.

203 {
204  arm::pipe::ReadBytes(buffer, offset, valueSize, outValue);
205 }
void ReadBytes(const unsigned char *buffer, unsigned int offset, unsigned int valueSize, uint8_t outValue[])

◆ ReadUint16() [1/2]

uint16_t ReadUint16 ( const IPacketBufferPtr packetBuffer,
unsigned int  offset 
)

Definition at line 188 of file ProfilingUtils.cpp.

References ARMNN_ASSERT.

Referenced by armnn::gatordmock::ReadString(), and TEST_SUITE().

189 {
190  ARMNN_ASSERT(packetBuffer);
191 
192  return ReadUint16(packetBuffer->GetReadableData(), offset);
193 }
uint16_t ReadUint16(const unsigned char *buffer, unsigned int offset)
#define ARMNN_ASSERT(COND)
Definition: Assert.hpp:14

◆ ReadUint16() [2/2]

uint16_t ReadUint16 ( const unsigned char *  buffer,
unsigned int  offset 
)

Definition at line 217 of file ProfilingUtils.cpp.

218 {
219  return arm::pipe::ReadUint16(buffer, offset);
220 }
uint16_t ReadUint16(const unsigned char *buffer, unsigned int offset)

◆ ReadUint32() [1/2]

uint32_t ReadUint32 ( const IPacketBufferPtr packetBuffer,
unsigned int  offset 
)

◆ ReadUint32() [2/2]

uint32_t ReadUint32 ( const unsigned char *  buffer,
unsigned int  offset 
)

Definition at line 212 of file ProfilingUtils.cpp.

213 {
214  return arm::pipe::ReadUint32(buffer, offset);
215 }
uint32_t ReadUint32(const unsigned char *buffer, unsigned int offset)

◆ ReadUint64() [1/2]

uint64_t ReadUint64 ( const IPacketBufferPtr packetBuffer,
unsigned int  offset 
)

Definition at line 174 of file ProfilingUtils.cpp.

References ARMNN_ASSERT.

Referenced by TEST_SUITE(), VerifyTimelineEntityBinaryPacketData(), VerifyTimelineEventBinaryPacket(), VerifyTimelineEventClassBinaryPacketData(), VerifyTimelineLabelBinaryPacketData(), and VerifyTimelineRelationshipBinaryPacketData().

175 {
176  ARMNN_ASSERT(packetBuffer);
177 
178  return ReadUint64(packetBuffer->GetReadableData(), offset);
179 }
#define ARMNN_ASSERT(COND)
Definition: Assert.hpp:14
uint64_t ReadUint64(const unsigned char *buffer, unsigned int offset)

◆ ReadUint64() [2/2]

uint64_t ReadUint64 ( const unsigned char *  buffer,
unsigned int  offset 
)

Definition at line 207 of file ProfilingUtils.cpp.

208 {
209  return arm::pipe::ReadUint64(buffer, offset);
210 }
uint64_t ReadUint64(const unsigned char *buffer, unsigned int offset)

◆ ReadUint8() [1/2]

uint8_t ReadUint8 ( const IPacketBufferPtr packetBuffer,
unsigned int  offset 
)

Definition at line 195 of file ProfilingUtils.cpp.

References ARMNN_ASSERT.

Referenced by DirectoryCaptureCommandHandler::GetCounterDirectory(), and TEST_SUITE().

196 {
197  ARMNN_ASSERT(packetBuffer);
198 
199  return ReadUint8(packetBuffer->GetReadableData(), offset);
200 }
uint8_t ReadUint8(const unsigned char *buffer, unsigned int offset)
#define ARMNN_ASSERT(COND)
Definition: Assert.hpp:14

◆ ReadUint8() [2/2]

uint8_t ReadUint8 ( const unsigned char *  buffer,
unsigned int  offset 
)

Definition at line 222 of file ProfilingUtils.cpp.

223 {
224  return arm::pipe::ReadUint8(buffer, offset);
225 }
uint8_t ReadUint8(const unsigned char *buffer, unsigned int offset)

◆ ReceivePacket()

arm::pipe::Packet ReceivePacket ( const unsigned char *  buffer,
uint32_t  length 
)

Definition at line 918 of file ProfilingUtils.cpp.

Referenced by FileOnlyProfilingConnection::WritePacket().

919 {
920  if (buffer == nullptr)
921  {
922  throw arm::pipe::ProfilingException("data buffer is nullptr");
923  }
924  if (length < 8)
925  {
926  throw arm::pipe::ProfilingException("length of data buffer is less than 8");
927  }
928 
929  uint32_t metadataIdentifier = 0;
930  std::memcpy(&metadataIdentifier, buffer, sizeof(metadataIdentifier));
931 
932  uint32_t dataLength = 0;
933  std::memcpy(&dataLength, buffer + 4u, sizeof(dataLength));
934 
935  std::unique_ptr<unsigned char[]> packetData;
936  if (dataLength > 0)
937  {
938  packetData = std::make_unique<unsigned char[]>(dataLength);
939  std::memcpy(packetData.get(), buffer + 8u, dataLength);
940  }
941 
942  return arm::pipe::Packet(metadataIdentifier, dataLength, packetData);
943 }

◆ WriteBytes() [1/3]

void armnn::profiling::WriteBytes ( const IPacketBuffer packetBuffer,
unsigned int  offset,
const void *  value,
unsigned int  valueSize 
)

◆ WriteBytes() [2/3]

void armnn::profiling::WriteBytes ( const IPacketBufferPtr packetBuffer,
unsigned int  offset,
const void *  value,
unsigned int  valueSize 
)

Definition at line 93 of file ProfilingUtils.cpp.

References ARMNN_ASSERT.

Referenced by WriteTimelineEventBinary().

94 {
95  ARMNN_ASSERT(packetBuffer);
96 
97  WriteBytes(packetBuffer->GetWritableData(), offset, value, valueSize);
98 }
void WriteBytes(unsigned char *buffer, unsigned int offset, const void *value, unsigned int valueSize)
#define ARMNN_ASSERT(COND)
Definition: Assert.hpp:14

◆ WriteBytes() [3/3]

void WriteBytes ( unsigned char *  buffer,
unsigned int  offset,
const void *  value,
unsigned int  valueSize 
)

Definition at line 142 of file ProfilingUtils.cpp.

143 {
144  arm::pipe::WriteBytes(buffer, offset, value, valueSize);
145 }
void WriteBytes(unsigned char *buffer, unsigned int offset, const void *value, unsigned int valueSize)

◆ WriteTimelineEntityBinary()

TimelinePacketStatus WriteTimelineEntityBinary ( uint64_t  profilingGuid,
unsigned char *  buffer,
unsigned int  remainingBufferSize,
unsigned int &  numberOfBytesWritten 
)

Definition at line 376 of file ProfilingUtils.cpp.

References BufferExhaustion, Ok, uint32_t_size, WriteUint32(), and WriteUint64().

Referenced by SendTimelinePacket::SendTimelineEntityBinaryPacket(), and TEST_SUITE().

380 {
381  // Initialize the output value
382  numberOfBytesWritten = 0;
383 
384  // Check that the given buffer is valid
385  if (buffer == nullptr || remainingBufferSize == 0)
386  {
387  return TimelinePacketStatus::BufferExhaustion;
388  }
389 
390  // Utils
391  unsigned int uint32_t_size = sizeof(uint32_t);
392  unsigned int uint64_t_size = sizeof(uint64_t);
393 
394  // Calculate the length of the data (in bytes)
395  unsigned int timelineEntityDataLength = uint32_t_size + uint64_t_size; // decl_id + Profiling GUID
396 
397  // Check whether the timeline binary packet fits in the given buffer
398  if (timelineEntityDataLength > remainingBufferSize)
399  {
400  return TimelinePacketStatus::BufferExhaustion;
401  }
402 
403  // Initialize the offset for writing in the buffer
404  unsigned int offset = 0;
405 
406  // Write the decl_Id to the buffer
407  WriteUint32(buffer, offset, 1u);
408  offset += uint32_t_size;
409 
410  // Write the timeline binary packet payload to the buffer
411  WriteUint64(buffer, offset, profilingGuid); // Profiling GUID
412 
413  // Update the number of bytes written
414  numberOfBytesWritten = timelineEntityDataLength;
415 
416  return TimelinePacketStatus::Ok;
417 }
void WriteUint32(unsigned char *buffer, unsigned int offset, uint32_t value)
void WriteUint64(unsigned char *buffer, unsigned int offset, uint64_t value)

◆ WriteTimelineEventBinary()

TimelinePacketStatus WriteTimelineEventBinary ( uint64_t  timestamp,
int  threadId,
uint64_t  profilingGuid,
unsigned char *  buffer,
unsigned int  remainingBufferSize,
unsigned int &  numberOfBytesWritten 
)

Definition at line 675 of file ProfilingUtils.cpp.

References BufferExhaustion, Ok, ThreadIdSize, uint32_t_size, WriteBytes(), WriteUint32(), and WriteUint64().

Referenced by SendTimelinePacket::SendTimelineEventBinaryPacket(), and TEST_SUITE().

681 {
682  // Initialize the output value
683  numberOfBytesWritten = 0;
684  // Check that the given buffer is valid
685  if (buffer == nullptr || remainingBufferSize == 0)
686  {
687  return TimelinePacketStatus::BufferExhaustion;
688  }
689 
690  // Utils
691  unsigned int uint32_t_size = sizeof(uint32_t);
692  unsigned int uint64_t_size = sizeof(uint64_t);
693 
694  // decl_id of the timeline message
695  uint32_t declId = 4;
696 
697  // Calculate the length of the data (in bytes)
698  unsigned int timelineEventDataLength = uint32_t_size + // decl_id
699  uint64_t_size + // Timestamp
700  ThreadIdSize + // Thread id
701  uint64_t_size; // Profiling GUID
702 
703  // Check whether the timeline binary packet fits in the given buffer
704  if (timelineEventDataLength > remainingBufferSize)
705  {
706  return TimelinePacketStatus::BufferExhaustion;
707  }
708 
709  // Initialize the offset for writing in the buffer
710  unsigned int offset = 0;
711 
712  // Write the timeline binary payload to the buffer
713  WriteUint32(buffer, offset, declId); // decl_id
714  offset += uint32_t_size;
715  WriteUint64(buffer, offset, timestamp); // Timestamp
716  offset += uint64_t_size;
717  WriteBytes(buffer, offset, &threadId, ThreadIdSize); // Thread id
718  offset += ThreadIdSize;
719  WriteUint64(buffer, offset, profilingGuid); // Profiling GUID
720  offset += uint64_t_size;
721  // Update the number of bytes written
722  numberOfBytesWritten = timelineEventDataLength;
723 
724  return TimelinePacketStatus::Ok;
725 }
void WriteBytes(unsigned char *buffer, unsigned int offset, const void *value, unsigned int valueSize)
void WriteUint32(unsigned char *buffer, unsigned int offset, uint32_t value)
constexpr unsigned int ThreadIdSize
void WriteUint64(unsigned char *buffer, unsigned int offset, uint64_t value)

◆ WriteTimelineEventClassBinary()

TimelinePacketStatus WriteTimelineEventClassBinary ( uint64_t  profilingGuid,
uint64_t  nameGuid,
unsigned char *  buffer,
unsigned int  remainingBufferSize,
unsigned int &  numberOfBytesWritten 
)

Definition at line 628 of file ProfilingUtils.cpp.

References BufferExhaustion, Ok, uint32_t_size, WriteUint32(), and WriteUint64().

Referenced by SendTimelinePacket::SendTimelineEventClassBinaryPacket(), and TEST_SUITE().

633 {
634  // Initialize the output value
635  numberOfBytesWritten = 0;
636 
637  // Check that the given buffer is valid
638  if (buffer == nullptr || remainingBufferSize == 0)
639  {
640  return TimelinePacketStatus::BufferExhaustion;
641  }
642 
643  // Utils
644  unsigned int uint32_t_size = sizeof(uint32_t);
645  unsigned int uint64_t_size = sizeof(uint64_t);
646 
647  // decl_id of the timeline message
648  uint32_t declId = 2;
649 
650  // Calculate the length of the data (in bytes)
651  unsigned int dataSize = uint32_t_size + (uint64_t_size * 2); // decl_id + Profiling GUID + Name GUID
652 
653  // Check whether the timeline binary fits in the given buffer
654  if (dataSize > remainingBufferSize)
655  {
656  return TimelinePacketStatus::BufferExhaustion;
657  }
658 
659  // Initialize the offset for writing in the buffer
660  unsigned int offset = 0;
661 
662  // Write the timeline binary payload to the buffer
663  WriteUint32(buffer, offset, declId); // decl_id
664  offset += uint32_t_size;
665  WriteUint64(buffer, offset, profilingGuid); // Profiling GUID
666  offset += uint64_t_size;
667  WriteUint64(buffer, offset, nameGuid); // Name GUID
668 
669  // Update the number of bytes written
670  numberOfBytesWritten = dataSize;
671 
672  return TimelinePacketStatus::Ok;
673 }
void WriteUint32(unsigned char *buffer, unsigned int offset, uint32_t value)
void WriteUint64(unsigned char *buffer, unsigned int offset, uint64_t value)

◆ WriteTimelineLabelBinaryPacket()

TimelinePacketStatus WriteTimelineLabelBinaryPacket ( uint64_t  profilingGuid,
const std::string &  label,
unsigned char *  buffer,
unsigned int  remainingBufferSize,
unsigned int &  numberOfBytesWritten 
)

Definition at line 313 of file ProfilingUtils.cpp.

References BufferExhaustion, Error, armnn::numeric_cast(), Ok, uint32_t_size, WriteUint32(), and WriteUint64().

Referenced by SendTimelinePacket::SendTimelineLabelBinaryPacket(), and TEST_SUITE().

318 {
319  // Initialize the output value
320  numberOfBytesWritten = 0;
321 
322  // Check that the given buffer is valid
323  if (buffer == nullptr || remainingBufferSize == 0)
324  {
325  return TimelinePacketStatus::BufferExhaustion;
326  }
327 
328  // Utils
329  unsigned int uint32_t_size = sizeof(uint32_t);
330  unsigned int uint64_t_size = sizeof(uint64_t);
331 
332  // Convert the label into a SWTrace string
333  std::vector<uint32_t> swTraceLabel;
334  bool result = arm::pipe::StringToSwTraceString<arm::pipe::SwTraceCharPolicy>(label, swTraceLabel);
335  if (!result)
336  {
337  return TimelinePacketStatus::Error;
338  }
339 
340  // Calculate the size of the SWTrace string label (in bytes)
341  unsigned int swTraceLabelSize = armnn::numeric_cast<unsigned int>(swTraceLabel.size()) * uint32_t_size;
342 
343  // Calculate the length of the data (in bytes)
344  unsigned int timelineLabelPacketDataLength = uint32_t_size + // decl_Id
345  uint64_t_size + // Profiling GUID
346  swTraceLabelSize; // Label
347 
348  // Check whether the timeline binary packet fits in the given buffer
349  if (timelineLabelPacketDataLength > remainingBufferSize)
350  {
351  return TimelinePacketStatus::BufferExhaustion;
352  }
353 
354  // Initialize the offset for writing in the buffer
355  unsigned int offset = 0;
356 
357  // Write decl_Id to the buffer
358  WriteUint32(buffer, offset, 0u);
359  offset += uint32_t_size;
360 
361  // Write the timeline binary packet payload to the buffer
362  WriteUint64(buffer, offset, profilingGuid); // Profiling GUID
363  offset += uint64_t_size;
364  for (uint32_t swTraceLabelWord : swTraceLabel)
365  {
366  WriteUint32(buffer, offset, swTraceLabelWord); // Label
367  offset += uint32_t_size;
368  }
369 
370  // Update the number of bytes written
371  numberOfBytesWritten = timelineLabelPacketDataLength;
372 
373  return TimelinePacketStatus::Ok;
374 }
void WriteUint32(unsigned char *buffer, unsigned int offset, uint32_t value)
std::enable_if_t< std::is_unsigned< Source >::value &&std::is_unsigned< Dest >::value, Dest > numeric_cast(Source source)
Definition: NumericCast.hpp:35
void WriteUint64(unsigned char *buffer, unsigned int offset, uint64_t value)

◆ WriteTimelineMessageDirectoryPackage()

TimelinePacketStatus WriteTimelineMessageDirectoryPackage ( unsigned char *  buffer,
unsigned int  remainingBufferSize,
unsigned int &  numberOfBytesWritten 
)

Definition at line 497 of file ProfilingUtils.cpp.

References BufferExhaustion, CreateTimelinePacketHeader(), Error, armnn::numeric_cast(), Ok, ThreadIdSize, uint32_t_size, WriteUint32(), and WriteUint8().

Referenced by SendTimelinePacket::SendTimelineMessageDirectoryPackage(), and TEST_SUITE().

500 {
501  // Initialize the output value
502  numberOfBytesWritten = 0;
503 
504  // Check that the given buffer is valid
505  if (buffer == nullptr || remainingBufferSize == 0)
506  {
507  return TimelinePacketStatus::BufferExhaustion;
508  }
509 
510  // Utils
511  unsigned int uint8_t_size = sizeof(uint8_t);
512  unsigned int uint32_t_size = sizeof(uint32_t);
513  unsigned int uint64_t_size = sizeof(uint64_t);
514 
515  // The payload/data of the packet consists of swtrace event definitions encoded according
516  // to the swtrace directory specification. The messages being the five defined below:
517  //
518  // | decl_id | decl_name | ui_name | arg_types | arg_names |
519  // |-----------|---------------------|-----------------------|-------------|-------------------------------------|
520  // | 0 | declareLabel | declare label | ps | guid,value |
521  // | 1 | declareEntity | declare entity | p | guid |
522  // | 2 | declareEventClass | declare event class | pp | guid,nameGuid |
523  // | 3 | declareRelationship | declare relationship | Ipppp | relationshipType,relationshipGuid, |
524  // | | | | | headGuid,tailGuid,attributeGuid |
525  // | 4 | declareEvent | declare event | @tp | timestamp,threadId,eventGuid |
526  std::vector<std::vector<std::string>> timelineDirectoryMessages
527  {
528  { "0", "declareLabel", "declare label", "ps", "guid,value" },
529  { "1", "declareEntity", "declare entity", "p", "guid" },
530  { "2", "declareEventClass", "declare event class", "pp", "guid,nameGuid" },
531  { "3", "declareRelationship", "declare relationship", "Ipppp",
532  "relationshipType,relationshipGuid,headGuid,tailGuid,attributeGuid" },
533  { "4", "declareEvent", "declare event", "@tp", "timestamp,threadId,eventGuid" }
534  };
535 
536  // Build the message declarations
537  std::vector<uint32_t> swTraceBuffer;
538  for (const auto& directoryComponent : timelineDirectoryMessages)
539  {
540  // decl_id
541  uint32_t declId = 0;
542  try
543  {
544  declId = armnn::numeric_cast<uint32_t>(std::stoul(directoryComponent[0]));
545  }
546  catch (const std::exception&)
547  {
548  return TimelinePacketStatus::Error;
549  }
550  swTraceBuffer.push_back(declId);
551 
552  bool result = true;
553  result &= arm::pipe::ConvertDirectoryComponent<arm::pipe::SwTraceNameCharPolicy>(
554  directoryComponent[1], swTraceBuffer); // decl_name
555  result &= arm::pipe::ConvertDirectoryComponent<arm::pipe::SwTraceCharPolicy> (
556  directoryComponent[2], swTraceBuffer); // ui_name
557  result &= arm::pipe::ConvertDirectoryComponent<arm::pipe::SwTraceTypeCharPolicy>(
558  directoryComponent[3], swTraceBuffer); // arg_types
559  result &= arm::pipe::ConvertDirectoryComponent<arm::pipe::SwTraceCharPolicy> (
560  directoryComponent[4], swTraceBuffer); // arg_names
561  if (!result)
562  {
563  return TimelinePacketStatus::Error;
564  }
565  }
566 
567  unsigned int dataLength = 3 * uint8_t_size + // Stream header (3 bytes)
568  armnn::numeric_cast<unsigned int>(swTraceBuffer.size()) *
569  uint32_t_size; // Trace directory (5 messages)
570 
571  // Calculate the timeline directory binary packet size (in bytes)
572  unsigned int timelineDirectoryPacketSize = 2 * uint32_t_size + // Header (2 words)
573  dataLength; // Payload
574 
575  // Check whether the timeline directory binary packet fits in the given buffer
576  if (timelineDirectoryPacketSize > remainingBufferSize)
577  {
578  return TimelinePacketStatus::BufferExhaustion;
579  }
580 
581  // Create packet header
582  auto packetHeader = CreateTimelinePacketHeader(1, 0, 0, 0, 0, armnn::numeric_cast<uint32_t>(dataLength));
583 
584  // Initialize the offset for writing in the buffer
585  unsigned int offset = 0;
586 
587  // Write the timeline binary packet header to the buffer
588  WriteUint32(buffer, offset, packetHeader.first);
589  offset += uint32_t_size;
590  WriteUint32(buffer, offset, packetHeader.second);
591  offset += uint32_t_size;
592 
593  // Write the stream header
594  uint8_t streamVersion = 4;
595  uint8_t pointerBytes = armnn::numeric_cast<uint8_t>(uint64_t_size); // All GUIDs are uint64_t
596  uint8_t threadIdBytes = armnn::numeric_cast<uint8_t>(ThreadIdSize);
597  switch (threadIdBytes)
598  {
599  case 4: // Typically Windows and Android
600  case 8: // Typically Linux
601  break; // Valid values
602  default:
603  return TimelinePacketStatus::Error; // Invalid value
604  }
605  WriteUint8(buffer, offset, streamVersion);
606  offset += uint8_t_size;
607  WriteUint8(buffer, offset, pointerBytes);
608  offset += uint8_t_size;
609  WriteUint8(buffer, offset, threadIdBytes);
610  offset += uint8_t_size;
611 
612  // Write the SWTrace directory
613  uint32_t numberOfDeclarations = armnn::numeric_cast<uint32_t>(timelineDirectoryMessages.size());
614  WriteUint32(buffer, offset, numberOfDeclarations); // Number of declarations
615  offset += uint32_t_size;
616  for (uint32_t i : swTraceBuffer)
617  {
618  WriteUint32(buffer, offset, i); // Message declarations
619  offset += uint32_t_size;
620  }
621 
622  // Update the number of bytes written
623  numberOfBytesWritten = timelineDirectoryPacketSize;
624 
625  return TimelinePacketStatus::Ok;
626 }
void WriteUint32(unsigned char *buffer, unsigned int offset, uint32_t value)
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 WriteUint8(unsigned char *buffer, unsigned int offset, uint8_t value)
constexpr unsigned int ThreadIdSize
std::enable_if_t< std::is_unsigned< Source >::value &&std::is_unsigned< Dest >::value, Dest > numeric_cast(Source source)
Definition: NumericCast.hpp:35

◆ WriteTimelineRelationshipBinary()

TimelinePacketStatus WriteTimelineRelationshipBinary ( ProfilingRelationshipType  relationshipType,
uint64_t  relationshipGuid,
uint64_t  headGuid,
uint64_t  tailGuid,
uint64_t  attributeGuid,
unsigned char *  buffer,
unsigned int  remainingBufferSize,
unsigned int &  numberOfBytesWritten 
)

Definition at line 419 of file ProfilingUtils.cpp.

References BufferExhaustion, DataLink, ExecutionLink, LabelLink, Ok, RetentionLink, uint32_t_size, WriteUint32(), and WriteUint64().

Referenced by SendTimelinePacket::SendTimelineRelationshipBinaryPacket(), and TEST_SUITE().

427 {
428  // Initialize the output value
429  numberOfBytesWritten = 0;
430 
431  // Check that the given buffer is valid
432  if (buffer == nullptr || remainingBufferSize == 0)
433  {
434  return TimelinePacketStatus::BufferExhaustion;
435  }
436 
437  // Utils
438  unsigned int uint32_t_size = sizeof(uint32_t);
439  unsigned int uint64_t_size = sizeof(uint64_t);
440 
441  // Calculate the length of the data (in bytes)
442  unsigned int timelineRelationshipDataLength = uint32_t_size * 2 + // decl_id + Relationship Type
443  uint64_t_size * 4; // Relationship GUID + Head GUID +
444  // tail GUID + attributeGuid
445 
446  // Check whether the timeline binary fits in the given buffer
447  if (timelineRelationshipDataLength > remainingBufferSize)
448  {
449  return TimelinePacketStatus::BufferExhaustion;
450  }
451 
452  // Initialize the offset for writing in the buffer
453  unsigned int offset = 0;
454 
455  uint32_t relationshipTypeUint = 0;
456 
457  switch (relationshipType)
458  {
459  case ProfilingRelationshipType::RetentionLink:
460  relationshipTypeUint = 0;
461  break;
462  case ProfilingRelationshipType::ExecutionLink:
463  relationshipTypeUint = 1;
464  break;
465  case ProfilingRelationshipType::DataLink:
466  relationshipTypeUint = 2;
467  break;
468  case ProfilingRelationshipType::LabelLink:
469  relationshipTypeUint = 3;
470  break;
471  default:
472  throw InvalidArgumentException("Unknown relationship type given.");
473  }
474 
475  // Write the timeline binary payload to the buffer
476  // decl_id of the timeline message
477  uint32_t declId = 3;
478  WriteUint32(buffer, offset, declId); // decl_id
479  offset += uint32_t_size;
480  WriteUint32(buffer, offset, relationshipTypeUint); // Relationship Type
481  offset += uint32_t_size;
482  WriteUint64(buffer, offset, relationshipGuid); // GUID of this relationship
483  offset += uint64_t_size;
484  WriteUint64(buffer, offset, headGuid); // head of relationship GUID
485  offset += uint64_t_size;
486  WriteUint64(buffer, offset, tailGuid); // tail of relationship GUID
487  offset += uint64_t_size;
488  WriteUint64(buffer, offset, attributeGuid); // attribute of relationship GUID
489 
490 
491  // Update the number of bytes written
492  numberOfBytesWritten = timelineRelationshipDataLength;
493 
494  return TimelinePacketStatus::Ok;
495 }
void WriteUint32(unsigned char *buffer, unsigned int offset, uint32_t value)
void WriteUint64(unsigned char *buffer, unsigned int offset, uint64_t value)

◆ WriteUint16() [1/2]

void WriteUint16 ( const IPacketBufferPtr packetBuffer,
unsigned int  offset,
uint16_t  value 
)

Definition at line 128 of file ProfilingUtils.cpp.

References ARMNN_ASSERT.

Referenced by RequestCountersPacketHandler::HandlePacket(), PacketWriter(), SendCounterPacket::SendPeriodicCounterCapturePacket(), GatordMockService::SendPeriodicCounterSelectionList(), SendCounterPacket::SendPeriodicCounterSelectionPacket(), and TEST_SUITE().

129 {
130  ARMNN_ASSERT(packetBuffer);
131 
132  WriteUint16(packetBuffer->GetWritableData(), offset, value);
133 }
void WriteUint16(unsigned char *buffer, unsigned int offset, uint16_t value)
#define ARMNN_ASSERT(COND)
Definition: Assert.hpp:14

◆ WriteUint16() [2/2]

void WriteUint16 ( unsigned char *  buffer,
unsigned int  offset,
uint16_t  value 
)

Definition at line 157 of file ProfilingUtils.cpp.

158 {
159  arm::pipe::WriteUint16(buffer, offset, value);
160 }
void WriteUint16(unsigned char *buffer, unsigned int offset, uint16_t value)

◆ WriteUint32() [1/2]

◆ WriteUint32() [2/2]

void WriteUint32 ( unsigned char *  buffer,
unsigned int  offset,
uint32_t  value 
)

Definition at line 152 of file ProfilingUtils.cpp.

153 {
154  arm::pipe::WriteUint32(buffer, offset, value);
155 }
void WriteUint32(unsigned char *buffer, unsigned int offset, uint32_t value)

◆ WriteUint64() [1/3]

void armnn::profiling::WriteUint64 ( const IPacketBufferPtr packetBuffer,
unsigned int  offset,
uint64_t  value 
)

◆ WriteUint64() [2/3]

void armnn::profiling::WriteUint64 ( const std::unique_ptr< IPacketBuffer > &  packetBuffer,
unsigned int  offset,
uint64_t  value 
)

Definition at line 114 of file ProfilingUtils.cpp.

References ARMNN_ASSERT.

Referenced by SendCounterPacket::SendPeriodicCounterCapturePacket(), TEST_SUITE(), WriteTimelineEntityBinary(), WriteTimelineEventBinary(), WriteTimelineEventClassBinary(), WriteTimelineLabelBinaryPacket(), and WriteTimelineRelationshipBinary().

115 {
116  ARMNN_ASSERT(packetBuffer);
117 
118  WriteUint64(packetBuffer->GetWritableData(), offset, value);
119 }
#define ARMNN_ASSERT(COND)
Definition: Assert.hpp:14
void WriteUint64(unsigned char *buffer, unsigned int offset, uint64_t value)

◆ WriteUint64() [3/3]

void WriteUint64 ( unsigned char *  buffer,
unsigned int  offset,
uint64_t  value 
)

Definition at line 147 of file ProfilingUtils.cpp.

148 {
149  arm::pipe::WriteUint64(buffer, offset, value);
150 }
void WriteUint64(unsigned char *buffer, unsigned int offset, uint64_t value)

◆ WriteUint8() [1/2]

void WriteUint8 ( const IPacketBufferPtr packetBuffer,
unsigned int  offset,
uint8_t  value 
)

Definition at line 135 of file ProfilingUtils.cpp.

References ARMNN_ASSERT.

Referenced by WriteTimelineMessageDirectoryPackage().

136 {
137  ARMNN_ASSERT(packetBuffer);
138 
139  WriteUint8(packetBuffer->GetWritableData(), offset, value);
140 }
void WriteUint8(unsigned char *buffer, unsigned int offset, uint8_t value)
#define ARMNN_ASSERT(COND)
Definition: Assert.hpp:14

◆ WriteUint8() [2/2]

void WriteUint8 ( unsigned char *  buffer,
unsigned int  offset,
uint8_t  value 
)

Definition at line 162 of file ProfilingUtils.cpp.

163 {
164  arm::pipe::WriteUint8(buffer, offset, value);
165 }
void WriteUint8(unsigned char *buffer, unsigned int offset, uint8_t value)

Variable Documentation

◆ ThreadIdSize

◆ uint16_t_size

◆ uint32_t_size