blob: e547e907981fc7d7e949de8594189e41c2a46c11 [file] [log] [blame]
Matteo Martincighcdfb9412019-11-08 11:23:06 +00001//
Jim Flynnbbfe6032020-07-20 16:57:44 +01002// Copyright © 2019 Arm Ltd and Contributors. All rights reserved.
Matteo Martincighcdfb9412019-11-08 11:23:06 +00003// SPDX-License-Identifier: MIT
4//
5
6#include "StreamMetadataCommandHandler.hpp"
7
Jim Flynnbbfe6032020-07-20 16:57:44 +01008#include <common/include/CommonProfilingUtils.hpp>
Matteo Martincighcdfb9412019-11-08 11:23:06 +00009
Matteo Martincighcdfb9412019-11-08 11:23:06 +000010#include <iostream>
Jim Flynnbbfe6032020-07-20 16:57:44 +010011#include <sstream>
Matteo Martincighcdfb9412019-11-08 11:23:06 +000012
13namespace armnn
14{
15
16namespace gatordmock
17{
18
Jim Flynnbbfe6032020-07-20 16:57:44 +010019void StreamMetadataCommandHandler::operator()(const arm::pipe::Packet& packet)
Matteo Martincighcdfb9412019-11-08 11:23:06 +000020{
21 ParseData(packet);
22
23 if (m_QuietOperation)
24 {
25 return;
26 }
27
28 std::stringstream ss;
29
30 ss << "Stream metadata packet received" << std::endl << std::endl;
31
32 ss << "Pipe magic: " << m_PipeMagic << std::endl;
33 ss << "Stream metadata version: " << m_StreamMetadataVersion << std::endl;
34 ss << "Max data len: " << m_MaxDataLen << std::endl;
35 ss << "Pid: " << m_Pid << std::endl;
36 ss << "Software info: " << m_SoftwareInfo << std::endl;
37 ss << "Hardware version: " << m_HardwareVersion << std::endl;
38 ss << "Software version: " << m_SoftwareVersion << std::endl;
39 ss << "Process name: " << m_ProcessName << std::endl;
40 ss << "Packet versions: " << m_PacketVersionTable.size() << std::endl;
41
42 for (const auto& packetVersion : m_PacketVersionTable)
43 {
44 ss << "-----------------------" << std::endl;
45 ss << "Packet family: " << packetVersion.m_PacketFamily << std::endl;
46 ss << "Packet id: " << packetVersion.m_PacketId << std::endl;
47 ss << "Packet version: " << packetVersion.m_PacketVersion << std::endl;
48 }
49
50 std::cout << ss.str() << std::endl;
51}
52
53std::string ReadString(const unsigned char* buffer, unsigned int &offset)
54{
55 const char* stringPtr = reinterpret_cast<const char*>(&buffer[offset]);
56 return stringPtr != nullptr ? std::string(stringPtr) : "";
57}
58
Jim Flynnbbfe6032020-07-20 16:57:44 +010059void StreamMetadataCommandHandler::ParseData(const arm::pipe::Packet &packet)
Matteo Martincighcdfb9412019-11-08 11:23:06 +000060{
61 // Check that at least the packet contains the fixed-length fields
62 if (packet.GetLength() < 80)
63 {
64 return;
65 }
66
67 // Utils
68 unsigned int uint16_t_size = sizeof(uint16_t);
69 unsigned int uint32_t_size = sizeof(uint32_t);
70
71 const unsigned char* buffer = packet.GetData();
72 unsigned int offset = 0;
73
74 // Get the fixed-length fields
Jim Flynnbbfe6032020-07-20 16:57:44 +010075 m_PipeMagic = arm::pipe::ReadUint32(buffer, offset);
Matteo Martincighcdfb9412019-11-08 11:23:06 +000076 offset += uint32_t_size;
Jim Flynnbbfe6032020-07-20 16:57:44 +010077 m_StreamMetadataVersion = arm::pipe::ReadUint32(buffer, offset);
Matteo Martincighcdfb9412019-11-08 11:23:06 +000078 offset += uint32_t_size;
Jim Flynnbbfe6032020-07-20 16:57:44 +010079 m_MaxDataLen = arm::pipe::ReadUint32(buffer, offset);
Matteo Martincighcdfb9412019-11-08 11:23:06 +000080 offset += uint32_t_size;
Jim Flynnbbfe6032020-07-20 16:57:44 +010081 m_Pid = arm::pipe::ReadUint32(buffer, offset);
Matteo Martincighcdfb9412019-11-08 11:23:06 +000082 offset += uint32_t_size;
Jim Flynnbbfe6032020-07-20 16:57:44 +010083 m_OffsetInfo = arm::pipe::ReadUint32(buffer, offset);
Matteo Martincighcdfb9412019-11-08 11:23:06 +000084 offset += uint32_t_size;
Jim Flynnbbfe6032020-07-20 16:57:44 +010085 m_OffsetHwVersion = arm::pipe::ReadUint32(buffer, offset);
Matteo Martincighcdfb9412019-11-08 11:23:06 +000086 offset += uint32_t_size;
Jim Flynnbbfe6032020-07-20 16:57:44 +010087 m_OffsetSwVersion = arm::pipe::ReadUint32(buffer, offset);
Matteo Martincighcdfb9412019-11-08 11:23:06 +000088 offset += uint32_t_size;
Jim Flynnbbfe6032020-07-20 16:57:44 +010089 m_OffsetProcessName = arm::pipe::ReadUint32(buffer, offset);
Matteo Martincighcdfb9412019-11-08 11:23:06 +000090 offset += uint32_t_size;
Jim Flynnbbfe6032020-07-20 16:57:44 +010091 m_OffsetPacketVersionTable = arm::pipe::ReadUint32(buffer, offset);
Matteo Martincighcdfb9412019-11-08 11:23:06 +000092 offset += uint32_t_size * 2; // Also skipping the reserved word (all zeros)
93
94 // Get the string fields
95 m_SoftwareInfo = m_OffsetInfo > 0 ? ReadString(buffer, m_OffsetInfo) : "";
96 m_HardwareVersion = m_OffsetHwVersion > 0 ? ReadString(buffer, m_OffsetHwVersion) : "";
97 m_SoftwareVersion = m_OffsetSwVersion > 0 ? ReadString(buffer, m_OffsetSwVersion) : "";
98 m_ProcessName = m_OffsetProcessName > 0 ? ReadString(buffer, m_OffsetProcessName) : "";
99
100 // Get the packet versions
101 m_PacketVersionTable.clear();
102 if (m_OffsetPacketVersionTable > 0)
103 {
104 offset = m_OffsetPacketVersionTable;
Jim Flynnbbfe6032020-07-20 16:57:44 +0100105 uint16_t packetEntries = arm::pipe::ReadUint16(buffer, offset + uint16_t_size);
Matteo Martincighcdfb9412019-11-08 11:23:06 +0000106 offset += uint32_t_size; // Also skipping the reserved bytes (all zeros)
107 for (uint16_t i = 0; i < packetEntries; i++)
108 {
Jim Flynnbbfe6032020-07-20 16:57:44 +0100109 uint16_t packetFamilyAndId = arm::pipe::ReadUint16(buffer, offset + uint16_t_size);
Matteo Martincighcdfb9412019-11-08 11:23:06 +0000110 uint16_t packetFamily = (packetFamilyAndId >> 10) & 0x003F;
111 uint16_t packetId = (packetFamilyAndId >> 0) & 0x03FF;
112 offset += uint32_t_size; // Also skipping the reserved bytes (all zeros)
Jim Flynnbbfe6032020-07-20 16:57:44 +0100113 uint32_t packetVersion = arm::pipe::ReadUint32(buffer, offset);
Matteo Martincighcdfb9412019-11-08 11:23:06 +0000114 offset += uint32_t_size;
115
116 m_PacketVersionTable.push_back({ packetFamily, packetId, packetVersion });
117 }
118 }
119}
120
121} // namespace gatordmock
122
123} // namespace armnn