ArmNN
 21.11
ProfilingService Class Reference

#include <ProfilingService.hpp>

Inheritance diagram for ProfilingService:
IReadWriteCounterValues IProfilingService INotifyBackends IReadCounterValues IWriteCounterValues 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 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 50 of file ProfilingService.hpp.

Member Typedef Documentation

◆ BackendProfilingContext

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

Definition at line 59 of file ProfilingService.hpp.

◆ CounterIndices

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

Definition at line 56 of file ProfilingService.hpp.

◆ CounterValues

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

Definition at line 57 of file ProfilingService.hpp.

◆ ExternalProfilingOptions

◆ IProfilingConnectionFactoryPtr

Definition at line 54 of file ProfilingService.hpp.

◆ IProfilingConnectionPtr

Definition at line 55 of file ProfilingService.hpp.

Constructor & Destructor Documentation

◆ ProfilingService()

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

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

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

◆ ~ProfilingService()

Definition at line 540 of file ProfilingService.cpp.

Referenced by ProfilingService::ProfilingService().

541 {
542  Stop();
543 }

Member Function Documentation

◆ AddBackendProfilingContext()

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

Definition at line 214 of file ProfilingService.cpp.

References ARMNN_ASSERT.

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

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

◆ AddCounterValue()

uint32_t AddCounterValue ( uint16_t  counterUid,
uint32_t  value 
)
overridevirtual

Implements IWriteCounterValues.

Definition at line 295 of file ProfilingService.cpp.

References ARMNN_ASSERT.

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

296 {
297  CheckCounterUid(counterUid);
298  std::atomic<uint32_t>* counterValuePtr = m_CounterIndex.at(counterUid);
299  ARMNN_ASSERT(counterValuePtr);
300  return counterValuePtr->fetch_add(value, std::memory_order::memory_order_relaxed);
301 }
#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 62 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 ProfilingService::ProfilingService(), RuntimeImpl::RuntimeImpl(), and TEST_SUITE().

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

◆ Disconnect()

void Disconnect ( )

Definition at line 193 of file ProfilingService.cpp.

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

Referenced by ProfilingService::ProfilingService().

194 {
195  ProfilingState currentState = m_StateMachine.GetCurrentState();
196  switch (currentState)
197  {
201  return; // NOP
203  // Stop the command thread (if running)
204  Stop();
205 
206  break;
207  default:
208  throw RuntimeException(fmt::format("Unknown profiling service state: {}",
209  static_cast<int>(currentState)));
210  }
211 }

◆ GenerateStaticId()

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

Create a ProfilingStaticGuid based on a hash of the string.

Definition at line 324 of file ProfilingService.cpp.

References ProfilingService::GetStaticId().

Referenced by ProfilingService::ProfilingService().

325 {
326  return ProfilingService::GetStaticId(str);
327 }
static ProfilingStaticGuid GetStaticId(const std::string &str)

◆ GetAbsoluteCounterValue()

uint32_t GetAbsoluteCounterValue ( uint16_t  counterUid) const
overridevirtual

Implements IReadCounterValues.

Definition at line 247 of file ProfilingService.cpp.

References ARMNN_ASSERT.

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

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

◆ GetBufferManager()

BufferManager& GetBufferManager ( ProfilingService instance)
inlineprotected

Definition at line 307 of file ProfilingService.hpp.

308  {
309  return instance.m_BufferManager;
310  }

◆ GetCaptureData()

CaptureData GetCaptureData ( )
overridevirtual

Implements IProfilingService.

Reimplemented in MockProfilingService.

Definition at line 275 of file ProfilingService.cpp.

References Holder::GetCaptureData().

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

276 {
277  return m_Holder.GetCaptureData();
278 }
CaptureData GetCaptureData() const
Definition: Holder.cpp:54

◆ GetCounterCount()

uint16_t GetCounterCount ( ) const
overridevirtual

Implements IReadCounterValues.

Definition at line 237 of file ProfilingService.cpp.

References CounterDirectory::GetCounterCount().

Referenced by ProfilingService::ProfilingService().

238 {
239  return m_CounterDirectory.GetCounterCount();
240 }
uint16_t GetCounterCount() const override

◆ GetCounterDirectory()

const ICounterDirectory & GetCounterDirectory ( ) const

Definition at line 222 of file ProfilingService.cpp.

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

223 {
224  return m_CounterDirectory;
225 }

◆ GetCounterMappingRegistry()

IRegisterCounterMapping & GetCounterMappingRegistry ( )

Definition at line 270 of file ProfilingService.cpp.

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

271 {
272  return m_CounterIdMap;
273 }

◆ GetCounterMappings()

const ICounterMappings & GetCounterMappings ( ) const
overridevirtual

◆ GetCounterRegistry()

ICounterRegistry & GetCounterRegistry ( )

Definition at line 227 of file ProfilingService.cpp.

Referenced by ProfilingService::ProfilingService().

228 {
229  return m_CounterDirectory;
230 }

◆ GetCurrentState()

ProfilingState GetCurrentState ( ) const

◆ GetDeltaCounterValue()

uint32_t GetDeltaCounterValue ( uint16_t  counterUid)
overridevirtual

Implements IReadCounterValues.

Definition at line 255 of file ProfilingService.cpp.

