ArmNN
 20.08
ProfilingService Class Reference

#include <ProfilingService.hpp>

Inheritance diagram for ProfilingService:
IReadWriteCounterValues IProfilingService INotifyBackends IReadCounterValues IWriteCounterValues IProfilingGuidGenerator IProfilingServiceStatus MockProfilingService ProfilingServiceRuntimeHelper SwapProfilingConnectionFactoryHelper

Public Types

using ExternalProfilingOptions = IRuntime::CreationOptions::ExternalProfilingOptions
 
using IProfilingConnectionFactoryPtr = std::unique_ptr< IProfilingConnectionFactory >
 
using IProfilingConnectionPtr = std::unique_ptr< IProfilingConnection >
 
using CounterIndices = std::vector< std::atomic< uint32_t > * >
 
using CounterValues = std::list< std::atomic< uint32_t > >
 
using BackendProfilingContext = std::unordered_map< BackendId, std::shared_ptr< armnn::profiling::IBackendProfilingContext > >
 

Public Member Functions

 ProfilingService (Optional< IReportStructure &> reportStructure=EmptyOptional())
 
 ~ProfilingService ()
 
void ResetExternalProfilingOptions (const ExternalProfilingOptions &options, bool resetProfilingService=false)
 
ProfilingState ConfigureProfilingService (const ExternalProfilingOptions &options, bool resetProfilingService=false)
 
void Update ()
 
void Disconnect ()
 
void AddBackendProfilingContext (const BackendId backendId, std::shared_ptr< armnn::profiling::IBackendProfilingContext > profilingContext)
 
void NotifyBackendsForTimelineReporting () override
 
const ICounterDirectoryGetCounterDirectory () const
 
ICounterRegistryGetCounterRegistry ()
 
ProfilingState GetCurrentState () const
 
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
 
const ICounterMappingsGetCounterMappings () const override
 
IRegisterCounterMappingGetCounterMappingRegistry ()
 
bool IsProfilingEnabled () const override
 
CaptureData GetCaptureData () override
 
void SetCaptureData (uint32_t capturePeriod, const std::vector< uint16_t > &counterIds, const std::set< BackendId > &activeBackends)
 
void SetCounterValue (uint16_t counterUid, uint32_t value) override
 
uint32_t AddCounterValue (uint16_t counterUid, uint32_t value) override
 
uint32_t SubtractCounterValue (uint16_t counterUid, uint32_t value) override
 
uint32_t IncrementCounterValue (uint16_t counterUid) override
 
ProfilingDynamicGuid NextGuid () override
 Return the next random Guid in the sequence. More...
 
ProfilingStaticGuid GenerateStaticId (const std::string &str) override
 Create a ProfilingStaticGuid based on a hash of the string. More...
 
std::unique_ptr< ISendTimelinePacketGetSendTimelinePacket () const override
 
ISendCounterPacketGetSendCounterPacket () override
 
void ResetGuidGenerator ()
 
bool IsTimelineReportingEnabled ()
 
void AddLocalPacketHandler (ILocalPacketHandlerSharedPtr localPacketHandler)
 
void NotifyProfilingServiceActive () override
 
void WaitForProfilingServiceActivation (unsigned int timeout) override
 
- Public Member Functions inherited from IReadWriteCounterValues
virtual ~IReadWriteCounterValues ()
 
- Public Member Functions inherited from IReadCounterValues
virtual ~IReadCounterValues ()
 
- Public Member Functions inherited from IWriteCounterValues
virtual ~IWriteCounterValues ()
 
- Public Member Functions inherited from IProfilingService
virtual ~IProfilingService ()
 
- Public Member Functions inherited from IProfilingGuidGenerator
virtual ~IProfilingGuidGenerator ()
 
- Public Member Functions inherited from IProfilingServiceStatus
virtual ~IProfilingServiceStatus ()
 
- Public Member Functions inherited from INotifyBackends
virtual ~INotifyBackends ()
 

Static Public Member Functions

static ProfilingDynamicGuid GetNextGuid ()
 
static ProfilingStaticGuid GetStaticId (const std::string &str)
 

Protected Member Functions

void SwapProfilingConnectionFactory (ProfilingService &instance, IProfilingConnectionFactory *other, IProfilingConnectionFactory *&backup)
 
IProfilingConnectionGetProfilingConnection (ProfilingService &instance)
 
void TransitionToState (ProfilingService &instance, ProfilingState newState)
 
