IVGCVSW-6811 replace ProfilingService includes with IProfilingService

Change-Id: I00521756c8a19d10bfdc98c6ef4204c7f84901c6
Signed-off-by: Jim Flynn <jim.flynn@arm.com>
diff --git a/src/profiling/IProfilingService.cpp b/src/profiling/IProfilingService.cpp
new file mode 100644
index 0000000..9b1aac5
--- /dev/null
+++ b/src/profiling/IProfilingService.cpp
@@ -0,0 +1,49 @@
+//
+// Copyright © 2022 Arm Ltd and Contributors. All rights reserved.
+// SPDX-License-Identifier: MIT
+//
+
+#include "IProfilingService.hpp"
+#include "ProfilingService.hpp"
+
+namespace arm
+{
+
+namespace pipe
+{
+
+std::unique_ptr<IProfilingService> IProfilingService::CreateProfilingService(
+    armnn::Optional<IReportStructure&> reportStructure)
+{
+    return std::make_unique<ProfilingService>(reportStructure);
+}
+
+ProfilingGuidGenerator IProfilingService::m_GuidGenerator;
+
+ProfilingDynamicGuid IProfilingService::GetNextGuid()
+{
+    return m_GuidGenerator.NextGuid();
+}
+
+ProfilingStaticGuid IProfilingService::GetStaticId(const std::string& str)
+{
+    return m_GuidGenerator.GenerateStaticId(str);
+}
+
+void IProfilingService::ResetGuidGenerator()
+{
+    m_GuidGenerator.Reset();
+}
+
+ProfilingDynamicGuid IProfilingService::NextGuid()
+{
+    return IProfilingService::GetNextGuid();
+}
+
+ProfilingStaticGuid IProfilingService::GenerateStaticId(const std::string& str)
+{
+    return IProfilingService::GetStaticId(str);
+}
+
+} // namespace pipe
+} // namespace arm
diff --git a/src/profiling/IProfilingService.hpp b/src/profiling/IProfilingService.hpp
index c2e824e..31d9b8d 100644
--- a/src/profiling/IProfilingService.hpp
+++ b/src/profiling/IProfilingService.hpp
@@ -7,9 +7,16 @@
 
 #include "CounterIdMap.hpp"
 #include "Holder.hpp"
+#include "ICounterValues.hpp"
+#include "ICounterRegistry.hpp"
 #include "IProfilingServiceStatus.hpp"
 #include "ISendCounterPacket.hpp"
+#include "IReportStructure.hpp"
+#include "ProfilingState.hpp"
 
+#include <armnn/backends/profiling/IBackendProfilingContext.hpp>
+#include <armnn/profiling/ProfilingOptions.hpp>
+#include <armnn/Optional.hpp>
 #include <common/include/ProfilingGuidGenerator.hpp>
 
 namespace arm
@@ -18,18 +25,44 @@
 namespace pipe
 {
 
-class IProfilingService : public IProfilingGuidGenerator, public IProfilingServiceStatus
+class IProfilingService : public IProfilingGuidGenerator,
+                          public IProfilingServiceStatus,
+                          public IReadWriteCounterValues
 {
 public:
+    static std::unique_ptr<IProfilingService> CreateProfilingService(
+        armnn::Optional<IReportStructure&> reportStructure = armnn::EmptyOptional());
     virtual ~IProfilingService() {};
     virtual std::unique_ptr<ISendTimelinePacket> GetSendTimelinePacket() const = 0;
     virtual const ICounterMappings& GetCounterMappings() const = 0;
     virtual ISendCounterPacket& GetSendCounterPacket() = 0;
     virtual bool IsProfilingEnabled() const = 0;
+    virtual bool IsTimelineReportingEnabled() const = 0;
     virtual CaptureData GetCaptureData() = 0;
+    virtual ProfilingState GetCurrentState() const = 0;
+    // Resets the profiling options, optionally clears the profiling service entirely
+    virtual void ResetExternalProfilingOptions(const ProfilingOptions& options,
+                                               bool resetProfilingService = false) = 0;
+    virtual ProfilingState ConfigureProfilingService(const ProfilingOptions& options,
+                                                     bool resetProfilingService = false) = 0;
+    // Store a profiling context returned from a backend that support profiling.
+    virtual void AddBackendProfilingContext(const armnn::BackendId backendId,
+        std::shared_ptr<IBackendProfilingContext> profilingContext) = 0;
+    virtual ICounterRegistry& GetCounterRegistry() = 0;
+    virtual IRegisterCounterMapping& GetCounterMappingRegistry() = 0;
+    // IProfilingGuidGenerator functions
+    /// Return the next random Guid in the sequence
+    ProfilingDynamicGuid NextGuid() override;
+    /// Create a ProfilingStaticGuid based on a hash of the string
+    ProfilingStaticGuid GenerateStaticId(const std::string& str) override;
+    static ProfilingDynamicGuid GetNextGuid();
+    static ProfilingStaticGuid GetStaticId(const std::string& str);
+    void ResetGuidGenerator();
+
+private:
+    static ProfilingGuidGenerator m_GuidGenerator;
 };
 
 } // namespace pipe
 
 } // namespace arm
