diff options
author | Matteo Martincigh <matteo.martincigh@arm.com> | 2019-10-02 12:50:57 +0100 |
---|---|---|
committer | Matteo Martincigh <matteo.martincigh@arm.com> | 2019-10-08 15:53:43 +0100 |
commit | 54fb957c9640d61ab575d7acfc4c430a15123315 (patch) | |
tree | 51ce829032913af068071be0dcfff7c7bef409b7 /src/profiling/ProfilingService.cpp | |
parent | c4728ad356b73915588c971f6de38f4493078397 (diff) | |
download | armnn-54fb957c9640d61ab575d7acfc4c430a15123315.tar.gz |
IVGCVSW-3937 Add the necessary components to the ProfilingService class to
process a connection to an external profiling service (e.g. gatord)
* Added the required components (CommandHandlerRegistry, CommandHandler,
SendCounterPacket, ...) to the ProfilingService class
* Reworked the ProfilingService::Run procedure and renamed it to Update
* Handling all states but Active in the Run method (future work)
* Updated the unit and tests accordingly
* Added component tests to check that the Connection Acknowledged packet
is handled correctly
* Added test util classes, made the default constructor/destructor protected
to superclass a ProfilingService object
* Added IProfilingConnectionFactory interface
Signed-off-by: Matteo Martincigh <matteo.martincigh@arm.com>
Change-Id: I010d94b18980c9e6394253f4b2bbe4fe5bb3fe4f
Diffstat (limited to 'src/profiling/ProfilingService.cpp')
-rw-r--r-- | src/profiling/ProfilingService.cpp | 92 |
1 files changed, 67 insertions, 25 deletions
diff --git a/src/profiling/ProfilingService.cpp b/src/profiling/ProfilingService.cpp index 2da0f79da2..19cf9cb58e 100644 --- a/src/profiling/ProfilingService.cpp +++ b/src/profiling/ProfilingService.cpp @@ -20,37 +20,76 @@ void ProfilingService::ResetExternalProfilingOptions(const ExternalProfilingOpti // Update the profiling options m_Options = options; + // Check if the profiling service needs to be reset if (resetProfilingService) { // Reset the profiling service - m_CounterDirectory.Clear(); - m_ProfilingConnection.reset(); - m_StateMachine.Reset(); - m_CounterIndex.clear(); - m_CounterValues.clear(); + Reset(); } - - // Re-initialize the profiling service - Initialize(); } -void ProfilingService::Run() +void ProfilingService::Update() { - if (m_StateMachine.GetCurrentState() == ProfilingState::Uninitialised) + if (!m_Options.m_EnableProfiling) { - Initialize(); + // Don't run if profiling is disabled + return; } - else if (m_StateMachine.GetCurrentState() == ProfilingState::NotConnected) + + ProfilingState currentState = m_StateMachine.GetCurrentState(); + switch (currentState) { + case ProfilingState::Uninitialised: + // Initialize the profiling service + Initialize(); + + // Move to the next state + m_StateMachine.TransitionToState(ProfilingState::NotConnected); + break; + case ProfilingState::NotConnected: + BOOST_ASSERT(m_ProfilingConnectionFactory); + + // Reset any existing profiling connection + m_ProfilingConnection.reset(); + try { - m_ProfilingConnectionFactory.GetProfilingConnection(m_Options); - m_StateMachine.TransitionToState(ProfilingState::WaitingForAck); + // Setup the profiling connection + //m_ProfilingConnection = m_ProfilingConnectionFactory.GetProfilingConnection(m_Options); + m_ProfilingConnection = m_ProfilingConnectionFactory->GetProfilingConnection(m_Options); } - catch (const armnn::Exception& e) + catch (const Exception& e) { - std::cerr << e.what() << std::endl; + BOOST_LOG_TRIVIAL(warning) << "An error has occurred when creating the profiling connection: " + << e.what(); } + + // Move to the next state + m_StateMachine.TransitionToState(m_ProfilingConnection + ? ProfilingState::WaitingForAck // Profiling connection obtained, wait for ack + : ProfilingState::NotConnected); // Profiling connection failed, stay in the + // "NotConnected" state + break; + case ProfilingState::WaitingForAck: + BOOST_ASSERT(m_ProfilingConnection); + + // Start the command thread + m_CommandHandler.Start(*m_ProfilingConnection); + + // Start the send thread, while in "WaitingForAck" state it'll send out a "Stream MetaData" packet waiting for + // a valid "Connection Acknowledged" packet confirming the connection + m_SendCounterPacket.Start(*m_ProfilingConnection); + + // The connection acknowledged command handler will automatically transition the state to "Active" once a + // valid "Connection Acknowledged" packet has been received + + break; + case ProfilingState::Active: + + break; + default: + throw RuntimeException(boost::str(boost::format("Unknown profiling service state: %1") + % static_cast<int>(currentState))); } } @@ -119,12 +158,6 @@ uint32_t ProfilingService::DecrementCounterValue(uint16_t counterUid) void ProfilingService::Initialize() { - if (!m_Options.m_EnableProfiling) - { - // Skip the initialization if profiling is disabled - return; - } - // Register a category for the basic runtime counters if (!m_CounterDirectory.IsCategoryRegistered("ArmNN_Runtime")) { @@ -175,9 +208,6 @@ void ProfilingService::Initialize() BOOST_ASSERT(inferencesRunCounter); InitializeCounterValue(inferencesRunCounter->m_Uid); } - - // Initialization is done, update the profiling service state - m_StateMachine.TransitionToState(ProfilingState::NotConnected); } void ProfilingService::InitializeCounterValue(uint16_t counterUid) @@ -196,6 +226,18 @@ void ProfilingService::InitializeCounterValue(uint16_t counterUid) m_CounterIndex.at(counterUid) = counterValuePtr; } +void ProfilingService::Reset() +{ + // Reset the profiling service + m_CounterDirectory.Clear(); + m_ProfilingConnection.reset(); + m_StateMachine.Reset(); + m_CounterIndex.clear(); + m_CounterValues.clear(); + m_CommandHandler.Stop(); + m_SendCounterPacket.Stop(false); +} + } // namespace profiling } // namespace armnn |