bool WaitForPacketSent (ProfilingService &instance, uint32_t timeout=1000)
 
BufferManagerGetBufferManager (ProfilingService &instance)
 

Detailed Description

Definition at line 49 of file ProfilingService.hpp.

Member Typedef Documentation

◆ BackendProfilingContext

using BackendProfilingContext = std::unordered_map<BackendId, std::shared_ptr<armnn::profiling::IBackendProfilingContext> >

Definition at line 58 of file ProfilingService.hpp.

◆ CounterIndices

using CounterIndices = std::vector<std::atomic<uint32_t>*>

Definition at line 55 of file ProfilingService.hpp.

◆ CounterValues

using CounterValues = std::list<std::atomic<uint32_t> >

Definition at line 56 of file ProfilingService.hpp.

◆ ExternalProfilingOptions

◆ IProfilingConnectionFactoryPtr

Definition at line 53 of file ProfilingService.hpp.

◆ IProfilingConnectionPtr

Definition at line 54 of file ProfilingService.hpp.

Constructor & Destructor Documentation

◆ ProfilingService()

ProfilingService ( Optional< IReportStructure &>  reportStructure = EmptyOptional())
inline

Definition at line 60 of file ProfilingService.hpp.

References ProfilingService::AddBackendProfilingContext(), ProfilingService::AddCounterValue(), ProfilingService::ConfigureProfilingService(), ProfilingService::Disconnect(), ProfilingService::GenerateStaticId(), ProfilingService::GetAbsoluteCounterValue(), ProfilingService::GetCaptureData(), ProfilingService::GetCounterCount(), ProfilingService::GetCounterDirectory(), ProfilingService::GetCounterMappingRegistry(), ProfilingService::GetCounterMappings(), ProfilingService::GetCounterRegistry(), ProfilingService::GetCurrentState(), ProfilingService::GetDeltaCounterValue(), ProfilingService::GetSendTimelinePacket(), ProfilingService::IncrementCounterValue(), ProfilingService::IsCounterRegistered(), ProfilingService::IsProfilingEnabled(), ProfilingService::NextGuid(), ProfilingService::NotifyBackendsForTimelineReporting(), ProfilingService::ResetExternalProfilingOptions(), ProfilingService::SetCaptureData(), ProfilingService::SetCounterValue(), ProfilingService::SubtractCounterValue(), ProfilingService::Update(), and ProfilingService::~ProfilingService().

Referenced by ProfilingService::IsTimelineReportingEnabled().

