diff options
author | Jim Flynn <jim.flynn@arm.com> | 2020-03-29 17:48:26 +0100 |
---|---|---|
committer | finn.williams <finn.williams@arm.com> | 2020-04-27 16:38:55 +0000 |
commit | 4e755a50e35a1f5ac1b011dc4baf89e6d97f116e (patch) | |
tree | 9660dba96819145e4f1bfe34e4482dca211ffc26 /src/profiling/test/TestTimelinePacketHandler.cpp | |
parent | 303980c502c721f13d65e7087be6c0758df65044 (diff) | |
download | armnn-4e755a50e35a1f5ac1b011dc4baf89e6d97f116e.tar.gz |
IVGCVSW-4595 Add IFileOnlyPacketHandlers to file only profiling connection
Change-Id: Ib49a8cbbf323da4109cdab9750e6c4d276e484b7
Signed-off-by: Jim Flynn <jim.flynn@arm.com>
Diffstat (limited to 'src/profiling/test/TestTimelinePacketHandler.cpp')
-rw-r--r-- | src/profiling/test/TestTimelinePacketHandler.cpp | 132 |
1 files changed, 132 insertions, 0 deletions
diff --git a/src/profiling/test/TestTimelinePacketHandler.cpp b/src/profiling/test/TestTimelinePacketHandler.cpp new file mode 100644 index 0000000000..93fb4b433c --- /dev/null +++ b/src/profiling/test/TestTimelinePacketHandler.cpp @@ -0,0 +1,132 @@ +// +// Copyright © 2020 Arm Ltd. All rights reserved. +// SPDX-License-Identifier: MIT +// + +#include "TestTimelinePacketHandler.hpp" +#include "IProfilingConnection.hpp" + +#include <armnn/utility/IgnoreUnused.hpp> + +#include <chrono> +#include <iostream> +#include <sstream> + +namespace armnn +{ + +namespace profiling +{ + +std::vector<uint32_t> TestTimelinePacketHandler::GetHeadersAccepted() +{ + std::vector<uint32_t> headers; + headers.push_back(m_DirectoryHeader); // message directory + headers.push_back(m_MessageHeader); // message + return headers; +} + +void TestTimelinePacketHandler::HandlePacket(const Packet& packet) +{ + if (packet.GetHeader() == m_DirectoryHeader) + { + ProcessDirectoryPacket(packet); + } + else if (packet.GetHeader() == m_MessageHeader) + { + ProcessMessagePacket(packet); + } + else + { + std::stringstream ss; + ss << "Received a packet with unknown header [" << packet.GetHeader() << "]"; + throw armnn::Exception(ss.str()); + } +} + +void TestTimelinePacketHandler::Stop() +{ + m_Connection->Close(); +} + +void TestTimelinePacketHandler::WaitOnInferenceCompletion(unsigned int timeout) +{ + std::unique_lock<std::mutex> lck(m_InferenceCompletedMutex); + + auto start = std::chrono::high_resolution_clock::now(); + // Here we we will go back to sleep after a spurious wake up if + // m_InferenceCompleted is not yet true. + if (!m_InferenceCompletedConditionVariable.wait_for(lck, + std::chrono::milliseconds(timeout), + [&]{return m_InferenceCompleted == true;})) + { + auto finish = std::chrono::high_resolution_clock::now(); + std::chrono::duration<double, std::milli> elapsed = finish - start; + std::stringstream ss; + ss << "Timed out waiting on inference completion for " << elapsed.count() << " ms"; + throw armnn::TimeoutException(ss.str()); + } + return; +} + +void TestTimelinePacketHandler::SetInferenceComplete() +{ + { // only lock when we are updating the inference completed variable + std::unique_lock<std::mutex> lck(m_InferenceCompletedMutex); + m_InferenceCompleted = true; + } + m_InferenceCompletedConditionVariable.notify_one(); +} + +void TestTimelinePacketHandler::ProcessDirectoryPacket(const Packet& packet) +{ + m_DirectoryDecoder(packet); +} + +void TestTimelinePacketHandler::ProcessMessagePacket(const Packet& packet) +{ + m_Decoder(packet); +} + +// TimelineMessageDecoder functions +ITimelineDecoder::TimelineStatus TimelineMessageDecoder::CreateEntity(const Entity& entity) +{ + m_TimelineModel.AddEntity(entity.m_Guid); + return ITimelineDecoder::TimelineStatus::TimelineStatus_Success; +} + +ITimelineDecoder::TimelineStatus TimelineMessageDecoder::CreateEventClass( + const ITimelineDecoder::EventClass& eventClass) +{ + // for the moment terminate the run here so we can get this code + // onto master prior to a major re-organisation + if (m_PacketHandler != nullptr) + { + m_PacketHandler->SetInferenceComplete(); + } + IgnoreUnused(eventClass); + return ITimelineDecoder::TimelineStatus::TimelineStatus_Success; +} + +ITimelineDecoder::TimelineStatus TimelineMessageDecoder::CreateEvent(const ITimelineDecoder::Event& event) +{ + IgnoreUnused(event); + return ITimelineDecoder::TimelineStatus::TimelineStatus_Success; +} + +ITimelineDecoder::TimelineStatus TimelineMessageDecoder::CreateLabel(const ITimelineDecoder::Label& label) +{ + m_TimelineModel.AddLabel(label); + return ITimelineDecoder::TimelineStatus::TimelineStatus_Success; +} + +ITimelineDecoder::TimelineStatus TimelineMessageDecoder::CreateRelationship( + const ITimelineDecoder::Relationship& relationship) +{ + m_TimelineModel.AddRelationship(relationship); + return ITimelineDecoder::TimelineStatus::TimelineStatus_Success; +} + +} // namespace profiling + +} // namespace armnn
\ No newline at end of file |