From 3184c907b2420e6c66485529f336251b2b62aecf Mon Sep 17 00:00:00 2001 From: Sadik Armagan Date: Wed, 18 Mar 2020 10:57:30 +0000 Subject: IVGCVSW-4463 Change ProfilingService to a member of runtime from a singleton Signed-off-by: Sadik Armagan Change-Id: I345c39a10a4693a500aa1687d9a5cee76da791c3 --- src/profiling/ProfilingService.hpp | 143 +++++++++++++++++++------------------ 1 file changed, 72 insertions(+), 71 deletions(-) (limited to 'src/profiling/ProfilingService.hpp') diff --git a/src/profiling/ProfilingService.hpp b/src/profiling/ProfilingService.hpp index 4629c126bf..f6e409daeb 100644 --- a/src/profiling/ProfilingService.hpp +++ b/src/profiling/ProfilingService.hpp @@ -48,13 +48,73 @@ public: using CounterIndices = std::vector*>; using CounterValues = std::list>; - // Getter for the singleton instance - static ProfilingService& Instance() + // Default constructor/destructor kept protected for testing + ProfilingService() + : m_Options() + , m_CounterDirectory() + , m_ProfilingConnectionFactory(new ProfilingConnectionFactory()) + , m_ProfilingConnection() + , m_StateMachine() + , m_CounterIndex() + , m_CounterValues() + , m_CommandHandlerRegistry() + , m_PacketVersionResolver() + , m_CommandHandler(1000, + false, + m_CommandHandlerRegistry, + m_PacketVersionResolver) + , m_BufferManager() + , m_SendCounterPacket(m_BufferManager) + , m_SendThread(m_StateMachine, m_BufferManager, m_SendCounterPacket) + , m_SendTimelinePacket(m_BufferManager) + , m_PeriodicCounterCapture(m_Holder, m_SendCounterPacket, *this, m_CounterIdMap, m_BackendProfilingContexts) + , m_ConnectionAcknowledgedCommandHandler(0, + 1, + m_PacketVersionResolver.ResolvePacketVersion(0, 1).GetEncodedValue(), + m_CounterDirectory, + m_SendCounterPacket, + m_SendTimelinePacket, + m_StateMachine) + , m_RequestCounterDirectoryCommandHandler(0, + 3, + m_PacketVersionResolver.ResolvePacketVersion(0, 3).GetEncodedValue(), + m_CounterDirectory, + m_SendCounterPacket, + m_SendTimelinePacket, + m_StateMachine) + , m_PeriodicCounterSelectionCommandHandler(0, + 4, + m_PacketVersionResolver.ResolvePacketVersion(0, 4).GetEncodedValue(), + m_BackendProfilingContexts, + m_CounterIdMap, + m_Holder, + MAX_ARMNN_COUNTER, + m_PeriodicCounterCapture, + *this, + m_SendCounterPacket, + m_StateMachine) + , m_PerJobCounterSelectionCommandHandler(0, + 5, + m_PacketVersionResolver.ResolvePacketVersion(0, 5).GetEncodedValue(), + m_StateMachine) + , m_TimelinePacketWriterFactory(m_BufferManager) + , m_MaxGlobalCounterId(armnn::profiling::INFERENCES_RUN) { - static ProfilingService instance; - return instance; + // Register the "Connection Acknowledged" command handler + m_CommandHandlerRegistry.RegisterFunctor(&m_ConnectionAcknowledgedCommandHandler); + + // Register the "Request Counter Directory" command handler + m_CommandHandlerRegistry.RegisterFunctor(&m_RequestCounterDirectoryCommandHandler); + + // Register the "Periodic Counter Selection" command handler + m_CommandHandlerRegistry.RegisterFunctor(&m_PeriodicCounterSelectionCommandHandler); + + // Register the "Per-Job Counter Selection" command handler + m_CommandHandlerRegistry.RegisterFunctor(&m_PerJobCounterSelectionCommandHandler); } + ~ProfilingService(); + // Resets the profiling options, optionally clears the profiling service entirely void ResetExternalProfilingOptions(const ExternalProfilingOptions& options, bool resetProfilingService = false); ProfilingState ConfigureProfilingService(const ExternalProfilingOptions& options, @@ -111,8 +171,12 @@ public: /// Check if the profiling is enabled bool IsEnabled() { return m_Options.m_EnableProfiling; } + static ProfilingDynamicGuid GetNextGuid(); + + static ProfilingStaticGuid GetStaticId(const std::string& str); + private: - // Copy/move constructors/destructors and copy/move assignment operators are deleted + //Copy/move constructors/destructors and copy/move assignment operators are deleted ProfilingService(const ProfilingService&) = delete; ProfilingService(ProfilingService&&) = delete; ProfilingService& operator=(const ProfilingService&) = delete; @@ -149,78 +213,15 @@ private: RequestCounterDirectoryCommandHandler m_RequestCounterDirectoryCommandHandler; PeriodicCounterSelectionCommandHandler m_PeriodicCounterSelectionCommandHandler; PerJobCounterSelectionCommandHandler m_PerJobCounterSelectionCommandHandler; - ProfilingGuidGenerator m_GuidGenerator; + TimelinePacketWriterFactory m_TimelinePacketWriterFactory; std::unordered_map> m_BackendProfilingContexts; uint16_t m_MaxGlobalCounterId; -protected: - // Default constructor/destructor kept protected for testing - ProfilingService() - : m_Options() - , m_CounterDirectory() - , m_ProfilingConnectionFactory(new ProfilingConnectionFactory()) - , m_ProfilingConnection() - , m_StateMachine() - , m_CounterIndex() - , m_CounterValues() - , m_CommandHandlerRegistry() - , m_PacketVersionResolver() - , m_CommandHandler(1000, - false, - m_CommandHandlerRegistry, - m_PacketVersionResolver) - , m_BufferManager() - , m_SendCounterPacket(m_BufferManager) - , m_SendThread(m_StateMachine, m_BufferManager, m_SendCounterPacket) - , m_SendTimelinePacket(m_BufferManager) - , m_PeriodicCounterCapture(m_Holder, m_SendCounterPacket, *this, m_CounterIdMap, m_BackendProfilingContexts) - , m_ConnectionAcknowledgedCommandHandler(0, - 1, - m_PacketVersionResolver.ResolvePacketVersion(0, 1).GetEncodedValue(), - m_CounterDirectory, - m_SendCounterPacket, - m_SendTimelinePacket, - m_StateMachine) - , m_RequestCounterDirectoryCommandHandler(0, - 3, - m_PacketVersionResolver.ResolvePacketVersion(0, 3).GetEncodedValue(), - m_CounterDirectory, - m_SendCounterPacket, - m_SendTimelinePacket, - m_StateMachine) - , m_PeriodicCounterSelectionCommandHandler(0, - 4, - m_PacketVersionResolver.ResolvePacketVersion(0, 4).GetEncodedValue(), - m_BackendProfilingContexts, - m_CounterIdMap, - m_Holder, - MAX_ARMNN_COUNTER, - m_PeriodicCounterCapture, - *this, - m_SendCounterPacket, - m_StateMachine) - , m_PerJobCounterSelectionCommandHandler(0, - 5, - m_PacketVersionResolver.ResolvePacketVersion(0, 5).GetEncodedValue(), - m_StateMachine) - , m_TimelinePacketWriterFactory(m_BufferManager) - , m_MaxGlobalCounterId(armnn::profiling::INFERENCES_RUN) - { - // Register the "Connection Acknowledged" command handler - m_CommandHandlerRegistry.RegisterFunctor(&m_ConnectionAcknowledgedCommandHandler); - - // Register the "Request Counter Directory" command handler - m_CommandHandlerRegistry.RegisterFunctor(&m_RequestCounterDirectoryCommandHandler); + static ProfilingGuidGenerator m_GuidGenerator; - // Register the "Periodic Counter Selection" command handler - m_CommandHandlerRegistry.RegisterFunctor(&m_PeriodicCounterSelectionCommandHandler); - - // Register the "Per-Job Counter Selection" command handler - m_CommandHandlerRegistry.RegisterFunctor(&m_PerJobCounterSelectionCommandHandler); - } - ~ProfilingService(); +protected: // Protected methods for testing void SwapProfilingConnectionFactory(ProfilingService& instance, -- cgit v1.2.1