ArmNN
 20.05
ProfilingService Class Reference

#include <ProfilingService.hpp>

Inheritance diagram for ProfilingService:
IReadWriteCounterValues IProfilingService INotifyBackends IReadCounterValues IWriteCounterValues IProfilingGuidGenerator 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
 
bool IsTimelineReportingEnabled ()
 
void AddLocalPacketHandler (ILocalPacketHandlerSharedPtr localPacketHandler)
 
- 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 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 47 of file ProfilingService.hpp.

Member Typedef Documentation

◆ BackendProfilingContext

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

Definition at line 56 of file ProfilingService.hpp.

◆ CounterIndices

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

Definition at line 53 of file ProfilingService.hpp.

◆ CounterValues

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

Definition at line 54 of file ProfilingService.hpp.

◆ ExternalProfilingOptions

◆ IProfilingConnectionFactoryPtr

Definition at line 51 of file ProfilingService.hpp.

◆ IProfilingConnectionPtr

Definition at line 52 of file ProfilingService.hpp.

Constructor & Destructor Documentation

◆ ProfilingService()

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

Definition at line 58 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(), options, CommandHandlerRegistry::RegisterFunctor(), ProfilingService::ResetExternalProfilingOptions(), ProfilingService::SetCaptureData(), ProfilingService::SetCounterValue(), ProfilingService::SubtractCounterValue(), ProfilingService::Update(), and ProfilingService::~ProfilingService().

Referenced by ProfilingService::IsTimelineReportingEnabled().

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

◆ ~ProfilingService()

Definition at line 494 of file ProfilingService.cpp.

Referenced by ProfilingService::ProfilingService().

495 {
496  Stop();
497 }

Member Function Documentation

◆ AddBackendProfilingContext()

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

Definition at line 205 of file ProfilingService.cpp.

References ARMNN_ASSERT.

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

207 {
208  ARMNN_ASSERT(profilingContext != nullptr);
209  // Register the backend counters
210  m_MaxGlobalCounterId = profilingContext->RegisterCounters(m_MaxGlobalCounterId);
211  m_BackendProfilingContexts.emplace(backendId, std::move(profilingContext));
212 }
#define ARMNN_ASSERT(COND)
Definition: Assert.hpp:14

◆ AddCounterValue()

uint32_t AddCounterValue ( uint16_t  counterUid,
uint32_t  value 
)
overridevirtual

Implements IWriteCounterValues.

Definition at line 286 of file ProfilingService.cpp.

References ARMNN_ASSERT.

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

287 {
288  CheckCounterUid(counterUid);
289  std::atomic<uint32_t>* counterValuePtr = m_CounterIndex.at(counterUid);
290  ARMNN_ASSERT(counterValuePtr);
291  return counterValuePtr->fetch_add(value, std::memory_order::memory_order_relaxed);
292 }
#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 53 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().

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

◆ Disconnect()

void Disconnect ( )

Definition at line 184 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().

185 {
186  ProfilingState currentState = m_StateMachine.GetCurrentState();
187  switch (currentState)
188  {
192  return; // NOP
194  // Stop the command thread (if running)
195  Stop();
196 
197  break;
198  default:
199  throw RuntimeException(boost::str(boost::format("Unknown profiling service state: %1")
200  % static_cast<int>(currentState)));
201  }
202 }

◆ 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 315 of file ProfilingService.cpp.

References ProfilingService::GetStaticId().

Referenced by ProfilingService::ProfilingService().

316 {
317  return ProfilingService::GetStaticId(str);
318 }
static ProfilingStaticGuid GetStaticId(const std::string &str)

◆ GetAbsoluteCounterValue()

uint32_t GetAbsoluteCounterValue ( uint16_t  counterUid) const
overridevirtual

Implements IReadCounterValues.

Definition at line 238 of file ProfilingService.cpp.

References ARMNN_ASSERT.

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

239 {
240  CheckCounterUid(counterUid);
241  std::atomic<uint32_t>* counterValuePtr = m_CounterIndex.at(counterUid);
242  ARMNN_ASSERT(counterValuePtr);
243  return counterValuePtr->load(std::memory_order::memory_order_relaxed);
244 }
#define ARMNN_ASSERT(COND)
Definition: Assert.hpp:14

