aboutsummaryrefslogtreecommitdiff
path: root/src/profiling/ProfilingUtils.cpp
diff options
context:
space:
mode:
authorMatteo Martincigh <matteo.martincigh@arm.com>2019-09-05 12:02:04 +0100
committerMatteo Martincigh <matteo.martincigh@arm.com>2019-09-09 16:47:56 +0000
commitab173e9b6978d5befb4884a803773967d52bcfef (patch)
tree1e632b4a8db54dc2051a2810ec485dd6b75755c1 /src/profiling/ProfilingUtils.cpp
parent149528e88c081e71fc7ec78e0c301eb2e487adfc (diff)
downloadarmnn-ab173e9b6978d5befb4884a803773967d52bcfef.tar.gz
IVGCVSW-3691 Add utility function to generate valid UIDs for profiling objects
Change-Id: I59ad320bfd52c881671c5e4710fb70c5d0293aad Signed-off-by: Matteo Martincigh <matteo.martincigh@arm.com>
Diffstat (limited to 'src/profiling/ProfilingUtils.cpp')
-rw-r--r--src/profiling/ProfilingUtils.cpp25
1 files changed, 24 insertions, 1 deletions
diff --git a/src/profiling/ProfilingUtils.cpp b/src/profiling/ProfilingUtils.cpp
index 015a66ed93..ef67f0324c 100644
--- a/src/profiling/ProfilingUtils.cpp
+++ b/src/profiling/ProfilingUtils.cpp
@@ -10,6 +10,8 @@
#include <boost/assert.hpp>
#include <fstream>
+#include <limits>
+#include <mutex>
namespace armnn
{
@@ -17,6 +19,27 @@ namespace armnn
namespace profiling
{
+uint16_t GetNextUid()
+{
+ // Static mutex for reading and modifying the global UID a single thread at the time
+ static std::mutex mutex;
+ std::unique_lock<std::mutex> lock(mutex);
+
+ // The UID used for profiling objects and events. The first valid UID is 1, as 0 is a reserved value
+ // (it is used to indicate that a record is not associated with any device)
+ static uint16_t uid{ 0 };
+
+ // Check that it is possible to generate the next UID without causing an overflow
+ if (uid == std::numeric_limits<uint16_t>::max())
+ {
+ throw RuntimeException("Generating the next UID for profiling would result in an overflow");
+ }
+
+ // Thread safe increment, the value that is incremented is the value checked for overflow,
+ // as this whole function is mutexed
+ return ++uid;
+}
+
void WriteUint64(unsigned char* buffer, unsigned int offset, uint64_t value)
{
BOOST_ASSERT(buffer);
@@ -54,7 +77,7 @@ uint64_t ReadUint64(const unsigned char* buffer, unsigned int offset)
BOOST_ASSERT(buffer);
uint64_t value = 0;
- value = static_cast<uint64_t>(buffer[offset]);
+ value = static_cast<uint64_t>(buffer[offset]);
value |= static_cast<uint64_t>(buffer[offset + 1]) << 8;
value |= static_cast<uint64_t>(buffer[offset + 2]) << 16;
value |= static_cast<uint64_t>(buffer[offset + 3]) << 24;