61  : m_Options()
62  , m_TimelineReporting(false)
63  , m_CounterDirectory()
64  , m_ProfilingConnectionFactory(new ProfilingConnectionFactory())
65  , m_ProfilingConnection()
66  , m_StateMachine()
67  , m_CounterIndex()
68  , m_CounterValues()
69  , m_CommandHandlerRegistry()
70  , m_PacketVersionResolver()
71  , m_CommandHandler(1000,
72  false,
73  m_CommandHandlerRegistry,
74  m_PacketVersionResolver)
75  , m_BufferManager()
76  , m_SendCounterPacket(m_BufferManager)
77  , m_SendThread(m_StateMachine, m_BufferManager, m_SendCounterPacket)
78  , m_SendTimelinePacket(m_BufferManager)
79  , m_PeriodicCounterCapture(m_Holder, m_SendCounterPacket, *this, m_CounterIdMap, m_BackendProfilingContexts)
80  , m_ConnectionAcknowledgedCommandHandler(0,
81  1,
82  m_PacketVersionResolver.ResolvePacketVersion(0, 1).GetEncodedValue(),
83  m_CounterDirectory,
84  m_SendCounterPacket,
85  m_SendTimelinePacket,
86  m_StateMachine,
87  *this,
88  m_BackendProfilingContexts)
89  , m_RequestCounterDirectoryCommandHandler(0,
90  3,
91  m_PacketVersionResolver.ResolvePacketVersion(0, 3).GetEncodedValue(),
92  m_CounterDirectory,
93  m_SendCounterPacket,
94  m_SendTimelinePacket,
95  m_StateMachine)
96  , m_PeriodicCounterSelectionCommandHandler(0,
97  4,
98  m_PacketVersionResolver.ResolvePacketVersion(0, 4).GetEncodedValue(),
99  m_BackendProfilingContexts,
100  m_CounterIdMap,
101  m_Holder,
102  MAX_ARMNN_COUNTER,
103  m_PeriodicCounterCapture,
104  *this,
105  m_SendCounterPacket,
106  m_StateMachine)
107  , m_PerJobCounterSelectionCommandHandler(0,
108  5,
109  m_PacketVersionResolver.ResolvePacketVersion(0, 5).GetEncodedValue(),
110  m_StateMachine)
111  , m_ActivateTimelineReportingCommandHandler(0,
112  6,
113  m_PacketVersionResolver.ResolvePacketVersion(0, 6)
114  .GetEncodedValue(),
115  m_SendTimelinePacket,
116  m_StateMachine,
117  reportStructure,
118  m_TimelineReporting,
119  *this)
120  , m_DeactivateTimelineReportingCommandHandler(0,
121  7,
122  m_PacketVersionResolver.ResolvePacketVersion(0, 7)
123  .GetEncodedValue(),
124  m_TimelineReporting,
125  m_StateMachine,
126  *this)
127  , m_TimelinePacketWriterFactory(m_BufferManager)
128  , m_MaxGlobalCounterId(armnn::profiling::INFERENCES_RUN)
129  , m_ServiceActive(false)
130  {
131  // Register the "Connection Acknowledged" command handler
132  m_CommandHandlerRegistry.RegisterFunctor(&m_ConnectionAcknowledgedCommandHandler);
133 
134  // Register the "Request Counter Directory" command handler
135  m_CommandHandlerRegistry.RegisterFunctor(&m_RequestCounterDirectoryCommandHandler);
136 
137  // Register the "Periodic Counter Selection" command handler
138  m_CommandHandlerRegistry.RegisterFunctor(&m_PeriodicCounterSelectionCommandHandler);
139 
140  // Register the "Per-Job Counter Selection" command handler
141  m_CommandHandlerRegistry.RegisterFunctor(&m_PerJobCounterSelectionCommandHandler);
142 
143  m_CommandHandlerRegistry.RegisterFunctor(&m_ActivateTimelineReportingCommandHandler);
144 
145  m_CommandHandlerRegistry.RegisterFunctor(&m_DeactivateTimelineReportingCommandHandler);
146  }

◆ ~ProfilingService()

Definition at line 536 of file ProfilingService.cpp.

Referenced by ProfilingService::ProfilingService().

537 {
538  Stop();
539 }

Member Function Documentation

◆ AddBackendProfilingContext()

void AddBackendProfilingContext ( const BackendId  backendId,
std::shared_ptr< armnn::profiling::IBackendProfilingContext profilingContext 
)

Definition at line 210 of file ProfilingService.cpp.

References ARMNN_ASSERT.

Referenced by ProfilingService::ProfilingService(), and Runtime::Runtime().

212 {
213  ARMNN_ASSERT(profilingContext != nullptr);
214  // Register the backend counters
215  m_MaxGlobalCounterId = profilingContext->RegisterCounters(m_MaxGlobalCounterId);
216  m_BackendProfilingContexts.emplace(backendId, std::move(profilingContext));
217 }
#define ARMNN_ASSERT(COND)
Definition: Assert.hpp:14

◆ AddCounterValue()

uint32_t AddCounterValue ( uint16_t  counterUid,
uint32_t  value 
)
overridevirtual

Implements IWriteCounterValues.

Definition at line 291 of file ProfilingService.cpp.

References ARMNN_ASSERT.

Referenced by BOOST_AUTO_TEST_CASE(), and ProfilingService::ProfilingService().

292 {
293  CheckCounterUid(counterUid);
294  std::atomic<uint32_t>* counterValuePtr = m_CounterIndex.at(counterUid);
295  ARMNN_ASSERT(counterValuePtr);
296  return counterValuePtr->fetch_add(value, std::memory_order::memory_order_relaxed);
297 }
#define ARMNN_ASSERT(COND)
Definition: Assert.hpp:14

◆ AddLocalPacketHandler()

void AddLocalPacketHandler ( ILocalPacketHandlerSharedPtr  localPacketHandler)

◆ ConfigureProfilingService()

ProfilingState ConfigureProfilingService ( const ExternalProfilingOptions options,
bool  resetProfilingService = false 
)

Definition at line 58 of file ProfilingService.cpp.

