ArmNN
 20.02
ProfilingService Class Reference

#include <ProfilingService.hpp>

Inheritance diagram for ProfilingService:
IReadWriteCounterValues IProfilingService IReadCounterValues IWriteCounterValues IProfilingGuidGenerator 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 > >
 

Public Member Functions

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)
 
const ICounterDirectoryGetCounterDirectory () const
 
ICounterRegistryGetCounterRegistry ()
 
ProfilingState GetCurrentState () const
 
bool IsCounterRegistered (uint16_t counterUid) const override
 
uint32_t GetCounterValue (uint16_t counterUid) const 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 IsEnabled ()
 Check if the profiling is enabled. More...
 
- 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 ()
 

Static Public Member Functions

static ProfilingServiceInstance ()
 

Protected Member Functions

 ProfilingService ()
 
 ~ProfilingService ()
 
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 42 of file ProfilingService.hpp.

Member Typedef Documentation

◆ CounterIndices

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

Definition at line 48 of file ProfilingService.hpp.

◆ CounterValues

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

Definition at line 49 of file ProfilingService.hpp.

◆ ExternalProfilingOptions

◆ IProfilingConnectionFactoryPtr

Definition at line 46 of file ProfilingService.hpp.

◆ IProfilingConnectionPtr

Definition at line 47 of file ProfilingService.hpp.

Constructor & Destructor Documentation

◆ ProfilingService()

ProfilingService ( )
inlineprotected

Definition at line 160 of file ProfilingService.hpp.

References CommandHandlerRegistry::RegisterFunctor(), and ProfilingService::~ProfilingService().

Referenced by ProfilingService::IsEnabled().

161  : m_Options()
162  , m_CounterDirectory()
163  , m_ProfilingConnectionFactory(new ProfilingConnectionFactory())
164  , m_ProfilingConnection()
165  , m_StateMachine()
166  , m_CounterIndex()
167  , m_CounterValues()
168  , m_CommandHandlerRegistry()
169  , m_PacketVersionResolver()
170  , m_CommandHandler(1000,
171  false,
172  m_CommandHandlerRegistry,
173  m_PacketVersionResolver)
174  , m_BufferManager()
175  , m_SendCounterPacket(m_BufferManager)
176  , m_SendThread(m_StateMachine, m_BufferManager, m_SendCounterPacket)
177  , m_SendTimelinePacket(m_BufferManager)
178  , m_PeriodicCounterCapture(m_Holder, m_SendCounterPacket, *this, m_CounterIdMap, m_BackendProfilingContexts)
179  , m_ConnectionAcknowledgedCommandHandler(0,
180  1,
181  m_PacketVersionResolver.ResolvePacketVersion(0, 1).GetEncodedValue(),
182  m_CounterDirectory,
183  m_SendCounterPacket,
184  m_SendTimelinePacket,
185  m_StateMachine)
186  , m_RequestCounterDirectoryCommandHandler(0,
187  3,
188  m_PacketVersionResolver.ResolvePacketVersion(0, 3).GetEncodedValue(),
189  m_CounterDirectory,
190  m_SendCounterPacket,
191  m_SendTimelinePacket,
192  m_StateMachine)
193  , m_PeriodicCounterSelectionCommandHandler(0,
194  4,
195  m_PacketVersionResolver.ResolvePacketVersion(0, 4).GetEncodedValue(),
196  m_BackendProfilingContexts,
197  m_CounterIdMap,
198  m_Holder,
199  MAX_ARMNN_COUNTER,
200  m_PeriodicCounterCapture,
201  *this,
202  m_SendCounterPacket,
203  m_StateMachine)
204  , m_PerJobCounterSelectionCommandHandler(0,
205  5,
206  m_PacketVersionResolver.ResolvePacketVersion(0, 5).GetEncodedValue(),
207  m_StateMachine)
208  , m_TimelinePacketWriterFactory(m_BufferManager)
209  , m_MaxGlobalCounterId(armnn::profiling::INFERENCES_RUN)
210  {
211  // Register the "Connection Acknowledged" command handler
212  m_CommandHandlerRegistry.RegisterFunctor(&m_ConnectionAcknowledgedCommandHandler);
213 
214  // Register the "Request Counter Directory" command handler
215  m_CommandHandlerRegistry.RegisterFunctor(&m_RequestCounterDirectoryCommandHandler);
216 
217  // Register the "Periodic Counter Selection" command handler
218  m_CommandHandlerRegistry.RegisterFunctor(&m_PeriodicCounterSelectionCommandHandler);
219 
220  // Register the "Per-Job Counter Selection" command handler
221  m_CommandHandlerRegistry.RegisterFunctor(&m_PerJobCounterSelectionCommandHandler);
222  }
Version ResolvePacketVersion(uint32_t familyId, uint32_t packetId) const
void RegisterFunctor(CommandHandlerFunctor *functor, uint32_t familyId, uint32_t packetId, uint32_t version)

