10 #include <common/include/SocketConnectionException.hpp> 12 #include <boost/format.hpp> 21 bool resetProfilingService)
27 if (resetProfilingService)
41 bool resetProfilingService)
110 m_CommandHandler.
Stop();
113 m_SendThread.
Stop(
false);
116 m_PeriodicCounterCapture.
Stop();
119 m_ProfilingConnection.reset();
124 BOOST_ASSERT(m_ProfilingConnectionFactory);
125 m_ProfilingConnection = m_ProfilingConnectionFactory->GetProfilingConnection(m_Options);
129 ARMNN_LOG(
warning) <<
"An error has occurred when creating the profiling connection: " 132 catch (
const armnnProfiling::SocketConnectionException& e)
134 ARMNN_LOG(
warning) <<
"An error has occurred when creating the profiling connection [" 135 << e.what() <<
"] on socket [" << e.GetSocketFd() <<
"].";
145 BOOST_ASSERT(m_ProfilingConnection);
148 m_CommandHandler.
Start(*m_ProfilingConnection);
152 m_SendThread.
Start(*m_ProfilingConnection);
165 throw RuntimeException(boost::str(boost::format(
"Unknown profiling service state: %1")
166 % static_cast<int>(currentState)));
173 switch (currentState)
185 throw RuntimeException(boost::str(boost::format(
"Unknown profiling service state: %1")
186 % static_cast<int>(currentState)));
192 std::shared_ptr<armnn::profiling::IBackendProfilingContext> profilingContext)
194 BOOST_ASSERT(profilingContext !=
nullptr);
196 m_MaxGlobalCounterId = profilingContext->RegisterCounters(m_MaxGlobalCounterId);
197 m_BackendProfilingContexts.emplace(backendId, std::move(profilingContext));
201 return m_CounterDirectory;
206 return m_CounterDirectory;
221 return counterUid < m_CounterIndex.size();
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);
234 return m_CounterIdMap;
239 return m_CounterIdMap;
248 const std::vector<uint16_t>& counterIds,
249 const std::set<BackendId>& activeBackends)
251 m_Holder.
SetCaptureData(capturePeriod, counterIds, activeBackends);
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);
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);
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);
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);
301 void ProfilingService::Initialize()
312 const Counter* loadedNetworksCounter =
314 armnn::profiling::NETWORK_LOADS,
320 "The number of networks loaded at runtime",
321 std::string(
"networks"));
322 BOOST_ASSERT(loadedNetworksCounter);
323 InitializeCounterValue(loadedNetworksCounter->
m_Uid);
328 const Counter* unloadedNetworksCounter =
330 armnn::profiling::NETWORK_UNLOADS,
336 "The number of networks unloaded at runtime",
337 std::string(
"networks"));
338 BOOST_ASSERT(unloadedNetworksCounter);
339 InitializeCounterValue(unloadedNetworksCounter->
m_Uid);
344 const Counter* registeredBackendsCounter =
346 armnn::profiling::REGISTERED_BACKENDS,
351 "Backends registered",
352 "The number of registered backends",
353 std::string(
"backends"));
354 BOOST_ASSERT(registeredBackendsCounter);
355 InitializeCounterValue(registeredBackendsCounter->
m_Uid);
360 const Counter* unregisteredBackendsCounter =
362 armnn::profiling::UNREGISTERED_BACKENDS,
367 "Backends unregistered",
368 "The number of unregistered backends",
369 std::string(
"backends"));
370 BOOST_ASSERT(unregisteredBackendsCounter);
371 InitializeCounterValue(unregisteredBackendsCounter->
m_Uid);
376 const Counter* inferencesRunCounter =
378 armnn::profiling::INFERENCES_RUN,
384 "The number of inferences run",
385 std::string(
"inferences"));
386 BOOST_ASSERT(inferencesRunCounter);
387 InitializeCounterValue(inferencesRunCounter->
m_Uid);
391 void ProfilingService::InitializeCounterValue(uint16_t counterUid)
394 if (counterUid >= m_CounterIndex.size())
396 m_CounterIndex.resize(boost::numeric_cast<size_t>(counterUid) + 1);
400 m_CounterValues.emplace_back(0);
403 std::atomic<uint32_t>* counterValuePtr = &(m_CounterValues.back());
404 m_CounterIndex.at(counterUid) = counterValuePtr;
407 void ProfilingService::Reset()
413 m_CounterIndex.clear();
414 m_CounterValues.clear();
415 m_CounterDirectory.
Clear();
416 m_CounterIdMap.
Reset();
417 m_BufferManager.
Reset();
420 m_StateMachine.
Reset();
421 m_BackendProfilingContexts.clear();
422 m_MaxGlobalCounterId = armnn::profiling::INFERENCES_RUN;
425 void ProfilingService::Stop()
430 m_CommandHandler.
Stop();
431 m_PeriodicCounterCapture.
Stop();
433 m_SendThread.
Stop(
false);
436 if (m_ProfilingConnection !=
nullptr && m_ProfilingConnection->IsOpen())
438 m_ProfilingConnection->Close();
440 m_ProfilingConnection.reset();
446 inline void ProfilingService::CheckCounterUid(uint16_t counterUid)
const bool IsCounterRegistered(uint16_t counterUid) const override
bool IsCategoryRegistered(const std::string &categoryName) const
ProfilingState GetCurrentState() const
const Category * RegisterCategory(const std::string &categoryName) override
const Counter * RegisterCounter(const BackendId &backendId, const uint16_t uid, const std::string &parentCategoryName, uint16_t counterClass, uint16_t interpolation, double multiplier, const std::string &name, const std::string &description, const Optional< std::string > &units=EmptyOptional(), const Optional< uint16_t > &numberOfCores=EmptyOptional(), const Optional< uint16_t > &deviceUid=EmptyOptional(), const Optional< uint16_t > &counterSetUid=EmptyOptional()) override
ProfilingState GetCurrentState() const
void Start(IProfilingConnection &profilingConnection)
ICounterRegistry & GetCounterRegistry()
uint32_t GetCounterValue(uint16_t counterUid) const override
Strongly typed guids to distinguish between those generated at runtime, and those that are statically...
virtual const char * what() const noexcept override
#define ARMNN_LOG(severity)
Copyright (c) 2020 ARM Limited.
ProfilingStaticGuid GenerateStaticId(const std::string &str) override
Create a ProfilingStaticGuid based on a hash of the string.
ProfilingDynamicGuid NextGuid() override
Return the next random Guid in the sequence.
uint32_t IncrementCounterValue(uint16_t counterUid) override
uint32_t SubtractCounterValue(uint16_t counterUid, uint32_t value) override
CaptureData GetCaptureData() const
void SetCaptureData(uint32_t capturePeriod, const std::vector< uint16_t > &counterIds, const std::set< BackendId > &activeBackends)
void SetCaptureData(uint32_t capturePeriod, const std::vector< uint16_t > &counterIds, const std::set< armnn::BackendId > &activeBackends)
std::unique_ptr< ISendTimelinePacket > GetSendTimelinePacket() const override
const ICounterMappings & GetCounterMappings() const override
void ResetExternalProfilingOptions(const ExternalProfilingOptions &options, bool resetProfilingService=false)
uint32_t AddCounterValue(uint16_t counterUid, uint32_t value) override
ProfilingDynamicGuid NextGuid() override
Return the next random Guid in the sequence.
IRegisterCounterMapping & GetCounterMappingRegistry()
void SetCounterValue(uint16_t counterUid, uint32_t value) override
CaptureData GetCaptureData() override
bool IsProfilingEnabled() const override
Base class for all ArmNN exceptions so that users can filter to just those.
bool IsCounterRegistered(uint16_t counterUid) const
uint16_t GetCounterCount() const override
void TransitionToState(ProfilingState newState)
void AddBackendProfilingContext(const BackendId backendId, std::shared_ptr< armnn::profiling::IBackendProfilingContext > profilingContext)
std::unique_ptr< ISendTimelinePacket > GetSendTimelinePacket() const
armnn::Runtime::CreationOptions::ExternalProfilingOptions options
const ICounterDirectory & GetCounterDirectory() const
ProfilingState ConfigureProfilingService(const ExternalProfilingOptions &options, bool resetProfilingService=false)
void Stop(bool rethrowSendThreadExceptions=true) override
Stop the thread.
uint16_t GetCounterCount() const override
void Start(IProfilingConnection &profilingConnection) override
Start the thread.
ProfilingStaticGuid GenerateStaticId(const std::string &str) override
Create a ProfilingStaticGuid based on a hash of the string.