References ProfilingStateMachine::GetCurrentState(), IRuntime::CreationOptions::ExternalProfilingOptions::m_EnableProfiling, armnn::profiling::NotConnected, ProfilingService::ResetExternalProfilingOptions(), armnn::profiling::Uninitialised, ProfilingService::Update(), and armnn::profiling::WaitingForAck.

Referenced by BOOST_AUTO_TEST_CASE(), ProfilingService::ProfilingService(), and Runtime::Runtime().

61 {
62  ResetExternalProfilingOptions(options, resetProfilingService);
63  ProfilingState currentState = m_StateMachine.GetCurrentState();
64  if (options.m_EnableProfiling)
65  {
66  switch (currentState)
67  {
69  Update(); // should transition to NotConnected
70  Update(); // will either stay in NotConnected because there is no server
71  // or will enter WaitingForAck.
72  currentState = m_StateMachine.GetCurrentState();
73  if (currentState == ProfilingState::WaitingForAck)
74  {
75  Update(); // poke it again to send out the metadata packet
76  }
77  currentState = m_StateMachine.GetCurrentState();
78  return currentState;
80  Update(); // will either stay in NotConnected because there is no server
81  // or will enter WaitingForAck
82  currentState = m_StateMachine.GetCurrentState();
83  if (currentState == ProfilingState::WaitingForAck)
84  {
85  Update(); // poke it again to send out the metadata packet
86  }
87  currentState = m_StateMachine.GetCurrentState();
88  return currentState;
89  default:
90  return currentState;
91  }
92  }
93  else
94  {
95  // Make sure profiling is shutdown
96  switch (currentState)
97  {
100  return currentState;
101  default:
102  Stop();
103  return m_StateMachine.GetCurrentState();
104  }
105  }
106 }
void ResetExternalProfilingOptions(const ExternalProfilingOptions &options, bool resetProfilingService=false)

◆ Disconnect()

void Disconnect ( )

Definition at line 189 of file ProfilingService.cpp.

References armnn::profiling::Active, ProfilingStateMachine::GetCurrentState(), armnn::profiling::NotConnected, armnn::profiling::Uninitialised, and armnn::profiling::WaitingForAck.

Referenced by BOOST_AUTO_TEST_CASE(), and ProfilingService::ProfilingService().

190 {
191  ProfilingState currentState = m_StateMachine.GetCurrentState();
192  switch (currentState)
193  {
197  return; // NOP
199  // Stop the command thread (if running)
200  Stop();
201 
202  break;
203  default:
204  throw RuntimeException(boost::str(boost::format("Unknown profiling service state: %1")
205  % static_cast<int>(currentState)));
206  }
207 }

◆ GenerateStaticId()

ProfilingStaticGuid GenerateStaticId ( const std::string &  str)
overridevirtual

Create a ProfilingStaticGuid based on a hash of the string.

Implements IProfilingGuidGenerator.

Reimplemented in MockProfilingService.

Definition at line 320 of file ProfilingService.cpp.

References ProfilingService::GetStaticId().

Referenced by ProfilingService::ProfilingService().

321 {
322  return ProfilingService::GetStaticId(str);
323 }
static ProfilingStaticGuid GetStaticId(const std::string &str)

◆ GetAbsoluteCounterValue()

uint32_t GetAbsoluteCounterValue ( uint16_t  counterUid) const
overridevirtual

Implements IReadCounterValues.

Definition at line 243 of file ProfilingService.cpp.

References ARMNN_ASSERT.

Referenced by BOOST_AUTO_TEST_CASE(), and ProfilingService::ProfilingService().

244 {
245  CheckCounterUid(counterUid);
246  std::atomic<uint32_t>* counterValuePtr = m_CounterIndex.at(counterUid);
247  ARMNN_ASSERT(counterValuePtr);
248  return counterValuePtr->load(std::memory_order::memory_order_relaxed);
249 }
#define ARMNN_ASSERT(COND)
Definition: Assert.hpp:14

◆ GetBufferManager()

BufferManager& GetBufferManager ( ProfilingService instance)
inlineprotected

Definition at line 306 of file ProfilingService.hpp.

307  {
308  return instance.m_BufferManager;
309  }

◆ GetCaptureData()

CaptureData GetCaptureData ( )
overridevirtual

Implements IProfilingService.

Reimplemented in MockProfilingService.

Definition at line 271 of file ProfilingService.cpp.

References Holder::GetCaptureData().

Referenced by BackendProfiling::GetActiveCounters(), BackendProfiling::GetCounterStatus(), and ProfilingService::ProfilingService().

