From 8e0c7a66efc8d61787c43cdaeab3754e2905f623 Mon Sep 17 00:00:00 2001 From: Jim Flynn Date: Thu, 30 Jan 2020 14:10:55 +0000 Subject: IVGCVSW-4394 Add CounterIdMap to Profiling Service Change-Id: I416397a7855fe45319b4801252e141b78f0325f0 Signed-off-by: Jim Flynn --- Android.mk | 1 + src/profiling/CounterIdMap.cpp | 8 ++++---- src/profiling/CounterIdMap.hpp | 31 ++++++++++++++++++++++++++----- src/profiling/ProfilingService.cpp | 10 ++++++++++ src/profiling/ProfilingService.hpp | 8 +++++++- 5 files changed, 48 insertions(+), 10 deletions(-) diff --git a/Android.mk b/Android.mk index 86f1602f15..9a38a7228d 100644 --- a/Android.mk +++ b/Android.mk @@ -184,6 +184,7 @@ LOCAL_SRC_FILES := \ src/profiling/CommandHandlerRegistry.cpp \ src/profiling/ConnectionAcknowledgedCommandHandler.cpp \ src/profiling/CounterDirectory.cpp \ + src/profiling/CounterIdMap.cpp \ src/profiling/DirectoryCaptureCommandHandler.cpp \ src/profiling/FileOnlyProfilingConnection.cpp \ src/profiling/Holder.cpp \ diff --git a/src/profiling/CounterIdMap.cpp b/src/profiling/CounterIdMap.cpp index a925fb9cb4..8ee80f913c 100644 --- a/src/profiling/CounterIdMap.cpp +++ b/src/profiling/CounterIdMap.cpp @@ -4,8 +4,8 @@ // #include "CounterIdMap.hpp" #include "armnn/BackendId.hpp" -#include #include +#include namespace armnn { @@ -21,7 +21,7 @@ void CounterIdMap::RegisterMapping(uint16_t globalCounterId, m_BackendCounterIdMap[backendIdPair] = globalCounterId; } -uint16_t CounterIdMap::GetGlobalId(uint16_t backendCounterId, const armnn::BackendId& backendId) +uint16_t CounterIdMap::GetGlobalId(uint16_t backendCounterId, const armnn::BackendId& backendId) const { std::pair backendIdPair(backendCounterId, backendId); auto it = m_BackendCounterIdMap.find(backendIdPair); @@ -34,7 +34,7 @@ uint16_t CounterIdMap::GetGlobalId(uint16_t backendCounterId, const armnn::Backe return it->second; } -const std::pair& CounterIdMap::GetBackendId(uint16_t globalCounterId) +const std::pair& CounterIdMap::GetBackendId(uint16_t globalCounterId) const { auto it = m_GlobalCounterIdMap.find(globalCounterId); if (it == m_GlobalCounterIdMap.end()) @@ -47,4 +47,4 @@ const std::pair& CounterIdMap::GetBackendId(uint16_t } } // namespace profiling -} // namespace armnn \ No newline at end of file +} // namespace armnn diff --git a/src/profiling/CounterIdMap.hpp b/src/profiling/CounterIdMap.hpp index e401491c10..cb6b9c92e8 100644 --- a/src/profiling/CounterIdMap.hpp +++ b/src/profiling/CounterIdMap.hpp @@ -12,17 +12,38 @@ namespace armnn namespace profiling { -class CounterIdMap +class ICounterMappings +{ +public: + virtual uint16_t GetGlobalId(uint16_t backendCounterId, const armnn::BackendId& backendId) const = 0; + virtual const std::pair& GetBackendId(uint16_t globalCounterId) const = 0; + virtual ~ICounterMappings() {} +}; + +class IRegisterCounterMapping +{ +public: + virtual void RegisterMapping(uint16_t globalCounterId, + uint16_t backendCounterId, + const armnn::BackendId& backendId) = 0; + virtual ~IRegisterCounterMapping() {} +}; + +class CounterIdMap : public ICounterMappings, public IRegisterCounterMapping { public: - void RegisterMapping(uint16_t globalCounterId, uint16_t backendCounterId, const armnn::BackendId& backendId); - uint16_t GetGlobalId(uint16_t backendCounterId, const armnn::BackendId& backendId); - const std::pair& GetBackendId(uint16_t globalCounterId); + CounterIdMap() = default; + virtual ~CounterIdMap() {} + void RegisterMapping(uint16_t globalCounterId, + uint16_t backendCounterId, + const armnn::BackendId& backendId) override; + uint16_t GetGlobalId(uint16_t backendCounterId, const armnn::BackendId& backendId) const override; + const std::pair& GetBackendId(uint16_t globalCounterId) const override; private: std::map> m_GlobalCounterIdMap; std::map, uint16_t> m_BackendCounterIdMap; }; } // namespace profiling -} // namespace armnn \ No newline at end of file +} // namespace armnn diff --git a/src/profiling/ProfilingService.cpp b/src/profiling/ProfilingService.cpp index cc41fb2d69..b06f149486 100644 --- a/src/profiling/ProfilingService.cpp +++ b/src/profiling/ProfilingService.cpp @@ -209,6 +209,16 @@ uint32_t ProfilingService::GetCounterValue(uint16_t counterUid) const return counterValuePtr->load(std::memory_order::memory_order_relaxed); } +const ICounterMappings& ProfilingService::GetCounterMappings() const +{ + return m_CounterIdMap; +} + +IRegisterCounterMapping& ProfilingService::GetCounterMappingRegistrar() +{ + return m_CounterIdMap; +} + void ProfilingService::SetCounterValue(uint16_t counterUid, uint32_t value) { CheckCounterUid(counterUid); diff --git a/src/profiling/ProfilingService.hpp b/src/profiling/ProfilingService.hpp index 24748bb69b..9cf7545205 100644 --- a/src/profiling/ProfilingService.hpp +++ b/src/profiling/ProfilingService.hpp @@ -9,6 +9,7 @@ #include "CommandHandler.hpp" #include "ConnectionAcknowledgedCommandHandler.hpp" #include "CounterDirectory.hpp" +#include "CounterIdMap.hpp" #include "ICounterValues.hpp" #include "PeriodicCounterCapture.hpp" #include "PeriodicCounterSelectionCommandHandler.hpp" @@ -61,12 +62,16 @@ public: // Disconnects the profiling service from the external server void Disconnect(); - // Getters for the profiling service state const ICounterDirectory& GetCounterDirectory() const; ProfilingState GetCurrentState() const; bool IsCounterRegistered(uint16_t counterUid) const override; uint32_t GetCounterValue(uint16_t counterUid) const override; uint16_t GetCounterCount() const override; + // counter global/backend mapping functions + const ICounterMappings& GetCounterMappings() const; + IRegisterCounterMapping& GetCounterMappingRegistrar(); + + // Getters for the profiling service state bool IsProfilingEnabled(); // Setters for the profiling service state @@ -105,6 +110,7 @@ private: // Profiling service components ExternalProfilingOptions m_Options; CounterDirectory m_CounterDirectory; + CounterIdMap m_CounterIdMap; IProfilingConnectionFactoryPtr m_ProfilingConnectionFactory; IProfilingConnectionPtr m_ProfilingConnection; ProfilingStateMachine m_StateMachine; -- cgit v1.2.1