References ARMNN_ASSERT, and ProfilingService::SubtractCounterValue().

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

256 {
257  CheckCounterUid(counterUid);
258  std::atomic<uint32_t>* counterValuePtr = m_CounterIndex.at(counterUid);
259  ARMNN_ASSERT(counterValuePtr);
260  const uint32_t counterValue = counterValuePtr->load(std::memory_order::memory_order_relaxed);
261  SubtractCounterValue(counterUid, counterValue);
262  return counterValue;
263 }
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 294 of file ProfilingService.hpp.

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

◆ GetSendCounterPacket()

ISendCounterPacket& GetSendCounterPacket ( )
inlineoverridevirtual

Implements IProfilingService.

Reimplemented in MockProfilingService.

Definition at line 204 of file ProfilingService.hpp.

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

Referenced by BackendProfiling::ReportCounters().

205  {
206  return m_SendCounterPacket;
207  }

◆ GetSendTimelinePacket()

◆ GetStaticId()

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

◆ IncrementCounterValue()

uint32_t IncrementCounterValue ( uint16_t  counterUid)
overridevirtual

Implements IWriteCounterValues.

Definition at line 311 of file ProfilingService.cpp.

References ARMNN_ASSERT.

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

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

◆ IsCounterRegistered()

bool IsCounterRegistered ( uint16_t  counterUid) const
overridevirtual

Implements IReadCounterValues.

Definition at line 242 of file ProfilingService.cpp.

References CounterDirectory::IsCounterRegistered().

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

243 {
244  return m_CounterDirectory.IsCounterRegistered(counterUid);
245 }
bool IsCounterRegistered(uint16_t counterUid) const

◆ IsProfilingEnabled()

bool IsProfilingEnabled ( ) const
overridevirtual

Implements IProfilingService.

Reimplemented in MockProfilingService.

Definition at line 57 of file ProfilingService.cpp.

References IRuntime::CreationOptions::ExternalProfilingOptions::m_EnableProfiling.

Referenced by BackendProfiling::IsProfilingEnabled(), and ProfilingService::ProfilingService().

58 {
59  return m_Options.m_EnableProfiling;
60 }
bool m_EnableProfiling
Indicates whether external profiling is enabled or not.
Definition: IRuntime.hpp:169

◆ IsTimelineReportingEnabled()

bool IsTimelineReportingEnabled ( )
inline

◆ NextGuid()

ProfilingDynamicGuid NextGuid ( )
override

Return the next random Guid in the sequence.

Definition at line 319 of file ProfilingService.cpp.

References ProfilingService::GetNextGuid().

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

320 {
322 }
static ProfilingDynamicGuid GetNextGuid()

◆ NotifyBackendsForTimelineReporting()

void NotifyBackendsForTimelineReporting ( )
overridevirtual

Implements INotifyBackends.

Definition at line 495 of file ProfilingService.cpp.

Referenced by ProfilingService::ProfilingService().

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

◆ NotifyProfilingServiceActive()

void NotifyProfilingServiceActive ( )
overridevirtual

Implements IProfilingServiceStatus.

Definition at line 507 of file ProfilingService.cpp.

Referenced by ProfilingService::IsTimelineReportingEnabled().

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

◆ ResetExternalProfilingOptions()

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

Definition at line 41 of file ProfilingService.cpp.

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

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

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

◆ ResetGuidGenerator()

void ResetGuidGenerator ( )

Definition at line 36 of file ProfilingService.cpp.

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

37 {
38  m_GuidGenerator.Reset();
39 }

◆ SetCaptureData()

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

Definition at line 280 of file ProfilingService.cpp.

References Holder::SetCaptureData().

Referenced by ProfilingService::ProfilingService().

283 {
284  m_Holder.SetCaptureData(capturePeriod, counterIds, activeBackends);
285 }
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 287 of file ProfilingService.cpp.

References ARMNN_ASSERT.

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

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

◆ SubtractCounterValue()

uint32_t SubtractCounterValue ( uint16_t  counterUid,
uint32_t  value 
)
overridevirtual

Implements IWriteCounterValues.

Definition at line 303 of file ProfilingService.cpp.

References ARMNN_ASSERT.

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

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

◆ SwapProfilingConnectionFactory()

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

Definition at line 284 of file ProfilingService.hpp.

References ARMNN_ASSERT.

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

◆ TransitionToState()

void TransitionToState ( ProfilingService instance,
ProfilingState  newState 
)
inlineprotected

Definition at line 298 of file ProfilingService.hpp.

References ProfilingStateMachine::TransitionToState().

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

◆ Update()

void Update ( )

Definition at line 112 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 ProfilingService::ConfigureProfilingService(), ProfilingService::ProfilingService(), and TEST_SUITE().

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

◆ WaitForPacketSent()

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

Definition at line 302 of file ProfilingService.hpp.

References SendThread::WaitForPacketSent().

Referenced by SwapProfilingConnectionFactoryHelper::WaitForPacketsSent().

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

◆ WaitForProfilingServiceActivation()

void WaitForProfilingServiceActivation ( unsigned int  timeout)
overridevirtual

Implements IProfilingServiceStatus.

Definition at line 516 of file ProfilingService.cpp.

References ARMNN_LOG, and armnn::warning.

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

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

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