◆ GetBufferManager()

BufferManager& GetBufferManager ( ProfilingService instance)
inlineprotected

Definition at line 290 of file ProfilingService.hpp.

291  {
292  return instance.m_BufferManager;
293  }

◆ GetCaptureData()

CaptureData GetCaptureData ( )
overridevirtual

Implements IProfilingService.

Reimplemented in MockProfilingService.

Definition at line 266 of file ProfilingService.cpp.

References Holder::GetCaptureData().

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

267 {
268  return m_Holder.GetCaptureData();
269 }
CaptureData GetCaptureData() const
Definition: Holder.cpp:54

◆ GetCounterCount()

uint16_t GetCounterCount ( ) const
overridevirtual

Implements IReadCounterValues.

Definition at line 228 of file ProfilingService.cpp.

References CounterDirectory::GetCounterCount().

Referenced by ProfilingService::ProfilingService().

229 {
230  return m_CounterDirectory.GetCounterCount();
231 }
uint16_t GetCounterCount() const override

◆ GetCounterDirectory()

const ICounterDirectory & GetCounterDirectory ( ) const

Definition at line 213 of file ProfilingService.cpp.

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

214 {
215  return m_CounterDirectory;
216 }

◆ GetCounterMappingRegistry()

IRegisterCounterMapping & GetCounterMappingRegistry ( )

Definition at line 261 of file ProfilingService.cpp.

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

262 {
263  return m_CounterIdMap;
264 }

◆ GetCounterMappings()

const ICounterMappings & GetCounterMappings ( ) const
overridevirtual

◆ GetCounterRegistry()

ICounterRegistry & GetCounterRegistry ( )

Definition at line 218 of file ProfilingService.cpp.

Referenced by ProfilingService::ProfilingService().

219 {
220  return m_CounterDirectory;
221 }

◆ GetCurrentState()

ProfilingState GetCurrentState ( ) const

◆ GetDeltaCounterValue()

uint32_t GetDeltaCounterValue ( uint16_t  counterUid)
overridevirtual

Implements IReadCounterValues.

Definition at line 246 of file ProfilingService.cpp.

References ARMNN_ASSERT, and ProfilingService::SubtractCounterValue().

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

247 {
248  CheckCounterUid(counterUid);
249  std::atomic<uint32_t>* counterValuePtr = m_CounterIndex.at(counterUid);
250  ARMNN_ASSERT(counterValuePtr);
251  const uint32_t counterValue = counterValuePtr->load(std::memory_order::memory_order_relaxed);
252  SubtractCounterValue(counterUid, counterValue);
253  return counterValue;
254 }
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 277 of file ProfilingService.hpp.

278  {
279  return instance.m_ProfilingConnection.get();
280  }

◆ GetSendCounterPacket()

ISendCounterPacket& GetSendCounterPacket ( )
inlineoverridevirtual

Implements IProfilingService.

Reimplemented in MockProfilingService.

Definition at line 198 of file ProfilingService.hpp.

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

Referenced by BackendProfiling::ReportCounters().

199  {
200  return m_SendCounterPacket;
201  }

◆ 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 302 of file ProfilingService.cpp.

References ARMNN_ASSERT.

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

303 {
304  CheckCounterUid(counterUid);
305  std::atomic<uint32_t>* counterValuePtr = m_CounterIndex.at(counterUid);
306  ARMNN_ASSERT(counterValuePtr);
307  return counterValuePtr->operator++(std::memory_order::memory_order_relaxed);
308 }
#define ARMNN_ASSERT(COND)
Definition: Assert.hpp:14

◆ IsCounterRegistered()

bool IsCounterRegistered ( uint16_t  counterUid) const
overridevirtual

Implements IReadCounterValues.

Definition at line 233 of file ProfilingService.cpp.

References CounterDirectory::IsCounterRegistered().

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

234 {
235  return m_CounterDirectory.IsCounterRegistered(counterUid);
236 }
bool IsCounterRegistered(uint16_t counterUid) const

◆ IsProfilingEnabled()

bool IsProfilingEnabled ( ) const
overridevirtual

◆ IsTimelineReportingEnabled()

