ArmNN
 20.02
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 "../profiling/ProfilingUtils.hpp"
8 
9 #include <iostream>
10 namespace armnn
11 {
12 namespace timelinedecoder
13 {
15 {
16  if (m_OnNewEntityCallback == nullptr)
17  {
19  }
20  m_OnNewEntityCallback(m_Model, entity);
21 
23 }
24 
26 {
27  if (m_OnNewEventClassCallback == nullptr)
28  {
30  }
31  m_OnNewEventClassCallback(m_Model, eventClass);
32 
34 }
35 
37 {
38  if (m_OnNewEventCallback == nullptr)
39  {
41  }
42  m_OnNewEventCallback(m_Model, event);
43 
45 }
46 
48 {
49  if (m_OnNewLabelCallback == nullptr)
50  {
52  }
53  m_OnNewLabelCallback(m_Model, label);
54 
56 }
57 
59 {
60  if (m_OnNewRelationshipCallback == nullptr)
61  {
63  }
64  m_OnNewRelationshipCallback(m_Model, relationship);
66 }
67 
69 {
70  return m_Model;
71 }
72 
74 {
75  if (cb == nullptr)
76  {
78  }
79  m_OnNewEntityCallback = cb;
81 }
82 
84 {
85  if (cb == nullptr)
86  {
88  }
89  m_OnNewEventClassCallback = cb;
91 }
92 
94 {
95  if (cb == nullptr)
96  {
98  }
99  m_OnNewEventCallback = cb;
101 }
102 
104 {
105  if (cb == nullptr)
106  {
108  }
109  m_OnNewLabelCallback = cb;
111 }
112 
114 {
115  if (cb == nullptr)
116  {
118  }
119  m_OnNewRelationshipCallback = cb;
121 }
122 
124 {
125  printLabels();
126  printEntities();
127  printEventClasses();
128  printEvents();
129  printRelationships();
130 }
131 
132 void TimelineDecoder::printLabels()
133 {
134  std::string header;
135 
136  header.append(profiling::CentreAlignFormatting("guid", 12));
137  header.append(" | ");
138  header.append(profiling::CentreAlignFormatting("value", 30));
139  header.append("\n");
140 
141  std::cout << "\n" << "\n";
142  std::cout << profiling::CentreAlignFormatting("LABELS", static_cast<int>(header.size()));
143  std::cout << "\n";
144  std::cout << std::string(header.size(), '=') << "\n";
145  std::cout << header;
146 
147  for (uint32_t i = 0; i < m_Model.m_Labels.size(); ++i)
148  {
149  std::string body;
150 
151  body.append(profiling::CentreAlignFormatting(std::to_string(m_Model.m_Labels[i].m_Guid), 12));
152  body.append(" | ");
153  body.append(profiling::CentreAlignFormatting(m_Model.m_Labels[i].m_Name, 30));
154  body.append("\n");
155 
156  std::cout << std::string(body.size(), '-') << "\n";
157  std::cout << body;
158  }
159 }
160 
161 void TimelineDecoder::printEntities()
162 {
163  std::string header;
164  header.append(profiling::CentreAlignFormatting("guid", 12));
165  header.append("\n");
166 
167  std::cout << "\n" << "\n";
168  std::cout << profiling::CentreAlignFormatting("ENTITIES", static_cast<int>(header.size()));
169  std::cout << "\n";
170  std::cout << std::string(header.size(), '=') << "\n";
171  std::cout << header;
172 
173  for (uint32_t i = 0; i < m_Model.m_Entities.size(); ++i)
174  {
175  std::string body;
176 
177  body.append(profiling::CentreAlignFormatting(std::to_string(m_Model.m_Entities[i].m_Guid), 12));
178  body.append("\n");
179 
180  std::cout << std::string(body.size(), '-') << "\n";
181  std::cout << body;
182  }
183 }
184 
185 void TimelineDecoder::printEventClasses()
186 {
187  std::string header;
188  header.append(profiling::CentreAlignFormatting("guid", 12));
189  header.append("\n");
190 
191  std::cout << "\n" << "\n";
192  std::cout << profiling::CentreAlignFormatting("EVENT CLASSES", static_cast<int>(header.size()));
193  std::cout << "\n";
194  std::cout << std::string(header.size(), '=') << "\n";
195  std::cout << header;
196 
197  for (uint32_t i = 0; i < m_Model.m_EventClasses.size(); ++i)
198  {
199  std::string body;
200 
201  body.append(profiling::CentreAlignFormatting(std::to_string(m_Model.m_EventClasses[i].m_Guid), 12));
202  body.append("\n");
203 
204  std::cout << std::string(body.size(), '-') << "\n";
205  std::cout << body;
206  }
207 }
208 
209 void TimelineDecoder::printEvents()
210 {
211  std::string header;
212 
213  header.append(profiling::CentreAlignFormatting("timestamp", 12));
214  header.append(" | ");
215  header.append(profiling::CentreAlignFormatting("threadId", 12));
216  header.append(" | ");
217  header.append(profiling::CentreAlignFormatting("eventGuid", 12));
218  header.append("\n");
219 
220  std::cout << "\n" << "\n";
221  std::cout << profiling::CentreAlignFormatting("EVENTS", static_cast<int>(header.size()));
222  std::cout << "\n";
223  std::cout << std::string(header.size(), '=') << "\n";
224  std::cout << header;
225 
226  for (uint32_t i = 0; i < m_Model.m_Events.size(); ++i)
227  {
228  std::string body;
229 
230  body.append(profiling::CentreAlignFormatting(std::to_string(m_Model.m_Events[i].m_TimeStamp), 12));
231  body.append(" | ");
232 
233  std::stringstream ss;
234  ss << m_Model.m_Events[i].m_ThreadId;
235  std::string threadId = ss.str();;
236 
237  body.append(profiling::CentreAlignFormatting(threadId, 12));
238  body.append(" | ");
239  body.append(profiling::CentreAlignFormatting(std::to_string(m_Model.m_Events[i].m_Guid), 12));
240  body.append("\n");
241 
242  std::cout << std::string(body.size(), '-') << "\n";
243  std::cout << body;
244  }
245 }
246 
247 void TimelineDecoder::printRelationships()
248 {
249  std::string header;
250  header.append(profiling::CentreAlignFormatting("relationshipType", 20));
251  header.append(" | ");
252  header.append(profiling::CentreAlignFormatting("relationshipGuid", 20));
253  header.append(" | ");
254  header.append(profiling::CentreAlignFormatting("headGuid", 12));
255  header.append(" | ");
256  header.append(profiling::CentreAlignFormatting("tailGuid", 12));
257  header.append("\n");
258 
259  std::cout << "\n" << "\n";
260  std::cout << profiling::CentreAlignFormatting("RELATIONSHIPS", static_cast<int>(header.size()));
261  std::cout << "\n";
262  std::cout << std::string(header.size(), '=') << "\n";
263  std::cout << header;
264 
265  for (uint32_t i = 0; i < m_Model.m_Relationships.size(); ++i)
266  {
267  std::string body;
268 
269  body.append(
270  profiling::CentreAlignFormatting(std::to_string(static_cast<unsigned int>
271  (m_Model.m_Relationships[i].m_RelationshipType)),
272  20));
273  body.append(" | ");
274  body.append(profiling::CentreAlignFormatting(std::to_string(m_Model.m_Relationships[i].m_Guid), 20));
275  body.append(" | ");
276  body.append(profiling::CentreAlignFormatting(std::to_string(m_Model.m_Relationships[i].m_HeadGuid), 12));
277  body.append(" | ");
278  body.append(profiling::CentreAlignFormatting(std::to_string(m_Model.m_Relationships[i].m_TailGuid), 12));
279  body.append(" | ");
280  body.append("\n");
281 
282  std::cout << std::string(body.size(), '-') << "\n";
283  std::cout << body;
284  }
285 }
286 }
287 }
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)