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