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 | |
Finn Williams | e63a026 | 2019-10-22 10:30:49 +0100 | [diff] [blame] | 8 | #include <string> |
Finn Williams | e6a2ccd | 2020-02-27 16:21:41 +0000 | [diff] [blame] | 9 | #include <armnn/Logging.hpp> |
Finn Williams | e63a026 | 2019-10-22 10:30:49 +0100 | [diff] [blame] | 10 | namespace armnn |
| 11 | { |
| 12 | |
Finn Williams | 8a2b468 | 2020-02-26 10:25:26 +0000 | [diff] [blame] | 13 | namespace timelinedecoder |
Finn Williams | e63a026 | 2019-10-22 10:30:49 +0100 | [diff] [blame] | 14 | { |
| 15 | |
| 16 | //Array of member functions, the array index matches the decl_id |
Finn Williams | 8a2b468 | 2020-02-26 10:25:26 +0000 | [diff] [blame] | 17 | const TimelineCaptureCommandHandler::ReadFunction TimelineCaptureCommandHandler::m_ReadFunctions[] |
Finn Williams | e63a026 | 2019-10-22 10:30:49 +0100 | [diff] [blame] | 18 | { |
| 19 | &TimelineCaptureCommandHandler::ReadLabel, // Label decl_id = 0 |
| 20 | &TimelineCaptureCommandHandler::ReadEntity, // Entity decl_id = 1 |
| 21 | &TimelineCaptureCommandHandler::ReadEventClass, // EventClass decl_id = 2 |
| 22 | &TimelineCaptureCommandHandler::ReadRelationship, // Relationship decl_id = 3 |
| 23 | &TimelineCaptureCommandHandler::ReadEvent // Event decl_id = 4 |
| 24 | }; |
| 25 | |
| 26 | void TimelineCaptureCommandHandler::ParseData(const armnn::profiling::Packet& packet) |
| 27 | { |
| 28 | uint32_t offset = 0; |
Keith Davis | 5238aff | 2020-03-11 12:17:05 +0000 | [diff] [blame] | 29 | m_PacketLength = packet.GetLength(); |
Finn Williams | e63a026 | 2019-10-22 10:30:49 +0100 | [diff] [blame] | 30 | |
Finn Williams | e6a2ccd | 2020-02-27 16:21:41 +0000 | [diff] [blame] | 31 | // We are expecting TimelineDirectoryCaptureCommandHandler to set the thread id size |
| 32 | // if it not set in the constructor |
| 33 | if (m_ThreadIdSize == 0) |
| 34 | { |
| 35 | ARMNN_LOG(error) << "TimelineCaptureCommandHandler: m_ThreadIdSize has not been set"; |
| 36 | return; |
| 37 | } |
| 38 | |
| 39 | if (packet.GetLength() < 8) |
Finn Williams | e63a026 | 2019-10-22 10:30:49 +0100 | [diff] [blame] | 40 | { |
| 41 | return; |
| 42 | } |
| 43 | |
| 44 | const unsigned char* data = reinterpret_cast<const unsigned char*>(packet.GetData()); |
| 45 | |
| 46 | uint32_t declId = 0; |
| 47 | |
Keith Davis | 5238aff | 2020-03-11 12:17:05 +0000 | [diff] [blame] | 48 | while ( offset < m_PacketLength ) |
| 49 | { |
| 50 | declId = profiling::ReadUint32(data, offset); |
| 51 | offset += uint32_t_size; |
Finn Williams | e63a026 | 2019-10-22 10:30:49 +0100 | [diff] [blame] | 52 | |
Keith Davis | 5238aff | 2020-03-11 12:17:05 +0000 | [diff] [blame] | 53 | (this->*m_ReadFunctions[declId])(data, offset); |
| 54 | } |
Finn Williams | e63a026 | 2019-10-22 10:30:49 +0100 | [diff] [blame] | 55 | } |
| 56 | |
Keith Davis | 5238aff | 2020-03-11 12:17:05 +0000 | [diff] [blame] | 57 | void TimelineCaptureCommandHandler::ReadLabel(const unsigned char* data, uint32_t& offset) |
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 | ITimelineDecoder::Label label; |
Finn Williams | e63a026 | 2019-10-22 10:30:49 +0100 | [diff] [blame] | 60 | label.m_Guid = profiling::ReadUint64(data, offset); |
| 61 | offset += uint64_t_size; |
| 62 | |
| 63 | uint32_t nameLength = profiling::ReadUint32(data, offset); |
| 64 | offset += uint32_t_size; |
| 65 | |
Keith Davis | 5238aff | 2020-03-11 12:17:05 +0000 | [diff] [blame] | 66 | uint32_t i = 0; |
| 67 | // nameLength - 1 to account for null operator \0 |
| 68 | for ( i = 0; i < nameLength - 1; ++i ) |
Finn Williams | e63a026 | 2019-10-22 10:30:49 +0100 | [diff] [blame] | 69 | { |
Finn Williams | 510f618 | 2020-02-21 11:14:08 +0000 | [diff] [blame] | 70 | label.m_Name += static_cast<char>(profiling::ReadUint8(data, offset + i)); |
Finn Williams | e63a026 | 2019-10-22 10:30:49 +0100 | [diff] [blame] | 71 | } |
Keith Davis | 5238aff | 2020-03-11 12:17:05 +0000 | [diff] [blame] | 72 | // Shift offset past nameLength |
| 73 | uint32_t uint32WordAmount = (nameLength / uint32_t_size) + (nameLength % uint32_t_size != 0 ? 1 : 0); |
| 74 | offset += uint32WordAmount * uint32_t_size; |
| 75 | |
Finn Williams | 510f618 | 2020-02-21 11:14:08 +0000 | [diff] [blame] | 76 | m_TimelineDecoder.CreateLabel(label); |
Finn Williams | e63a026 | 2019-10-22 10:30:49 +0100 | [diff] [blame] | 77 | } |
| 78 | |
Keith Davis | 5238aff | 2020-03-11 12:17:05 +0000 | [diff] [blame] | 79 | void TimelineCaptureCommandHandler::ReadEntity(const unsigned char* data, uint32_t& offset) |
Finn Williams | e63a026 | 2019-10-22 10:30:49 +0100 | [diff] [blame] | 80 | { |
Finn Williams | 510f618 | 2020-02-21 11:14:08 +0000 | [diff] [blame] | 81 | ITimelineDecoder::Entity entity; |
Finn Williams | e63a026 | 2019-10-22 10:30:49 +0100 | [diff] [blame] | 82 | entity.m_Guid = profiling::ReadUint64(data, offset); |
Keith Davis | 5238aff | 2020-03-11 12:17:05 +0000 | [diff] [blame] | 83 | offset += uint64_t_size; |
Finn Williams | 510f618 | 2020-02-21 11:14:08 +0000 | [diff] [blame] | 84 | m_TimelineDecoder.CreateEntity(entity); |
Finn Williams | e63a026 | 2019-10-22 10:30:49 +0100 | [diff] [blame] | 85 | } |
| 86 | |
Keith Davis | 5238aff | 2020-03-11 12:17:05 +0000 | [diff] [blame] | 87 | void TimelineCaptureCommandHandler::ReadEventClass(const unsigned char* data, uint32_t& offset) |
Finn Williams | e63a026 | 2019-10-22 10:30:49 +0100 | [diff] [blame] | 88 | { |
Finn Williams | 510f618 | 2020-02-21 11:14:08 +0000 | [diff] [blame] | 89 | ITimelineDecoder::EventClass eventClass; |
Finn Williams | e63a026 | 2019-10-22 10:30:49 +0100 | [diff] [blame] | 90 | eventClass.m_Guid = profiling::ReadUint64(data, offset); |
Keith Davis | 5238aff | 2020-03-11 12:17:05 +0000 | [diff] [blame] | 91 | offset += uint64_t_size; |
Finn Williams | 510f618 | 2020-02-21 11:14:08 +0000 | [diff] [blame] | 92 | m_TimelineDecoder.CreateEventClass(eventClass); |
Finn Williams | e63a026 | 2019-10-22 10:30:49 +0100 | [diff] [blame] | 93 | } |
| 94 | |
Keith Davis | 5238aff | 2020-03-11 12:17:05 +0000 | [diff] [blame] | 95 | void TimelineCaptureCommandHandler::ReadRelationship(const unsigned char* data, uint32_t& offset) |
Finn Williams | e63a026 | 2019-10-22 10:30:49 +0100 | [diff] [blame] | 96 | { |
Finn Williams | 510f618 | 2020-02-21 11:14:08 +0000 | [diff] [blame] | 97 | ITimelineDecoder::Relationship relationship; |
| 98 | relationship.m_RelationshipType = |
| 99 | static_cast<ITimelineDecoder::RelationshipType>(profiling::ReadUint32(data, offset)); |
Finn Williams | e63a026 | 2019-10-22 10:30:49 +0100 | [diff] [blame] | 100 | offset += uint32_t_size; |
| 101 | |
| 102 | relationship.m_Guid = profiling::ReadUint64(data, offset); |
| 103 | offset += uint64_t_size; |
| 104 | |
Keith Davis | 5238aff | 2020-03-11 12:17:05 +0000 | [diff] [blame] | 105 | relationship.m_HeadGuid = profiling::ReadUint64(data, offset); |
Finn Williams | e63a026 | 2019-10-22 10:30:49 +0100 | [diff] [blame] | 106 | offset += uint64_t_size; |
| 107 | |
| 108 | relationship.m_TailGuid = profiling::ReadUint64(data, offset); |
Keith Davis | 5238aff | 2020-03-11 12:17:05 +0000 | [diff] [blame] | 109 | offset += uint64_t_size; |
Finn Williams | 510f618 | 2020-02-21 11:14:08 +0000 | [diff] [blame] | 110 | m_TimelineDecoder.CreateRelationship(relationship); |
Finn Williams | e63a026 | 2019-10-22 10:30:49 +0100 | [diff] [blame] | 111 | } |
| 112 | |
Keith Davis | 5238aff | 2020-03-11 12:17:05 +0000 | [diff] [blame] | 113 | void TimelineCaptureCommandHandler::ReadEvent(const unsigned char* data, uint32_t& offset) |
Finn Williams | e63a026 | 2019-10-22 10:30:49 +0100 | [diff] [blame] | 114 | { |
Finn Williams | 510f618 | 2020-02-21 11:14:08 +0000 | [diff] [blame] | 115 | ITimelineDecoder::Event event; |
Finn Williams | e63a026 | 2019-10-22 10:30:49 +0100 | [diff] [blame] | 116 | event.m_TimeStamp = profiling::ReadUint64(data, offset); |
| 117 | offset += uint64_t_size; |
| 118 | |
Keith Davis | 5238aff | 2020-03-11 12:17:05 +0000 | [diff] [blame] | 119 | if ( m_ThreadIdSize == 4 ) |
Finn Williams | 510f618 | 2020-02-21 11:14:08 +0000 | [diff] [blame] | 120 | { |
| 121 | event.m_ThreadId = profiling::ReadUint32(data, offset); |
| 122 | } |
Keith Davis | 5238aff | 2020-03-11 12:17:05 +0000 | [diff] [blame] | 123 | else if ( m_ThreadIdSize == 8 ) |
Finn Williams | 510f618 | 2020-02-21 11:14:08 +0000 | [diff] [blame] | 124 | { |
| 125 | event.m_ThreadId = profiling::ReadUint64(data, offset); |
| 126 | } |
| 127 | |
| 128 | offset += m_ThreadIdSize; |
Finn Williams | e63a026 | 2019-10-22 10:30:49 +0100 | [diff] [blame] | 129 | |
| 130 | event.m_Guid = profiling::ReadUint64(data, offset); |
Keith Davis | 5238aff | 2020-03-11 12:17:05 +0000 | [diff] [blame] | 131 | offset += uint64_t_size; |
Finn Williams | e63a026 | 2019-10-22 10:30:49 +0100 | [diff] [blame] | 132 | |
Finn Williams | 510f618 | 2020-02-21 11:14:08 +0000 | [diff] [blame] | 133 | m_TimelineDecoder.CreateEvent(event); |
Finn Williams | e63a026 | 2019-10-22 10:30:49 +0100 | [diff] [blame] | 134 | } |
| 135 | |
Finn Williams | e6a2ccd | 2020-02-27 16:21:41 +0000 | [diff] [blame] | 136 | void TimelineCaptureCommandHandler::SetThreadIdSize(uint32_t size) |
| 137 | { |
| 138 | m_ThreadIdSize = size; |
| 139 | } |
| 140 | |
Finn Williams | e63a026 | 2019-10-22 10:30:49 +0100 | [diff] [blame] | 141 | void TimelineCaptureCommandHandler::operator()(const profiling::Packet& packet) |
| 142 | { |
| 143 | ParseData(packet); |
| 144 | } |
| 145 | |
Finn Williams | e63a026 | 2019-10-22 10:30:49 +0100 | [diff] [blame] | 146 | } //namespace gatordmock |
| 147 | |
| 148 | } //namespace armnn |