From 6db5f20ade72896ebf0f6513a4832b8f2e917aa0 Mon Sep 17 00:00:00 2001 From: Matteo Martincigh Date: Thu, 5 Sep 2019 12:02:04 +0100 Subject: IVGCVSW-3691 Rework the CounterDirectory class to take into consideration the connections between components * Added constructors and connections to the profiling classes * Used hash table to keep track of the profiling objects by UID * Added register methods * Added find/check helper methods * Updated the makefile to include the profiling directory * Added unit tests for the CounterDirectory class * Added ICounterDirectory interface class for read-only use * Added custom macro to locally disable conversion warnings Change-Id: I3f53a68663ee77b8d03ac0ef7dc01e90c6893511 Signed-off-by: Matteo Martincigh --- src/profiling/ProfilingUtils.hpp | 66 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 64 insertions(+), 2 deletions(-) (limited to 'src/profiling/ProfilingUtils.hpp') diff --git a/src/profiling/ProfilingUtils.hpp b/src/profiling/ProfilingUtils.hpp index 0e94e612d9..793f94d91b 100644 --- a/src/profiling/ProfilingUtils.hpp +++ b/src/profiling/ProfilingUtils.hpp @@ -7,8 +7,12 @@ #include +#include + #include -#include +#include +#include +#include namespace armnn { @@ -16,7 +20,65 @@ namespace armnn namespace profiling { -uint16_t GetNextUid(); +struct SwTraceCharPolicy +{ + static bool IsValidChar(unsigned char c) + { + // Check that the given character has ASCII 7-bit encoding + return c < 128; + } +}; + +struct SwTraceNameCharPolicy +{ + static bool IsValidChar(unsigned char c) + { + // Check that the given character has ASCII 7-bit encoding, alpha-numeric and underscore only + return c < 128 && (std::isalnum(c) || c == '_'); + } +}; + +template +bool IsValidSwTraceString(const std::string& s) +{ + // Check that all the characters in the given string conform to the given policy + return std::all_of(s.begin(), s.end(), [](unsigned char c) + { + return SwTracePolicy::IsValidChar(c); + }); +} + +template +bool StringToSwTraceString(const std::string& s, std::vector& outputBuffer) +{ + // Converts the given string to an SWTrace "string" (i.e. a string of "chars"), and writes it into + // the given buffer including the null-terminator. It also pads it to the next uint32_t if necessary + + // Clear the output buffer + outputBuffer.clear(); + + // Check that the given string is a valid SWTrace "string" (i.e. a string of "chars") + if (!IsValidSwTraceString(s)) + { + return false; + } + + // Prepare the output buffer + size_t s_size = s.size() + 1; // The size of the string (in chars) plus the null-terminator + size_t uint32_t_size = sizeof(uint32_t); + size_t outBufferSize = 1 + s_size / uint32_t_size + (s_size % uint32_t_size != 0 ? 1 : 0); + outputBuffer.resize(outBufferSize, '\0'); + + // Write the SWTrace string to the output buffer + outputBuffer[0] = boost::numeric_cast(s_size); + std::memcpy(outputBuffer.data() + 1, s.data(), s_size); + + return true; +} + +uint16_t GetNextUid(bool peekOnly = false); + +std::vector GetNextCounterUids(uint16_t cores); void WriteUint64(unsigned char* buffer, unsigned int offset, uint64_t value); -- cgit v1.2.1