ArmNN
 21.02
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 538 of file ProfilingService.cpp.

Referenced by ProfilingService::ProfilingService().

539 {
540  Stop();
541 }

Member Function Documentation

◆ AddBackendProfilingContext()

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

Definition at line 212 of file ProfilingService.cpp.

References ARMNN_ASSERT.

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

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

◆ AddCounterValue()

uint32_t AddCounterValue ( uint16_t  counterUid,
uint32_t  value 
)
overridevirtual

Implements IWriteCounterValues.

Definition at line 293 of file ProfilingService.cpp.

References ARMNN_ASSERT.

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

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

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

◆ Disconnect()

void Disconnect ( )

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

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

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

References ProfilingService::GetStaticId().

Referenced by ProfilingService::ProfilingService().

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

◆ GetAbsoluteCounterValue()

uint32_t GetAbsoluteCounterValue ( uint16_t  counterUid) const
overridevirtual

Implements IReadCounterValues.

Definition at line 245 of file ProfilingService.cpp.

References ARMNN_ASSERT.

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

246 {
247  CheckCounterUid(counterUid);
248  std::atomic<uint32_t>* counterValuePtr = m_CounterIndex.at(counterUid);
249  ARMNN_ASSERT(counterValuePtr);
250  return counterValuePtr->load(std::memory_order::memory_order_relaxed);
251 }
#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 273 of file ProfilingService.cpp.

References Holder::GetCaptureData().

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

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

◆ GetCounterCount()

uint16_t GetCounterCount ( ) const
overridevirtual

Implements IReadCounterValues.

Definition at line 235 of file ProfilingService.cpp.

References CounterDirectory::GetCounterCount().

Referenced by ProfilingService::ProfilingService().

236 {
237  return m_CounterDirectory.GetCounterCount();
238 }
uint16_t GetCounterCount() const override

◆ GetCounterDirectory()

const ICounterDirectory & GetCounterDirectory ( ) const

Definition at line 220 of file ProfilingService.cpp.

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

221 {
222  return m_CounterDirectory;
223 }

◆ GetCounterMappingRegistry()

IRegisterCounterMapping & GetCounterMappingRegistry ( )

Definition at line 268 of file ProfilingService.cpp.

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

269 {
270  return m_CounterIdMap;
271 }

◆ GetCounterMappings()

const ICounterMappings & GetCounterMappings ( ) const
overridevirtual

◆ GetCounterRegistry()

ICounterRegistry & GetCounterRegistry ( )

Definition at line 225 of file ProfilingService.cpp.

Referenced by ProfilingService::ProfilingService().

226 {
227  return m_CounterDirectory;
228 }

◆ GetCurrentState()

ProfilingState GetCurrentState ( ) const

◆ GetDeltaCounterValue()

uint32_t GetDeltaCounterValue ( uint16_t  counterUid)
overridevirtual

Implements IReadCounterValues.

Definition at line 253 of file ProfilingService.cpp.

References ARMNN_ASSERT, and ProfilingService::SubtractCounterValue().

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

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

References ProfilingGuidGenerator::GenerateStaticId().

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

30 {
31  return m_GuidGenerator.GenerateStaticId(str);
32 }
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 309 of file ProfilingService.cpp.

References ARMNN_ASSERT.

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

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

◆ IsCounterRegistered()

bool IsCounterRegistered ( uint16_t  counterUid) const
overridevirtual

Implements IReadCounterValues.

Definition at line 240 of file ProfilingService.cpp.

References CounterDirectory::IsCounterRegistered().

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

241 {
242  return m_CounterDirectory.IsCounterRegistered(counterUid);
243 }
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 317 of file ProfilingService.cpp.

References ProfilingService::GetNextGuid().

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

318 {
320 }
static ProfilingDynamicGuid GetNextGuid()

◆ NotifyBackendsForTimelineReporting()

void NotifyBackendsForTimelineReporting ( )
overridevirtual

Implements INotifyBackends.

Definition at line 493 of file ProfilingService.cpp.

Referenced by ProfilingService::ProfilingService().

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

◆ NotifyProfilingServiceActive()

void NotifyProfilingServiceActive ( )
overridevirtual

Implements IProfilingServiceStatus.

Definition at line 505 of file ProfilingService.cpp.

Referenced by ProfilingService::IsTimelineReportingEnabled().

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

◆ ResetExternalProfilingOptions()

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

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

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

◆ ResetGuidGenerator()

void ResetGuidGenerator ( )

Definition at line 34 of file ProfilingService.cpp.

References ProfilingGuidGenerator::Reset().

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

35 {
36  m_GuidGenerator.Reset();
37 }
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 278 of file ProfilingService.cpp.

References Holder::SetCaptureData().

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

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

References ARMNN_ASSERT.

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

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

◆ SubtractCounterValue()

uint32_t SubtractCounterValue ( uint16_t  counterUid,
uint32_t  value 
)
overridevirtual

Implements IWriteCounterValues.

Definition at line 301 of file ProfilingService.cpp.

References ARMNN_ASSERT.

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

302 {
303  CheckCounterUid(counterUid);
304  std::atomic<uint32_t>* counterValuePtr = m_CounterIndex.at(counterUid);
305  ARMNN_ASSERT(counterValuePtr);
306  return counterValuePtr->fetch_sub(value, std::memory_order::memory_order_relaxed);
307 }
#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 110 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().

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

References ARMNN_LOG, and armnn::warning.

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

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

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