272 {
273  return m_Holder.GetCaptureData();
274 }
CaptureData GetCaptureData() const
Definition: Holder.cpp:54

◆ GetCounterCount()

uint16_t GetCounterCount ( ) const
overridevirtual

Implements IReadCounterValues.

Definition at line 233 of file ProfilingService.cpp.

References CounterDirectory::GetCounterCount().

Referenced by ProfilingService::ProfilingService().

234 {
235  return m_CounterDirectory.GetCounterCount();
236 }
uint16_t GetCounterCount() const override

◆ GetCounterDirectory()

const ICounterDirectory & GetCounterDirectory ( ) const

Definition at line 218 of file ProfilingService.cpp.

Referenced by BOOST_AUTO_TEST_CASE(), and ProfilingService::ProfilingService().

219 {
220  return m_CounterDirectory;
221 }

◆ GetCounterMappingRegistry()

IRegisterCounterMapping & GetCounterMappingRegistry ( )

Definition at line 266 of file ProfilingService.cpp.

Referenced by ProfilingService::ProfilingService(), and RegisterBackendCounters::RegisterCounter().

267 {
268  return m_CounterIdMap;
269 }

◆ GetCounterMappings()

const ICounterMappings & GetCounterMappings ( ) const
overridevirtual

◆ GetCounterRegistry()

ICounterRegistry & GetCounterRegistry ( )

Definition at line 223 of file ProfilingService.cpp.

Referenced by ProfilingService::ProfilingService().

224 {
225  return m_CounterDirectory;
226 }

◆ GetCurrentState()

ProfilingState GetCurrentState ( ) const

◆ GetDeltaCounterValue()

uint32_t GetDeltaCounterValue ( uint16_t  counterUid)
overridevirtual

Implements IReadCounterValues.

Definition at line 251 of file ProfilingService.cpp.

References ARMNN_ASSERT, and ProfilingService::SubtractCounterValue().

Referenced by BOOST_AUTO_TEST_CASE(), and ProfilingService::ProfilingService().

252 {
253  CheckCounterUid(counterUid);
254  std::atomic<uint32_t>* counterValuePtr = m_CounterIndex.at(counterUid);
255  ARMNN_ASSERT(counterValuePtr);
256  const uint32_t counterValue = counterValuePtr->load(std::memory_order::memory_order_relaxed);
257  SubtractCounterValue(counterUid, counterValue);
258  return counterValue;
259 }
uint32_t SubtractCounterValue(uint16_t counterUid, uint32_t value) override
#define ARMNN_ASSERT(COND)
Definition: Assert.hpp:14

◆ GetNextGuid()

◆ GetProfilingConnection()

IProfilingConnection* GetProfilingConnection ( ProfilingService instance)
inlineprotected

Definition at line 293 of file ProfilingService.hpp.

294  {
295  return instance.m_ProfilingConnection.get();
296  }

◆ GetSendCounterPacket()

ISendCounterPacket& GetSendCounterPacket ( )
inlineoverridevirtual

Implements IProfilingService.

Reimplemented in MockProfilingService.

Definition at line 203 of file ProfilingService.hpp.

References ProfilingService::GetNextGuid(), ProfilingService::GetStaticId(), and ProfilingService::ResetGuidGenerator().

Referenced by BackendProfiling::ReportCounters().

204  {
205  return m_SendCounterPacket;
206  }

◆ GetSendTimelinePacket()

◆ GetStaticId()

ProfilingStaticGuid GetStaticId ( const std::string &  str)
static

Definition at line 27 of file ProfilingService.cpp.

References ProfilingGuidGenerator::GenerateStaticId().

Referenced by BOOST_AUTO_TEST_CASE(), TimelineUtilityMethods::DeclareLabel(), ProfilingService::GenerateStaticId(), ProfilingService::GetSendCounterPacket(), and VerifyTimelineLabelBinaryPacketData().

28 {
29  return m_GuidGenerator.GenerateStaticId(str);
30 }
ProfilingStaticGuid GenerateStaticId(const std::string &str) override
Create a ProfilingStaticGuid based on a hash of the string.

◆ IncrementCounterValue()

uint32_t IncrementCounterValue ( uint16_t  counterUid)
overridevirtual

Implements IWriteCounterValues.

Definition at line 307 of file ProfilingService.cpp.

References ARMNN_ASSERT.

