ArmNN
 20.02
TimelineCaptureCommandHandler.cpp
Go to the documentation of this file.
1 //
2 // Copyright © 2019 Arm Ltd. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5 
7 
8 #include <string>
9 
10 namespace armnn
11 {
12 
13 namespace timelinedecoder
14 {
15 
16 //Array of member functions, the array index matches the decl_id
17 const TimelineCaptureCommandHandler::ReadFunction TimelineCaptureCommandHandler::m_ReadFunctions[]
18 {
19  &TimelineCaptureCommandHandler::ReadLabel, // Label decl_id = 0
20  &TimelineCaptureCommandHandler::ReadEntity, // Entity decl_id = 1
21  &TimelineCaptureCommandHandler::ReadEventClass, // EventClass decl_id = 2
22  &TimelineCaptureCommandHandler::ReadRelationship, // Relationship decl_id = 3
23  &TimelineCaptureCommandHandler::ReadEvent // Event decl_id = 4
24 };
25 
26 void TimelineCaptureCommandHandler::ParseData(const armnn::profiling::Packet& packet)
27 {
28  uint32_t offset = 0;
29  m_PacketLength = packet.GetLength();
30 
31  if ( m_PacketLength < 8 )
32  {
33  return;
34  }
35 
36  const unsigned char* data = reinterpret_cast<const unsigned char*>(packet.GetData());
37 
38  uint32_t declId = 0;
39 
40  while ( offset < m_PacketLength )
41  {
42  declId = profiling::ReadUint32(data, offset);
43  offset += uint32_t_size;
44 
45  (this->*m_ReadFunctions[declId])(data, offset);
46  }
47 }
48 
49 void TimelineCaptureCommandHandler::ReadLabel(const unsigned char* data, uint32_t& offset)
50 {
52  label.m_Guid = profiling::ReadUint64(data, offset);
53  offset += uint64_t_size;
54 
55  uint32_t nameLength = profiling::ReadUint32(data, offset);
56  offset += uint32_t_size;
57 
58  uint32_t i = 0;
59  // nameLength - 1 to account for null operator \0
60  for ( i = 0; i < nameLength - 1; ++i )
61  {
62  label.m_Name += static_cast<char>(profiling::ReadUint8(data, offset + i));
63  }
64  // Shift offset past nameLength
65  uint32_t uint32WordAmount = (nameLength / uint32_t_size) + (nameLength % uint32_t_size != 0 ? 1 : 0);
66  offset += uint32WordAmount * uint32_t_size;
67 
68  m_TimelineDecoder.CreateLabel(label);
69 }
70 
71 void TimelineCaptureCommandHandler::ReadEntity(const unsigned char* data, uint32_t& offset)
72 {
74  entity.m_Guid = profiling::ReadUint64(data, offset);
75  offset += uint64_t_size;
76  m_TimelineDecoder.CreateEntity(entity);
77 }
78 
79 void TimelineCaptureCommandHandler::ReadEventClass(const unsigned char* data, uint32_t& offset)
80 {
82  eventClass.m_Guid = profiling::ReadUint64(data, offset);
83  offset += uint64_t_size;
84  m_TimelineDecoder.CreateEventClass(eventClass);
85 }
86 
87 void TimelineCaptureCommandHandler::ReadRelationship(const unsigned char* data, uint32_t& offset)
88 {
89  ITimelineDecoder::Relationship relationship;
90  relationship.m_RelationshipType =
92  offset += uint32_t_size;
93 
94  relationship.m_Guid = profiling::ReadUint64(data, offset);
95  offset += uint64_t_size;
96 
97  relationship.m_HeadGuid = profiling::ReadUint64(data, offset);
98  offset += uint64_t_size;
99 
100  relationship.m_TailGuid = profiling::ReadUint64(data, offset);
101  offset += uint64_t_size;
102  m_TimelineDecoder.CreateRelationship(relationship);
103 }
104 
105 void TimelineCaptureCommandHandler::ReadEvent(const unsigned char* data, uint32_t& offset)
106 {
108  event.m_TimeStamp = profiling::ReadUint64(data, offset);
109  offset += uint64_t_size;
110 
111  if ( m_ThreadIdSize == 4 )
112  {
113  event.m_ThreadId = profiling::ReadUint32(data, offset);
114  }
115  else if ( m_ThreadIdSize == 8 )
116  {
117  event.m_ThreadId = profiling::ReadUint64(data, offset);
118  }
119 
120  offset += m_ThreadIdSize;
121 
122  event.m_Guid = profiling::ReadUint64(data, offset);
123  offset += uint64_t_size;
124 
125  m_TimelineDecoder.CreateEvent(event);
126 }
127 
129 {
130  ParseData(packet);
131 }
132 
133 } //namespace gatordmock
134 
135 } //namespace armnn
uint64_t ReadUint64(const IPacketBufferPtr &packetBuffer, unsigned int offset)
virtual TimelineStatus CreateEvent(const Event &)=0
virtual TimelineStatus CreateLabel(const Label &)=0
virtual TimelineStatus CreateRelationship(const Relationship &)=0
virtual TimelineStatus CreateEntity(const Entity &)=0
uint8_t ReadUint8(const IPacketBufferPtr &packetBuffer, unsigned int offset)
Copyright (c) 2020 ARM Limited.
virtual TimelineStatus CreateEventClass(const EventClass &)=0
void ReadEventClass(const unsigned char *data, uint32_t &offset)
void ReadRelationship(const unsigned char *data, uint32_t &offset)
void operator()(const armnn::profiling::Packet &packet) override
void ReadLabel(const unsigned char *data, uint32_t &offset)
uint32_t ReadUint32(const IPacketBufferPtr &packetBuffer, unsigned int offset)
uint32_t GetLength() const
Definition: Packet.hpp:74
const unsigned char * GetData() const
Definition: Packet.hpp:75
void ReadEntity(const unsigned char *data, uint32_t &offset)
void ReadEvent(const unsigned char *data, uint32_t &offset)