diff options
author | Finn Williams <Finn.Williams@arm.com> | 2020-02-21 11:14:08 +0000 |
---|---|---|
committer | Jim Flynn <jim.flynn@arm.com> | 2020-03-02 12:51:36 +0000 |
commit | 510f6183d289b176702a18f020449c68be6f1075 (patch) | |
tree | 28e8e4f27af5d1ee912c93d47628ec219d37a722 /tests/profiling/timelineDecoder | |
parent | 4c998993bda1475595be5505690ff4e08dc2389e (diff) | |
download | armnn-510f6183d289b176702a18f020449c68be6f1075.tar.gz |
IVGCVSW-4164 Change the callbacks to a C++ pure virtual interface
Signed-off-by: Finn Williams <Finn.Williams@arm.com>
Change-Id: I0a15b9f228ceb5a8393a48571b345394c005ee1f
Diffstat (limited to 'tests/profiling/timelineDecoder')
9 files changed, 419 insertions, 601 deletions
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 <cstdint> +#include <string> + +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<char>(profiling::ReadUint8(data, offset + i)); - } - - CreateLabel(label, m_Model); - - if (!m_QuietOperation) - { - printLabels(); + label.m_Name += static_cast<char>(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<RelationshipType>(profiling::ReadUint32(data, offset)); + ITimelineDecoder::Relationship relationship; + relationship.m_RelationshipType = + static_cast<ITimelineDecoder::RelationshipType>(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<int>(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<int>(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<int>(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<int>(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<int>(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<char>(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 <CommandHandlerFunctor.hpp> #include <Packet.hpp> @@ -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 <ProfilingUtils.hpp> + +#include <iostream> +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<int>(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<int>(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<int>(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<int>(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<int>(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<unsigned int> + (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 <vector> +namespace armnn +{ +class TimelineDecoder : public ITimelineDecoder +{ + +public: + + struct Model + { + std::vector<Entity> m_Entities; + std::vector<EventClass> m_EventClasses; + std::vector<Event> m_Events; + std::vector<Label> m_Labels; + std::vector<Relationship> m_Relationships; + }; + + using OnNewEntityCallback = void (*)(Model &, const Entity); + using OnNewEventClassCallback = void (*)(Model &, const EventClass); + using OnNewEventCallback = void (*)(Model &, const Event); + using OnNewLabelCallback = void (*)(Model &, const Label); + using OnNewRelationshipCallback = void (*)(Model &, const Relationship); + + virtual ErrorCode CreateEntity(const Entity &) override; + virtual ErrorCode CreateEventClass(const EventClass &) override; + virtual ErrorCode CreateEvent(const Event &) override; + virtual ErrorCode CreateLabel(const Label &) override; + virtual ErrorCode CreateRelationship(const Relationship &) override; + + const Model& GetModel(); + + + ErrorCode SetEntityCallback(const OnNewEntityCallback); + ErrorCode SetEventClassCallback(const OnNewEventClassCallback); + ErrorCode SetEventCallback(const OnNewEventCallback); + ErrorCode SetLabelCallback(const OnNewLabelCallback); + ErrorCode SetRelationshipCallback(const OnNewRelationshipCallback); + + void print(); + +private: + Model m_Model; + + OnNewEntityCallback m_OnNewEntityCallback; + OnNewEventClassCallback m_OnNewEventClassCallback; + OnNewEventCallback m_OnNewEventCallback; + OnNewLabelCallback m_OnNewLabelCallback; + OnNewRelationshipCallback m_OnNewRelationshipCallback; + + void printLabels(); + void printEntities(); + void printEventClasses(); + void printRelationships(); + void printEvents(); +}; +}
\ No newline at end of file diff --git a/tests/profiling/timelineDecoder/TimelineModel.h b/tests/profiling/timelineDecoder/TimelineModel.h deleted file mode 100644 index a4fbd0dbde..0000000000 --- a/tests/profiling/timelineDecoder/TimelineModel.h +++ /dev/null @@ -1,96 +0,0 @@ -// -// Copyright © 2019 Arm Ltd. All rights reserved. -// SPDX-License-Identifier: MIT -// -#ifndef ARMNN_ITIMELINEMODEL_H -#define ARMNN_ITIMELINEMODEL_H - -#ifdef __cplusplus -extern "C" -{ -#endif - -#include <stdint.h> - -struct Model; - -typedef enum 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). -} RelationshipType; - -typedef struct Entity -{ - uint64_t m_Guid; -} Entity; - -typedef struct EventClass -{ - uint64_t m_Guid; -} EventClass; - -typedef struct Event -{ - uint64_t m_Guid; - uint64_t m_TimeStamp; - unsigned char* m_ThreadId; -} ProfilingEvent; - -typedef struct Label -{ - uint64_t m_Guid; - char* m_Name; -} Label; - -typedef struct Relationship -{ - RelationshipType m_RelationshipType; - uint64_t m_Guid; - uint64_t m_HeadGuid; - uint64_t m_TailGuid; -} Relationship; - -typedef void (*OnNewEntityCallback)(const Entity, struct Model* model); -typedef void (*OnNewEventClassCallback)(const EventClass, struct Model* model); -typedef void (*OnNewEventCallback)(const Event, struct Model* model); -typedef void (*OnNewLabelCallback)(const Label, struct Model* model); -typedef void (*OnNewRelationshipCallback)(const Relationship, struct Model* model) ; - -typedef struct Model -{ - OnNewEntityCallback m_EntityCb; - OnNewEventClassCallback m_EventClassCb; - OnNewEventCallback m_EventCb; - OnNewLabelCallback m_LabelCb; - OnNewRelationshipCallback m_RelationshipCb; - - Entity** m_Entities; - EventClass** m_EventClasses; - Event** m_Events; - Label** m_Labels; - Relationship** m_Relationships; - - uint32_t m_EntityCount; - uint32_t m_EntityCapacity; - - uint32_t m_EventClassCount; - uint32_t m_EventClassCapacity; - - uint32_t m_EventCount; - uint32_t m_EventCapacity; - - uint32_t m_LabelCount; - uint32_t m_LabelCapacity; - - uint32_t m_RelationshipCount; - uint32_t m_RelationshipCapacity; -} Model; - -#ifdef __cplusplus -} -#endif - -#endif //ARMNN_ITIMELINEMODEL_H
\ No newline at end of file diff --git a/tests/profiling/timelineDecoder/tests/TimelineTestFunctions.hpp b/tests/profiling/timelineDecoder/tests/TimelineTestFunctions.hpp deleted file mode 100644 index 3fd9d04dbc..0000000000 --- a/tests/profiling/timelineDecoder/tests/TimelineTestFunctions.hpp +++ /dev/null @@ -1,143 +0,0 @@ -// -// Copyright © 2019 Arm Ltd. All rights reserved. -// SPDX-License-Identifier: MIT -// - -#include <algorithm> -#include "../TimelineModel.h" - -void PushEntity(const Entity entity, Model* model) -{ - if(model->m_EntityCount == 0) - { - model->m_EntityCapacity = 1; - model->m_Entities = new Entity*[model->m_EntityCapacity]; - } - else if(model->m_EntityCount >= model->m_EntityCapacity) - { - Entity** newEntityArray = new Entity*[model->m_EntityCapacity*2]; - - std::copy(model->m_Entities, model->m_Entities + model->m_EntityCapacity, newEntityArray); - delete[] model->m_Entities; - model->m_Entities = newEntityArray; - - model->m_EntityCapacity = model->m_EntityCapacity *2; - } - - Entity* newEntity = new Entity; - - newEntity->m_Guid = entity.m_Guid; - - model->m_Entities[model->m_EntityCount] = newEntity; - model->m_EntityCount++; -}; - -void PushEventClass(const EventClass eventClass, Model* model) -{ - if(model->m_EventClassCount == 0) - { - model->m_EventClassCapacity = 1; - model->m_EventClasses = new EventClass*[model->m_EventClassCapacity]; - } - else if(model->m_EventClassCount >= model->m_EventClassCapacity) - { - EventClass** newEventClassArray = new EventClass*[model->m_EventClassCapacity *2]; - - std::copy(model->m_EventClasses, model->m_EventClasses + model->m_EventClassCapacity, newEventClassArray); - delete[] model->m_EventClasses; - model->m_EventClasses = newEventClassArray; - - model->m_EventClassCapacity = model->m_EventClassCapacity *2; - } - - EventClass* newEventClass = new EventClass; - - newEventClass->m_Guid = eventClass.m_Guid; - - model->m_EventClasses[model->m_EventClassCount] = newEventClass; - model->m_EventClassCount++; -}; - -void PushEvent(const Event event, Model* model) -{ - if(model->m_EventCount == 0) - { - model->m_EventCapacity = 1; - model->m_Events = new Event*[model->m_EventCapacity]; - } - else if(model->m_EventCount >= model->m_EventCapacity) - { - Event** newEventArray = new Event*[model->m_EventCapacity * 2]; - - std::copy(model->m_Events, model->m_Events + model->m_EventCapacity, newEventArray); - delete[] model->m_Events; - model->m_Events = newEventArray; - - model->m_EventCapacity = model->m_EventCapacity *2; - } - - Event* newEvent = new Event; - - newEvent->m_TimeStamp = event.m_TimeStamp; - newEvent->m_ThreadId = event.m_ThreadId; - newEvent->m_Guid = event.m_Guid; - - model->m_Events[model->m_EventCount] = newEvent; - model->m_EventCount++; -}; - -void PushLabel(const Label label, Model* model) -{ - if(model->m_LabelCount == 0) - { - model->m_LabelCapacity = 1; - model->m_Labels = new Label*[model->m_LabelCapacity]; - } - else if(model->m_LabelCount >= model->m_LabelCapacity) - { - Label** newLabelArray = new Label*[model->m_LabelCapacity *2]; - - std::copy(model->m_Labels, model->m_Labels + model->m_LabelCapacity, newLabelArray); - delete[] model->m_Labels; - model->m_Labels = newLabelArray; - - model->m_LabelCapacity = model->m_LabelCapacity *2; - } - - Label* newLabel = new Label; - - newLabel->m_Guid = label.m_Guid; - newLabel->m_Name = label.m_Name; - - model->m_Labels[model->m_LabelCount] = newLabel; - model->m_LabelCount++; -}; - -void PushRelationship(const Relationship relationship, Model* model) -{ - if(model->m_RelationshipCount == 0) - { - model->m_RelationshipCapacity = 1; - model->m_Relationships = new Relationship*[model->m_RelationshipCapacity]; - } - else if(model->m_RelationshipCount >= model->m_RelationshipCapacity) - { - Relationship** newRelationshipArray = new Relationship*[model->m_RelationshipCapacity *2]; - - std::copy(model->m_Relationships, model->m_Relationships + model->m_RelationshipCapacity, newRelationshipArray); - delete[] model->m_Relationships; - model->m_Relationships = newRelationshipArray; - - model->m_RelationshipCapacity = model->m_RelationshipCapacity *2; - } - - Relationship* newRelationship = new Relationship; - - newRelationship->m_Guid = relationship.m_Guid; - newRelationship->m_RelationshipType = relationship.m_RelationshipType; - newRelationship->m_HeadGuid = relationship.m_HeadGuid; - newRelationship->m_TailGuid = relationship.m_TailGuid; - - model->m_Relationships[model->m_RelationshipCount] = newRelationship; - model->m_RelationshipCount++; -}; diff --git a/tests/profiling/timelineDecoder/tests/TimelineTests.cpp b/tests/profiling/timelineDecoder/tests/TimelineTests.cpp index 8106e6a996..5d3c3eaea9 100644 --- a/tests/profiling/timelineDecoder/tests/TimelineTests.cpp +++ b/tests/profiling/timelineDecoder/tests/TimelineTests.cpp @@ -5,9 +5,7 @@ #include "../TimelineCaptureCommandHandler.hpp" #include "../TimelineDirectoryCaptureCommandHandler.hpp" -#include "../ITimelineDecoder.h" -#include "../TimelineModel.h" -#include "TimelineTestFunctions.hpp" +#include "timelineDecoder/TimelineDecoder.hpp" #include <CommandHandlerFunctor.hpp> #include <ProfilingService.hpp> @@ -45,6 +43,31 @@ void SendTimelinePacketToCommandHandler(const unsigned char* packetBuffer, CommandHandler(packet); } +void PushEntity(TimelineDecoder::Model& model, const ITimelineDecoder::Entity entity) +{ + model.m_Entities.emplace_back(entity); +} + +void PushEventClass(TimelineDecoder::Model& model, const ITimelineDecoder::EventClass eventClass) +{ + model.m_EventClasses.emplace_back(eventClass); +} + +void PushEvent(TimelineDecoder::Model& model, const ITimelineDecoder::Event event) +{ + model.m_Events.emplace_back(event); +} + +void PushLabel(TimelineDecoder::Model& model, const ITimelineDecoder::Label label) +{ + model.m_Labels.emplace_back(label); +} + +void PushRelationship(TimelineDecoder::Model& model, const ITimelineDecoder::Relationship relationship) +{ + model.m_Relationships.emplace_back(relationship); +} + BOOST_AUTO_TEST_CASE(TimelineDirectoryTest) { uint32_t uint8_t_size = sizeof(uint8_t); @@ -116,8 +139,7 @@ BOOST_AUTO_TEST_CASE(TimelineDirectoryTest) BOOST_AUTO_TEST_CASE(TimelineCaptureTest) { - uint32_t threadId_size = sizeof(std::thread::id); - + unsigned int threadIdSize = sizeof(std::thread::id); profiling::BufferManager bufferManager(50); profiling::TimelinePacketWriterFactory timelinePacketWriterFactory(bufferManager); @@ -126,33 +148,49 @@ BOOST_AUTO_TEST_CASE(TimelineCaptureTest) profiling::PacketVersionResolver packetVersionResolver; - Model* modelPtr; - CreateModel(&modelPtr); + TimelineDecoder timelineDecoder; + const TimelineDecoder::Model& model = timelineDecoder.GetModel(); gatordmock::TimelineCaptureCommandHandler timelineCaptureCommandHandler( - 1, 1, packetVersionResolver.ResolvePacketVersion(1, 1).GetEncodedValue(), modelPtr, true); + 1, 1, packetVersionResolver.ResolvePacketVersion(1, 1).GetEncodedValue(), timelineDecoder, threadIdSize); - BOOST_CHECK(SetEntityCallback(PushEntity, modelPtr) == ErrorCode_Success); - BOOST_CHECK(SetEventClassCallback(PushEventClass, modelPtr) == ErrorCode_Success); - BOOST_CHECK(SetEventCallback(PushEvent, modelPtr) == ErrorCode_Success); - BOOST_CHECK(SetLabelCallback(PushLabel, modelPtr) == ErrorCode_Success); - BOOST_CHECK(SetRelationshipCallback(PushRelationship, modelPtr) == ErrorCode_Success); + BOOST_CHECK(timelineDecoder.SetEntityCallback(PushEntity) == ITimelineDecoder::ErrorCode::ErrorCode_Success); + BOOST_CHECK( + timelineDecoder.SetEventClassCallback(PushEventClass )== ITimelineDecoder::ErrorCode::ErrorCode_Success); + BOOST_CHECK(timelineDecoder.SetEventCallback(PushEvent) == ITimelineDecoder::ErrorCode::ErrorCode_Success); + BOOST_CHECK(timelineDecoder.SetLabelCallback(PushLabel) == ITimelineDecoder::ErrorCode::ErrorCode_Success); + BOOST_CHECK( + timelineDecoder.SetRelationshipCallback(PushRelationship) == ITimelineDecoder::ErrorCode::ErrorCode_Success); - const uint64_t entityGuid = 22222u; + const uint64_t entityGuid = 111111u ; + const uint64_t eventClassGuid = 22222u; + const uint64_t timestamp = 33333u; + const uint64_t eventGuid = 44444u; - const uint64_t eventClassGuid = 33333u; + const std::thread::id threadId = std::this_thread::get_id(); - const uint64_t timestamp = 111111u; - const uint64_t eventGuid = 55555u; + // need to do a bit of work here to extract the value from threadId + unsigned char* uCharThreadId = new unsigned char[threadIdSize]();; + uint64_t uint64ThreadId; - const std::thread::id threadId = std::this_thread::get_id();; + profiling::WriteBytes(uCharThreadId, 0, &threadId, threadIdSize); - const uint64_t labelGuid = 11111u; + if (threadIdSize == 4) + { + uint64ThreadId = profiling::ReadUint32(uCharThreadId, 0); + } + else if (threadIdSize == 8) + { + uint64ThreadId = profiling::ReadUint64(uCharThreadId, 0); + } + delete[] uCharThreadId; + + const uint64_t labelGuid = 66666u; std::string labelName = "test_label"; - const uint64_t relationshipGuid = 44444u; - const uint64_t headGuid = 111111u; - const uint64_t tailGuid = 222222u; + const uint64_t relationshipGuid = 77777u; + const uint64_t headGuid = 888888u; + const uint64_t tailGuid = 999999u; for (int i = 0; i < 10; ++i) { @@ -191,30 +229,24 @@ BOOST_AUTO_TEST_CASE(TimelineCaptureTest) timelineCaptureCommandHandler); } - for (int i = 0; i < 10; ++i) + for (unsigned long i = 0; i < 10; ++i) { - BOOST_CHECK(modelPtr->m_Entities[i]->m_Guid == entityGuid); + BOOST_CHECK(model.m_Entities[i].m_Guid == entityGuid); - BOOST_CHECK(modelPtr->m_EventClasses[i]->m_Guid == eventClassGuid); + BOOST_CHECK(model.m_EventClasses[i].m_Guid == eventClassGuid); - BOOST_CHECK(modelPtr->m_Events[i]->m_TimeStamp == timestamp); + BOOST_CHECK(model.m_Events[i].m_TimeStamp == timestamp); + BOOST_CHECK(model.m_Events[i].m_ThreadId == uint64ThreadId); + BOOST_CHECK(model.m_Events[i].m_Guid == eventGuid); - std::vector<uint8_t> readThreadId(threadId_size, 0); - profiling::ReadBytes(modelPtr->m_Events[i]->m_ThreadId, 0, threadId_size, readThreadId.data()); - BOOST_CHECK(readThreadId == threadId); + BOOST_CHECK(model.m_Labels[i].m_Guid == labelGuid); + BOOST_CHECK(model.m_Labels[i].m_Name == labelName); - BOOST_CHECK(modelPtr->m_Events[i]->m_Guid == eventGuid); - - BOOST_CHECK(modelPtr->m_Labels[i]->m_Guid == labelGuid); - BOOST_CHECK(std::string(modelPtr->m_Labels[i]->m_Name) == labelName); - - BOOST_CHECK(modelPtr->m_Relationships[i]->m_RelationshipType == RelationshipType::DataLink); - BOOST_CHECK(modelPtr->m_Relationships[i]->m_Guid == relationshipGuid); - BOOST_CHECK(modelPtr->m_Relationships[i]->m_HeadGuid == headGuid); - BOOST_CHECK(modelPtr->m_Relationships[i]->m_TailGuid == tailGuid); + BOOST_CHECK(model.m_Relationships[i].m_RelationshipType == ITimelineDecoder::RelationshipType::DataLink); + BOOST_CHECK(model.m_Relationships[i].m_Guid == relationshipGuid); + BOOST_CHECK(model.m_Relationships[i].m_HeadGuid == headGuid); + BOOST_CHECK(model.m_Relationships[i].m_TailGuid == tailGuid); } - - DestroyModel(&modelPtr); } BOOST_AUTO_TEST_SUITE_END() |