1 //
2 // Copyright © 2019 Arm Ltd and Contributors. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5
6 #include <common/include/CommonProfilingUtils.hpp>
7 #include <common/include/SwTrace.hpp>
8 #include <server/include/timelineDecoder/TimelineCaptureCommandHandler.hpp>
9 #include <server/include/timelineDecoder/TimelineDirectoryCaptureCommandHandler.hpp>
10
11 #include <iostream>
12 #include <string>
13
14 namespace arm
15 {
16
17 namespace pipe
18 {
19
ParseData(const arm::pipe::Packet & packet)20 void TimelineDirectoryCaptureCommandHandler::ParseData(const arm::pipe::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 = arm::pipe::ReadUint32(data, offset);
39 offset += uint32_t_size;
40
41 for (uint32_t declaration = 0; declaration < numberOfDeclarations; ++declaration)
42 {
43 m_SwTraceMessages.push_back(arm::pipe::ReadSwTraceMessage(data, offset, packet.GetLength()));
44 }
45
46 m_TimelineCaptureCommandHandler.SetThreadIdSize(m_SwTraceHeader.m_ThreadIdBytes);
47 }
48
Print()49 void TimelineDirectoryCaptureCommandHandler::Print()
50 {
51 std::string header;
52
53 header.append(arm::pipe::CentreAlignFormatting("decl_id", 12));
54 header.append(" | ");
55 header.append(arm::pipe::CentreAlignFormatting("decl_name", 20));
56 header.append(" | ");
57 header.append(arm::pipe::CentreAlignFormatting("ui_name", 20));
58 header.append(" | ");
59 header.append(arm::pipe::CentreAlignFormatting("arg_types", 16));
60 header.append(" | ");
61 header.append(arm::pipe::CentreAlignFormatting("arg_names", 80));
62 header.append("\n");
63
64 std::cout << "\n" << "\n";
65 std::cout << arm::pipe::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(arm::pipe::CentreAlignFormatting(std::to_string(swTraceMessage.m_Id), 12));
76 body.append(" | ");
77 body.append(arm::pipe::CentreAlignFormatting(swTraceMessage.m_Name, 20));
78 body.append(" | ");
79 body.append(arm::pipe::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(arm::pipe::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(arm::pipe::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
operator ()(const arm::pipe::Packet & packet)106 void TimelineDirectoryCaptureCommandHandler::operator()(const arm::pipe::Packet& packet)
107 {
108 ParseData(packet);
109
110 if (!m_QuietOperation)
111 {
112 Print();
113 }
114 }
115
116 } //namespace pipe
117 } //namespace arm
118