-
diff --git a/src/profiling/ProfilingService.cpp b/src/profiling/ProfilingService.cpp
index cef8a6d..2e67dc8 100644
--- a/src/profiling/ProfilingService.cpp
+++ b/src/profiling/ProfilingService.cpp
@@ -21,23 +21,6 @@
 namespace pipe
 {
 
-ProfilingGuidGenerator ProfilingService::m_GuidGenerator;
-
-ProfilingDynamicGuid ProfilingService::GetNextGuid()
-{
-    return m_GuidGenerator.NextGuid();
-}
-
-ProfilingStaticGuid ProfilingService::GetStaticId(const std::string& str)
-{
-    return m_GuidGenerator.GenerateStaticId(str);
-}
-
-void ProfilingService::ResetGuidGenerator()
-{
-    m_GuidGenerator.Reset();
-}
-
 void ProfilingService::ResetExternalProfilingOptions(const arm::pipe::ProfilingOptions& options,
                                                      bool resetProfilingService)
 {
@@ -316,16 +299,6 @@
     return counterValuePtr->operator++(std::memory_order::memory_order_relaxed);
 }
 
-ProfilingDynamicGuid ProfilingService::NextGuid()
-{
-    return ProfilingService::GetNextGuid();
-}
-
-ProfilingStaticGuid ProfilingService::GenerateStaticId(const std::string& str)
-{
-    return ProfilingService::GetStaticId(str);
-}
-
 std::unique_ptr<ISendTimelinePacket> ProfilingService::GetSendTimelinePacket() const
 {
     return m_TimelinePacketWriterFactory.GetSendTimelinePacket();
diff --git a/src/profiling/ProfilingService.hpp b/src/profiling/ProfilingService.hpp
index ab71b0c..a4b02c1 100644
--- a/src/profiling/ProfilingService.hpp
+++ b/src/profiling/ProfilingService.hpp
@@ -15,7 +15,6 @@
 #include "ICounterRegistry.hpp"
 #include "ICounterValues.hpp"
 #include <armnn/profiling/ILocalPacketHandler.hpp>
-#include <armnn/profiling/ProfilingOptions.hpp>
 #include "IProfilingService.hpp"
 #include "IReportStructure.hpp"
 #include "PeriodicCounterCapture.hpp"
@@ -29,9 +28,9 @@
 #include "SendTimelinePacket.hpp"
 #include "TimelinePacketWriterFactory.hpp"
 #include "INotifyBackends.hpp"
+#include <armnn/profiling/ArmNNProfiling.hpp>
 #include <armnn/backends/profiling/IBackendProfilingContext.hpp>
 
-#include <common/include/ProfilingGuidGenerator.hpp>
 
 #include <list>
 
@@ -40,15 +39,8 @@
 
 namespace pipe
 {
-// Static constants describing ArmNN's counter UID's
-static const uint16_t NETWORK_LOADS         = 0;
-static const uint16_t NETWORK_UNLOADS       = 1;
-static const uint16_t REGISTERED_BACKENDS   = 2;
-static const uint16_t UNREGISTERED_BACKENDS = 3;
-static const uint16_t INFERENCES_RUN        = 4;
-static const uint16_t MAX_ARMNN_COUNTER     = INFERENCES_RUN;
 
-class ProfilingService : public IReadWriteCounterValues, public IProfilingService, public INotifyBackends
+class ProfilingService : public IProfilingService, public INotifyBackends
 {
 public:
     using IProfilingConnectionFactoryPtr = std::unique_ptr<IProfilingConnectionFactory>;
@@ -150,9 +142,9 @@
 
     // Resets the profiling options, optionally clears the profiling service entirely
     void ResetExternalProfilingOptions(const ProfilingOptions& options,
-                                       bool resetProfilingService = false);
+                                       bool resetProfilingService = false) override;
     ProfilingState ConfigureProfilingService(const ProfilingOptions& options,
-                                             bool resetProfilingService = false);
+                                             bool resetProfilingService = false) override;
 
 
     // Updates the profiling service, making it transition to a new state if necessary
@@ -163,21 +155,21 @@
 
     // Store a profiling context returned from a backend that support profiling.
     void AddBackendProfilingContext(const armnn::BackendId backendId,
-        std::shared_ptr<IBackendProfilingContext> profilingContext);
+        std::shared_ptr<IBackendProfilingContext> profilingContext) override;
 
     // Enable the recording of timeline events and entities
     void NotifyBackendsForTimelineReporting() override;
 
     const ICounterDirectory& GetCounterDirectory() const;
-    ICounterRegistry& GetCounterRegistry();
-    ProfilingState GetCurrentState() const;
+    ICounterRegistry& GetCounterRegistry() override;
+    ProfilingState GetCurrentState() const override;
     bool IsCounterRegistered(uint16_t counterUid) const override;
     uint32_t GetAbsoluteCounterValue(uint16_t counterUid) const override;
     uint32_t GetDeltaCounterValue(uint16_t counterUid) override;
     uint16_t GetCounterCount() const override;
     // counter global/backend mapping functions
     const ICounterMappings& GetCounterMappings() const override;
-    IRegisterCounterMapping& GetCounterMappingRegistry();
+    IRegisterCounterMapping& GetCounterMappingRegistry() override;
 
     // Getters for the profiling service state
     bool IsProfilingEnabled() const override;
@@ -193,13 +185,6 @@
     uint32_t SubtractCounterValue(uint16_t counterUid, uint32_t value) override;
     uint32_t IncrementCounterValue(uint16_t counterUid) override;
 
-    // IProfilingGuidGenerator functions
-    /// Return the next random Guid in the sequence
-    ProfilingDynamicGuid NextGuid() override;
-    /// Create a ProfilingStaticGuid based on a hash of the string
-    ProfilingStaticGuid GenerateStaticId(const std::string& str) override;
-
-
     std::unique_ptr<ISendTimelinePacket> GetSendTimelinePacket() const override;
 
     ISendCounterPacket& GetSendCounterPacket() override
@@ -207,13 +192,7 @@
         return m_SendCounterPacket;
     }
 