Referenced by BOOST_AUTO_TEST_CASE(), and ProfilingService::ProfilingService().

308 {
309  CheckCounterUid(counterUid);
310  std::atomic<uint32_t>* counterValuePtr = m_CounterIndex.at(counterUid);
311  ARMNN_ASSERT(counterValuePtr);
312  return counterValuePtr->operator++(std::memory_order::memory_order_relaxed);
313 }
#define ARMNN_ASSERT(COND)
Definition: Assert.hpp:14

◆ IsCounterRegistered()

bool IsCounterRegistered ( uint16_t  counterUid) const
overridevirtual

Implements IReadCounterValues.

Definition at line 238 of file ProfilingService.cpp.

References CounterDirectory::IsCounterRegistered().

Referenced by ProfilingService::GetSendTimelinePacket(), and ProfilingService::ProfilingService().

239 {
240  return m_CounterDirectory.IsCounterRegistered(counterUid);
241 }
bool IsCounterRegistered(uint16_t counterUid) const

◆ IsProfilingEnabled()

bool IsProfilingEnabled ( ) const
overridevirtual

◆ IsTimelineReportingEnabled()

bool IsTimelineReportingEnabled ( )
inline

◆ NextGuid()

ProfilingDynamicGuid NextGuid ( )
overridevirtual

Return the next random Guid in the sequence.

Implements IProfilingGuidGenerator.

Reimplemented in MockProfilingService.

Definition at line 315 of file ProfilingService.cpp.

References ProfilingService::GetNextGuid().

Referenced by BOOST_AUTO_TEST_CASE(), and ProfilingService::ProfilingService().

316 {
318 }
static ProfilingDynamicGuid GetNextGuid()

◆ NotifyBackendsForTimelineReporting()

void NotifyBackendsForTimelineReporting ( )
overridevirtual

Implements INotifyBackends.

Definition at line 491 of file ProfilingService.cpp.

Referenced by ProfilingService::ProfilingService().

492 {
493  BackendProfilingContext::iterator it = m_BackendProfilingContexts.begin();
494  while (it != m_BackendProfilingContexts.end())
495  {
496  auto& backendProfilingContext = it->second;
497  backendProfilingContext->EnableTimelineReporting(m_TimelineReporting);
498  // Increment the Iterator to point to next entry
499  it++;
500  }
501 }

◆ NotifyProfilingServiceActive()

void NotifyProfilingServiceActive ( )
overridevirtual

Implements IProfilingServiceStatus.

Definition at line 503 of file ProfilingService.cpp.

Referenced by ProfilingService::IsTimelineReportingEnabled().

504 {
505  { // only lock when we are updating the inference completed variable
506  std::unique_lock<std::mutex> lck(m_ServiceActiveMutex);
507  m_ServiceActive = true;
508  }
509  m_ServiceActiveConditionVariable.notify_one();
510 }

◆ ResetExternalProfilingOptions()

void ResetExternalProfilingOptions ( const ExternalProfilingOptions options,
bool  resetProfilingService = false 
)

Definition at line 37 of file ProfilingService.cpp.

References IRuntime::CreationOptions::ExternalProfilingOptions::m_TimelineEnabled, and ConnectionAcknowledgedCommandHandler::setTimelineEnabled().

Referenced by BOOST_AUTO_TEST_CASE(), ProfilingService::ConfigureProfilingService(), ProfilingService::ProfilingService(), and VerifyPostOptimisationStructureTestImpl().

39 {
40  // Update the profiling options
41  m_Options = options;
42  m_TimelineReporting = options.m_TimelineEnabled;
43  m_ConnectionAcknowledgedCommandHandler.setTimelineEnabled(options.m_TimelineEnabled);
44 
45  // Check if the profiling service needs to be reset
46  if (resetProfilingService)
47  {
48  // Reset the profiling service
49  Reset();
50  }
51 }

◆ ResetGuidGenerator()

void ResetGuidGenerator ( )

Definition at line 32 of file ProfilingService.cpp.

References ProfilingGuidGenerator::Reset().

Referenced by BOOST_AUTO_TEST_CASE(), and ProfilingService::GetSendCounterPacket().

33 {
34  m_GuidGenerator.Reset();
35 }
void Reset()
Reset the generator back to zero. Used mainly for test.

◆ SetCaptureData()

void SetCaptureData ( uint32_t  capturePeriod,
const std::vector< uint16_t > &  counterIds,
const std::set< BackendId > &  activeBackends 
)

