Finn Williams | e63a026 | 2019-10-22 10:30:49 +0100 | [diff] [blame] | 1 | // |
| 2 | // Copyright © 2019 Arm Ltd. All rights reserved. |
| 3 | // SPDX-License-Identifier: MIT |
| 4 | // |
| 5 | |
| 6 | #include "TimelineDirectoryCaptureCommandHandler.hpp" |
| 7 | |
Matteo Martincigh | 34a407d | 2019-11-06 15:30:54 +0000 | [diff] [blame] | 8 | #include <ProfilingUtils.hpp> |
| 9 | |
Finn Williams | e63a026 | 2019-10-22 10:30:49 +0100 | [diff] [blame] | 10 | #include <iostream> |
| 11 | #include <string> |
| 12 | |
Matteo Martincigh | 34a407d | 2019-11-06 15:30:54 +0000 | [diff] [blame] | 13 | using namespace armnn::profiling; |
| 14 | |
Finn Williams | e63a026 | 2019-10-22 10:30:49 +0100 | [diff] [blame] | 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 | |
Matteo Martincigh | 34a407d | 2019-11-06 15:30:54 +0000 | [diff] [blame] | 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 | |
Finn Williams | e63a026 | 2019-10-22 10:30:49 +0100 | [diff] [blame] | 39 | uint32_t numberOfDeclarations = profiling::ReadUint32(data, offset); |
| 40 | offset += uint32_t_size; |
| 41 | |
Matteo Martincigh | 34a407d | 2019-11-06 15:30:54 +0000 | [diff] [blame] | 42 | for (uint32_t declaration = 0; declaration < numberOfDeclarations; ++declaration) |
Finn Williams | e63a026 | 2019-10-22 10:30:49 +0100 | [diff] [blame] | 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 | |
Matteo Martincigh | 34a407d | 2019-11-06 15:30:54 +0000 | [diff] [blame] | 68 | std::cout << header; |
Finn Williams | e63a026 | 2019-10-22 10:30:49 +0100 | [diff] [blame] | 69 | |
Matteo Martincigh | 34a407d | 2019-11-06 15:30:54 +0000 | [diff] [blame] | 70 | for (const auto& swTraceMessage : m_SwTraceMessages) |
Finn Williams | e63a026 | 2019-10-22 10:30:49 +0100 | [diff] [blame] | 71 | { |
| 72 | std::string body; |
| 73 | |
Matteo Martincigh | 34a407d | 2019-11-06 15:30:54 +0000 | [diff] [blame] | 74 | body.append(profiling::CentreAlignFormatting(std::to_string(swTraceMessage.m_Id), 12)); |
Finn Williams | e63a026 | 2019-10-22 10:30:49 +0100 | [diff] [blame] | 75 | body.append(" | "); |
Matteo Martincigh | 34a407d | 2019-11-06 15:30:54 +0000 | [diff] [blame] | 76 | body.append(profiling::CentreAlignFormatting(swTraceMessage.m_Name, 20)); |
Finn Williams | e63a026 | 2019-10-22 10:30:49 +0100 | [diff] [blame] | 77 | body.append(" | "); |
Matteo Martincigh | 34a407d | 2019-11-06 15:30:54 +0000 | [diff] [blame] | 78 | body.append(profiling::CentreAlignFormatting(swTraceMessage.m_UiName, 20)); |
Finn Williams | e63a026 | 2019-10-22 10:30:49 +0100 | [diff] [blame] | 79 | body.append(" | "); |
| 80 | |
| 81 | std::string argTypes; |
Matteo Martincigh | 34a407d | 2019-11-06 15:30:54 +0000 | [diff] [blame] | 82 | for (auto argType: swTraceMessage.m_ArgTypes) |
Finn Williams | e63a026 | 2019-10-22 10:30:49 +0100 | [diff] [blame] | 83 | { |
| 84 | argTypes += argType; |
| 85 | argTypes += " "; |
| 86 | } |
| 87 | body.append(profiling::CentreAlignFormatting(argTypes, 16)); |
| 88 | body.append(" | "); |
| 89 | |
| 90 | std::string argNames; |
Matteo Martincigh | 34a407d | 2019-11-06 15:30:54 +0000 | [diff] [blame] | 91 | for (auto argName: swTraceMessage.m_ArgNames) |
Finn Williams | e63a026 | 2019-10-22 10:30:49 +0100 | [diff] [blame] | 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 | |
Matteo Martincigh | 34a407d | 2019-11-06 15:30:54 +0000 | [diff] [blame] | 101 | std::cout << body; |
Finn Williams | e63a026 | 2019-10-22 10:30:49 +0100 | [diff] [blame] | 102 | } |
| 103 | } |
| 104 | |
| 105 | void TimelineDirectoryCaptureCommandHandler::operator()(const profiling::Packet& packet) |
| 106 | { |
| 107 | ParseData(packet); |
| 108 | |
Matteo Martincigh | 34a407d | 2019-11-06 15:30:54 +0000 | [diff] [blame] | 109 | if (!m_QuietOperation) |
Finn Williams | e63a026 | 2019-10-22 10:30:49 +0100 | [diff] [blame] | 110 | { |
| 111 | Print(); |
| 112 | } |
| 113 | } |
| 114 | |
| 115 | } //namespace gatordmock |
| 116 | |
Matteo Martincigh | 34a407d | 2019-11-06 15:30:54 +0000 | [diff] [blame] | 117 | } //namespace armnn |