-    static ProfilingDynamicGuid GetNextGuid();
-
-    static ProfilingStaticGuid GetStaticId(const std::string& str);
-
-    void ResetGuidGenerator();
-
-    bool IsTimelineReportingEnabled()
+    bool IsTimelineReportingEnabled() const override
     {
         return m_TimelineReporting;
     }
@@ -272,8 +251,6 @@
     BackendProfilingContext     m_BackendProfilingContexts;
     uint16_t                    m_MaxGlobalCounterId;
 
-    static ProfilingGuidGenerator m_GuidGenerator;
-
     // Signalling to let external actors know when service is active or not
     std::mutex m_ServiceActiveMutex;
     std::condition_variable m_ServiceActiveConditionVariable;
diff --git a/src/profiling/ProfilingState.hpp b/src/profiling/ProfilingState.hpp
new file mode 100644
index 0000000..0fc1903
--- /dev/null
+++ b/src/profiling/ProfilingState.hpp
@@ -0,0 +1,24 @@
+//
+// Copyright © 2022 Arm Ltd. All rights reserved.
+// SPDX-License-Identifier: MIT
+//
+
+#pragma once
+
+namespace arm
+{
+
+namespace pipe
+{
+
+enum class ProfilingState
+{
+    Uninitialised,
+    NotConnected,
+    WaitingForAck,
+    Active
+};
+
+} // namespace pipe
+
+} // namespace arm
diff --git a/src/profiling/ProfilingStateMachine.hpp b/src/profiling/ProfilingStateMachine.hpp
index 2980556..2648bca 100644
--- a/src/profiling/ProfilingStateMachine.hpp
+++ b/src/profiling/ProfilingStateMachine.hpp
@@ -5,6 +5,8 @@
 
 #pragma once
 
