blob: cb860a950b38f6dbc1ba23495420db50ba508f69 [file] [log] [blame]
Finn Williamse63a0262019-10-22 10:30:49 +01001//
2// Copyright © 2019 Arm Ltd. All rights reserved.
3// SPDX-License-Identifier: MIT
4//
5
6#include "TimelineDirectoryCaptureCommandHandler.hpp"
7
8#include <iostream>
9#include <string>
10
11namespace armnn
12{
13
14namespace gatordmock
15{
16
17void TimelineDirectoryCaptureCommandHandler::ParseData(const armnn::profiling::Packet& packet)
18{
19 uint32_t offset = 0;
20
21 if (packet.GetLength() < 8)
22 {
23 return;
24 }
25
26 const unsigned char* data = packet.GetData();
27
28 uint32_t numberOfDeclarations = profiling::ReadUint32(data, offset);
29 offset += uint32_t_size;
30
31 for (uint32_t declaration = 0; declaration < numberOfDeclarations; ++declaration)
32 {
33 m_SwTraceMessages.push_back(profiling::ReadSwTraceMessage(data, offset));
34 }
35}
36
37void TimelineDirectoryCaptureCommandHandler::Print()
38{
39 std::string header;
40
41 header.append(profiling::CentreAlignFormatting("decl_id", 12));
42 header.append(" | ");
43 header.append(profiling::CentreAlignFormatting("decl_name", 20));
44 header.append(" | ");
45 header.append(profiling::CentreAlignFormatting("ui_name", 20));
46 header.append(" | ");
47 header.append(profiling::CentreAlignFormatting("arg_types", 16));
48 header.append(" | ");
49 header.append(profiling::CentreAlignFormatting("arg_names", 80));
50 header.append("\n");
51
52 std::cout << "\n" << "\n";
53 std::cout << profiling::CentreAlignFormatting("SW DIRECTORY", static_cast<int>(header.size()));
54 std::cout << "\n";
55 std::cout << std::string(header.size(), '=') << "\n";
56
57 std::cout<< header;
58
59 for (auto swTraceMessage : m_SwTraceMessages)
60 {
61 std::string body;
62
63 body.append(profiling::CentreAlignFormatting(std::to_string(swTraceMessage.id), 12));
64 body.append(" | ");
65 body.append(profiling::CentreAlignFormatting(swTraceMessage.name, 20));
66 body.append(" | ");
67 body.append(profiling::CentreAlignFormatting(swTraceMessage.uiName, 20));
68 body.append(" | ");
69
70 std::string argTypes;
71 for(auto argType: swTraceMessage.argTypes)
72 {
73 argTypes += argType;
74 argTypes += " ";
75 }
76 body.append(profiling::CentreAlignFormatting(argTypes, 16));
77 body.append(" | ");
78
79 std::string argNames;
80 for(auto argName: swTraceMessage.argNames)
81 {
82 argNames += argName + " ";
83 }
84 body.append(profiling::CentreAlignFormatting(argNames, 80));
85
86 body.append("\n");
87
88 std::cout << std::string(body.size(), '-') << "\n";
89
90 std::cout<< body;
91 }
92}
93
94void TimelineDirectoryCaptureCommandHandler::operator()(const profiling::Packet& packet)
95{
96 ParseData(packet);
97
98 if(!m_QuietOperation)
99 {
100 Print();
101 }
102}
103
104} //namespace gatordmock
105
106} //namespace armnn