◆ ~ProfilingService()

~ProfilingService ( )
protected

Definition at line 454 of file ProfilingService.cpp.

Referenced by ProfilingService::ProfilingService().

455 {
456  Stop();
457 }

Member Function Documentation

◆ AddBackendProfilingContext()

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

Definition at line 191 of file ProfilingService.cpp.

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

193 {
194  BOOST_ASSERT(profilingContext != nullptr);
195  // Register the backend counters
196  m_MaxGlobalCounterId = profilingContext->RegisterCounters(m_MaxGlobalCounterId);
197  m_BackendProfilingContexts.emplace(backendId, std::move(profilingContext));
198 }

◆ AddCounterValue()

uint32_t AddCounterValue ( uint16_t  counterUid,
uint32_t  value 
)
overridevirtual

Implements IWriteCounterValues.

Definition at line 262 of file ProfilingService.cpp.

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

263 {
264  CheckCounterUid(counterUid);
265  std::atomic<uint32_t>* counterValuePtr = m_CounterIndex.at(counterUid);
266  BOOST_ASSERT(counterValuePtr);
267  return counterValuePtr->fetch_add(value, std::memory_order::memory_order_relaxed);
268 }

◆ ConfigureProfilingService()

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

Definition at line 39 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::Instance(), Runtime::Runtime(), and VerifyPostOptimisationStructureTestImpl().

42 {
43  ResetExternalProfilingOptions(options, resetProfilingService);
44  ProfilingState currentState = m_StateMachine.GetCurrentState();
45  if (options.m_EnableProfiling)
46  {
47  switch (currentState)
48  {
50  Update(); // should transition to NotConnected
51  Update(); // will either stay in NotConnected because there is no server
52  // or will enter WaitingForAck.
53  currentState = m_StateMachine.GetCurrentState();
54  if (currentState == ProfilingState::WaitingForAck)
55  {
56  Update(); // poke it again to send out the metadata packet
57  }
58  currentState = m_StateMachine.GetCurrentState();
59  return currentState;
61  Update(); // will either stay in NotConnected because there is no server
62  // or will enter WaitingForAck
63  currentState = m_StateMachine.GetCurrentState();
64  if (currentState == ProfilingState::WaitingForAck)
65  {
66  Update(); // poke it again to send out the metadata packet
67  }
68  currentState = m_StateMachine.GetCurrentState();
69  return currentState;
70  default:
71  return currentState;
72  }
73  }
74  else
75  {
76  // Make sure profiling is shutdown
77  switch (currentState)
78  {
81  return currentState;
82  default:
83  Stop();
84  return m_StateMachine.GetCurrentState();
85  }
86  }
87 }
void ResetExternalProfilingOptions(const ExternalProfilingOptions &options, bool resetProfilingService=false)
armnn::Runtime::CreationOptions::ExternalProfilingOptions options

◆ Disconnect()

void Disconnect ( )

Definition at line 170 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::Instance().

171 {
172  ProfilingState currentState = m_StateMachine.GetCurrentState();
173  switch (currentState)
174  {
178  return; // NOP
180  // Stop the command thread (if running)
181  Stop();
182 
183  break;
184  default:
185  throw RuntimeException(boost::str(boost::format("Unknown profiling service state: %1")
186  % static_cast<int>(currentState)));
187  }
188 }