Definition at line 276 of file ProfilingService.cpp.

References Holder::SetCaptureData().

Referenced by BOOST_AUTO_TEST_CASE(), and ProfilingService::ProfilingService().

279 {
280  m_Holder.SetCaptureData(capturePeriod, counterIds, activeBackends);
281 }
void SetCaptureData(uint32_t capturePeriod, const std::vector< uint16_t > &counterIds, const std::set< armnn::BackendId > &activeBackends)
Definition: Holder.cpp:74

◆ SetCounterValue()

void SetCounterValue ( uint16_t  counterUid,
uint32_t  value 
)
overridevirtual

Implements IWriteCounterValues.

Definition at line 283 of file ProfilingService.cpp.

References ARMNN_ASSERT.

Referenced by BOOST_AUTO_TEST_CASE(), ProfilingService::GetSendTimelinePacket(), and ProfilingService::ProfilingService().

284 {
285  CheckCounterUid(counterUid);
286  std::atomic<uint32_t>* counterValuePtr = m_CounterIndex.at(counterUid);
287  ARMNN_ASSERT(counterValuePtr);
288  counterValuePtr->store(value, std::memory_order::memory_order_relaxed);
289 }
#define ARMNN_ASSERT(COND)
Definition: Assert.hpp:14

◆ SubtractCounterValue()

uint32_t SubtractCounterValue ( uint16_t  counterUid,
uint32_t  value 
)
overridevirtual

Implements IWriteCounterValues.

Definition at line 299 of file ProfilingService.cpp.

References ARMNN_ASSERT.

Referenced by BOOST_AUTO_TEST_CASE(), ProfilingService::GetDeltaCounterValue(), and ProfilingService::ProfilingService().

300 {
301  CheckCounterUid(counterUid);
302  std::atomic<uint32_t>* counterValuePtr = m_CounterIndex.at(counterUid);
303  ARMNN_ASSERT(counterValuePtr);
304  return counterValuePtr->fetch_sub(value, std::memory_order::memory_order_relaxed);
305 }
#define ARMNN_ASSERT(COND)
Definition: Assert.hpp:14

◆ SwapProfilingConnectionFactory()

void SwapProfilingConnectionFactory ( ProfilingService instance,
IProfilingConnectionFactory other,
IProfilingConnectionFactory *&  backup 
)
inlineprotected

Definition at line 283 of file ProfilingService.hpp.

References ARMNN_ASSERT.

286  {
287  ARMNN_ASSERT(instance.m_ProfilingConnectionFactory);
288  ARMNN_ASSERT(other);
289 
290  backup = instance.m_ProfilingConnectionFactory.release();
291  instance.m_ProfilingConnectionFactory.reset(other);
292  }
#define ARMNN_ASSERT(COND)
Definition: Assert.hpp:14

◆ TransitionToState()

void TransitionToState ( ProfilingService instance,
ProfilingState  newState 
)
inlineprotected

Definition at line 297 of file ProfilingService.hpp.

References ProfilingStateMachine::TransitionToState().

298  {
299  instance.m_StateMachine.TransitionToState(newState);
300  }

◆ Update()

void Update ( )

Definition at line 108 of file ProfilingService.cpp.

References armnn::profiling::Active, ARMNN_ASSERT, ARMNN_LOG, ProfilingStateMachine::GetCurrentState(), IRuntime::CreationOptions::ExternalProfilingOptions::m_EnableProfiling, armnn::profiling::NotConnected, SendThread::Start(), CommandHandler::Start(), SendThread::Stop(), CommandHandler::Stop(), PeriodicCounterCapture::Stop(), ProfilingStateMachine::TransitionToState(), armnn::profiling::Uninitialised, armnn::profiling::WaitingForAck, armnn::warning, and Exception::what().

Referenced by BOOST_AUTO_TEST_CASE(), ProfilingService::ConfigureProfilingService(), and ProfilingService::ProfilingService().

