IVGCVSW-4031 Provide well known profiling GUIDs

Change-Id: Ibf99b025f51503e8937012b655aad74698f32e38
Signed-off-by: Jim Flynn <jim.flynn@arm.com>
Signed-off-by: Matteo Martincigh <matteo.martincigh@arm.com>
diff --git a/Android.mk b/Android.mk
index 929eac0..c91b43f 100644
--- a/Android.mk
+++ b/Android.mk
@@ -178,6 +178,7 @@
         src/profiling/ConnectionAcknowledgedCommandHandler.cpp \
         src/profiling/CounterDirectory.cpp \
         src/profiling/Holder.cpp \
+        src/profiling/LabelsAndEventClasses.cpp \
         src/profiling/PacketBuffer.cpp \
         src/profiling/PacketVersionResolver.cpp \
         src/profiling/PeriodicCounterCapture.cpp \
diff --git a/CMakeLists.txt b/CMakeLists.txt
index ac8b7e4..005650f 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -462,6 +462,8 @@
     src/profiling/IProfilingConnection.hpp
     src/profiling/IProfilingConnectionFactory.hpp
     src/profiling/IProfilingGuidGenerator.hpp
+    src/profiling/LabelsAndEventClasses.cpp
+    src/profiling/LabelsAndEventClasses.hpp
     src/profiling/Packet.hpp
     src/profiling/PacketBuffer.cpp
     src/profiling/PacketBuffer.hpp
diff --git a/src/profiling/IProfilingGuidGenerator.hpp b/src/profiling/IProfilingGuidGenerator.hpp
index 96e1792..34ee967 100644
--- a/src/profiling/IProfilingGuidGenerator.hpp
+++ b/src/profiling/IProfilingGuidGenerator.hpp
@@ -7,6 +7,8 @@
 
 #include "ProfilingGuid.hpp"
 
+#include <string>
+
 namespace armnn
 {
 
diff --git a/src/profiling/LabelsAndEventClasses.cpp b/src/profiling/LabelsAndEventClasses.cpp
new file mode 100644
index 0000000..a00562d
--- /dev/null
+++ b/src/profiling/LabelsAndEventClasses.cpp
@@ -0,0 +1,36 @@
+//
+// Copyright © 2019 Arm Ltd. All rights reserved.
+// SPDX-License-Identifier: MIT
+//
+
+#include "LabelsAndEventClasses.hpp"
+
+namespace armnn
+{
+
+namespace profiling
+{
+
+ProfilingGuidGenerator LabelsAndEventClasses::m_GuidGenerator;
+
+// Labels (string value + GUID)
+std::string LabelsAndEventClasses::NAME_LABEL("name");
+std::string LabelsAndEventClasses::TYPE_LABEL("type");
+std::string LabelsAndEventClasses::INDEX_LABEL("index");
+
+ProfilingStaticGuid LabelsAndEventClasses::NAME_GUID(
+    m_GuidGenerator.GenerateStaticId(LabelsAndEventClasses::NAME_LABEL));
+ProfilingStaticGuid LabelsAndEventClasses::TYPE_GUID(
+    m_GuidGenerator.GenerateStaticId(LabelsAndEventClasses::TYPE_LABEL));
+ProfilingStaticGuid LabelsAndEventClasses::INDEX_GUID(
+    m_GuidGenerator.GenerateStaticId(LabelsAndEventClasses::INDEX_LABEL));
+
+// Event Class GUIDs
+ProfilingStaticGuid LabelsAndEventClasses::ARMNN_PROFILING_SOL_EVENT_CLASS(
+    m_GuidGenerator.GenerateStaticId("ARMNN_PROFILING_SOL"));
+ProfilingStaticGuid LabelsAndEventClasses::ARMNN_PROFILING_EOL_EVENT_CLASS(
+    m_GuidGenerator.GenerateStaticId("ARMNN_PROFILING_EOL"));
+
+} // namespace profiling
+
+} // namespace armnn
diff --git a/src/profiling/LabelsAndEventClasses.hpp b/src/profiling/LabelsAndEventClasses.hpp
new file mode 100644
index 0000000..07aeb81
--- /dev/null
+++ b/src/profiling/LabelsAndEventClasses.hpp
@@ -0,0 +1,38 @@
+//
+// Copyright © 2019 Arm Ltd. All rights reserved.
+// SPDX-License-Identifier: MIT
+//
+
+#pragma once
+
+#include "ProfilingGuid.hpp"
+#include "ProfilingGuidGenerator.hpp"
+
+namespace armnn
+{
+
+namespace profiling
+{
+
+class LabelsAndEventClasses
+{
+public:
+    // Labels (string value + GUID)
+    static std::string NAME_LABEL;
+    static std::string TYPE_LABEL;
+    static std::string INDEX_LABEL;
+    static ProfilingStaticGuid NAME_GUID;
+    static ProfilingStaticGuid TYPE_GUID;
+    static ProfilingStaticGuid INDEX_GUID;
+
+    // Event Class GUIDs
+    static ProfilingStaticGuid ARMNN_PROFILING_SOL_EVENT_CLASS;
+    static ProfilingStaticGuid ARMNN_PROFILING_EOL_EVENT_CLASS;
+
+private:
+    static ProfilingGuidGenerator m_GuidGenerator;
+};
+
+} // namespace profiling
+
+} // namespace armnn
diff --git a/src/profiling/ProfilingGuidGenerator.hpp b/src/profiling/ProfilingGuidGenerator.hpp
index 38816fa..81997e1 100644
--- a/src/profiling/ProfilingGuidGenerator.hpp
+++ b/src/profiling/ProfilingGuidGenerator.hpp
@@ -7,6 +7,8 @@
 
 #include "IProfilingGuidGenerator.hpp"
 
+#include <functional>
+
 namespace armnn
 {
 
@@ -17,15 +19,28 @@
 {
 public:
     /// Construct a generator with the default address space static/dynamic partitioning
-    ProfilingGuidGenerator() {}
+    ProfilingGuidGenerator() : m_Sequence(0) {}
 
     /// Return the next random Guid in the sequence
     // NOTE: dummy implementation for the moment
-    inline ProfilingDynamicGuid NextGuid() override { return ProfilingDynamicGuid(0); }
+    inline ProfilingDynamicGuid NextGuid() override
+    {
+        ProfilingDynamicGuid guid(m_Sequence);
+        m_Sequence++;
+        return guid;
+    }
 
     /// 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); }
+    inline ProfilingStaticGuid GenerateStaticId(const std::string& str) override
+    {
+        uint64_t guid = static_cast<uint64_t>(m_StringHasher(str));
+        return guid;
+    }
+
+private:
+    std::hash<std::string> m_StringHasher;
+    uint64_t m_Sequence;
 };
 
 } // namespace profiling
diff --git a/src/profiling/test/SendTimelinePacketTests.cpp b/src/profiling/test/SendTimelinePacketTests.cpp
index 9b144bb..53e52b5 100644
--- a/src/profiling/test/SendTimelinePacketTests.cpp
+++ b/src/profiling/test/SendTimelinePacketTests.cpp
@@ -12,6 +12,9 @@
 #include <TimelinePacketWriterFactory.hpp>
 
 #include <boost/test/unit_test.hpp>
+#include <LabelsAndEventClasses.hpp>
+
+#include <functional>
 
 using namespace armnn::profiling;
 
@@ -392,14 +395,16 @@
     ProfilingService& profilingService = ProfilingService::Instance();
     profilingService.ResetExternalProfilingOptions(options, true);
     ProfilingStaticGuid staticGuid = profilingService.GenerateStaticId("dummy");
-    // TODO when actual value gets generated verify its correctness
-    ProfilingStaticGuid expectedStaticValue(0);
+    // TODO this will change again...
+    std::hash<std::string> hasher;
+    uint64_t hash = static_cast<uint64_t>(hasher("dummy"));
+    ProfilingStaticGuid expectedStaticValue(hash);
     BOOST_CHECK(staticGuid == expectedStaticValue);
     ProfilingDynamicGuid dynamicGuid = profilingService.NextGuid();
-    // TODO when actual value gets generated verify its correctness by verifying
-    //      it is in the correct range i.e. > x and that if NextGuid is invoked
-    //      again it is equal to the previous + 1
-    ProfilingDynamicGuid expectedDynamicValue(0);
+    uint64_t dynamicGuidValue = static_cast<uint64_t>(dynamicGuid);
+    ++dynamicGuidValue;
+    ProfilingDynamicGuid expectedDynamicValue(dynamicGuidValue);
+    dynamicGuid = profilingService.NextGuid();
     BOOST_CHECK(dynamicGuid == expectedDynamicValue);
 }
 
