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 | { |
| 48 | Label label; |
| 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 | |
| 55 | label.m_Name = new char[nameLength]; |
| 56 | for (uint32_t i = 0; i< nameLength; ++i) |
| 57 | { |
| 58 | label.m_Name[i] = static_cast<char>(profiling::ReadUint8(data, offset + i)); |
| 59 | } |
| 60 | |
| 61 | CreateLabel(label, m_Model); |
| 62 | |
| 63 | if (!m_QuietOperation) |
| 64 | { |
| 65 | printLabels(); |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | void TimelineCaptureCommandHandler::ReadEntity(const unsigned char* data, uint32_t offset) |
| 70 | { |
| 71 | Entity entity; |
| 72 | entity.m_Guid = profiling::ReadUint64(data, offset); |
| 73 | |
| 74 | CreateEntity(entity, m_Model); |
| 75 | |
| 76 | if (!m_QuietOperation) |
| 77 | { |
| 78 | printEntities(); |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | void TimelineCaptureCommandHandler::ReadEventClass(const unsigned char* data, uint32_t offset) |
| 83 | { |
| 84 | EventClass eventClass; |
| 85 | eventClass.m_Guid = profiling::ReadUint64(data, offset); |
| 86 | |
| 87 | CreateEventClass(eventClass, m_Model); |
| 88 | |
| 89 | if (!m_QuietOperation) |
| 90 | { |
| 91 | printEventClasses(); |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | void TimelineCaptureCommandHandler::ReadRelationship(const unsigned char* data, uint32_t offset) |
| 96 | { |
| 97 | Relationship relationship; |
| 98 | relationship.m_RelationshipType = static_cast<RelationshipType>(profiling::ReadUint32(data, offset)); |
| 99 | offset += uint32_t_size; |
| 100 | |
| 101 | relationship.m_Guid = profiling::ReadUint64(data, offset); |
| 102 | offset += uint64_t_size; |
| 103 | |
| 104 | relationship.m_HeadGuid = profiling::ReadUint64(data, offset); |
| 105 | offset += uint64_t_size; |
| 106 | |
| 107 | relationship.m_TailGuid = profiling::ReadUint64(data, offset); |
| 108 | |
| 109 | CreateRelationship(relationship, m_Model); |
| 110 | |
| 111 | if (!m_QuietOperation) |
| 112 | { |
| 113 | printRelationships(); |
| 114 | } |
| 115 | } |
| 116 | |
| 117 | |
| 118 | |
| 119 | void TimelineCaptureCommandHandler::ReadEvent(const unsigned char* data, uint32_t offset) |
| 120 | { |
| 121 | Event event; |
| 122 | event.m_TimeStamp = profiling::ReadUint64(data, offset); |
| 123 | offset += uint64_t_size; |
| 124 | |
Rob Hughes | 25b7436 | 2020-01-13 11:14:59 +0000 | [diff] [blame] | 125 | event.m_ThreadId = new uint8_t[threadId_size]; |
Finn Williams | e63a026 | 2019-10-22 10:30:49 +0100 | [diff] [blame] | 126 | profiling::ReadBytes(data, offset, threadId_size, event.m_ThreadId); |
| 127 | offset += threadId_size; |
| 128 | |
| 129 | event.m_Guid = profiling::ReadUint64(data, offset); |
| 130 | |
| 131 | CreateEvent(event, m_Model); |
| 132 | |
| 133 | if (!m_QuietOperation) |
| 134 | { |
| 135 | printEvents(); |
| 136 | } |
| 137 | } |
| 138 | |
| 139 | void TimelineCaptureCommandHandler::operator()(const profiling::Packet& packet) |
| 140 | { |
| 141 | ParseData(packet); |
| 142 | } |
| 143 | |
| 144 | void TimelineCaptureCommandHandler::printLabels() |
| 145 | { |
| 146 | std::string header; |
| 147 | |
| 148 | header.append(profiling::CentreAlignFormatting("guid", 12)); |
| 149 | header.append(" | "); |
| 150 | header.append(profiling::CentreAlignFormatting("value", 30)); |
| 151 | header.append("\n"); |
| 152 | |
| 153 | std::cout << "\n" << "\n"; |
| 154 | std::cout << profiling::CentreAlignFormatting("LABELS", static_cast<int>(header.size())); |
| 155 | std::cout << "\n"; |
| 156 | std::cout << std::string(header.size(), '=') << "\n"; |
| 157 | std::cout << header; |
| 158 | |
| 159 | for (uint32_t i = 0; i < m_Model->m_LabelCount; ++i) |
| 160 | { |
| 161 | std::string body; |
| 162 | |
| 163 | body.append(profiling::CentreAlignFormatting(std::to_string(m_Model->m_Labels[i]->m_Guid), 12)); |
| 164 | body.append(" | "); |
| 165 | body.append(profiling::CentreAlignFormatting(m_Model->m_Labels[i]->m_Name, 30)); |
| 166 | body.append("\n"); |
| 167 | |
| 168 | std::cout << std::string(body.size(), '-') << "\n"; |
| 169 | std::cout<< body; |
| 170 | } |
| 171 | } |
| 172 | |
| 173 | void TimelineCaptureCommandHandler::printEntities() |
| 174 | { |
| 175 | std::string header; |
| 176 | header.append(profiling::CentreAlignFormatting("guid", 12)); |
| 177 | header.append("\n"); |
| 178 | |
| 179 | std::cout << "\n" << "\n"; |
| 180 | std::cout << profiling::CentreAlignFormatting("ENTITIES", static_cast<int>(header.size())); |
| 181 | std::cout << "\n"; |
| 182 | std::cout << std::string(header.size(), '=') << "\n"; |
| 183 | std::cout << header; |
| 184 | |
| 185 | for (uint32_t i = 0; i < m_Model->m_EntityCount; ++i) |
| 186 | { |
| 187 | std::string body; |
| 188 | |
| 189 | body.append(profiling::CentreAlignFormatting(std::to_string(m_Model->m_Entities[i]->m_Guid), 12)); |
| 190 | body.append("\n"); |
| 191 | |
| 192 | std::cout << std::string(body.size(), '-') << "\n"; |
| 193 | std::cout<< body; |
| 194 | } |
| 195 | } |
| 196 | |
| 197 | void TimelineCaptureCommandHandler::printEventClasses() |
| 198 | { |
| 199 | std::string header; |
| 200 | header.append(profiling::CentreAlignFormatting("guid", 12)); |
| 201 | header.append("\n"); |
| 202 | |
| 203 | std::cout << "\n" << "\n"; |
| 204 | std::cout << profiling::CentreAlignFormatting("EVENT CLASSES", static_cast<int>(header.size())); |
| 205 | std::cout << "\n"; |
| 206 | std::cout << std::string(header.size(), '=') << "\n"; |
| 207 | std::cout << header; |
| 208 | |
| 209 | for (uint32_t i = 0; i < m_Model->m_EventClassCount; ++i) |
| 210 | { |
| 211 | std::string body; |
| 212 | |
| 213 | body.append(profiling::CentreAlignFormatting(std::to_string(m_Model->m_EventClasses[i]->m_Guid), 12)); |
| 214 | body.append("\n"); |
| 215 | |
| 216 | std::cout << std::string(body.size(), '-') << "\n"; |
| 217 | std::cout<< body; |
| 218 | } |
| 219 | } |
| 220 | |
| 221 | void TimelineCaptureCommandHandler::printRelationships() |
| 222 | { |
| 223 | std::string header; |
| 224 | header.append(profiling::CentreAlignFormatting("relationshipType", 20)); |
| 225 | header.append(" | "); |
| 226 | header.append(profiling::CentreAlignFormatting("relationshipGuid", 20)); |
| 227 | header.append(" | "); |
| 228 | header.append(profiling::CentreAlignFormatting("headGuid", 12)); |
| 229 | header.append(" | "); |
| 230 | header.append(profiling::CentreAlignFormatting("tailGuid", 12)); |
| 231 | header.append("\n"); |
| 232 | |
| 233 | std::cout << "\n" << "\n"; |
| 234 | std::cout << profiling::CentreAlignFormatting("RELATIONSHIPS", static_cast<int>(header.size())); |
| 235 | std::cout << "\n"; |
| 236 | std::cout << std::string(header.size(), '=') << "\n"; |
| 237 | std::cout << header; |
| 238 | |
| 239 | for (uint32_t i = 0; i < m_Model->m_RelationshipCount; ++i) |
| 240 | { |
| 241 | std::string body; |
| 242 | |
| 243 | body.append( |
| 244 | profiling::CentreAlignFormatting(std::to_string(m_Model->m_Relationships[i]->m_RelationshipType), 20)); |
| 245 | body.append(" | "); |
| 246 | body.append(profiling::CentreAlignFormatting(std::to_string(m_Model->m_Relationships[i]->m_Guid), 20)); |
| 247 | body.append(" | "); |
| 248 | body.append(profiling::CentreAlignFormatting(std::to_string(m_Model->m_Relationships[i]->m_HeadGuid), 12)); |
| 249 | body.append(" | "); |
| 250 | body.append(profiling::CentreAlignFormatting(std::to_string(m_Model->m_Relationships[i]->m_TailGuid), 12)); |
| 251 | body.append(" | "); |
| 252 | body.append("\n"); |
| 253 | |
| 254 | std::cout << std::string(body.size(), '-') << "\n"; |
| 255 | std::cout<< body; |
| 256 | } |
| 257 | } |
| 258 | |
| 259 | void TimelineCaptureCommandHandler::printEvents() |
| 260 | { |
| 261 | std::string header; |
| 262 | |
| 263 | header.append(profiling::CentreAlignFormatting("timestamp", 12)); |
| 264 | header.append(" | "); |
| 265 | header.append(profiling::CentreAlignFormatting("threadId", 12)); |
| 266 | header.append(" | "); |
| 267 | header.append(profiling::CentreAlignFormatting("eventGuid", 12)); |
| 268 | header.append("\n"); |
| 269 | |
| 270 | std::cout << "\n" << "\n"; |
| 271 | std::cout << profiling::CentreAlignFormatting("EVENTS", static_cast<int>(header.size())); |
| 272 | std::cout << "\n"; |
| 273 | std::cout << std::string(header.size(), '=') << "\n"; |
| 274 | std::cout << header; |
| 275 | |
| 276 | for (uint32_t i = 0; i < m_Model->m_EventCount; ++i) |
| 277 | { |
| 278 | std::string body; |
| 279 | |
| 280 | body.append(profiling::CentreAlignFormatting(std::to_string(m_Model->m_Events[i]->m_TimeStamp), 12)); |
| 281 | body.append(" | "); |
| 282 | |
| 283 | std::string threadId; |
| 284 | for(uint32_t j =0; j< threadId_size; j++) |
| 285 | { |
| 286 | threadId += static_cast<char>(m_Model->m_Events[i]->m_ThreadId[j]); |
| 287 | } |
| 288 | body.append(profiling::CentreAlignFormatting(threadId, 12)); |
| 289 | body.append(" | "); |
| 290 | body.append(profiling::CentreAlignFormatting(std::to_string(m_Model->m_Events[i]->m_Guid), 12)); |
| 291 | body.append("\n"); |
| 292 | |
| 293 | std::cout << std::string(body.size(), '-') << "\n"; |
| 294 | std::cout<< body; |
| 295 | } |
| 296 | } |
| 297 | |
| 298 | } //namespace gatordmock |
| 299 | |
| 300 | } //namespace armnn |