Jim Flynn | 4e755a5 | 2020-03-29 17:48:26 +0100 | [diff] [blame] | 1 | // |
Jim Flynn | 6398a98 | 2020-05-27 17:05:21 +0100 | [diff] [blame] | 2 | // Copyright © 2020 Arm Ltd and Contributors. All rights reserved. |
Jim Flynn | 4e755a5 | 2020-03-29 17:48:26 +0100 | [diff] [blame] | 3 | // SPDX-License-Identifier: MIT |
| 4 | // |
| 5 | |
| 6 | #pragma once |
| 7 | |
| 8 | #include <armnn/profiling/ILocalPacketHandler.hpp> |
Jim Flynn | bbfe603 | 2020-07-20 16:57:44 +0100 | [diff] [blame] | 9 | #include <server/include/timelineDecoder/ITimelineDecoder.hpp> |
Finn Williams | 0c8cb99 | 2020-05-07 10:38:15 +0100 | [diff] [blame] | 10 | |
Jim Flynn | 4e755a5 | 2020-03-29 17:48:26 +0100 | [diff] [blame] | 11 | #include "ProfilingUtils.hpp" |
Jim Flynn | bbfe603 | 2020-07-20 16:57:44 +0100 | [diff] [blame] | 12 | #include <server/include/timelineDecoder/TimelineCaptureCommandHandler.hpp> |
| 13 | #include <server/include/timelineDecoder/TimelineDirectoryCaptureCommandHandler.hpp> |
Jim Flynn | 4e755a5 | 2020-03-29 17:48:26 +0100 | [diff] [blame] | 14 | #include "TimelineModel.hpp" |
| 15 | |
Jim Flynn | bbfe603 | 2020-07-20 16:57:44 +0100 | [diff] [blame] | 16 | #include <common/include/Packet.hpp> |
| 17 | |
Jim Flynn | 4e755a5 | 2020-03-29 17:48:26 +0100 | [diff] [blame] | 18 | #include <condition_variable> |
| 19 | #include <map> |
| 20 | #include <mutex> |
| 21 | #include <vector> |
| 22 | |
Cathal Corbett | 5aa9fd7 | 2022-02-25 15:33:28 +0000 | [diff] [blame] | 23 | namespace arm |
Jim Flynn | 4e755a5 | 2020-03-29 17:48:26 +0100 | [diff] [blame] | 24 | { |
| 25 | |
Cathal Corbett | 5aa9fd7 | 2022-02-25 15:33:28 +0000 | [diff] [blame] | 26 | namespace pipe |
Jim Flynn | 4e755a5 | 2020-03-29 17:48:26 +0100 | [diff] [blame] | 27 | { |
| 28 | |
| 29 | // forward declaration of class |
| 30 | class TestTimelinePacketHandler; |
Jim Flynn | bbfe603 | 2020-07-20 16:57:44 +0100 | [diff] [blame] | 31 | class TimelineMessageDecoder : public arm::pipe::ITimelineDecoder |
Jim Flynn | 4e755a5 | 2020-03-29 17:48:26 +0100 | [diff] [blame] | 32 | { |
| 33 | public: |
| 34 | TimelineMessageDecoder(TimelineModel& model) : m_PacketHandler(nullptr), m_TimelineModel(model) {} |
| 35 | virtual TimelineStatus CreateEntity(const Entity&) override; |
| 36 | virtual TimelineStatus CreateEventClass(const EventClass&) override; |
| 37 | virtual TimelineStatus CreateEvent(const Event&) override; |
| 38 | virtual TimelineStatus CreateLabel(const Label&) override; |
| 39 | virtual TimelineStatus CreateRelationship(const Relationship&) override; |
| 40 | void SetPacketHandler(TestTimelinePacketHandler* packetHandler) {m_PacketHandler = packetHandler;}; |
| 41 | private: |
| 42 | TestTimelinePacketHandler* m_PacketHandler; |
| 43 | TimelineModel& m_TimelineModel; |
| 44 | }; |
| 45 | |
| 46 | class TestTimelinePacketHandler : public ILocalPacketHandler |
| 47 | { |
| 48 | public: |
| 49 | TestTimelinePacketHandler() : |
| 50 | m_Connection(nullptr), |
| 51 | m_InferenceCompleted(false), |
| 52 | m_DirectoryHeader(CreateTimelinePacketHeader(1, 0, 0, 0, 0, 0).first), |
| 53 | m_MessageHeader(CreateTimelinePacketHeader(1, 0, 1, 0, 0, 0).first), |
| 54 | m_MessageDecoder(m_TimelineModel), |
| 55 | m_Decoder(1, 1, 0, m_MessageDecoder), |
| 56 | m_DirectoryDecoder(1, 0, 0, m_Decoder, true) |
| 57 | { m_MessageDecoder.SetPacketHandler(this); } |
| 58 | |
| 59 | virtual std::vector<uint32_t> GetHeadersAccepted() override; // ILocalPacketHandler |
| 60 | |
Jim Flynn | bbfe603 | 2020-07-20 16:57:44 +0100 | [diff] [blame] | 61 | virtual void HandlePacket(const arm::pipe::Packet& packet) override; // ILocalPacketHandler |
Jim Flynn | 4e755a5 | 2020-03-29 17:48:26 +0100 | [diff] [blame] | 62 | |
| 63 | void Stop(); |
| 64 | |
| 65 | void WaitOnInferenceCompletion(unsigned int timeout); |
| 66 | void SetInferenceComplete(); |
| 67 | |
| 68 | const TimelineModel& GetTimelineModel() const {return m_TimelineModel;} |
| 69 | |
Jim Flynn | 01d0281 | 2020-04-29 21:12:13 +0100 | [diff] [blame] | 70 | virtual void SetConnection(IInternalProfilingConnection* profilingConnection) override // ILocalPacketHandler |
Jim Flynn | 4e755a5 | 2020-03-29 17:48:26 +0100 | [diff] [blame] | 71 | { |
| 72 | m_Connection = profilingConnection; |
| 73 | } |
| 74 | |
| 75 | private: |
Jim Flynn | bbfe603 | 2020-07-20 16:57:44 +0100 | [diff] [blame] | 76 | void ProcessDirectoryPacket(const arm::pipe::Packet& packet); |
| 77 | void ProcessMessagePacket(const arm::pipe::Packet& packet); |
Jim Flynn | 01d0281 | 2020-04-29 21:12:13 +0100 | [diff] [blame] | 78 | IInternalProfilingConnection* m_Connection; |
Jim Flynn | 4e755a5 | 2020-03-29 17:48:26 +0100 | [diff] [blame] | 79 | std::mutex m_InferenceCompletedMutex; |
| 80 | std::condition_variable m_InferenceCompletedConditionVariable; |
| 81 | bool m_InferenceCompleted; |
| 82 | TimelineModel m_TimelineModel; |
| 83 | uint32_t m_DirectoryHeader; |
| 84 | uint32_t m_MessageHeader; |
| 85 | TimelineMessageDecoder m_MessageDecoder; |
Jim Flynn | bbfe603 | 2020-07-20 16:57:44 +0100 | [diff] [blame] | 86 | arm::pipe::TimelineCaptureCommandHandler m_Decoder; |
| 87 | arm::pipe::TimelineDirectoryCaptureCommandHandler m_DirectoryDecoder; |
Jim Flynn | 4e755a5 | 2020-03-29 17:48:26 +0100 | [diff] [blame] | 88 | }; |
| 89 | |
Cathal Corbett | 5aa9fd7 | 2022-02-25 15:33:28 +0000 | [diff] [blame] | 90 | } // namespace pipe |
Jim Flynn | 4e755a5 | 2020-03-29 17:48:26 +0100 | [diff] [blame] | 91 | |
Cathal Corbett | 5aa9fd7 | 2022-02-25 15:33:28 +0000 | [diff] [blame] | 92 | } // namespace arm |