@@ -414,4 +419,33 @@
     BOOST_CHECK(writer != nullptr);
 }
 
+BOOST_AUTO_TEST_CASE(CheckStaticGuidsAndEvents)
+{
+    BOOST_CHECK("name" == LabelsAndEventClasses::NAME_LABEL);
+    BOOST_CHECK("type" == LabelsAndEventClasses::TYPE_LABEL);
+    BOOST_CHECK("index" == LabelsAndEventClasses::INDEX_LABEL);
+
+    std::hash<std::string> hasher;
+
+    uint64_t hash = static_cast<uint64_t>(hasher(LabelsAndEventClasses::NAME_LABEL));
+    ProfilingStaticGuid expectedNameGuid(hash);
+    BOOST_CHECK(LabelsAndEventClasses::NAME_GUID == expectedNameGuid);
+
+    hash = static_cast<uint64_t>(hasher(LabelsAndEventClasses::TYPE_LABEL));
+    ProfilingStaticGuid expectedTypeGuid(hash);
+    BOOST_CHECK(LabelsAndEventClasses::TYPE_GUID == expectedTypeGuid);
+
+    hash = static_cast<uint64_t>(hasher(LabelsAndEventClasses::INDEX_LABEL));
+    ProfilingStaticGuid expectedIndexGuid(hash);
+    BOOST_CHECK(LabelsAndEventClasses::INDEX_GUID == expectedIndexGuid);
+
+    hash = static_cast<uint64_t>(hasher("ARMNN_PROFILING_SOL"));
+    ProfilingStaticGuid expectedSol(hash);
+    BOOST_CHECK(LabelsAndEventClasses::ARMNN_PROFILING_SOL_EVENT_CLASS == expectedSol);
+
+    hash = static_cast<uint64_t>(hasher("ARMNN_PROFILING_EOL"));
+    ProfilingStaticGuid expectedEol(hash);
+    BOOST_CHECK(LabelsAndEventClasses::ARMNN_PROFILING_EOL_EVENT_CLASS == expectedEol);
+}
+
 BOOST_AUTO_TEST_SUITE_END()