◆ GenerateStaticId()

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

Create a ProfilingStaticGuid based on a hash of the string.

Implements IProfilingGuidGenerator.

Definition at line 291 of file ProfilingService.cpp.

References ProfilingGuidGenerator::GenerateStaticId().

Referenced by BOOST_AUTO_TEST_CASE(), TimelineUtilityMethods::DeclareLabel(), and ProfilingService::Instance().

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

◆ GetBufferManager()

BufferManager& GetBufferManager ( ProfilingService instance)
inlineprotected

Definition at line 249 of file ProfilingService.hpp.

250  {
251  return instance.m_BufferManager;
252  }

◆ GetCaptureData()

CaptureData GetCaptureData ( )
overridevirtual

Implements IProfilingService.

Definition at line 242 of file ProfilingService.cpp.

References Holder::GetCaptureData().

Referenced by ProfilingService::Instance().

243 {
244  return m_Holder.GetCaptureData();
245 }
CaptureData GetCaptureData() const
Definition: Holder.cpp:54

◆ GetCounterCount()

uint16_t GetCounterCount ( ) const
overridevirtual

Implements IReadCounterValues.

Definition at line 214 of file ProfilingService.cpp.

References CounterDirectory::GetCounterCount().

Referenced by ProfilingService::Instance().

215 {
216  return m_CounterDirectory.GetCounterCount();
217 }
uint16_t GetCounterCount() const override

◆ GetCounterDirectory()

const ICounterDirectory & GetCounterDirectory ( ) const

Definition at line 199 of file ProfilingService.cpp.

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

200 {
201  return m_CounterDirectory;
202 }

◆ GetCounterMappingRegistry()

IRegisterCounterMapping & GetCounterMappingRegistry ( )

Definition at line 237 of file ProfilingService.cpp.

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

238 {
239  return m_CounterIdMap;
240 }

◆ GetCounterMappings()

const ICounterMappings & GetCounterMappings ( ) const
overridevirtual

Implements IProfilingService.

Definition at line 232 of file ProfilingService.cpp.

Referenced by BOOST_AUTO_TEST_CASE(), BackendProfiling::GetActiveCounters(), and ProfilingService::Instance().

233 {
234  return m_CounterIdMap;
235 }

◆ GetCounterRegistry()

ICounterRegistry & GetCounterRegistry ( )

Definition at line 204 of file ProfilingService.cpp.

Referenced by ProfilingService::Instance().

205 {
206  return m_CounterDirectory;
207 }

◆ GetCounterValue()

uint32_t GetCounterValue ( uint16_t  counterUid) const
overridevirtual

Implements IReadCounterValues.

Definition at line 224 of file ProfilingService.cpp.

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

225 {
226  CheckCounterUid(counterUid);
227  std::atomic<uint32_t>* counterValuePtr = m_CounterIndex.at(counterUid);
228  BOOST_ASSERT(counterValuePtr);
229  return counterValuePtr->load(std::memory_order::memory_order_relaxed);
230 }

◆ GetCurrentState()

ProfilingState GetCurrentState ( ) const

Definition at line 209 of file ProfilingService.cpp.

References ProfilingStateMachine::GetCurrentState().

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

210 {
211  return m_StateMachine.GetCurrentState();
212 }

◆ GetProfilingConnection()

IProfilingConnection* GetProfilingConnection ( ProfilingService instance)
inlineprotected

Definition at line 236 of file ProfilingService.hpp.

237  {
238  return instance.m_ProfilingConnection.get();
239  }

◆ GetSendCounterPacket()

ISendCounterPacket& GetSendCounterPacket ( )
inlineoverridevirtual

Implements IProfilingService.

Definition at line 106 of file ProfilingService.hpp.

107  {
108  return m_SendCounterPacket;
109  }

◆ GetSendTimelinePacket()

◆ IncrementCounterValue()

uint32_t IncrementCounterValue ( uint16_t  counterUid)
overridevirtual

Implements IWriteCounterValues.

Definition at line 278 of file ProfilingService.cpp.