+#include "ProfilingState.hpp"
+
 #include <atomic>
 
 #include <armnn/utility/IgnoreUnused.hpp>
@@ -15,14 +17,6 @@
 namespace pipe
 {
 
-enum class ProfilingState
-{
-    Uninitialised,
-    NotConnected,
-    WaitingForAck,
-    Active
-};
-
 class ProfilingStateMachine
 {
 public:
@@ -71,4 +65,3 @@
 } // namespace pipe
 
 } // namespace arm
-
diff --git a/src/profiling/RegisterBackendCounters.hpp b/src/profiling/RegisterBackendCounters.hpp
index f25feb5..34f9f3a 100644
--- a/src/profiling/RegisterBackendCounters.hpp
+++ b/src/profiling/RegisterBackendCounters.hpp
@@ -8,7 +8,7 @@
 #include "armnn/backends/profiling/IBackendProfiling.hpp"
 #include "CounterIdMap.hpp"
 #include "CounterDirectory.hpp"
-#include "ProfilingService.hpp"
+#include "IProfilingService.hpp"
 
 namespace arm
 {
@@ -21,7 +21,7 @@
 public:
 
     RegisterBackendCounters(
-        uint16_t currentMaxGlobalCounterID, const armnn::BackendId& backendId, ProfilingService& profilingService)
+        uint16_t currentMaxGlobalCounterID, const armnn::BackendId& backendId, IProfilingService& profilingService)
         : m_CurrentMaxGlobalCounterID(currentMaxGlobalCounterID),
           m_BackendId(backendId),
           m_ProfilingService(profilingService),
@@ -55,10 +55,10 @@
 private:
     uint16_t m_CurrentMaxGlobalCounterID;
     const armnn::BackendId& m_BackendId;
-    ProfilingService& m_ProfilingService;
+    IProfilingService& m_ProfilingService;
     ICounterRegistry& m_CounterDirectory;
 };
 
 } // namespace pipe
 
