ArmNN
 20.05
TimelineDirectoryCaptureCommandHandler.cpp
Go to the documentation of this file.
1 //
2 // Copyright © 2019 Arm Ltd. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5 
8 
9 #include <iostream>
10 #include <string>
11 
12 using namespace armnn::profiling;
13 
14 namespace armnn
15 {
16 
17 namespace timelinedecoder
18 {
19 
20 void TimelineDirectoryCaptureCommandHandler::ParseData(const armnn::profiling::Packet& packet)
21 {
22  uint32_t offset = 0;
23 
24  if (packet.GetLength() < 8)
25  {
26  return;
27  }
28 
29  const unsigned char* data = packet.GetData();
30 
31  m_SwTraceHeader.m_StreamVersion = ReadUint8(data, offset);
32  offset += uint8_t_size;
33  m_SwTraceHeader.m_PointerBytes = ReadUint8(data, offset);
34  offset += uint8_t_size;
35  m_SwTraceHeader.m_ThreadIdBytes = ReadUint8(data, offset);
36  offset += uint8_t_size;
37 
38  uint32_t numberOfDeclarations = profiling::ReadUint32(data, offset);
39  offset += uint32_t_size;
40 
41  for (uint32_t declaration = 0; declaration < numberOfDeclarations; ++declaration)
42  {
43  m_SwTraceMessages.push_back(profiling::ReadSwTraceMessage(data, offset));
44  }
45 
46  m_TimelineCaptureCommandHandler.SetThreadIdSize(m_SwTraceHeader.m_ThreadIdBytes);
47 }
48 
49 void TimelineDirectoryCaptureCommandHandler::Print()
50 {
51  std::string header;
52 
53  header.append(profiling::CentreAlignFormatting("decl_id", 12));
54  header.append(" | ");
55  header.append(profiling::CentreAlignFormatting("decl_name", 20));
56  header.append(" | ");
57  header.append(profiling::CentreAlignFormatting("ui_name", 20));
58  header.append(" | ");
59  header.append(profiling::CentreAlignFormatting("arg_types", 16));
60  header.append(" | ");
61  header.append(profiling::CentreAlignFormatting("arg_names", 80));
62  header.append("\n");
63 
64  std::cout << "\n" << "\n";
65  std::cout << profiling::CentreAlignFormatting("SW DIRECTORY", static_cast<int>(header.size()));
66  std::cout << "\n";
67  std::cout << std::string(header.size(), '=') << "\n";
68 
69  std::cout << header;
70 
71  for (const auto& swTraceMessage : m_SwTraceMessages)
72  {
73  std::string body;
74 
75  body.append(profiling::CentreAlignFormatting(std::to_string(swTraceMessage.m_Id), 12));
76  body.append(" | ");
77  body.append(profiling::CentreAlignFormatting(swTraceMessage.m_Name, 20));
78  body.append(" | ");
79  body.append(profiling::CentreAlignFormatting(swTraceMessage.m_UiName, 20));
80  body.append(" | ");
81 
82  std::string argTypes;
83  for (auto argType: swTraceMessage.m_ArgTypes)
84  {
85  argTypes += argType;
86  argTypes += " ";
87  }
88  body.append(profiling::CentreAlignFormatting(argTypes, 16));
89  body.append(" | ");
90 
91  std::string argNames;
92  for (auto argName: swTraceMessage.m_ArgNames)
93  {
94  argNames += argName + " ";
95  }
96  body.append(profiling::CentreAlignFormatting(argNames, 80));
97 
98  body.append("\n");
99 
100  std::cout << std::string(body.size(), '-') << "\n";
101 
102  std::cout << body;
103  }
104 }
105 
106 void TimelineDirectoryCaptureCommandHandler::operator()(const profiling::Packet& packet)
107 {
108  ParseData(packet);
109 
110  if (!m_QuietOperation)
111  {
112  Print();
113  }
114 }
115 
116 } //namespace gatordmock
117 
118 } //namespace armnn
uint8_t ReadUint8(const IPacketBufferPtr &packetBuffer, unsigned int offset)
Copyright (c) 2020 ARM Limited.
SwTraceMessage ReadSwTraceMessage(const unsigned char *packetBuffer, unsigned int &offset)
uint32_t ReadUint32(const IPacketBufferPtr &packetBuffer, unsigned int offset)
std::string CentreAlignFormatting(const std::string &stringToPass, const int spacingWidth)