ArmNN
 20.05
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 #include <armnn/Logging.hpp>
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  // We are expecting TimelineDirectoryCaptureCommandHandler to set the thread id size
32  // if it not set in the constructor
33  if (m_ThreadIdSize == 0)
34  {
35  ARMNN_LOG(error) << "TimelineCaptureCommandHandler: m_ThreadIdSize has not been set";
36  return;
37  }
38 
39  if (packet.GetLength() < 8)
40  {
41  return;
42  }
43 
44  const unsigned char* data = reinterpret_cast<const unsigned char*>(packet.GetData());
45 
46  uint32_t declId = 0;
47 
48  while ( offset < m_PacketLength )
49  {
50  declId = profiling::ReadUint32(data, offset);
51  offset += uint32_t_size;
52 
53  (this->*m_ReadFunctions[declId])(data, offset);
54  }
55 }
56 
57 void TimelineCaptureCommandHandler::ReadLabel(const unsigned char* data, uint32_t& offset)
58 {
60  label.m_Guid = profiling::ReadUint64(data, offset);
61  offset += uint64_t_size;
62 
63  uint32_t nameLength = profiling::ReadUint32(data, offset);
64  offset += uint32_t_size;
65 
66  uint32_t i = 0;
67  // nameLength - 1 to account for null operator \0
68  for ( i = 0; i < nameLength - 1; ++i )
69  {
70  label.m_Name += static_cast<char>(profiling::ReadUint8(data, offset + i));
71  }
72  // Shift offset past nameLength
73  uint32_t uint32WordAmount = (nameLength / uint32_t_size) + (nameLength % uint32_t_size != 0 ? 1 : 0);
74  offset += uint32WordAmount * uint32_t_size;
75 
76  m_TimelineDecoder.CreateLabel(label);
77 }
78 
79 void TimelineCaptureCommandHandler::ReadEntity(const unsigned char* data, uint32_t& offset)
80 {
82  entity.m_Guid = profiling::ReadUint64(data, offset);
83  offset += uint64_t_size;
84  m_TimelineDecoder.CreateEntity(entity);
85 }
86 
87 void TimelineCaptureCommandHandler::ReadEventClass(const unsigned char* data, uint32_t& offset)
88 {
90  eventClass.m_Guid = profiling::ReadUint64(data, offset);
91  offset += uint64_t_size;
92  m_TimelineDecoder.CreateEventClass(eventClass);
93 }
94 
95 void TimelineCaptureCommandHandler::ReadRelationship(const unsigned char* data, uint32_t& offset)
96 {
97  ITimelineDecoder::Relationship relationship;
98  relationship.m_RelationshipType =
100  offset += uint32_t_size;
101 
102  relationship.m_Guid = profiling::ReadUint64(data, offset);
103  offset += uint64_t_size;
104 
105  relationship.m_HeadGuid = profiling::ReadUint64(data, offset);
106  offset += uint64_t_size;
107 
108  relationship.m_TailGuid = profiling::ReadUint64(data, offset);
109  offset += uint64_t_size;
110  m_TimelineDecoder.CreateRelationship(relationship);
111 }
112 
113 void TimelineCaptureCommandHandler::ReadEvent(const unsigned char* data, uint32_t& offset)
114 {
116  event.m_TimeStamp = profiling::ReadUint64(data, offset);
117  offset += uint64_t_size;
118 
119  if ( m_ThreadIdSize == 4 )
120  {
121  event.m_ThreadId = profiling::ReadUint32(data, offset);
122  }
123  else if ( m_ThreadIdSize == 8 )
124  {
125  event.m_ThreadId = profiling::ReadUint64(data, offset);
126  }
127 
128  offset += m_ThreadIdSize;
129 
130  event.m_Guid = profiling::ReadUint64(data, offset);
131  offset += uint64_t_size;
132 
133  m_TimelineDecoder.CreateEvent(event);
134 }
135 
137 {
138  m_ThreadIdSize = size;
139 }
140 
141 void TimelineCaptureCommandHandler::operator()(const profiling::Packet& packet)
142 {
143  ParseData(packet);
144 }
145 
146 } //namespace gatordmock
147 
148 } //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
#define ARMNN_LOG(severity)
Definition: Logging.hpp:163
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)
void ReadEntity(const unsigned char *data, uint32_t &offset)
void ReadEvent(const unsigned char *data, uint32_t &offset)