From 510f6183d289b176702a18f020449c68be6f1075 Mon Sep 17 00:00:00 2001 From: Finn Williams Date: Fri, 21 Feb 2020 11:14:08 +0000 Subject: IVGCVSW-4164 Change the callbacks to a C++ pure virtual interface Signed-off-by: Finn Williams Change-Id: I0a15b9f228ceb5a8393a48571b345394c005ee1f --- tests/profiling/timelineDecoder/ITimelineDecoder.h | 41 ---- .../profiling/timelineDecoder/ITimelineDecoder.hpp | 68 ++++++ .../TimelineCaptureCommandHandler.cpp | 219 ++---------------- .../TimelineCaptureCommandHandler.hpp | 23 +- .../profiling/timelineDecoder/TimelineDecoder.cpp | 255 +++++++++++++++------ .../profiling/timelineDecoder/TimelineDecoder.hpp | 63 +++++ tests/profiling/timelineDecoder/TimelineModel.h | 96 -------- .../tests/TimelineTestFunctions.hpp | 143 ------------ .../timelineDecoder/tests/TimelineTests.cpp | 112 +++++---- 9 files changed, 419 insertions(+), 601 deletions(-) delete mode 100644 tests/profiling/timelineDecoder/ITimelineDecoder.h create mode 100644 tests/profiling/timelineDecoder/ITimelineDecoder.hpp create mode 100644 tests/profiling/timelineDecoder/TimelineDecoder.hpp delete mode 100644 tests/profiling/timelineDecoder/TimelineModel.h delete mode 100644 tests/profiling/timelineDecoder/tests/TimelineTestFunctions.hpp (limited to 'tests/profiling/timelineDecoder') diff --git a/tests/profiling/timelineDecoder/ITimelineDecoder.h b/tests/profiling/timelineDecoder/ITimelineDecoder.h deleted file mode 100644 index 65ec8bfa6e..0000000000 --- a/tests/profiling/timelineDecoder/ITimelineDecoder.h +++ /dev/null @@ -1,41 +0,0 @@ -// -// Copyright © 2019 Arm Ltd. All rights reserved. -// SPDX-License-Identifier: MIT -// - -#ifndef ARMNN_ITIMELINEDECODER_H -#define ARMNN_ITIMELINEDECODER_H - -#ifdef __cplusplus -extern "C" -{ -#endif - -#include "TimelineModel.h" - -typedef enum ErrorCode -{ - ErrorCode_Success, - ErrorCode_Fail -} ErrorCode; - -ErrorCode CreateModel(Model** model); -ErrorCode DestroyModel(Model** model); - -ErrorCode SetEntityCallback(OnNewEntityCallback cb, Model* model); -ErrorCode SetEventClassCallback(OnNewEventClassCallback cb, Model* model); -ErrorCode SetEventCallback(OnNewEventCallback cb, Model* model); -ErrorCode SetLabelCallback(OnNewLabelCallback cb, Model* model); -ErrorCode SetRelationshipCallback(OnNewRelationshipCallback cb, Model* model); - -ErrorCode CreateEntity(const Entity entity, Model* model); -ErrorCode CreateEventClass(const EventClass eventClass, Model* model); -ErrorCode CreateEvent(const Event event, Model* model); -ErrorCode CreateLabel(const Label label, Model* model); -ErrorCode CreateRelationship(const Relationship relationship, Model* model); - -#ifdef __cplusplus -} -#endif - -#endif //ARMNN_ITIMELINEDECODER_H \ No newline at end of file diff --git a/tests/profiling/timelineDecoder/ITimelineDecoder.hpp b/tests/profiling/timelineDecoder/ITimelineDecoder.hpp new file mode 100644 index 0000000000..7199b38d24 --- /dev/null +++ b/tests/profiling/timelineDecoder/ITimelineDecoder.hpp @@ -0,0 +1,68 @@ +// +// Copyright © 2020 Arm Ltd. All rights reserved. +// SPDX-License-Identifier: MIT +// + +#pragma once + +#include +#include + +class ITimelineDecoder +{ + +public: + + enum class ErrorCode + { + ErrorCode_Success, + ErrorCode_Fail + }; + + enum class RelationshipType + { + RetentionLink, /// Head retains(parents) Tail + ExecutionLink, /// Head execution start depends on Tail execution completion + DataLink, /// Head uses data of Tail + LabelLink /// Head uses label Tail (Tail MUST be a guid of a label). + }; + + struct Entity + { + uint64_t m_Guid; + }; + + struct EventClass + { + uint64_t m_Guid; + }; + + struct Event + { + uint64_t m_Guid; + uint64_t m_TimeStamp; + uint64_t m_ThreadId; + }; + + struct Label + { + uint64_t m_Guid; + std::string m_Name; + }; + + struct Relationship + { + RelationshipType m_RelationshipType; + uint64_t m_Guid; + uint64_t m_HeadGuid; + uint64_t m_TailGuid; + }; + + virtual ~ITimelineDecoder() = default; + + virtual ErrorCode CreateEntity(const Entity&) = 0; + virtual ErrorCode CreateEventClass(const EventClass&) = 0; + virtual ErrorCode CreateEvent(const Event&) = 0; + virtual ErrorCode CreateLabel(const Label&) = 0; + virtual ErrorCode CreateRelationship(const Relationship&) = 0; +}; \ No newline at end of file diff --git a/tests/profiling/timelineDecoder/TimelineCaptureCommandHandler.cpp b/tests/profiling/timelineDecoder/TimelineCaptureCommandHandler.cpp index 78b1300ed3..1fd0d4745a 100644 --- a/tests/profiling/timelineDecoder/TimelineCaptureCommandHandler.cpp +++ b/tests/profiling/timelineDecoder/TimelineCaptureCommandHandler.cpp @@ -45,57 +45,41 @@ void TimelineCaptureCommandHandler::ParseData(const armnn::profiling::Packet& pa void TimelineCaptureCommandHandler::ReadLabel(const unsigned char* data, uint32_t offset) { - Label label; + ITimelineDecoder::Label label; label.m_Guid = profiling::ReadUint64(data, offset); offset += uint64_t_size; uint32_t nameLength = profiling::ReadUint32(data, offset); offset += uint32_t_size; - label.m_Name = new char[nameLength]; - for (uint32_t i = 0; i< nameLength; ++i) + for (uint32_t i = 0; i < nameLength-1; ++i) { - label.m_Name[i] = static_cast(profiling::ReadUint8(data, offset + i)); - } - - CreateLabel(label, m_Model); - - if (!m_QuietOperation) - { - printLabels(); + label.m_Name += static_cast(profiling::ReadUint8(data, offset + i)); } + m_TimelineDecoder.CreateLabel(label); } void TimelineCaptureCommandHandler::ReadEntity(const unsigned char* data, uint32_t offset) { - Entity entity; + ITimelineDecoder::Entity entity; entity.m_Guid = profiling::ReadUint64(data, offset); - CreateEntity(entity, m_Model); - - if (!m_QuietOperation) - { - printEntities(); - } + m_TimelineDecoder.CreateEntity(entity); } void TimelineCaptureCommandHandler::ReadEventClass(const unsigned char* data, uint32_t offset) { - EventClass eventClass; + ITimelineDecoder::EventClass eventClass; eventClass.m_Guid = profiling::ReadUint64(data, offset); - CreateEventClass(eventClass, m_Model); - - if (!m_QuietOperation) - { - printEventClasses(); - } + m_TimelineDecoder.CreateEventClass(eventClass); } void TimelineCaptureCommandHandler::ReadRelationship(const unsigned char* data, uint32_t offset) { - Relationship relationship; - relationship.m_RelationshipType = static_cast(profiling::ReadUint32(data, offset)); + ITimelineDecoder::Relationship relationship; + relationship.m_RelationshipType = + static_cast(profiling::ReadUint32(data, offset)); offset += uint32_t_size; relationship.m_Guid = profiling::ReadUint64(data, offset); @@ -106,193 +90,34 @@ void TimelineCaptureCommandHandler::ReadRelationship(const unsigned char* data, relationship.m_TailGuid = profiling::ReadUint64(data, offset); - CreateRelationship(relationship, m_Model); - - if (!m_QuietOperation) - { - printRelationships(); - } + m_TimelineDecoder.CreateRelationship(relationship); } - - void TimelineCaptureCommandHandler::ReadEvent(const unsigned char* data, uint32_t offset) { - Event event; + ITimelineDecoder::Event event; event.m_TimeStamp = profiling::ReadUint64(data, offset); offset += uint64_t_size; - event.m_ThreadId = new uint8_t[threadId_size]; - profiling::ReadBytes(data, offset, threadId_size, event.m_ThreadId); - offset += threadId_size; - - event.m_Guid = profiling::ReadUint64(data, offset); - - CreateEvent(event, m_Model); - - if (!m_QuietOperation) + if (m_ThreadIdSize == 4) { - printEvents(); + event.m_ThreadId = profiling::ReadUint32(data, offset); } -} - -void TimelineCaptureCommandHandler::operator()(const profiling::Packet& packet) -{ - ParseData(packet); -} - -void TimelineCaptureCommandHandler::printLabels() -{ - std::string header; - - header.append(profiling::CentreAlignFormatting("guid", 12)); - header.append(" | "); - header.append(profiling::CentreAlignFormatting("value", 30)); - header.append("\n"); - - std::cout << "\n" << "\n"; - std::cout << profiling::CentreAlignFormatting("LABELS", static_cast(header.size())); - std::cout << "\n"; - std::cout << std::string(header.size(), '=') << "\n"; - std::cout << header; - - for (uint32_t i = 0; i < m_Model->m_LabelCount; ++i) + else if (m_ThreadIdSize == 8) { - std::string body; - - body.append(profiling::CentreAlignFormatting(std::to_string(m_Model->m_Labels[i]->m_Guid), 12)); - body.append(" | "); - body.append(profiling::CentreAlignFormatting(m_Model->m_Labels[i]->m_Name, 30)); - body.append("\n"); - - std::cout << std::string(body.size(), '-') << "\n"; - std::cout<< body; + event.m_ThreadId = profiling::ReadUint64(data, offset); } -} -void TimelineCaptureCommandHandler::printEntities() -{ - std::string header; - header.append(profiling::CentreAlignFormatting("guid", 12)); - header.append("\n"); + offset += m_ThreadIdSize; - std::cout << "\n" << "\n"; - std::cout << profiling::CentreAlignFormatting("ENTITIES", static_cast(header.size())); - std::cout << "\n"; - std::cout << std::string(header.size(), '=') << "\n"; - std::cout << header; - - for (uint32_t i = 0; i < m_Model->m_EntityCount; ++i) - { - std::string body; - - body.append(profiling::CentreAlignFormatting(std::to_string(m_Model->m_Entities[i]->m_Guid), 12)); - body.append("\n"); - - std::cout << std::string(body.size(), '-') << "\n"; - std::cout<< body; - } -} - -void TimelineCaptureCommandHandler::printEventClasses() -{ - std::string header; - header.append(profiling::CentreAlignFormatting("guid", 12)); - header.append("\n"); - - std::cout << "\n" << "\n"; - std::cout << profiling::CentreAlignFormatting("EVENT CLASSES", static_cast(header.size())); - std::cout << "\n"; - std::cout << std::string(header.size(), '=') << "\n"; - std::cout << header; - - for (uint32_t i = 0; i < m_Model->m_EventClassCount; ++i) - { - std::string body; - - body.append(profiling::CentreAlignFormatting(std::to_string(m_Model->m_EventClasses[i]->m_Guid), 12)); - body.append("\n"); - - std::cout << std::string(body.size(), '-') << "\n"; - std::cout<< body; - } -} - -void TimelineCaptureCommandHandler::printRelationships() -{ - std::string header; - header.append(profiling::CentreAlignFormatting("relationshipType", 20)); - header.append(" | "); - header.append(profiling::CentreAlignFormatting("relationshipGuid", 20)); - header.append(" | "); - header.append(profiling::CentreAlignFormatting("headGuid", 12)); - header.append(" | "); - header.append(profiling::CentreAlignFormatting("tailGuid", 12)); - header.append("\n"); - - std::cout << "\n" << "\n"; - std::cout << profiling::CentreAlignFormatting("RELATIONSHIPS", static_cast(header.size())); - std::cout << "\n"; - std::cout << std::string(header.size(), '=') << "\n"; - std::cout << header; - - for (uint32_t i = 0; i < m_Model->m_RelationshipCount; ++i) - { - std::string body; - - body.append( - profiling::CentreAlignFormatting(std::to_string(m_Model->m_Relationships[i]->m_RelationshipType), 20)); - body.append(" | "); - body.append(profiling::CentreAlignFormatting(std::to_string(m_Model->m_Relationships[i]->m_Guid), 20)); - body.append(" | "); - body.append(profiling::CentreAlignFormatting(std::to_string(m_Model->m_Relationships[i]->m_HeadGuid), 12)); - body.append(" | "); - body.append(profiling::CentreAlignFormatting(std::to_string(m_Model->m_Relationships[i]->m_TailGuid), 12)); - body.append(" | "); - body.append("\n"); + event.m_Guid = profiling::ReadUint64(data, offset); - std::cout << std::string(body.size(), '-') << "\n"; - std::cout<< body; - } + m_TimelineDecoder.CreateEvent(event); } -void TimelineCaptureCommandHandler::printEvents() +void TimelineCaptureCommandHandler::operator()(const profiling::Packet& packet) { - std::string header; - - header.append(profiling::CentreAlignFormatting("timestamp", 12)); - header.append(" | "); - header.append(profiling::CentreAlignFormatting("threadId", 12)); - header.append(" | "); - header.append(profiling::CentreAlignFormatting("eventGuid", 12)); - header.append("\n"); - - std::cout << "\n" << "\n"; - std::cout << profiling::CentreAlignFormatting("EVENTS", static_cast(header.size())); - std::cout << "\n"; - std::cout << std::string(header.size(), '=') << "\n"; - std::cout << header; - - for (uint32_t i = 0; i < m_Model->m_EventCount; ++i) - { - std::string body; - - body.append(profiling::CentreAlignFormatting(std::to_string(m_Model->m_Events[i]->m_TimeStamp), 12)); - body.append(" | "); - - std::string threadId; - for(uint32_t j =0; j< threadId_size; j++) - { - threadId += static_cast(m_Model->m_Events[i]->m_ThreadId[j]); - } - body.append(profiling::CentreAlignFormatting(threadId, 12)); - body.append(" | "); - body.append(profiling::CentreAlignFormatting(std::to_string(m_Model->m_Events[i]->m_Guid), 12)); - body.append("\n"); - - std::cout << std::string(body.size(), '-') << "\n"; - std::cout<< body; - } + ParseData(packet); } } //namespace gatordmock diff --git a/tests/profiling/timelineDecoder/TimelineCaptureCommandHandler.hpp b/tests/profiling/timelineDecoder/TimelineCaptureCommandHandler.hpp index 3f3240491f..9cdbbdc32a 100644 --- a/tests/profiling/timelineDecoder/TimelineCaptureCommandHandler.hpp +++ b/tests/profiling/timelineDecoder/TimelineCaptureCommandHandler.hpp @@ -5,7 +5,7 @@ #pragma once -#include "ITimelineDecoder.h" +#include "ITimelineDecoder.hpp" #include #include @@ -22,7 +22,6 @@ class TimelineCaptureCommandHandler : public profiling::CommandHandlerFunctor // Utils uint32_t uint32_t_size = sizeof(uint32_t); uint32_t uint64_t_size = sizeof(uint64_t); - uint32_t threadId_size = sizeof(std::thread::id); using ReadFunction = void (TimelineCaptureCommandHandler::*)(const unsigned char*, uint32_t); @@ -30,11 +29,11 @@ public: TimelineCaptureCommandHandler(uint32_t familyId, uint32_t packetId, uint32_t version, - Model* model, - bool quietOperation = false) + ITimelineDecoder& timelineDecoder, + uint32_t threadId_size) : CommandHandlerFunctor(familyId, packetId, version) - , m_Model(model) - , m_QuietOperation(quietOperation) + , m_TimelineDecoder(timelineDecoder) + , m_ThreadIdSize(threadId_size) {} void operator()(const armnn::profiling::Packet& packet) override; @@ -45,20 +44,12 @@ public: void ReadRelationship(const unsigned char* data, uint32_t offset); void ReadEvent(const unsigned char* data, uint32_t offset); - void print(); - private: void ParseData(const armnn::profiling::Packet& packet); - Model* m_Model; - bool m_QuietOperation; + ITimelineDecoder& m_TimelineDecoder; + const uint32_t m_ThreadIdSize; static const ReadFunction m_ReadFunctions[]; - - void printLabels(); - void printEntities(); - void printEventClasses(); - void printRelationships(); - void printEvents(); }; } //namespace gatordmock diff --git a/tests/profiling/timelineDecoder/TimelineDecoder.cpp b/tests/profiling/timelineDecoder/TimelineDecoder.cpp index b6f051b745..2924b7a287 100644 --- a/tests/profiling/timelineDecoder/TimelineDecoder.cpp +++ b/tests/profiling/timelineDecoder/TimelineDecoder.cpp @@ -3,164 +3,283 @@ // SPDX-License-Identifier: MIT // -#include "ITimelineDecoder.h" +#include "TimelineDecoder.hpp" -ErrorCode CreateEntity(const Entity entity, Model* model) +#include + +#include +namespace armnn +{ +TimelineDecoder::ErrorCode TimelineDecoder::CreateEntity(const Entity &entity) { - if (model == nullptr || model->m_EntityCb == nullptr) + if (m_OnNewEntityCallback == nullptr) { return ErrorCode::ErrorCode_Fail; } - model->m_EntityCb(entity, model); + m_OnNewEntityCallback(m_Model, entity); + return ErrorCode::ErrorCode_Success; } -ErrorCode CreateEventClass(const EventClass eventClass, Model* model) +TimelineDecoder::ErrorCode TimelineDecoder::CreateEventClass(const EventClass &eventClass) { - if (model == nullptr || model->m_EventClassCb == nullptr) + if (m_OnNewEventClassCallback == nullptr) { return ErrorCode::ErrorCode_Fail; } - model->m_EventClassCb(eventClass, model); + m_OnNewEventClassCallback(m_Model, eventClass); + return ErrorCode::ErrorCode_Success; } -ErrorCode CreateEvent(const Event event, Model* model) +TimelineDecoder::ErrorCode TimelineDecoder::CreateEvent(const Event &event) { - if (model == nullptr || model->m_EventCb == nullptr) + if (m_OnNewEventCallback == nullptr) { return ErrorCode::ErrorCode_Fail; } - model->m_EventCb(event, model); + m_OnNewEventCallback(m_Model, event); + return ErrorCode::ErrorCode_Success; } -ErrorCode CreateLabel(const Label label, Model* model) +TimelineDecoder::ErrorCode TimelineDecoder::CreateLabel(const Label &label) { - if (model == nullptr || model->m_LabelCb == nullptr) + if (m_OnNewLabelCallback == nullptr) { return ErrorCode::ErrorCode_Fail; } - model->m_LabelCb(label, model); + m_OnNewLabelCallback(m_Model, label); + return ErrorCode::ErrorCode_Success; } -ErrorCode CreateRelationship(Relationship relationship, Model* model) +TimelineDecoder::ErrorCode TimelineDecoder::CreateRelationship(const Relationship &relationship) { - if (model == nullptr || model->m_RelationshipCb == nullptr) + if (m_OnNewRelationshipCallback == nullptr) { return ErrorCode::ErrorCode_Fail; } - model->m_RelationshipCb(relationship, model); + m_OnNewRelationshipCallback(m_Model, relationship); return ErrorCode::ErrorCode_Success; } -ErrorCode SetEntityCallback(OnNewEntityCallback cb, Model* model) +const TimelineDecoder::Model &TimelineDecoder::GetModel() { - if (cb == nullptr || model == nullptr) + return m_Model; +} + +TimelineDecoder::ErrorCode TimelineDecoder::SetEntityCallback(OnNewEntityCallback cb) +{ + if (cb == nullptr) { return ErrorCode::ErrorCode_Fail; } - model->m_EntityCb = cb; + m_OnNewEntityCallback = cb; return ErrorCode::ErrorCode_Success; } -ErrorCode SetEventClassCallback(OnNewEventClassCallback cb, Model* model) +TimelineDecoder::ErrorCode TimelineDecoder::SetEventClassCallback(OnNewEventClassCallback cb) { - if (cb == nullptr || model == nullptr) + if (cb == nullptr) { return ErrorCode::ErrorCode_Fail; } - model->m_EventClassCb = cb; + m_OnNewEventClassCallback = cb; return ErrorCode::ErrorCode_Success; } -ErrorCode SetEventCallback(OnNewEventCallback cb, Model* model) +TimelineDecoder::ErrorCode TimelineDecoder::SetEventCallback(OnNewEventCallback cb) { - if (cb == nullptr || model == nullptr) + if (cb == nullptr) { return ErrorCode::ErrorCode_Fail; } - model->m_EventCb = cb; + m_OnNewEventCallback = cb; return ErrorCode::ErrorCode_Success; } -ErrorCode SetLabelCallback(OnNewLabelCallback cb, Model* model) +TimelineDecoder::ErrorCode TimelineDecoder::SetLabelCallback(OnNewLabelCallback cb) { - if (cb == nullptr || model == nullptr) + if (cb == nullptr) { return ErrorCode::ErrorCode_Fail; } - model->m_LabelCb = cb; + m_OnNewLabelCallback = cb; return ErrorCode::ErrorCode_Success; } -ErrorCode SetRelationshipCallback(OnNewRelationshipCallback cb, Model* model) +TimelineDecoder::ErrorCode TimelineDecoder::SetRelationshipCallback(OnNewRelationshipCallback cb) { - if (cb == nullptr || model == nullptr) + if (cb == nullptr) { return ErrorCode::ErrorCode_Fail; } - model->m_RelationshipCb = cb; + m_OnNewRelationshipCallback = cb; return ErrorCode::ErrorCode_Success; } -ErrorCode CreateModel(Model** model) +void TimelineDecoder::print() { - Model* modelPtr = new Model; - - modelPtr->m_EntityCount = 0; - modelPtr->m_EventClassCount = 0; - modelPtr->m_EventCount = 0; - modelPtr->m_LabelCount = 0; - modelPtr->m_RelationshipCount = 0; - - *model = modelPtr; - return ErrorCode::ErrorCode_Success; + printLabels(); + printEntities(); + printEventClasses(); + printEvents(); + printRelationships(); } -ErrorCode DestroyModel(Model** model) +void TimelineDecoder::printLabels() { - if (*model == nullptr) - { - return ErrorCode::ErrorCode_Fail; - } + std::string header; - Model* modelPtr = *model; + header.append(profiling::CentreAlignFormatting("guid", 12)); + header.append(" | "); + header.append(profiling::CentreAlignFormatting("value", 30)); + header.append("\n"); - for (uint32_t i = 0; i < modelPtr->m_EntityCount; ++i) + std::cout << "\n" << "\n"; + std::cout << profiling::CentreAlignFormatting("LABELS", static_cast(header.size())); + std::cout << "\n"; + std::cout << std::string(header.size(), '=') << "\n"; + std::cout << header; + + for (uint32_t i = 0; i < m_Model.m_Labels.size(); ++i) { - delete modelPtr->m_Entities[i]; + std::string body; + + body.append(profiling::CentreAlignFormatting(std::to_string(m_Model.m_Labels[i].m_Guid), 12)); + body.append(" | "); + body.append(profiling::CentreAlignFormatting(m_Model.m_Labels[i].m_Name, 30)); + body.append("\n"); + + std::cout << std::string(body.size(), '-') << "\n"; + std::cout << body; } +} + +void TimelineDecoder::printEntities() +{ + std::string header; + header.append(profiling::CentreAlignFormatting("guid", 12)); + header.append("\n"); - for (uint32_t i = 0; i < modelPtr->m_EventClassCount; ++i) + std::cout << "\n" << "\n"; + std::cout << profiling::CentreAlignFormatting("ENTITIES", static_cast(header.size())); + std::cout << "\n"; + std::cout << std::string(header.size(), '=') << "\n"; + std::cout << header; + + for (uint32_t i = 0; i < m_Model.m_Entities.size(); ++i) { - delete modelPtr->m_EventClasses[i]; + std::string body; + + body.append(profiling::CentreAlignFormatting(std::to_string(m_Model.m_Entities[i].m_Guid), 12)); + body.append("\n"); + + std::cout << std::string(body.size(), '-') << "\n"; + std::cout << body; } +} + +void TimelineDecoder::printEventClasses() +{ + std::string header; + header.append(profiling::CentreAlignFormatting("guid", 12)); + header.append("\n"); - for (uint32_t i = 0; i < modelPtr->m_EventCount; ++i) + std::cout << "\n" << "\n"; + std::cout << profiling::CentreAlignFormatting("EVENT CLASSES", static_cast(header.size())); + std::cout << "\n"; + std::cout << std::string(header.size(), '=') << "\n"; + std::cout << header; + + for (uint32_t i = 0; i < m_Model.m_EventClasses.size(); ++i) { - delete[] modelPtr->m_Events[i]->m_ThreadId; - delete modelPtr->m_Events[i]; + std::string body; + + body.append(profiling::CentreAlignFormatting(std::to_string(m_Model.m_EventClasses[i].m_Guid), 12)); + body.append("\n"); + + std::cout << std::string(body.size(), '-') << "\n"; + std::cout << body; } +} + +void TimelineDecoder::printEvents() +{ + std::string header; - for (uint32_t i = 0; i < modelPtr->m_LabelCount; ++i) + header.append(profiling::CentreAlignFormatting("timestamp", 12)); + header.append(" | "); + header.append(profiling::CentreAlignFormatting("threadId", 12)); + header.append(" | "); + header.append(profiling::CentreAlignFormatting("eventGuid", 12)); + header.append("\n"); + + std::cout << "\n" << "\n"; + std::cout << profiling::CentreAlignFormatting("EVENTS", static_cast(header.size())); + std::cout << "\n"; + std::cout << std::string(header.size(), '=') << "\n"; + std::cout << header; + + for (uint32_t i = 0; i < m_Model.m_Events.size(); ++i) { - delete[] modelPtr->m_Labels[i]->m_Name; - delete modelPtr->m_Labels[i]; + std::string body; + + body.append(profiling::CentreAlignFormatting(std::to_string(m_Model.m_Events[i].m_TimeStamp), 12)); + body.append(" | "); + + std::stringstream ss; + ss << m_Model.m_Events[i].m_ThreadId; + std::string threadId = ss.str();; + + body.append(profiling::CentreAlignFormatting(threadId, 12)); + body.append(" | "); + body.append(profiling::CentreAlignFormatting(std::to_string(m_Model.m_Events[i].m_Guid), 12)); + body.append("\n"); + + std::cout << std::string(body.size(), '-') << "\n"; + std::cout << body; } +} + +void TimelineDecoder::printRelationships() +{ + std::string header; + header.append(profiling::CentreAlignFormatting("relationshipType", 20)); + header.append(" | "); + header.append(profiling::CentreAlignFormatting("relationshipGuid", 20)); + header.append(" | "); + header.append(profiling::CentreAlignFormatting("headGuid", 12)); + header.append(" | "); + header.append(profiling::CentreAlignFormatting("tailGuid", 12)); + header.append("\n"); - for (uint32_t i = 0; i < modelPtr->m_RelationshipCount; ++i) + std::cout << "\n" << "\n"; + std::cout << profiling::CentreAlignFormatting("RELATIONSHIPS", static_cast(header.size())); + std::cout << "\n"; + std::cout << std::string(header.size(), '=') << "\n"; + std::cout << header; + + for (uint32_t i = 0; i < m_Model.m_Relationships.size(); ++i) { - delete modelPtr->m_Relationships[i]; - } + std::string body; - delete[] modelPtr->m_Entities; - delete[] modelPtr->m_EventClasses; - delete[] modelPtr->m_Events; - delete[] modelPtr->m_Labels; - delete[] modelPtr->m_Relationships; + body.append( + profiling::CentreAlignFormatting(std::to_string(static_cast + (m_Model.m_Relationships[i].m_RelationshipType)), + 20)); + body.append(" | "); + body.append(profiling::CentreAlignFormatting(std::to_string(m_Model.m_Relationships[i].m_Guid), 20)); + body.append(" | "); + body.append(profiling::CentreAlignFormatting(std::to_string(m_Model.m_Relationships[i].m_HeadGuid), 12)); + body.append(" | "); + body.append(profiling::CentreAlignFormatting(std::to_string(m_Model.m_Relationships[i].m_TailGuid), 12)); + body.append(" | "); + body.append("\n"); - delete modelPtr; - return ErrorCode::ErrorCode_Success; + std::cout << std::string(body.size(), '-') << "\n"; + std::cout << body; + } +} } \ No newline at end of file diff --git a/tests/profiling/timelineDecoder/TimelineDecoder.hpp b/tests/profiling/timelineDecoder/TimelineDecoder.hpp new file mode 100644 index 0000000000..81e6a95c09 --- /dev/null +++ b/tests/profiling/timelineDecoder/TimelineDecoder.hpp @@ -0,0 +1,63 @@ +// +// Copyright © 2020 Arm Ltd. All rights reserved. +// SPDX-License-Identifier: MIT +// +#pragma once + +#include "ITimelineDecoder.hpp" +#include +namespace armnn +{ +class TimelineDecoder : public ITimelineDecoder +{ + +public: + + struct Model + { + std::vector m_Entities; + std::vector m_EventClasses; + std::vector m_Events; + std::vector