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