From 830101c2debac8b3f22c048fad603f34b76bdca1 Mon Sep 17 00:00:00 2001 From: Matteo Martincigh Date: Tue, 22 Oct 2019 11:07:45 +0100 Subject: IVGCVSW-4022 Create a DeclareLabel utility function * Created new TimelineUtilityMethods class * Created the DeclareLabel utility methods inside the new class * Added unit tests Change-Id: Ife0f7853a556d48206b76baeb3934344a990bee9 Signed-off-by: Matteo Martincigh --- Android.mk | 3 +- CMakeLists.txt | 3 ++ src/profiling/ProfilingGuid.hpp | 4 +- src/profiling/ProfilingGuidGenerator.hpp | 2 - src/profiling/TimelineUtilityMethods.cpp | 35 +++++++++++++++++ src/profiling/TimelineUtilityMethods.hpp | 33 ++++++++++++++++ src/profiling/test/TimelineUtilityMethodsTests.cpp | 45 ++++++++++++++++++++++ 7 files changed, 120 insertions(+), 5 deletions(-) create mode 100644 src/profiling/TimelineUtilityMethods.cpp create mode 100644 src/profiling/TimelineUtilityMethods.hpp create mode 100644 src/profiling/test/TimelineUtilityMethodsTests.cpp diff --git a/Android.mk b/Android.mk index 29ca0830c4..929eac0af7 100644 --- a/Android.mk +++ b/Android.mk @@ -190,7 +190,8 @@ LOCAL_SRC_FILES := \ src/profiling/ProfilingUtils.cpp \ src/profiling/RequestCounterDirectoryCommandHandler.cpp \ src/profiling/SendCounterPacket.cpp \ - src/profiling/SocketProfilingConnection.cpp + src/profiling/SocketProfilingConnection.cpp \ + src/profiling/TimelineUtilityMethods.cpp LOCAL_STATIC_LIBRARIES := \ armnn-arm_compute \ diff --git a/CMakeLists.txt b/CMakeLists.txt index 38605cac18..ac8b7e4264 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -495,6 +495,8 @@ list(APPEND armnn_sources src/profiling/SocketProfilingConnection.hpp src/profiling/TimelinePacketWriterFactory.cpp src/profiling/TimelinePacketWriterFactory.hpp + src/profiling/TimelineUtilityMethods.cpp + src/profiling/TimelineUtilityMethods.hpp third-party/half/half.hpp ) @@ -626,6 +628,7 @@ if(BUILD_UNIT_TESTS) src/profiling/test/SendCounterPacketTests.hpp src/profiling/test/SendTimelinePacketTests.cpp src/profiling/test/TimelinePacketTests.cpp + src/profiling/test/TimelineUtilityMethodsTests.cpp ) if(ARMNNREF) diff --git a/src/profiling/ProfilingGuid.hpp b/src/profiling/ProfilingGuid.hpp index 84d2db7363..5deee11783 100644 --- a/src/profiling/ProfilingGuid.hpp +++ b/src/profiling/ProfilingGuid.hpp @@ -18,7 +18,7 @@ class ProfilingGuid public: ProfilingGuid(uint64_t guid) : m_Guid(guid) {} - operator uint64_t () const { return m_Guid; } + operator uint64_t() const { return m_Guid; } bool operator==(const ProfilingGuid& other) const { @@ -27,7 +27,7 @@ public: bool operator!=(const ProfilingGuid& other) const { - return !(*this == other); + return m_Guid != other.m_Guid; } bool operator<(const ProfilingGuid& other) const diff --git a/src/profiling/ProfilingGuidGenerator.hpp b/src/profiling/ProfilingGuidGenerator.hpp index ff27c8ebe7..38816faf3e 100644 --- a/src/profiling/ProfilingGuidGenerator.hpp +++ b/src/profiling/ProfilingGuidGenerator.hpp @@ -26,8 +26,6 @@ public: /// Create a ProfilingStaticGuid based on a hash of the string // NOTE: dummy implementation for the moment inline ProfilingStaticGuid GenerateStaticId(const std::string& str) override { return ProfilingStaticGuid(0); } - -private: }; } // namespace profiling diff --git a/src/profiling/TimelineUtilityMethods.cpp b/src/profiling/TimelineUtilityMethods.cpp new file mode 100644 index 0000000000..5ae0cf6ee1 --- /dev/null +++ b/src/profiling/TimelineUtilityMethods.cpp @@ -0,0 +1,35 @@ +// +// Copyright © 2019 Arm Ltd. All rights reserved. +// SPDX-License-Identifier: MIT +// + +#include "TimelineUtilityMethods.hpp" +#include "ProfilingService.hpp" + +namespace armnn +{ + +namespace profiling +{ + +ProfilingStaticGuid TimelineUtilityMethods::DeclareLabel(const std::string& labelName) +{ + // Check that the label name is valid + if (labelName.empty()) + { + // The label name is invalid + throw InvalidArgumentException("Invalid label name, the label name cannot be empty"); + } + + // Generate a static GUID for the given label name + ProfilingStaticGuid labelGuid = ProfilingService::Instance().GenerateStaticId(labelName); + + // Send the new label to the external profiling service, this call throws in case of error + m_SendTimelinePacket.SendTimelineLabelBinaryPacket(labelGuid, labelName); + + return labelGuid; +} + +} // namespace profiling + +} // namespace armnn diff --git a/src/profiling/TimelineUtilityMethods.hpp b/src/profiling/TimelineUtilityMethods.hpp new file mode 100644 index 0000000000..22727c8b9a --- /dev/null +++ b/src/profiling/TimelineUtilityMethods.hpp @@ -0,0 +1,33 @@ +// +// Copyright © 2019 Arm Ltd. All rights reserved. +// SPDX-License-Identifier: MIT +// + +#pragma once + +#include "ISendTimelinePacket.hpp" +#include "ProfilingGuid.hpp" + +namespace armnn +{ + +namespace profiling +{ + +class TimelineUtilityMethods +{ +public: + TimelineUtilityMethods(ISendTimelinePacket& sendTimelinePacket) + : m_SendTimelinePacket(sendTimelinePacket) + {} + ~TimelineUtilityMethods() = default; + + ProfilingStaticGuid DeclareLabel(const std::string& labelName); + +private: + ISendTimelinePacket& m_SendTimelinePacket; +}; + +} // namespace profiling + +} // namespace armnn diff --git a/src/profiling/test/TimelineUtilityMethodsTests.cpp b/src/profiling/test/TimelineUtilityMethodsTests.cpp new file mode 100644 index 0000000000..c205712d62 --- /dev/null +++ b/src/profiling/test/TimelineUtilityMethodsTests.cpp @@ -0,0 +1,45 @@ +// +// Copyright © 2019 Arm Ltd. All rights reserved. +// SPDX-License-Identifier: MIT +// + +#include "SendCounterPacketTests.hpp" + +#include +#include + +#include + +using namespace armnn; +using namespace armnn::profiling; + +BOOST_AUTO_TEST_SUITE(TimelineUtilityMethodsTests) + +BOOST_AUTO_TEST_CASE(DeclareLabelTest1) +{ + MockBufferManager mockBufferManager(1024); + SendTimelinePacket sendTimelinePacket(mockBufferManager); + TimelineUtilityMethods timelineUtilityMethods(sendTimelinePacket); + + // Try declaring an invalid (empty) label + BOOST_CHECK_THROW(timelineUtilityMethods.DeclareLabel(""), InvalidArgumentException); + + // Try declaring an invalid (wrong SWTrace format) label + BOOST_CHECK_THROW(timelineUtilityMethods.DeclareLabel("inv@lid lab€l"), RuntimeException); + + // Declare a valid label + const std::string labelName = "valid label"; + ProfilingGuid labelGuid = 0; + BOOST_CHECK_NO_THROW(labelGuid = timelineUtilityMethods.DeclareLabel(labelName)); + // TODO when the implementation of the profiling GUID generator is done, enable the following test + //BOOST_CHECK(labelGuid != ProfilingGuid(0)); + + // TODO when the implementation of the profiling GUID generator is done, enable the following tests + // Try adding the same label as before + //ProfilingGuid newLabelGuid = 0; + //BOOST_CHECK_NO_THROW(labelGuid = timelineUtilityMethods.DeclareLabel(labelName)); + //BOOST_CHECK(newLabelGuid != ProfilingGuid(0)); + //BOOST_CHECK(newLabelGuid == labelGuid); +} + +BOOST_AUTO_TEST_SUITE_END() -- cgit v1.2.1