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