-} // namespace arm
\ No newline at end of file
+} // namespace arm
diff --git a/src/profiling/TimelineUtilityMethods.cpp b/src/profiling/TimelineUtilityMethods.cpp
index bc8e7b6..fea8ed7 100644
--- a/src/profiling/TimelineUtilityMethods.cpp
+++ b/src/profiling/TimelineUtilityMethods.cpp
@@ -15,7 +15,7 @@
 namespace pipe
 {
 
-std::unique_ptr<TimelineUtilityMethods> TimelineUtilityMethods::GetTimelineUtils(ProfilingService& profilingService)
+std::unique_ptr<TimelineUtilityMethods> TimelineUtilityMethods::GetTimelineUtils(IProfilingService& profilingService)
 {
     if (profilingService.GetCurrentState() == ProfilingState::Active && profilingService.IsTimelineReportingEnabled())
     {
@@ -114,7 +114,7 @@
     }
 
     // Generate dynamic GUID of the entity
-    ProfilingDynamicGuid entityGuid = ProfilingService::GetNextGuid();
+    ProfilingDynamicGuid entityGuid = IProfilingService::GetNextGuid();
 
     CreateNamedTypedEntity(entityGuid, name, type);
 
@@ -177,7 +177,7 @@
     }
 
     // Generate a static GUID for the given label name
-    ProfilingStaticGuid labelGuid = ProfilingService::GetStaticId(labelName);
+    ProfilingStaticGuid labelGuid = IProfilingService::GetStaticId(labelName);
 
     // Send the new label to the external profiling service, this call throws in case of error
     m_SendTimelinePacket->SendTimelineLabelBinaryPacket(labelGuid, labelName);
@@ -200,7 +200,7 @@
     ProfilingStaticGuid labelGuid = DeclareLabel(labelName);
 
     // Generate a GUID for the label relationship
-    ProfilingDynamicGuid relationshipGuid = ProfilingService::GetNextGuid();
+    ProfilingDynamicGuid relationshipGuid = IProfilingService::GetNextGuid();
 
     // Send the new label link to the external profiling service, this call throws in case of error
     m_SendTimelinePacket->SendTimelineRelationshipBinaryPacket(ProfilingRelationshipType::LabelLink,
@@ -214,7 +214,7 @@
                                                 ProfilingStaticGuid typeNameGuid)
 {
     // Generate a GUID for the label relationship
-    ProfilingDynamicGuid relationshipGuid = ProfilingService::GetNextGuid();
+    ProfilingDynamicGuid relationshipGuid = IProfilingService::GetNextGuid();
 
     // Send the new label link to the external profiling service, this call throws in case of error
     m_SendTimelinePacket->SendTimelineRelationshipBinaryPacket(ProfilingRelationshipType::LabelLink,
@@ -256,7 +256,7 @@
     ProfilingDynamicGuid childEntityGuid = CreateNamedTypedEntity(entityName, entityType);
 
     // Generate a GUID for the retention link relationship
-    ProfilingDynamicGuid retentionLinkGuid = ProfilingService::GetNextGuid();
+    ProfilingDynamicGuid retentionLinkGuid = IProfilingService::GetNextGuid();
 
     // Send the new retention link to the external profiling service, this call throws in case of error
     m_SendTimelinePacket->SendTimelineRelationshipBinaryPacket(ProfilingRelationshipType::RetentionLink,
@@ -291,7 +291,7 @@
     CreateNamedTypedEntity(childEntityGuid, entityName, entityType);
 
     // Generate a GUID for the retention link relationship
-    ProfilingDynamicGuid retentionLinkGuid = ProfilingService::GetNextGuid();
+    ProfilingDynamicGuid retentionLinkGuid = IProfilingService::GetNextGuid();
 
     // Send the new retention link to the external profiling service, this call throws in case of error
     m_SendTimelinePacket->SendTimelineRelationshipBinaryPacket(ProfilingRelationshipType::RetentionLink,
@@ -317,7 +317,7 @@
     CreateNamedTypedEntity(childEntityGuid, entityName, typeGuid);
 
     // Generate a GUID for the retention link relationship
-    ProfilingDynamicGuid retentionLinkGuid = ProfilingService::GetNextGuid();
+    ProfilingDynamicGuid retentionLinkGuid = IProfilingService::GetNextGuid();
 
     // Send the new retention link to the external profiling service, this call throws in case of error
     m_SendTimelinePacket->SendTimelineRelationshipBinaryPacket(ProfilingRelationshipType::RetentionLink,
@@ -333,7 +333,7 @@
                                                                 ProfilingGuid relationshipCategory)
 {
     // Generate a GUID for the relationship
-    ProfilingDynamicGuid relationshipGuid = ProfilingService::GetNextGuid();
+    ProfilingDynamicGuid relationshipGuid = IProfilingService::GetNextGuid();
 
     // Send the new retention link to the external profiling service, this call throws in case of error
     m_SendTimelinePacket->SendTimelineRelationshipBinaryPacket(relationshipType,
@@ -349,7 +349,7 @@
                                                                           ProfilingGuid tailGuid)
 {
     // Generate a GUID for the relationship
-    ProfilingDynamicGuid relationshipGuid = ProfilingService::GetNextGuid();
+    ProfilingDynamicGuid relationshipGuid = IProfilingService::GetNextGuid();
 
     // Send the new retention link to the external profiling service, this call throws in case of error
     m_SendTimelinePacket->SendTimelineRelationshipBinaryPacket(relationshipType,
@@ -378,13 +378,13 @@
     int threadId = armnnUtils::Threads::GetCurrentThreadId();
 
     // Generate a GUID for the event
-    ProfilingDynamicGuid eventGuid = ProfilingService::GetNextGuid();
+    ProfilingDynamicGuid eventGuid = IProfilingService::GetNextGuid();
 
     // Send the new timeline event to the external profiling service, this call throws in case of error
     m_SendTimelinePacket->SendTimelineEventBinaryPacket(timestamp, threadId, eventGuid);
 
     // Generate a GUID for the execution link
-    ProfilingDynamicGuid executionLinkId = ProfilingService::GetNextGuid();
+    ProfilingDynamicGuid executionLinkId = IProfilingService::GetNextGuid();
 
     // Send the new execution link to the external profiling service, this call throws in case of error
     m_SendTimelinePacket->SendTimelineRelationshipBinaryPacket(ProfilingRelationshipType::ExecutionLink,
@@ -399,7 +399,7 @@
 ProfilingDynamicGuid TimelineUtilityMethods::RecordWorkloadInferenceAndStartOfLifeEvent(ProfilingGuid workloadGuid,
                                                                                         ProfilingGuid inferenceGuid)
 {
-    ProfilingDynamicGuid workloadInferenceGuid = ProfilingService::GetNextGuid();
+    ProfilingDynamicGuid workloadInferenceGuid = IProfilingService::GetNextGuid();
     CreateTypedEntity(workloadInferenceGuid, LabelsAndEventClasses::WORKLOAD_EXECUTION_GUID);
     CreateRelationship(ProfilingRelationshipType::RetentionLink,
                        inferenceGuid,
diff --git a/src/profiling/TimelineUtilityMethods.hpp b/src/profiling/TimelineUtilityMethods.hpp
index d0c9658..fa25dc4 100644
--- a/src/profiling/TimelineUtilityMethods.hpp
+++ b/src/profiling/TimelineUtilityMethods.hpp
@@ -5,7 +5,7 @@
 
 #pragma once
 
-#include "ProfilingService.hpp"
+#include "IProfilingService.hpp"
 #include "armnn/profiling/ISendTimelinePacket.hpp"
 
 #include <armnn/Types.hpp>
@@ -22,7 +22,7 @@
 
     // static factory method which will return a pointer to a timelie utility methods
     // object if profiling is enabled. Otherwise will return a null unique_ptr
-    static std::unique_ptr<TimelineUtilityMethods> GetTimelineUtils(ProfilingService& profilingService);
+    static std::unique_ptr<TimelineUtilityMethods> GetTimelineUtils(IProfilingService& profilingService);
 
     TimelineUtilityMethods(
         std::unique_ptr<ISendTimelinePacket>& sendTimelinePacket)
diff --git a/src/profiling/backends/BackendProfiling.hpp b/src/profiling/backends/BackendProfiling.hpp
index 82678a1..545234d 100644
--- a/src/profiling/backends/BackendProfiling.hpp
+++ b/src/profiling/backends/BackendProfiling.hpp
@@ -18,7 +18,7 @@
 {
 public:
     BackendProfiling(const ProfilingOptions& options,
-                     ProfilingService& profilingService,
+                     IProfilingService& profilingService,
                      const armnn::BackendId& backendId)
             : m_Options(options),
               m_ProfilingService(profilingService),
@@ -44,7 +44,7 @@
 
 private:
     ProfilingOptions m_Options;
-    ProfilingService& m_ProfilingService;
+    IProfilingService& m_ProfilingService;
     armnn::BackendId m_BackendId;
 };
 
diff --git a/src/profiling/test/ProfilingTestUtils.hpp b/src/profiling/test/ProfilingTestUtils.hpp
index 810a34c..16c6dde 100644
--- a/src/profiling/test/ProfilingTestUtils.hpp
+++ b/src/profiling/test/ProfilingTestUtils.hpp
@@ -72,23 +72,22 @@
 class ProfilingServiceRuntimeHelper : public ProfilingService
 {
 public:
-    ProfilingServiceRuntimeHelper(ProfilingService& profilingService)
+    ProfilingServiceRuntimeHelper(IProfilingService& profilingService)
     : m_ProfilingService(profilingService) {}
     ~ProfilingServiceRuntimeHelper() = default;
 
     BufferManager& GetProfilingBufferManager()
     {
-        return GetBufferManager(m_ProfilingService);
+        return GetBufferManager(static_cast<ProfilingService&>(m_ProfilingService));
     }
-    ProfilingService& m_ProfilingService;
+    IProfilingService& m_ProfilingService;
 
     void ForceTransitionToState(ProfilingState newState)
     {
-        TransitionToState(m_ProfilingService, newState);
+        TransitionToState(static_cast<ProfilingService&>(m_ProfilingService), newState);
     }
 };
 
 } // namespace pipe
 
 } // namespace arm
-