diff options
author | Jim Flynn <jim.flynn@arm.com> | 2022-03-16 18:43:18 +0000 |
---|---|---|
committer | Jim Flynn <jim.flynn@arm.com> | 2022-03-16 21:41:51 +0000 |
commit | c454ac95267beecd67b1ec3ef8851d5089f99c4c (patch) | |
tree | 56a240e14004d05e8a4454374bac8fe80fca8d3c | |
parent | 9c85b41a9fcb3c64d7a686373e7dde75630ccd49 (diff) | |
download | armnn-c454ac95267beecd67b1ec3ef8851d5089f99c4c.tar.gz |
IVGCVSW-6851 Move DirectoryCaptureCommandHandler to the profiling server library
Change-Id: Ib14fdcca15f40fedc0f992b0fd882458dc58c9ba
Signed-off-by: Jim Flynn <jim.flynn@arm.com>
29 files changed, 292 insertions, 288 deletions
diff --git a/Android.mk b/Android.mk index ee2fedd9b5..b0436bdeb3 100644 --- a/Android.mk +++ b/Android.mk @@ -110,6 +110,7 @@ LOCAL_SRC_FILES := \ profiling/common/src/CommandHandlerKey.cpp \ profiling/common/src/CommandHandlerRegistry.cpp \ profiling/common/src/CommonProfilingUtils.cpp \ + profiling/common/src/CounterDirectory.cpp \ profiling/common/src/LabelsAndEventClasses.cpp \ profiling/common/src/Logging.cpp \ profiling/common/src/NetworkSockets.cpp \ @@ -117,6 +118,7 @@ LOCAL_SRC_FILES := \ profiling/common/src/Processes.cpp \ profiling/common/src/SwTrace.cpp \ profiling/common/src/Threads.cpp \ + profiling/server/src/timelineDecoder/DirectoryCaptureCommandHandler.cpp \ profiling/server/src/timelineDecoder/TimelineCaptureCommandHandler.cpp \ profiling/server/src/timelineDecoder/TimelineDecoder.cpp \ profiling/server/src/timelineDecoder/TimelineDirectoryCaptureCommandHandler.cpp \ @@ -239,10 +241,8 @@ LOCAL_SRC_FILES := \ src/profiling/BufferManager.cpp \ src/profiling/CommandHandler.cpp \ src/profiling/ConnectionAcknowledgedCommandHandler.cpp \ - src/profiling/CounterDirectory.cpp \ src/profiling/CounterIdMap.cpp \ src/profiling/DeactivateTimelineReportingCommandHandler.cpp \ - src/profiling/DirectoryCaptureCommandHandler.cpp \ src/profiling/FileOnlyProfilingConnection.cpp \ src/profiling/Holder.cpp \ src/profiling/IProfilingService.cpp \ diff --git a/CMakeLists.txt b/CMakeLists.txt index c739828763..e2fa9f3b06 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -422,23 +422,16 @@ list(APPEND armnn_sources src/profiling/CommandHandler.hpp src/profiling/ConnectionAcknowledgedCommandHandler.cpp src/profiling/ConnectionAcknowledgedCommandHandler.hpp - src/profiling/Counter.hpp - src/profiling/CounterDirectory.cpp - src/profiling/CounterDirectory.hpp src/profiling/CounterIdMap.cpp src/profiling/CounterIdMap.hpp src/profiling/DeactivateTimelineReportingCommandHandler.cpp src/profiling/DeactivateTimelineReportingCommandHandler.hpp - src/profiling/DirectoryCaptureCommandHandler.cpp - src/profiling/DirectoryCaptureCommandHandler.hpp src/profiling/FileOnlyProfilingConnection.cpp src/profiling/FileOnlyProfilingConnection.hpp src/profiling/Holder.cpp src/profiling/Holder.hpp src/profiling/IBufferManager.hpp src/profiling/IConsumer.hpp - src/profiling/ICounterDirectory.hpp - src/profiling/ICounterRegistry.hpp src/profiling/ICounterValues.hpp src/profiling/IInitialiseProfilingService.hpp src/profiling/INotifyBackends.hpp diff --git a/profiling/common/include/CommonProfilingUtils.hpp b/profiling/common/include/CommonProfilingUtils.hpp index 68fe6bb8ca..c07beafedf 100644 --- a/profiling/common/include/CommonProfilingUtils.hpp +++ b/profiling/common/include/CommonProfilingUtils.hpp @@ -4,6 +4,8 @@ // #pragma once +#include "ICounterDirectory.hpp" + #include <cstdint> #include <string> @@ -34,5 +36,11 @@ void WriteUint8(unsigned char* buffer, unsigned int offset, uint8_t value); std::string CentreAlignFormatting(const std::string& stringToPass, const int spacingWidth); +void PrintCounterDirectory(ICounterDirectory& counterDirectory); + +uint16_t GetNextUid(bool peekOnly = false); + + std::vector<uint16_t> GetNextCounterUids(uint16_t firstUid, uint16_t cores); + } // namespace pipe -} // namespace arm
\ No newline at end of file +} // namespace arm diff --git a/src/profiling/Counter.hpp b/profiling/common/include/Counter.hpp index ff96d257e7..ff96d257e7 100644 --- a/src/profiling/Counter.hpp +++ b/profiling/common/include/Counter.hpp diff --git a/src/profiling/CounterDirectory.hpp b/profiling/common/include/CounterDirectory.hpp index ecc349edff..ecc349edff 100644 --- a/src/profiling/CounterDirectory.hpp +++ b/profiling/common/include/CounterDirectory.hpp diff --git a/src/profiling/ICounterDirectory.hpp b/profiling/common/include/ICounterDirectory.hpp index d024516ab8..d024516ab8 100644 --- a/src/profiling/ICounterDirectory.hpp +++ b/profiling/common/include/ICounterDirectory.hpp diff --git a/src/profiling/ICounterRegistry.hpp b/profiling/common/include/ICounterRegistry.hpp index 5c34e7a3de..5c34e7a3de 100644 --- a/src/profiling/ICounterRegistry.hpp +++ b/profiling/common/include/ICounterRegistry.hpp diff --git a/profiling/common/src/CMakeLists.txt b/profiling/common/src/CMakeLists.txt index e02c785581..264902c0dc 100644 --- a/profiling/common/src/CMakeLists.txt +++ b/profiling/common/src/CMakeLists.txt @@ -10,6 +10,7 @@ if(BUILD_TIMELINE_DECODER) CommandHandlerKey.cpp CommandHandlerRegistry.cpp CommonProfilingUtils.cpp + CounterDirectory.cpp LabelsAndEventClasses.cpp Logging.cpp NetworkSockets.cpp diff --git a/profiling/common/src/CommonProfilingUtils.cpp b/profiling/common/src/CommonProfilingUtils.cpp index fe98e0aaa9..01bc461dd2 100644 --- a/profiling/common/src/CommonProfilingUtils.cpp +++ b/profiling/common/src/CommonProfilingUtils.cpp @@ -5,7 +5,10 @@ #include <common/include/Assert.hpp> #include <common/include/CommonProfilingUtils.hpp> +#include <common/include/ProfilingException.hpp> +#include <iostream> +#include <limits> #include <sstream> namespace arm @@ -140,6 +143,242 @@ std::string CentreAlignFormatting(const std::string& stringToPass, const int spa return outputStream.str(); } +void PrintDeviceDetails(const std::pair<const unsigned short, std::unique_ptr<Device>>& devicePair) +{ + std::string body; + + body.append(CentreAlignFormatting(devicePair.second->m_Name, 20)); + body.append(" | "); + body.append(CentreAlignFormatting(std::to_string(devicePair.first), 13)); + body.append(" | "); + body.append(CentreAlignFormatting(std::to_string(devicePair.second->m_Cores), 10)); + body.append("\n"); + + std::cout << std::string(body.size(), '-') << "\n"; + std::cout<< body; +} + +void PrintCounterSetDetails(const std::pair<const unsigned short, std::unique_ptr<CounterSet>>& counterSetPair) +{ + std::string body; + + body.append(CentreAlignFormatting(counterSetPair.second->m_Name, 20)); + body.append(" | "); + body.append(CentreAlignFormatting(std::to_string(counterSetPair.first), 13)); + body.append(" | "); + body.append(CentreAlignFormatting(std::to_string(counterSetPair.second->m_Count), 10)); + body.append("\n"); + + std::cout << std::string(body.size(), '-') << "\n"; + + std::cout<< body; +} + +void PrintCounterDetails(std::shared_ptr<Counter>& counter) +{ + std::string body; + + body.append(CentreAlignFormatting(counter->m_Name, 20)); + body.append(" | "); + body.append(CentreAlignFormatting(counter->m_Description, 50)); + body.append(" | "); + body.append(CentreAlignFormatting(counter->m_Units, 14)); + body.append(" | "); + body.append(CentreAlignFormatting(std::to_string(counter->m_Uid), 6)); + body.append(" | "); + body.append(CentreAlignFormatting(std::to_string(counter->m_MaxCounterUid), 10)); + body.append(" | "); + body.append(CentreAlignFormatting(std::to_string(counter->m_Class), 8)); + body.append(" | "); + body.append(CentreAlignFormatting(std::to_string(counter->m_Interpolation), 14)); + body.append(" | "); + body.append(CentreAlignFormatting(std::to_string(counter->m_Multiplier), 20)); + body.append(" | "); + body.append(CentreAlignFormatting(std::to_string(counter->m_CounterSetUid), 16)); + body.append(" | "); + body.append(CentreAlignFormatting(std::to_string(counter->m_DeviceUid), 14)); + + body.append("\n"); + + std::cout << std::string(body.size(), '-') << "\n"; + + std::cout << body; +} + +void PrintCategoryDetails(const std::unique_ptr<Category>& category, + std::unordered_map<unsigned short, std::shared_ptr<Counter>> counterMap) +{ + std::string categoryBody; + std::string categoryHeader; + + categoryHeader.append(CentreAlignFormatting("Name", 20)); + categoryHeader.append(" | "); + categoryHeader.append(CentreAlignFormatting("Event Count", 14)); + categoryHeader.append("\n"); + + categoryBody.append(CentreAlignFormatting(category->m_Name, 20)); + categoryBody.append(" | "); + categoryBody.append(CentreAlignFormatting(std::to_string(category->m_Counters.size()), 14)); + + std::cout << "\n" << "\n"; + std::cout << CentreAlignFormatting("CATEGORY", static_cast<int>(categoryHeader.size())); + std::cout << "\n"; + std::cout << std::string(categoryHeader.size(), '=') << "\n"; + + std::cout << categoryHeader; + + std::cout << std::string(categoryBody.size(), '-') << "\n"; + + std::cout << categoryBody; + + std::string counterHeader; + + counterHeader.append(CentreAlignFormatting("Counter Name", 20)); + counterHeader.append(" | "); + counterHeader.append(CentreAlignFormatting("Description", 50)); + counterHeader.append(" | "); + counterHeader.append(CentreAlignFormatting("Units", 14)); + counterHeader.append(" | "); + counterHeader.append(CentreAlignFormatting("UID", 6)); + counterHeader.append(" | "); + counterHeader.append(CentreAlignFormatting("Max UID", 10)); + counterHeader.append(" | "); + counterHeader.append(CentreAlignFormatting("Class", 8)); + counterHeader.append(" | "); + counterHeader.append(CentreAlignFormatting("Interpolation", 14)); + counterHeader.append(" | "); + counterHeader.append(CentreAlignFormatting("Multiplier", 20)); + counterHeader.append(" | "); + counterHeader.append(CentreAlignFormatting("Counter set UID", 16)); + counterHeader.append(" | "); + counterHeader.append(CentreAlignFormatting("Device UID", 14)); + counterHeader.append("\n"); + + std::cout << "\n" << "\n"; + std::cout << CentreAlignFormatting("EVENTS IN CATEGORY: " + category->m_Name, + static_cast<int>(counterHeader.size())); + std::cout << "\n"; + std::cout << std::string(counterHeader.size(), '=') << "\n"; + std::cout << counterHeader; + for (auto& it: category->m_Counters) { + auto search = counterMap.find(it); + if(search != counterMap.end()) { + PrintCounterDetails(search->second); + } + } +} + +void PrintCounterDirectory(ICounterDirectory& counterDirectory) +{ + std::string devicesHeader; + + devicesHeader.append(CentreAlignFormatting("Device name", 20)); + devicesHeader.append(" | "); + devicesHeader.append(CentreAlignFormatting("UID", 13)); + devicesHeader.append(" | "); + devicesHeader.append(CentreAlignFormatting("Cores", 10)); + devicesHeader.append("\n"); + + std::cout << "\n" << "\n"; + std::cout << CentreAlignFormatting("DEVICES", static_cast<int>(devicesHeader.size())); + std::cout << "\n"; + std::cout << std::string(devicesHeader.size(), '=') << "\n"; + std::cout << devicesHeader; + for (auto& it: counterDirectory.GetDevices()) { + PrintDeviceDetails(it); + } + + std::string counterSetHeader; + + counterSetHeader.append(CentreAlignFormatting("Counter set name", 20)); + counterSetHeader.append(" | "); + counterSetHeader.append(CentreAlignFormatting("UID", 13)); + counterSetHeader.append(" | "); + counterSetHeader.append(CentreAlignFormatting("Count", 10)); + counterSetHeader.append("\n"); + + std::cout << "\n" << "\n"; + std::cout << CentreAlignFormatting("COUNTER SETS", static_cast<int>(counterSetHeader.size())); + std::cout << "\n"; + std::cout << std::string(counterSetHeader.size(), '=') << "\n"; + + std::cout << counterSetHeader; + + for (auto& it: counterDirectory.GetCounterSets()) { + PrintCounterSetDetails(it); + } + + auto counters = counterDirectory.GetCounters(); + for (auto& it: counterDirectory.GetCategories()) { + PrintCategoryDetails(it, counters); + } + std::cout << "\n"; +} + +namespace +{ + +void ThrowIfCantGenerateNextUid(uint16_t uid, uint16_t cores = 0) +{ + // Check that it is possible to generate the next UID without causing an overflow + switch (cores) + { + case 0: + case 1: + // Number of cores not specified or set to 1 (a value of zero indicates the device is not capable of + // running multiple parallel workloads and will not provide multiple streams of data for each event) + if (uid == std::numeric_limits<uint16_t>::max()) + { + throw arm::pipe::ProfilingException("Generating the next UID for profiling would result in an overflow"); + } + break; + default: // cores > 1 + // Multiple cores available, as max_counter_uid has to be set to: counter_uid + cores - 1, the maximum + // allowed value for a counter UID is consequently: uint16_t_max - cores + 1 + if (uid >= std::numeric_limits<uint16_t>::max() - cores + 1) + { + throw arm::pipe::ProfilingException("Generating the next UID for profiling would result in an overflow"); + } + break; + } +} + +} // Anonymous namespace + +uint16_t GetNextUid(bool peekOnly) +{ + // The UID used for profiling objects and events. The first valid UID is 1, as 0 is a reserved value + static uint16_t uid = 1; + + // Check that it is possible to generate the next UID without causing an overflow (throws in case of error) + ThrowIfCantGenerateNextUid(uid); + + if (peekOnly) + { + // Peek only + return uid; + } + else + { + // Get the next UID + return uid++; + } +} + +std::vector<uint16_t> GetNextCounterUids(uint16_t firstUid, uint16_t cores) +{ + // Check that it is possible to generate the next counter UID without causing an overflow (throws in case of error) + ThrowIfCantGenerateNextUid(firstUid, cores); + + // Get the next counter UIDs + size_t counterUidsSize = cores == 0 ? 1 : cores; + std::vector<uint16_t> counterUids(counterUidsSize, 0); + for (size_t i = 0; i < counterUidsSize; i++) + { + counterUids[i] = firstUid++; + } + return counterUids; +} } // namespace pipe -} // namespace arm
\ No newline at end of file +} // namespace arm diff --git a/src/profiling/CounterDirectory.cpp b/profiling/common/src/CounterDirectory.cpp index 0f6147f833..f338858498 100644 --- a/src/profiling/CounterDirectory.cpp +++ b/profiling/common/src/CounterDirectory.cpp @@ -3,8 +3,8 @@ // SPDX-License-Identifier: MIT // -#include "CounterDirectory.hpp" -#include "ProfilingUtils.hpp" +#include <common/include/CounterDirectory.hpp> +#include <common/include/CommonProfilingUtils.hpp> #include <common/include/Assert.hpp> #include <common/include/SwTrace.hpp> diff --git a/src/profiling/DirectoryCaptureCommandHandler.hpp b/profiling/server/include/timelineDecoder/DirectoryCaptureCommandHandler.hpp index 007cf05d18..de10ec8892 100644 --- a/src/profiling/DirectoryCaptureCommandHandler.hpp +++ b/profiling/server/include/timelineDecoder/DirectoryCaptureCommandHandler.hpp @@ -5,9 +5,8 @@ #pragma once -#include "CounterDirectory.hpp" - #include <common/include/CommandHandlerFunctor.hpp> +#include <common/include/CounterDirectory.hpp> #include <atomic> diff --git a/profiling/server/src/timelineDecoder/CMakeLists.txt b/profiling/server/src/timelineDecoder/CMakeLists.txt index 7154722fa6..4ac68a52af 100644 --- a/profiling/server/src/timelineDecoder/CMakeLists.txt +++ b/profiling/server/src/timelineDecoder/CMakeLists.txt @@ -6,6 +6,7 @@ if(BUILD_TIMELINE_DECODER) set(timelineDecoder_sources) list(APPEND timelineDecoder_sources + DirectoryCaptureCommandHandler.cpp TimelineCaptureCommandHandler.cpp TimelineDecoder.cpp TimelineDirectoryCaptureCommandHandler.cpp) diff --git a/src/profiling/DirectoryCaptureCommandHandler.cpp b/profiling/server/src/timelineDecoder/DirectoryCaptureCommandHandler.cpp index 4011c9b1ff..48dce40dd1 100644 --- a/src/profiling/DirectoryCaptureCommandHandler.cpp +++ b/profiling/server/src/timelineDecoder/DirectoryCaptureCommandHandler.cpp @@ -3,9 +3,9 @@ // SPDX-License-Identifier: MIT // -#include "DirectoryCaptureCommandHandler.hpp" +#include <common/include/CommonProfilingUtils.hpp> -#include "ProfilingUtils.hpp" +#include <server/include/timelineDecoder/DirectoryCaptureCommandHandler.hpp> #include <atomic> #include <iostream> diff --git a/src/armnn/ArmNNProfilingServiceInitialiser.cpp b/src/armnn/ArmNNProfilingServiceInitialiser.cpp index 03ca56288b..bbed43ae4c 100644 --- a/src/armnn/ArmNNProfilingServiceInitialiser.cpp +++ b/src/armnn/ArmNNProfilingServiceInitialiser.cpp @@ -9,7 +9,7 @@ #include <armnn/profiling/ArmNNProfiling.hpp> #include <armnn/utility/Assert.hpp> -#include <Counter.hpp> +#include <common/include/Counter.hpp> namespace armnn { diff --git a/src/backends/backendsCommon/test/BackendProfilingTests.cpp b/src/backends/backendsCommon/test/BackendProfilingTests.cpp index 164efb3b9d..9b80a8fa72 100644 --- a/src/backends/backendsCommon/test/BackendProfilingTests.cpp +++ b/src/backends/backendsCommon/test/BackendProfilingTests.cpp @@ -4,7 +4,6 @@ // #include "ArmNNProfilingServiceInitialiser.hpp" -#include "CounterDirectory.hpp" #include "CounterIdMap.hpp" #include "Holder.hpp" #include "MockBackendId.hpp" @@ -15,24 +14,28 @@ #include "ProfilingUtils.hpp" #include "RequestCounterDirectoryCommandHandler.hpp" -#include <armnn/profiling/ArmNNProfiling.hpp> - #include <TestUtils.hpp> -#include <armnn/utility/IgnoreUnused.hpp> #include <armnn/BackendId.hpp> #include <armnn/Logging.hpp> + +#include <armnn/profiling/ArmNNProfiling.hpp> #include <armnn/profiling/ISendTimelinePacket.hpp> #include <armnn/profiling/ProfilingOptions.hpp> + +#include <armnn/utility/IgnoreUnused.hpp> + #include <armnnTestUtils/MockBackend.hpp> +#include <backends/BackendProfiling.hpp> + +#include <common/include/CounterDirectory.hpp> + #include <doctest/doctest.h> -#include <vector> +#include <vector> #include <cstdint> #include <limits> -#include <backends/BackendProfiling.hpp> - namespace arm { diff --git a/src/profiling/FileOnlyProfilingConnection.hpp b/src/profiling/FileOnlyProfilingConnection.hpp index 48fb4d37f2..9d40420ec8 100644 --- a/src/profiling/FileOnlyProfilingConnection.hpp +++ b/src/profiling/FileOnlyProfilingConnection.hpp @@ -8,13 +8,14 @@ #include <armnn/profiling/ILocalPacketHandler.hpp> #include <armnn/profiling/ProfilingOptions.hpp> -#include "DirectoryCaptureCommandHandler.hpp" #include "IProfilingConnection.hpp" #include "ProfilingUtils.hpp" #include <common/include/Assert.hpp> #include <common/include/Packet.hpp> +#include <server/include/timelineDecoder/DirectoryCaptureCommandHandler.hpp> + #include <atomic> #include <condition_variable> #include <fstream> diff --git a/src/profiling/IProfilingService.hpp b/src/profiling/IProfilingService.hpp index 6486b6f246..353059aec3 100644 --- a/src/profiling/IProfilingService.hpp +++ b/src/profiling/IProfilingService.hpp @@ -8,7 +8,6 @@ #include "CounterIdMap.hpp" #include "Holder.hpp" #include "ICounterValues.hpp" -#include "ICounterRegistry.hpp" #include "IInitialiseProfilingService.hpp" #include "IProfilingServiceStatus.hpp" #include "ISendCounterPacket.hpp" @@ -18,9 +17,11 @@ #include <armnn/backends/profiling/IBackendProfilingContext.hpp> #include <armnn/profiling/ProfilingOptions.hpp> +#include <common/include/ICounterRegistry.hpp> #include <common/include/Optional.hpp> #include <common/include/ProfilingGuidGenerator.hpp> + namespace arm { diff --git a/src/profiling/ISendCounterPacket.hpp b/src/profiling/ISendCounterPacket.hpp index 0e3ae6faf2..522dc7c7cb 100644 --- a/src/profiling/ISendCounterPacket.hpp +++ b/src/profiling/ISendCounterPacket.hpp @@ -6,7 +6,7 @@ #pragma once #include <armnn/backends/profiling/IBackendProfiling.hpp> -#include "ICounterDirectory.hpp" +#include <common/include/ICounterDirectory.hpp> namespace arm { @@ -38,4 +38,3 @@ public: } // namespace pipe } // namespace arm - diff --git a/src/profiling/ProfilingService.hpp b/src/profiling/ProfilingService.hpp index 9e788fd4b3..58bfd3afcf 100644 --- a/src/profiling/ProfilingService.hpp +++ b/src/profiling/ProfilingService.hpp @@ -9,12 +9,10 @@ #include "BufferManager.hpp" #include "CommandHandler.hpp" #include "ConnectionAcknowledgedCommandHandler.hpp" -#include "CounterDirectory.hpp" #include "CounterIdMap.hpp" #include "DeactivateTimelineReportingCommandHandler.hpp" -#include "ICounterRegistry.hpp" #include "ICounterValues.hpp" -#include <armnn/profiling/ILocalPacketHandler.hpp> +#include "INotifyBackends.hpp" #include "IProfilingService.hpp" #include "IReportStructure.hpp" #include "PeriodicCounterCapture.hpp" @@ -27,9 +25,12 @@ #include "SendThread.hpp" #include "SendTimelinePacket.hpp" #include "TimelinePacketWriterFactory.hpp" -#include "INotifyBackends.hpp" + #include <armnn/backends/profiling/IBackendProfilingContext.hpp> +#include <armnn/profiling/ILocalPacketHandler.hpp> + +#include <common/include/CounterDirectory.hpp> #include <list> diff --git a/src/profiling/ProfilingUtils.cpp b/src/profiling/ProfilingUtils.cpp index e403b1cacf..2963a98621 100644 --- a/src/profiling/ProfilingUtils.cpp +++ b/src/profiling/ProfilingUtils.cpp @@ -23,71 +23,6 @@ namespace arm namespace pipe { -namespace -{ - -void ThrowIfCantGenerateNextUid(uint16_t uid, uint16_t cores = 0) -{ - // Check that it is possible to generate the next UID without causing an overflow - switch (cores) - { - case 0: - case 1: - // Number of cores not specified or set to 1 (a value of zero indicates the device is not capable of - // running multiple parallel workloads and will not provide multiple streams of data for each event) - if (uid == std::numeric_limits<uint16_t>::max()) - { - throw arm::pipe::ProfilingException("Generating the next UID for profiling would result in an overflow"); - } - break; - default: // cores > 1 - // Multiple cores available, as max_counter_uid has to be set to: counter_uid + cores - 1, the maximum - // allowed value for a counter UID is consequently: uint16_t_max - cores + 1 - if (uid >= std::numeric_limits<uint16_t>::max() - cores + 1) - { - throw arm::pipe::ProfilingException("Generating the next UID for profiling would result in an overflow"); - } - break; - } -} - -} // Anonymous namespace - -uint16_t GetNextUid(bool peekOnly) -{ - // The UID used for profiling objects and events. The first valid UID is 1, as 0 is a reserved value - static uint16_t uid = 1; - - // Check that it is possible to generate the next UID without causing an overflow (throws in case of error) - ThrowIfCantGenerateNextUid(uid); - - if (peekOnly) - { - // Peek only - return uid; - } - else - { - // Get the next UID - return uid++; - } -} - -std::vector<uint16_t> GetNextCounterUids(uint16_t firstUid, uint16_t cores) -{ - // Check that it is possible to generate the next counter UID without causing an overflow (throws in case of error) - ThrowIfCantGenerateNextUid(firstUid, cores); - - // Get the next counter UIDs - size_t counterUidsSize = cores == 0 ? 1 : cores; - std::vector<uint16_t> counterUids(counterUidsSize, 0); - for (size_t i = 0; i < counterUidsSize; i++) - { - counterUids[i] = firstUid++; - } - return counterUids; -} - void WriteBytes(const IPacketBufferPtr& packetBuffer, unsigned int offset, const void* value, unsigned int valueSize) { ARM_PIPE_ASSERT(packetBuffer); @@ -656,178 +591,6 @@ TimelinePacketStatus WriteTimelineEventBinary(uint64_t timestamp, return TimelinePacketStatus::Ok; } -void PrintDeviceDetails(const std::pair<const unsigned short, std::unique_ptr<Device>>& devicePair) -{ - std::string body; - - body.append(CentreAlignFormatting(devicePair.second->m_Name, 20)); - body.append(" | "); - body.append(CentreAlignFormatting(std::to_string(devicePair.first), 13)); - body.append(" | "); - body.append(CentreAlignFormatting(std::to_string(devicePair.second->m_Cores), 10)); - body.append("\n"); - - std::cout << std::string(body.size(), '-') << "\n"; - std::cout<< body; -} - -void PrintCounterSetDetails(const std::pair<const unsigned short, std::unique_ptr<CounterSet>>& counterSetPair) -{ - std::string body; - - body.append(CentreAlignFormatting(counterSetPair.second->m_Name, 20)); - body.append(" | "); - body.append(CentreAlignFormatting(std::to_string(counterSetPair.first), 13)); - body.append(" | "); - body.append(CentreAlignFormatting(std::to_string(counterSetPair.second->m_Count), 10)); - body.append("\n"); - - std::cout << std::string(body.size(), '-') << "\n"; - - std::cout<< body; -} - -void PrintCounterDetails(std::shared_ptr<Counter>& counter) -{ - std::string body; - - body.append(CentreAlignFormatting(counter->m_Name, 20)); - body.append(" | "); - body.append(CentreAlignFormatting(counter->m_Description, 50)); - body.append(" | "); - body.append(CentreAlignFormatting(counter->m_Units, 14)); - body.append(" | "); - body.append(CentreAlignFormatting(std::to_string(counter->m_Uid), 6)); - body.append(" | "); - body.append(CentreAlignFormatting(std::to_string(counter->m_MaxCounterUid), 10)); - body.append(" | "); - body.append(CentreAlignFormatting(std::to_string(counter->m_Class), 8)); - body.append(" | "); - body.append(CentreAlignFormatting(std::to_string(counter->m_Interpolation), 14)); - body.append(" | "); - body.append(CentreAlignFormatting(std::to_string(counter->m_Multiplier), 20)); - body.append(" | "); - body.append(CentreAlignFormatting(std::to_string(counter->m_CounterSetUid), 16)); - body.append(" | "); - body.append(CentreAlignFormatting(std::to_string(counter->m_DeviceUid), 14)); - - body.append("\n"); - - std::cout << std::string(body.size(), '-') << "\n"; - - std::cout << body; -} - -void PrintCategoryDetails(const std::unique_ptr<Category>& category, - std::unordered_map<unsigned short, std::shared_ptr<Counter>> counterMap) -{ - std::string categoryBody; - std::string categoryHeader; - - categoryHeader.append(CentreAlignFormatting("Name", 20)); - categoryHeader.append(" | "); - categoryHeader.append(CentreAlignFormatting("Event Count", 14)); - categoryHeader.append("\n"); - - categoryBody.append(CentreAlignFormatting(category->m_Name, 20)); - categoryBody.append(" | "); - categoryBody.append(CentreAlignFormatting(std::to_string(category->m_Counters.size()), 14)); - - std::cout << "\n" << "\n"; - std::cout << CentreAlignFormatting("CATEGORY", static_cast<int>(categoryHeader.size())); - std::cout << "\n"; - std::cout << std::string(categoryHeader.size(), '=') << "\n"; - - std::cout << categoryHeader; - - std::cout << std::string(categoryBody.size(), '-') << "\n"; - - std::cout << categoryBody; - - std::string counterHeader; - - counterHeader.append(CentreAlignFormatting("Counter Name", 20)); - counterHeader.append(" | "); - counterHeader.append(CentreAlignFormatting("Description", 50)); - counterHeader.append(" | "); - counterHeader.append(CentreAlignFormatting("Units", 14)); - counterHeader.append(" | "); - counterHeader.append(CentreAlignFormatting("UID", 6)); - counterHeader.append(" | "); - counterHeader.append(CentreAlignFormatting("Max UID", 10)); - counterHeader.append(" | "); - counterHeader.append(CentreAlignFormatting("Class", 8)); - counterHeader.append(" | "); - counterHeader.append(CentreAlignFormatting("Interpolation", 14)); - counterHeader.append(" | "); - counterHeader.append(CentreAlignFormatting("Multiplier", 20)); - counterHeader.append(" | "); - counterHeader.append(CentreAlignFormatting("Counter set UID", 16)); - counterHeader.append(" | "); - counterHeader.append(CentreAlignFormatting("Device UID", 14)); - counterHeader.append("\n"); - - std::cout << "\n" << "\n"; - std::cout << CentreAlignFormatting("EVENTS IN CATEGORY: " + category->m_Name, - static_cast<int>(counterHeader.size())); - std::cout << "\n"; - std::cout << std::string(counterHeader.size(), '=') << "\n"; - std::cout << counterHeader; - for (auto& it: category->m_Counters) { - auto search = counterMap.find(it); - if(search != counterMap.end()) { - PrintCounterDetails(search->second); - } - } -} - -void PrintCounterDirectory(ICounterDirectory& counterDirectory) -{ - std::string devicesHeader; - - devicesHeader.append(CentreAlignFormatting("Device name", 20)); - devicesHeader.append(" | "); - devicesHeader.append(CentreAlignFormatting("UID", 13)); - devicesHeader.append(" | "); - devicesHeader.append(CentreAlignFormatting("Cores", 10)); - devicesHeader.append("\n"); - - std::cout << "\n" << "\n"; - std::cout << CentreAlignFormatting("DEVICES", static_cast<int>(devicesHeader.size())); - std::cout << "\n"; - std::cout << std::string(devicesHeader.size(), '=') << "\n"; - std::cout << devicesHeader; - for (auto& it: counterDirectory.GetDevices()) { - PrintDeviceDetails(it); - } - - std::string counterSetHeader; - - counterSetHeader.append(CentreAlignFormatting("Counter set name", 20)); - counterSetHeader.append(" | "); - counterSetHeader.append(CentreAlignFormatting("UID", 13)); - counterSetHeader.append(" | "); - counterSetHeader.append(CentreAlignFormatting("Count", 10)); - counterSetHeader.append("\n"); - - std::cout << "\n" << "\n"; - std::cout << CentreAlignFormatting("COUNTER SETS", static_cast<int>(counterSetHeader.size())); - std::cout << "\n"; - std::cout << std::string(counterSetHeader.size(), '=') << "\n"; - - std::cout << counterSetHeader; - - for (auto& it: counterDirectory.GetCounterSets()) { - PrintCounterSetDetails(it); - } - - auto counters = counterDirectory.GetCounters(); - for (auto& it: counterDirectory.GetCategories()) { - PrintCategoryDetails(it, counters); - } - std::cout << "\n"; -} - uint64_t GetTimestamp() { #if USE_CLOCK_MONOTONIC_RAW diff --git a/src/profiling/ProfilingUtils.hpp b/src/profiling/ProfilingUtils.hpp index 649ebfa63a..593dd6b924 100644 --- a/src/profiling/ProfilingUtils.hpp +++ b/src/profiling/ProfilingUtils.hpp @@ -5,11 +5,11 @@ #pragma once +#include <common/include/ICounterDirectory.hpp> #include <common/include/ProfilingException.hpp> #include <armnn/profiling/ISendTimelinePacket.hpp> -#include "ICounterDirectory.hpp" #include "IPacketBuffer.hpp" #include <common/include/Packet.hpp> @@ -29,10 +29,6 @@ namespace pipe constexpr unsigned int ThreadIdSize = sizeof(int); // Is platform dependent -uint16_t GetNextUid(bool peekOnly = false); - -std::vector<uint16_t> GetNextCounterUids(uint16_t firstUid, uint16_t cores); - void WriteBytes(const IPacketBuffer& packetBuffer, unsigned int offset, const void* value, unsigned int valueSize); uint32_t ConstructHeader(uint32_t packetFamily, uint32_t packetId); @@ -132,8 +128,6 @@ TimelinePacketStatus WriteTimelineEventBinary(uint64_t timestamp, std::string CentreAlignFormatting(const std::string& stringToPass, const int spacingWidth); -void PrintCounterDirectory(ICounterDirectory& counterDirectory); - uint64_t GetTimestamp(); arm::pipe::Packet ReceivePacket(const unsigned char* buffer, uint32_t length); diff --git a/src/profiling/RegisterBackendCounters.hpp b/src/profiling/RegisterBackendCounters.hpp index e3045b2b8c..3d3b11a626 100644 --- a/src/profiling/RegisterBackendCounters.hpp +++ b/src/profiling/RegisterBackendCounters.hpp @@ -5,11 +5,13 @@ #pragma once -#include "armnn/backends/profiling/IBackendProfiling.hpp" #include "CounterIdMap.hpp" -#include "CounterDirectory.hpp" #include "IProfilingService.hpp" +#include "armnn/backends/profiling/IBackendProfiling.hpp" + +#include <common/include/CounterDirectory.hpp> + namespace arm { diff --git a/src/profiling/SendCounterPacket.hpp b/src/profiling/SendCounterPacket.hpp index c33bdcc025..047dd3c7c9 100644 --- a/src/profiling/SendCounterPacket.hpp +++ b/src/profiling/SendCounterPacket.hpp @@ -6,7 +6,6 @@ #pragma once #include "IBufferManager.hpp" -#include "ICounterDirectory.hpp" #include "ISendCounterPacket.hpp" #include "ProfilingUtils.hpp" diff --git a/src/profiling/SendThread.hpp b/src/profiling/SendThread.hpp index 6512c8aac6..f68a74c1d3 100644 --- a/src/profiling/SendThread.hpp +++ b/src/profiling/SendThread.hpp @@ -7,13 +7,14 @@ #include "IBufferManager.hpp" #include "IConsumer.hpp" -#include "ICounterDirectory.hpp" #include "ISendCounterPacket.hpp" #include "ISendThread.hpp" #include "IProfilingConnection.hpp" #include "ProfilingStateMachine.hpp" #include "ProfilingUtils.hpp" +#include <common/include/ICounterDirectory.hpp> + #include <atomic> #include <condition_variable> #include <mutex> diff --git a/src/profiling/test/ProfilingMocks.hpp b/src/profiling/test/ProfilingMocks.hpp index cfc1096b8d..80ac1fed0e 100644 --- a/src/profiling/test/ProfilingMocks.hpp +++ b/src/profiling/test/ProfilingMocks.hpp @@ -17,6 +17,7 @@ #include <armnn/profiling/ArmNNProfiling.hpp> #include <common/include/Assert.hpp> +#include <common/include/CommonProfilingUtils.hpp> #include <common/include/IgnoreUnused.hpp> #include <common/include/NumericCast.hpp> #include <common/include/Optional.hpp> diff --git a/src/profiling/test/ProfilingTests.cpp b/src/profiling/test/ProfilingTests.cpp index 19e5f1baa6..22b2ae233a 100644 --- a/src/profiling/test/ProfilingTests.cpp +++ b/src/profiling/test/ProfilingTests.cpp @@ -9,7 +9,6 @@ #include <ArmNNProfilingServiceInitialiser.hpp> #include <CommandHandler.hpp> #include <ConnectionAcknowledgedCommandHandler.hpp> -#include <CounterDirectory.hpp> #include <CounterIdMap.hpp> #include <Holder.hpp> #include <ICounterValues.hpp> @@ -34,6 +33,7 @@ #include <common/include/CommandHandlerKey.hpp> #include <common/include/CommandHandlerRegistry.hpp> +#include <common/include/CounterDirectory.hpp> #include <common/include/EncodeVersion.hpp> #include <common/include/IgnoreUnused.hpp> #include <common/include/NumericCast.hpp> diff --git a/src/profiling/test/RequestCountersPacketHandler.cpp b/src/profiling/test/RequestCountersPacketHandler.cpp index 0a71d3cd62..6a757c2c0b 100644 --- a/src/profiling/test/RequestCountersPacketHandler.cpp +++ b/src/profiling/test/RequestCountersPacketHandler.cpp @@ -5,12 +5,12 @@ #include "RequestCountersPacketHandler.hpp" -#include "DirectoryCaptureCommandHandler.hpp" - #include <common/include/NumericCast.hpp> #include <common/include/PacketVersionResolver.hpp> #include <common/include/ProfilingException.hpp> +#include <server/include/timelineDecoder/DirectoryCaptureCommandHandler.hpp> + namespace arm { diff --git a/src/profiling/test/SendCounterPacketTests.cpp b/src/profiling/test/SendCounterPacketTests.cpp index 4f7886afe3..4ba5eed6ac 100644 --- a/src/profiling/test/SendCounterPacketTests.cpp +++ b/src/profiling/test/SendCounterPacketTests.cpp @@ -8,7 +8,6 @@ #include "SendCounterPacketTests.hpp" #include <BufferManager.hpp> -#include <CounterDirectory.hpp> #include <ProfilingUtils.hpp> #include <SendCounterPacket.hpp> @@ -17,6 +16,7 @@ #include <common/include/Assert.hpp> #include <common/include/Conversion.hpp> #include <common/include/Constants.hpp> +#include <common/include/CounterDirectory.hpp> #include <common/include/EncodeVersion.hpp> #include <common/include/NumericCast.hpp> #include <common/include/Processes.hpp> diff --git a/tests/profiling/gatordmock/GatordMockService.hpp b/tests/profiling/gatordmock/GatordMockService.hpp index cc9cdd1d8e..fa483e0a51 100644 --- a/tests/profiling/gatordmock/GatordMockService.hpp +++ b/tests/profiling/gatordmock/GatordMockService.hpp @@ -16,13 +16,11 @@ #include <server/include/basePipeServer/BasePipeServer.hpp> +#include <server/include/timelineDecoder/DirectoryCaptureCommandHandler.hpp> #include <server/include/timelineDecoder/TimelineDecoder.hpp> #include <server/include/timelineDecoder/TimelineCaptureCommandHandler.hpp> #include <server/include/timelineDecoder/TimelineDirectoryCaptureCommandHandler.hpp> -// src/profiling -#include <DirectoryCaptureCommandHandler.hpp> - #include <atomic> #include <string> #include <thread> |