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 "TimelineCaptureCommandHandler.hpp" |
| 7 | |
| 8 | #include <iostream> |
| 9 | #include <string> |
| 10 | |
| 11 | namespace armnn |
| 12 | { |
| 13 | |
| 14 | namespace gatordmock |
| 15 | { |
| 16 | |
| 17 | //Array of member functions, the array index matches the decl_id |
| 18 | const TimelineCaptureCommandHandler::ReadFunction TimelineCaptureCommandHandler::m_ReadFunctions[5] |
| 19 | { |
| 20 | &TimelineCaptureCommandHandler::ReadLabel, // Label decl_id = 0 |
| 21 | &TimelineCaptureCommandHandler::ReadEntity, // Entity decl_id = 1 |
| 22 | &TimelineCaptureCommandHandler::ReadEventClass, // EventClass decl_id = 2 |
| 23 | &TimelineCaptureCommandHandler::ReadRelationship, // Relationship decl_id = 3 |
| 24 | &TimelineCaptureCommandHandler::ReadEvent // Event decl_id = 4 |
| 25 | }; |
| 26 | |
| 27 | void TimelineCaptureCommandHandler::ParseData(const armnn::profiling::Packet& packet) |
| 28 | { |
| 29 | uint32_t offset = 0; |
| 30 | |
| 31 | if (packet.GetLength() < 8) |
| 32 | { |
| 33 | return; |
| 34 | } |
| 35 | |
| 36 | const unsigned char* data = reinterpret_cast<const unsigned char*>(packet.GetData()); |
| 37 | |
| 38 | uint32_t declId = 0; |
| 39 | |
| 40 | declId = profiling::ReadUint32(data, offset); |
| 41 | offset += uint32_t_size; |
| 42 | |
| 43 | (this->*m_ReadFunctions[declId])(data, offset); |
| 44 | } |
| 45 | |
| 46 | void TimelineCaptureCommandHandler::ReadLabel(const unsigned char* data, uint32_t offset) |
| 47 | { |
Finn Williams | 510f618 | 2020-02-21 11:14:08 +0000 | [diff] [blame] | 48 | ITimelineDecoder::Label label; |
Finn Williams | e63a026 | 2019-10-22 10:30:49 +0100 | [diff] [blame] | 49 | label.m_Guid = profiling::ReadUint64(data, offset); |
| 50 | offset += uint64_t_size; |
| 51 | |
| 52 | uint32_t nameLength = profiling::ReadUint32(data, offset); |
| 53 | offset += uint32_t_size; |
| 54 | |
Finn Williams | 510f618 | 2020-02-21 11:14:08 +0000 | [diff] [blame] | 55 | for (uint32_t i = 0; i < nameLength-1; ++i) |
Finn Williams | e63a026 | 2019-10-22 10:30:49 +0100 | [diff] [blame] | 56 | { |
Finn Williams | 510f618 | 2020-02-21 11:14:08 +0000 | [diff] [blame] | 57 | label.m_Name += static_cast<char>(profiling::ReadUint8(data, offset + i)); |
Finn Williams | e63a026 | 2019-10-22 10:30:49 +0100 | [diff] [blame] | 58 | } |
Finn Williams | 510f618 | 2020-02-21 11:14:08 +0000 | [diff] [blame] | 59 | m_TimelineDecoder.CreateLabel(label); |
Finn Williams | e63a026 | 2019-10-22 10:30:49 +0100 | [diff] [blame] | 60 | } |
| 61 | |
| 62 | void TimelineCaptureCommandHandler::ReadEntity(const unsigned char* data, uint32_t offset) |
| 63 | { |
Finn Williams | 510f618 | 2020-02-21 11:14:08 +0000 | [diff] [blame] | 64 | ITimelineDecoder::Entity entity; |
Finn Williams | e63a026 | 2019-10-22 10:30:49 +0100 | [diff] [blame] | 65 | entity.m_Guid = profiling::ReadUint64(data, offset); |
| 66 | |
Finn Williams | 510f618 | 2020-02-21 11:14:08 +0000 | [diff] [blame] | 67 | m_TimelineDecoder.CreateEntity(entity); |
Finn Williams | e63a026 | 2019-10-22 10:30:49 +0100 | [diff] [blame] | 68 | } |
| 69 | |
| 70 | void TimelineCaptureCommandHandler::ReadEventClass(const unsigned char* data, uint32_t offset) |
| 71 | { |
Finn Williams | 510f618 | 2020-02-21 11:14:08 +0000 | [diff] [blame] | 72 | ITimelineDecoder::EventClass eventClass; |
Finn Williams | e63a026 | 2019-10-22 10:30:49 +0100 | [diff] [blame] | 73 | eventClass.m_Guid = profiling::ReadUint64(data, offset); |
| 74 | |
Finn Williams | 510f618 | 2020-02-21 11:14:08 +0000 | [diff] [blame] | 75 | m_TimelineDecoder.CreateEventClass(eventClass); |
Finn Williams | e63a026 | 2019-10-22 10:30:49 +0100 | [diff] [blame] | 76 | } |
| 77 | |
| 78 | void TimelineCaptureCommandHandler::ReadRelationship(const unsigned char* data, uint32_t offset) |
| 79 | { |
Finn Williams | 510f618 | 2020-02-21 11:14:08 +0000 | [diff] [blame] | 80 | ITimelineDecoder::Relationship relationship; |
| 81 | relationship.m_RelationshipType = |
| 82 | static_cast<ITimelineDecoder::RelationshipType>(profiling::ReadUint32(data, offset)); |
Finn Williams | e63a026 | 2019-10-22 10:30:49 +0100 | [diff] [blame] | 83 | offset += uint32_t_size; |
| 84 | |
| 85 | relationship.m_Guid = profiling::ReadUint64(data, offset); |
| 86 | offset += uint64_t_size; |
| 87 | |
| 88 | relationship.m_HeadGuid = profiling::ReadUint64(data, offset); |
| 89 | offset += uint64_t_size; |
| 90 | |
| 91 | relationship.m_TailGuid = profiling::ReadUint64(data, offset); |
| 92 | |
Finn Williams | 510f618 | 2020-02-21 11:14:08 +0000 | [diff] [blame] | 93 | m_TimelineDecoder.CreateRelationship(relationship); |
Finn Williams | e63a026 | 2019-10-22 10:30:49 +0100 | [diff] [blame] | 94 | } |
| 95 | |
Finn Williams | e63a026 | 2019-10-22 10:30:49 +0100 | [diff] [blame] | 96 | void TimelineCaptureCommandHandler::ReadEvent(const unsigned char* data, uint32_t offset) |
| 97 | { |
Finn Williams | 510f618 | 2020-02-21 11:14:08 +0000 | [diff] [blame] | 98 | ITimelineDecoder::Event event; |
Finn Williams | e63a026 | 2019-10-22 10:30:49 +0100 | [diff] [blame] | 99 | event.m_TimeStamp = profiling::ReadUint64(data, offset); |
| 100 | offset += uint64_t_size; |
| 101 | |
Finn Williams | 510f618 | 2020-02-21 11:14:08 +0000 | [diff] [blame] | 102 | if (m_ThreadIdSize == 4) |
| 103 | { |
| 104 | event.m_ThreadId = profiling::ReadUint32(data, offset); |
| 105 | } |
| 106 | else if (m_ThreadIdSize == 8) |
| 107 | { |
| 108 | event.m_ThreadId = profiling::ReadUint64(data, offset); |
| 109 | } |
| 110 | |
| 111 | offset += m_ThreadIdSize; |
Finn Williams | e63a026 | 2019-10-22 10:30:49 +0100 | [diff] [blame] | 112 | |
| 113 | event.m_Guid = profiling::ReadUint64(data, offset); |
| 114 | |
Finn Williams | 510f618 | 2020-02-21 11:14:08 +0000 | [diff] [blame] | 115 | m_TimelineDecoder.CreateEvent(event); |
Finn Williams | e63a026 | 2019-10-22 10:30:49 +0100 | [diff] [blame] | 116 | } |
| 117 | |
| 118 | void TimelineCaptureCommandHandler::operator()(const profiling::Packet& packet) |
| 119 | { |
| 120 | ParseData(packet); |
| 121 | } |
| 122 | |
Finn Williams | e63a026 | 2019-10-22 10:30:49 +0100 | [diff] [blame] | 123 | } //namespace gatordmock |
| 124 | |
| 125 | } //namespace armnn |