Referenced by BOOST_AUTO_TEST_CASE(), BackendRegistry::Deregister(), LoadedNetwork::EnqueueWorkload(), ProfilingService::Instance(), Runtime::LoadNetwork(), BackendRegistry::Register(), Runtime::UnloadNetwork(), and while().

279 {
280  CheckCounterUid(counterUid);
281  std::atomic<uint32_t>* counterValuePtr = m_CounterIndex.at(counterUid);
282  BOOST_ASSERT(counterValuePtr);
283  return counterValuePtr->operator++(std::memory_order::memory_order_relaxed);
284 }

◆ Instance()

static ProfilingService& Instance ( )
inlinestatic

Definition at line 52 of file ProfilingService.hpp.

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

Referenced by BOOST_AUTO_TEST_CASE(), TimelineUtilityMethods::CreateConnectionRelationship(), TimelineUtilityMethods::CreateNamedTypedChildEntity(), TimelineUtilityMethods::CreateNamedTypedEntity(), TimelineUtilityMethods::CreateRelationship(), TimelineUtilityMethods::DeclareLabel(), BackendRegistry::Deregister(), LoadedNetwork::EnqueueWorkload(), SwapProfilingConnectionFactoryHelper::ForceTransitionToState(), BackendProfiling::GetActiveCounters(), SwapProfilingConnectionFactoryHelper::GetMockProfilingConnection(), ProfilingServiceRuntimeHelper::GetProfilingBufferManager(), TimelineUtilityMethods::GetTimelineUtils(), Runtime::LoadNetwork(), TimelineUtilityMethods::MarkEntityWithLabel(), TimelineUtilityMethods::MarkEntityWithType(), TimelineUtilityMethods::RecordEvent(), TimelineUtilityMethods::RecordWorkloadInferenceAndStartOfLifeEvent(), BackendRegistry::Register(), RegisterBackendCounters::RegisterCounter(), Runtime::Runtime(), SwapProfilingConnectionFactoryHelper::SwapProfilingConnectionFactoryHelper(), Runtime::UnloadNetwork(), VerifyPostOptimisationStructureTestImpl(), SwapProfilingConnectionFactoryHelper::WaitForPacketsSent(), and SwapProfilingConnectionFactoryHelper::~SwapProfilingConnectionFactoryHelper().

53  {
54  static ProfilingService instance;
55  return instance;
56  }

◆ IsCounterRegistered()

bool IsCounterRegistered ( uint16_t  counterUid) const
overridevirtual

Implements IReadCounterValues.

Definition at line 219 of file ProfilingService.cpp.

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

220 {
221  return counterUid < m_CounterIndex.size();
222 }

◆ IsEnabled()

bool IsEnabled ( )
inline

◆ IsProfilingEnabled()

bool IsProfilingEnabled ( ) const
overridevirtual

◆ NextGuid()

◆ ResetExternalProfilingOptions()

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

Definition at line 20 of file ProfilingService.cpp.

References options.

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

22 {
23  // Update the profiling options
24  m_Options = options;
25 
26  // Check if the profiling service needs to be reset
27  if (resetProfilingService)
28  {
29  // Reset the profiling service
30  Reset();
31  }
32 }
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 247 of file ProfilingService.cpp.

References Holder::SetCaptureData().

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

250 {
251  m_Holder.SetCaptureData(capturePeriod, counterIds, activeBackends);
252 }
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 254 of file ProfilingService.cpp.

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

255 {
256  CheckCounterUid(counterUid);
257  std::atomic<uint32_t>* counterValuePtr = m_CounterIndex.at(counterUid);
258  BOOST_ASSERT(counterValuePtr);
259  counterValuePtr->store(value, std::memory_order::memory_order_relaxed);
260 }

◆ SubtractCounterValue()

uint32_t SubtractCounterValue ( uint16_t  counterUid,
uint32_t  value 
)
overridevirtual

Implements IWriteCounterValues.

Definition at line 270 of file ProfilingService.cpp.

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

