ArmNN
 20.05
TimelineDecoder.cpp
Go to the documentation of this file.
1 //
2 // Copyright © 2019 Arm Ltd. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5 
6 #include "TimelineDecoder.hpp"
7 #include <ProfilingUtils.hpp>
8 #include <iostream>
9 
10 namespace armnn
11 {
12 namespace timelinedecoder
13 {
14 
16 {
17  if (m_OnNewEntityCallback == nullptr)
18  {
20  }
21  m_OnNewEntityCallback(m_Model, entity);
22 
24 }
25 
27 {
28  if (m_OnNewEventClassCallback == nullptr)
29  {
31  }
32  m_OnNewEventClassCallback(m_Model, eventClass);
33 
35 }
36 
38 {
39  if (m_OnNewEventCallback == nullptr)
40  {
42  }
43  m_OnNewEventCallback(m_Model, event);
44 
46 }
47 
49 {
50  if (m_OnNewLabelCallback == nullptr)
51  {
53  }
54  m_OnNewLabelCallback(m_Model, label);
55 
57 }
58 
60 {
61  if (m_OnNewRelationshipCallback == nullptr)
62  {
64  }
65  m_OnNewRelationshipCallback(m_Model, relationship);
67 }
68 
70 {
71  return m_Model;
72 }
73 
75 {
76  if (cb == nullptr)
77  {
79  }
80  m_OnNewEntityCallback = cb;
82 }
83 
85 {
86  if (cb == nullptr)
87  {
89  }
90  m_OnNewEventClassCallback = cb;
92 }
93 
95 {
96  if (cb == nullptr)
97  {
99  }
100  m_OnNewEventCallback = cb;
102 }
103 
105 {
106  if (cb == nullptr)
107  {
109  }
110  m_OnNewLabelCallback = cb;
112 }
113 
115 {
116  if (cb == nullptr)
117  {
119  }
120  m_OnNewRelationshipCallback = cb;
122 }
123 
125 {
126  SetEntityCallback([](Model& model, const ITimelineDecoder::Entity entity)
127  {
128  model.m_Entities.emplace_back(entity);
129  });
130 
131  SetEventClassCallback([](Model& model, const ITimelineDecoder::EventClass eventClass)
132  {
133  model.m_EventClasses.emplace_back(eventClass);
134  });
135 
136  SetEventCallback([](Model& model, const ITimelineDecoder::Event event)
137  {
138  model.m_Events.emplace_back(event);
139  });
140 
141  SetLabelCallback([](Model& model, const ITimelineDecoder::Label label)
142  {
143  model.m_Labels.emplace_back(label);
144  });
145 
146  SetRelationshipCallback([](Model& model, const ITimelineDecoder::Relationship relationship)
147  {
148  model.m_Relationships.emplace_back(relationship);
149  });
150 }
151 
153 {
154  if (m_Model.m_Labels.empty() && m_Model.m_Entities.empty() && m_Model.m_EventClasses.empty() &&
155  m_Model.m_Events.empty() && m_Model.m_Relationships.empty())
156  {
157  std::cout << "No timeline packets received" << std::endl;
158  return;
159  }
160 
161  printLabels();
162  printEntities();
163  printEventClasses();
164  printEvents();
165  printRelationships();
166 }
167 
168 void TimelineDecoder::printLabels()
169 {
170  std::string header;
171 
172  header.append(profiling::CentreAlignFormatting("guid", 12));
173  header.append(" | ");
174  header.append(profiling::CentreAlignFormatting("value", 30));
175  header.append("\n");
176 
177  std::cout << "\n" << "\n";
178  std::cout << profiling::CentreAlignFormatting("LABELS", static_cast<int>(header.size()));
179  std::cout << "\n";
180  std::cout << std::string(header.size(), '=') << "\n";
181  std::cout << header;
182 
183  for (uint32_t i = 0; i < m_Model.m_Labels.size(); ++i)
184  {
185  std::string body;
186 
187  body.append(profiling::CentreAlignFormatting(std::to_string(m_Model.m_Labels[i].m_Guid), 12));
188  body.append(" | ");
189  body.append(profiling::CentreAlignFormatting(m_Model.m_Labels[i].m_Name, 30));
190  body.append("\n");
191 
192  std::cout << std::string(body.size(), '-') << "\n";
193  std::cout << body;
194  }
195 }
196 
197 void TimelineDecoder::printEntities()
198 {
199  std::string header;
200  header.append(profiling::CentreAlignFormatting("guid", 12));
201  header.append("\n");
202 
203  std::cout << "\n" << "\n";
204  std::cout << profiling::CentreAlignFormatting("ENTITIES", static_cast<int>(header.size()));
205  std::cout << "\n";
206  std::cout << std::string(header.size(), '=') << "\n";
207  std::cout << header;
208 
209  for (uint32_t i = 0; i < m_Model.m_Entities.size(); ++i)
210  {
211  std::string body;
212 
213  body.append(profiling::CentreAlignFormatting(std::to_string(m_Model.m_Entities[i].m_Guid), 12));
214  body.append("\n");
215 
216  std::cout << std::string(body.size(), '-') << "\n";
217  std::cout << body;
218  }
219 }
220 
221 void TimelineDecoder::printEventClasses()
222 {
223  std::string header;
224  header.append(profiling::CentreAlignFormatting("guid", 12));
225  header.append("\n");
226 
227  std::cout << "\n" << "\n";
228  std::cout << profiling::CentreAlignFormatting("EVENT CLASSES", static_cast<int>(header.size()));
229  std::cout << "\n";
230  std::cout << std::string(header.size(), '=') << "\n";
231  std::cout << header;
232 
233  for (uint32_t i = 0; i < m_Model.m_EventClasses.size(); ++i)
234  {
235  std::string body;
236 
237  body.append(profiling::CentreAlignFormatting(std::to_string(m_Model.m_EventClasses[i].m_Guid), 12));
238  body.append("\n");
239 
240  std::cout << std::string(body.size(), '-') << "\n";
241  std::cout << body;
242  }
243 }
244 
245 void TimelineDecoder::printEvents()
246 {
247  std::string header;
248 
249  header.append(profiling::CentreAlignFormatting("timestamp", 12));
250  header.append(" | ");
251  header.append(profiling::CentreAlignFormatting("threadId", 12));
252  header.append(" | ");
253  header.append(profiling::CentreAlignFormatting("eventGuid", 12));
254  header.append("\n");
255 
256  std::cout << "\n" << "\n";
257  std::cout << profiling::CentreAlignFormatting("EVENTS", static_cast<int>(header.size()));
258  std::cout << "\n";
259  std::cout << std::string(header.size(), '=') << "\n";
260  std::cout << header;
261 
262  for (uint32_t i = 0; i < m_Model.m_Events.size(); ++i)
263  {
264  std::string body;
265 
266  body.append(profiling::CentreAlignFormatting(std::to_string(m_Model.m_Events[i].m_TimeStamp), 12));
267  body.append(" | ");
268 
269  std::stringstream ss;
270  ss << m_Model.m_Events[i].m_ThreadId;
271  std::string threadId = ss.str();;
272 
273  body.append(profiling::CentreAlignFormatting(threadId, 12));
274  body.append(" | ");
275  body.append(profiling::CentreAlignFormatting(std::to_string(m_Model.m_Events[i].m_Guid), 12));
276  body.append("\n");
277 
278  std::cout << std::string(body.size(), '-') << "\n";
279  std::cout << body;
280  }
281 }
282 
283 void TimelineDecoder::printRelationships()
284 {
285  std::string header;
286  header.append(profiling::CentreAlignFormatting("relationshipType", 20));
287  header.append(" | ");
288  header.append(profiling::CentreAlignFormatting("relationshipGuid", 20));
289  header.append(" | ");
290  header.append(profiling::CentreAlignFormatting("headGuid", 12));
291  header.append(" | ");
292  header.append(profiling::CentreAlignFormatting("tailGuid", 12));
293  header.append("\n");
294 
295  std::cout << "\n" << "\n";
296  std::cout << profiling::CentreAlignFormatting("RELATIONSHIPS", static_cast<int>(header.size()));
297  std::cout << "\n";
298  std::cout << std::string(header.size(), '=') << "\n";
299  std::cout << header;
300 
301  for (uint32_t i = 0; i < m_Model.m_Relationships.size(); ++i)
302  {
303  std::string body;
304 
305  body.append(
306  profiling::CentreAlignFormatting(std::to_string(static_cast<unsigned int>
307  (m_Model.m_Relationships[i].m_RelationshipType)),
308  20));
309  body.append(" | ");
310  body.append(profiling::CentreAlignFormatting(std::to_string(m_Model.m_Relationships[i].m_Guid), 20));
311  body.append(" | ");
312  body.append(profiling::CentreAlignFormatting(std::to_string(m_Model.m_Relationships[i].m_HeadGuid), 12));
313  body.append(" | ");
314  body.append(profiling::CentreAlignFormatting(std::to_string(m_Model.m_Relationships[i].m_TailGuid), 12));
315  body.append(" | ");
316  body.append("\n");
317 
318  std::cout << std::string(body.size(), '-') << "\n";
319  std::cout << body;
320  }
321 }
322 }
323 }
TimelineStatus SetRelationshipCallback(const OnNewRelationshipCallback)
virtual TimelineStatus CreateEvent(const Event &) override
void(*)(Model &, const Relationship) OnNewRelationshipCallback
Copyright (c) 2020 ARM Limited.
virtual TimelineStatus CreateEntity(const Entity &) override
void(*)(Model &, const Event) OnNewEventCallback
virtual TimelineStatus CreateLabel(const Label &) override
TimelineStatus SetEventClassCallback(const OnNewEventClassCallback)
void(*)(Model &, const Entity) OnNewEntityCallback
virtual TimelineStatus CreateRelationship(const Relationship &) override
void(*)(Model &, const EventClass) OnNewEventClassCallback
virtual TimelineStatus CreateEventClass(const EventClass &) override
void(*)(Model &, const Label) OnNewLabelCallback
TimelineStatus SetLabelCallback(const OnNewLabelCallback)
std::string CentreAlignFormatting(const std::string &stringToPass, const int spacingWidth)
TimelineStatus SetEntityCallback(const OnNewEntityCallback)
TimelineStatus SetEventCallback(const OnNewEventCallback)