bool IsTimelineReportingEnabled ( )
inline

Definition at line 207 of file ProfilingService.hpp.

References ProfilingService::AddLocalPacketHandler(), and ProfilingService::ProfilingService().

Referenced by TimelineUtilityMethods::GetTimelineUtils().

208  {
209  return m_TimelineReporting;
210  }

◆ NextGuid()

ProfilingDynamicGuid NextGuid ( )
overridevirtual

Return the next random Guid in the sequence.

Implements IProfilingGuidGenerator.

Reimplemented in MockProfilingService.

Definition at line 310 of file ProfilingService.cpp.

References ProfilingService::GetNextGuid().

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

311 {
313 }
static ProfilingDynamicGuid GetNextGuid()

◆ NotifyBackendsForTimelineReporting()

void NotifyBackendsForTimelineReporting ( )
overridevirtual

Implements INotifyBackends.

Definition at line 482 of file ProfilingService.cpp.

Referenced by ProfilingService::ProfilingService().

483 {
484  BackendProfilingContext::iterator it = m_BackendProfilingContexts.begin();
485  while (it != m_BackendProfilingContexts.end())
486  {
487  auto& backendProfilingContext = it->second;
488  backendProfilingContext->EnableTimelineReporting(m_TimelineReporting);
489  // Increment the Iterator to point to next entry
490  it++;
491  }
492 }

◆ ResetExternalProfilingOptions()

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

Definition at line 32 of file ProfilingService.cpp.

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

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

34 {
35  // Update the profiling options
36  m_Options = options;
37  m_TimelineReporting = options.m_TimelineEnabled;
38  m_ConnectionAcknowledgedCommandHandler.setTimelineEnabled(options.m_TimelineEnabled);
39 
40  // Check if the profiling service needs to be reset
41  if (resetProfilingService)
42  {
43  // Reset the profiling service
44  Reset();
45  }
46 }
armnn::Runtime::CreationOptions::ExternalProfilingOptions options

◆ SetCaptureData()

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

Definition at line 271 of file ProfilingService.cpp.

References Holder::SetCaptureData().

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

274 {
275  m_Holder.SetCaptureData(capturePeriod, counterIds, activeBackends);
276 }
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 278 of file ProfilingService.cpp.

References ARMNN_ASSERT.

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

279 {
280  CheckCounterUid(counterUid);
281  std::atomic<uint32_t>* counterValuePtr = m_CounterIndex.at(counterUid);
282  ARMNN_ASSERT(counterValuePtr);
283  counterValuePtr->store(value, std::memory_order::memory_order_relaxed);
284 }
#define ARMNN_ASSERT(COND)
Definition: Assert.hpp:14

◆ SubtractCounterValue()

uint32_t SubtractCounterValue ( uint16_t  counterUid,
uint32_t  value 
)
overridevirtual

Implements IWriteCounterValues.

Definition at line 294 of file ProfilingService.cpp.

References ARMNN_ASSERT.

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

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

◆ SwapProfilingConnectionFactory()

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

Definition at line 267 of file ProfilingService.hpp.

References ARMNN_ASSERT.

270  {
271  ARMNN_ASSERT(instance.m_ProfilingConnectionFactory);
272  ARMNN_ASSERT(other);
273 
274  backup = instance.m_ProfilingConnectionFactory.release();
275  instance.m_ProfilingConnectionFactory.reset(other);
276  }
#define ARMNN_ASSERT(COND)
Definition: Assert.hpp:14

◆ TransitionToState()

void TransitionToState ( ProfilingService instance,
ProfilingState  newState 
)
inlineprotected

Definition at line 281 of file ProfilingService.hpp.

References ProfilingStateMachine::TransitionToState().

282  {
283  instance.m_StateMachine.TransitionToState(newState);
284  }

◆ Update()

void Update ( )

Definition at line 103 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().

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

◆ WaitForPacketSent()

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

Definition at line 285 of file ProfilingService.hpp.

References SendThread::WaitForPacketSent().

Referenced by SwapProfilingConnectionFactoryHelper::WaitForPacketsSent().

286  {
287  return instance.m_SendThread.WaitForPacketSent(timeout);
288  }

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