271 {
272  CheckCounterUid(counterUid);
273  std::atomic<uint32_t>* counterValuePtr = m_CounterIndex.at(counterUid);
274  BOOST_ASSERT(counterValuePtr);
275  return counterValuePtr->fetch_sub(value, std::memory_order::memory_order_relaxed);
276 }

◆ SwapProfilingConnectionFactory()

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

Definition at line 226 of file ProfilingService.hpp.

229  {
230  BOOST_ASSERT(instance.m_ProfilingConnectionFactory);
231  BOOST_ASSERT(other);
232 
233  backup = instance.m_ProfilingConnectionFactory.release();
234  instance.m_ProfilingConnectionFactory.reset(other);
235  }

◆ TransitionToState()

void TransitionToState ( ProfilingService instance,
ProfilingState  newState 
)
inlineprotected

Definition at line 240 of file ProfilingService.hpp.

References ProfilingStateMachine::TransitionToState().

241  {
242  instance.m_StateMachine.TransitionToState(newState);
243  }

◆ Update()

void Update ( )

Definition at line 89 of file ProfilingService.cpp.

References armnn::profiling::Active, 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::Instance().

90 {
91  if (!m_Options.m_EnableProfiling)
92  {
93  // Don't run if profiling is disabled
94  return;
95  }
96 
97  ProfilingState currentState = m_StateMachine.GetCurrentState();
98  switch (currentState)
99  {
101 
102  // Initialize the profiling service
103  Initialize();
104 
105  // Move to the next state
107  break;
109  // Stop the command thread (if running)
110  m_CommandHandler.Stop();
111 
112  // Stop the send thread (if running)
113  m_SendThread.Stop(false);
114 
115  // Stop the periodic counter capture thread (if running)
116  m_PeriodicCounterCapture.Stop();
117 
118  // Reset any existing profiling connection
119  m_ProfilingConnection.reset();
120 
121  try
122  {
123  // Setup the profiling connection
124  BOOST_ASSERT(m_ProfilingConnectionFactory);
125  m_ProfilingConnection = m_ProfilingConnectionFactory->GetProfilingConnection(m_Options);
126  }
127  catch (const Exception& e)
128  {
129  ARMNN_LOG(warning) << "An error has occurred when creating the profiling connection: "
130  << e.what();
131  }
132  catch (const armnnProfiling::SocketConnectionException& e)
133  {
134  ARMNN_LOG(warning) << "An error has occurred when creating the profiling connection ["
135  << e.what() << "] on socket [" << e.GetSocketFd() << "].";
136  }
137 
138  // Move to the next state
139  m_StateMachine.TransitionToState(m_ProfilingConnection
140  ? ProfilingState::WaitingForAck // Profiling connection obtained, wait for ack
141  : ProfilingState::NotConnected); // Profiling connection failed, stay in the
142  // "NotConnected" state
143  break;
145  BOOST_ASSERT(m_ProfilingConnection);
146 
147  // Start the command thread
148  m_CommandHandler.Start(*m_ProfilingConnection);
149 
150  // Start the send thread, while in "WaitingForAck" state it'll send out a "Stream MetaData" packet waiting for
151  // a valid "Connection Acknowledged" packet confirming the connection
152  m_SendThread.Start(*m_ProfilingConnection);
153 
154  // The connection acknowledged command handler will automatically transition the state to "Active" once a
155  // valid "Connection Acknowledged" packet has been received
156 
157  break;
159 
160  // The period counter capture thread is started by the Periodic Counter Selection command handler upon
161  // request by an external profiling service
162 
163  break;
164  default:
165  throw RuntimeException(boost::str(boost::format("Unknown profiling service state: %1")
166  % static_cast<int>(currentState)));
167  }
168 }
void Start(IProfilingConnection &profilingConnection)
#define ARMNN_LOG(severity)
Definition: Logging.hpp:163
bool Initialize()
Performs any required one-time setup.
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 244 of file ProfilingService.hpp.

References SendThread::WaitForPacketSent().

Referenced by SwapProfilingConnectionFactoryHelper::WaitForPacketsSent().

245  {
246  return instance.m_SendThread.WaitForPacketSent(timeout);
247  }

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