109 {
110  if (!m_Options.m_EnableProfiling)
111  {
112  // Don't run if profiling is disabled
113  return;
114  }
115 
116  ProfilingState currentState = m_StateMachine.GetCurrentState();
117  switch (currentState)
118  {
120 
121  // Initialize the profiling service
122  Initialize();
123 
124  // Move to the next state
126  break;
128  // Stop the command thread (if running)
129  m_CommandHandler.Stop();
130 
131  // Stop the send thread (if running)
132  m_SendThread.Stop(false);
133 
134  // Stop the periodic counter capture thread (if running)
135  m_PeriodicCounterCapture.Stop();
136 
137  // Reset any existing profiling connection
138  m_ProfilingConnection.reset();
139 
140  try
141  {
142  // Setup the profiling connection
143  ARMNN_ASSERT(m_ProfilingConnectionFactory);
144  m_ProfilingConnection = m_ProfilingConnectionFactory->GetProfilingConnection(m_Options);
145  }
146  catch (const Exception& e)
147  {
148  ARMNN_LOG(warning) << "An error has occurred when creating the profiling connection: "
149  << e.what();
150  }
151  catch (const arm::pipe::SocketConnectionException& e)
152  {
153  ARMNN_LOG(warning) << "An error has occurred when creating the profiling connection ["
154  << e.what() << "] on socket [" << e.GetSocketFd() << "].";
155  }
156 
157  // Move to the next state
158  m_StateMachine.TransitionToState(m_ProfilingConnection
159  ? ProfilingState::WaitingForAck // Profiling connection obtained, wait for ack
160  : ProfilingState::NotConnected); // Profiling connection failed, stay in the
161  // "NotConnected" state
162  break;
164  ARMNN_ASSERT(m_ProfilingConnection);
165 
166  // Start the command thread
167  m_CommandHandler.Start(*m_ProfilingConnection);
168 
169  // Start the send thread, while in "WaitingForAck" state it'll send out a "Stream MetaData" packet waiting for
170  // a valid "Connection Acknowledged" packet confirming the connection
171  m_SendThread.Start(*m_ProfilingConnection);
172 
173  // The connection acknowledged command handler will automatically transition the state to "Active" once a
174  // valid "Connection Acknowledged" packet has been received
175 
176  break;
178 
179  // The period counter capture thread is started by the Periodic Counter Selection command handler upon
180  // request by an external profiling service
181 
182  break;
183  default:
184  throw RuntimeException(boost::str(boost::format("Unknown profiling service state: %1")
185  % static_cast<int>(currentState)));
186  }
187 }
void Start(IProfilingConnection &profilingConnection)
#define ARMNN_LOG(severity)
Definition: Logging.hpp:163
#define ARMNN_ASSERT(COND)
Definition: Assert.hpp:14
void TransitionToState(ProfilingState newState)
void Stop(bool rethrowSendThreadExceptions=true) override
Stop the thread.
Definition: SendThread.cpp:82
void Start(IProfilingConnection &profilingConnection) override
Start the thread.
Definition: SendThread.cpp:52

◆ WaitForPacketSent()

bool WaitForPacketSent ( ProfilingService instance,
uint32_t  timeout = 1000 
)
inlineprotected

Definition at line 301 of file ProfilingService.hpp.

References SendThread::WaitForPacketSent().

Referenced by SwapProfilingConnectionFactoryHelper::WaitForPacketsSent().

302  {
303  return instance.m_SendThread.WaitForPacketSent(timeout);
304  }

◆ WaitForProfilingServiceActivation()

void WaitForProfilingServiceActivation ( unsigned int  timeout)
overridevirtual

Implements IProfilingServiceStatus.

Definition at line 512 of file ProfilingService.cpp.

References ARMNN_LOG, and armnn::warning.

Referenced by ProfilingService::IsTimelineReportingEnabled(), and Runtime::Runtime().

513 {
514  std::unique_lock<std::mutex> lck(m_ServiceActiveMutex);
515 
516  auto start = std::chrono::high_resolution_clock::now();
517  // Here we we will go back to sleep after a spurious wake up if
518  // m_InferenceCompleted is not yet true.
519  if (!m_ServiceActiveConditionVariable.wait_for(lck,
520  std::chrono::milliseconds(timeout),
521  [&]{return m_ServiceActive == true;}))
522  {
523  if (m_ServiceActive == true)
524  {
525  return;
526  }
527  auto finish = std::chrono::high_resolution_clock::now();
528  std::chrono::duration<double, std::milli> elapsed = finish - start;
529  std::stringstream ss;
530  ss << "Timed out waiting on profiling service activation for " << elapsed.count() << " ms";
531  ARMNN_LOG(warning) << ss.str();
532  }
533  return;
534 }
#define ARMNN_LOG(severity)
Definition: Logging.hpp:163

The documentation for this class was generated from the following files: