blob: e42ef134dcc117ca3bb92d8f61b53520a2c36ed1 [file] [log] [blame]
Keith Davis02356de2019-08-26 18:28:17 +01001//
2// Copyright © 2017 Arm Ltd. All rights reserved.
3// SPDX-License-Identifier: MIT
4//
5
6#include "ProfilingService.hpp"
7
Keith Davise394bd92019-12-02 15:12:19 +00008#include <armnn/BackendId.hpp>
Derek Lamberti08446972019-11-26 16:38:31 +00009#include <armnn/Logging.hpp>
Sadik Armagana97a0be2020-03-03 10:44:56 +000010#include <common/include/SocketConnectionException.hpp>
Derek Lamberti08446972019-11-26 16:38:31 +000011
Matteo Martincigha84edee2019-10-02 12:50:57 +010012#include <boost/format.hpp>
13
Keith Davis02356de2019-08-26 18:28:17 +010014namespace armnn
15{
16
17namespace profiling
18{
19
Sadik Armagan3184c902020-03-18 10:57:30 +000020ProfilingGuidGenerator ProfilingService::m_GuidGenerator;
21
22ProfilingDynamicGuid ProfilingService::GetNextGuid()
23{
24 return m_GuidGenerator.NextGuid();
25}
26
27ProfilingStaticGuid ProfilingService::GetStaticId(const std::string& str)
28{
29 return m_GuidGenerator.GenerateStaticId(str);
30}
31
Matteo Martincigha84edee2019-10-02 12:50:57 +010032void ProfilingService::ResetExternalProfilingOptions(const ExternalProfilingOptions& options,
33 bool resetProfilingService)
Keith Davis02356de2019-08-26 18:28:17 +010034{
Matteo Martincigha84edee2019-10-02 12:50:57 +010035 // Update the profiling options
36 m_Options = options;
Keith Davis02356de2019-08-26 18:28:17 +010037
Matteo Martincigh54fb9572019-10-02 12:50:57 +010038 // Check if the profiling service needs to be reset
Matteo Martincigha84edee2019-10-02 12:50:57 +010039 if (resetProfilingService)
Keith Davis02356de2019-08-26 18:28:17 +010040 {
Matteo Martincigha84edee2019-10-02 12:50:57 +010041 // Reset the profiling service
Matteo Martincigh54fb9572019-10-02 12:50:57 +010042 Reset();
Keith Davis02356de2019-08-26 18:28:17 +010043 }
44}
45
Jim Flynn64063552020-02-14 10:18:08 +000046bool ProfilingService::IsProfilingEnabled() const
Keith Davise394bd92019-12-02 15:12:19 +000047{
48 return m_Options.m_EnableProfiling;
49}
50
Jim Flynn672d06e2019-10-15 10:18:11 +010051ProfilingState ProfilingService::ConfigureProfilingService(
52 const ExternalProfilingOptions& options,
53 bool resetProfilingService)
54{
55 ResetExternalProfilingOptions(options, resetProfilingService);
56 ProfilingState currentState = m_StateMachine.GetCurrentState();
57 if (options.m_EnableProfiling)
58 {
59 switch (currentState)
60 {
61 case ProfilingState::Uninitialised:
62 Update(); // should transition to NotConnected
63 Update(); // will either stay in NotConnected because there is no server
64 // or will enter WaitingForAck.
65 currentState = m_StateMachine.GetCurrentState();
66 if (currentState == ProfilingState::WaitingForAck)
67 {
68 Update(); // poke it again to send out the metadata packet
69 }
70 currentState = m_StateMachine.GetCurrentState();
71 return currentState;
72 case ProfilingState::NotConnected:
73 Update(); // will either stay in NotConnected because there is no server
74 // or will enter WaitingForAck
75 currentState = m_StateMachine.GetCurrentState();
76 if (currentState == ProfilingState::WaitingForAck)
77 {
78 Update(); // poke it again to send out the metadata packet
79 }
80 currentState = m_StateMachine.GetCurrentState();
81 return currentState;
82 default:
83 return currentState;
84 }
85 }
86 else
87 {
88 // Make sure profiling is shutdown
89 switch (currentState)
90 {
91 case ProfilingState::Uninitialised:
92 case ProfilingState::NotConnected:
93 return currentState;
94 default:
95 Stop();
96 return m_StateMachine.GetCurrentState();
97 }
98 }
99}
100
Matteo Martincigh54fb9572019-10-02 12:50:57 +0100101void ProfilingService::Update()
Keith Davis02356de2019-08-26 18:28:17 +0100102{
Matteo Martincigh54fb9572019-10-02 12:50:57 +0100103 if (!m_Options.m_EnableProfiling)
Matteo Martincigha84edee2019-10-02 12:50:57 +0100104 {
Matteo Martincigh54fb9572019-10-02 12:50:57 +0100105 // Don't run if profiling is disabled
106 return;
Matteo Martincigha84edee2019-10-02 12:50:57 +0100107 }
Matteo Martincigh54fb9572019-10-02 12:50:57 +0100108
109 ProfilingState currentState = m_StateMachine.GetCurrentState();
110 switch (currentState)
Keith Davis02356de2019-08-26 18:28:17 +0100111 {
Matteo Martincigh54fb9572019-10-02 12:50:57 +0100112 case ProfilingState::Uninitialised:
janeil01811ca552019-12-03 17:01:32 +0000113
Matteo Martincigh54fb9572019-10-02 12:50:57 +0100114 // Initialize the profiling service
115 Initialize();
116
117 // Move to the next state
118 m_StateMachine.TransitionToState(ProfilingState::NotConnected);
119 break;
120 case ProfilingState::NotConnected:
Matteo Martincighd0613b52019-10-09 16:47:04 +0100121 // Stop the command thread (if running)
122 m_CommandHandler.Stop();
123
124 // Stop the send thread (if running)
Sadik Armagan3896b472020-02-10 12:24:15 +0000125 m_SendThread.Stop(false);
Matteo Martincigh54fb9572019-10-02 12:50:57 +0100126
Matteo Martincighe8485382019-10-10 14:08:21 +0100127 // Stop the periodic counter capture thread (if running)
128 m_PeriodicCounterCapture.Stop();
129
Matteo Martincigh54fb9572019-10-02 12:50:57 +0100130 // Reset any existing profiling connection
131 m_ProfilingConnection.reset();
132
Sadik Armaganbd9e2c52019-09-26 23:13:31 +0100133 try
Keith Davis02356de2019-08-26 18:28:17 +0100134 {
Matteo Martincigh54fb9572019-10-02 12:50:57 +0100135 // Setup the profiling connection
Matteo Martincighd0613b52019-10-09 16:47:04 +0100136 BOOST_ASSERT(m_ProfilingConnectionFactory);
Matteo Martincigh54fb9572019-10-02 12:50:57 +0100137 m_ProfilingConnection = m_ProfilingConnectionFactory->GetProfilingConnection(m_Options);
Keith Davis02356de2019-08-26 18:28:17 +0100138 }
Matteo Martincigh54fb9572019-10-02 12:50:57 +0100139 catch (const Exception& e)
Sadik Armaganbd9e2c52019-09-26 23:13:31 +0100140 {
Derek Lamberti08446972019-11-26 16:38:31 +0000141 ARMNN_LOG(warning) << "An error has occurred when creating the profiling connection: "
142 << e.what();
Sadik Armaganbd9e2c52019-09-26 23:13:31 +0100143 }
Sadik Armagana97a0be2020-03-03 10:44:56 +0000144 catch (const armnnProfiling::SocketConnectionException& e)
145 {
146 ARMNN_LOG(warning) << "An error has occurred when creating the profiling connection ["
147 << e.what() << "] on socket [" << e.GetSocketFd() << "].";
148 }
Matteo Martincigh54fb9572019-10-02 12:50:57 +0100149
150 // Move to the next state
151 m_StateMachine.TransitionToState(m_ProfilingConnection
152 ? ProfilingState::WaitingForAck // Profiling connection obtained, wait for ack
153 : ProfilingState::NotConnected); // Profiling connection failed, stay in the
154 // "NotConnected" state
155 break;
156 case ProfilingState::WaitingForAck:
157 BOOST_ASSERT(m_ProfilingConnection);
158
159 // Start the command thread
160 m_CommandHandler.Start(*m_ProfilingConnection);
161
162 // Start the send thread, while in "WaitingForAck" state it'll send out a "Stream MetaData" packet waiting for
163 // a valid "Connection Acknowledged" packet confirming the connection
Sadik Armagan3896b472020-02-10 12:24:15 +0000164 m_SendThread.Start(*m_ProfilingConnection);
Matteo Martincigh54fb9572019-10-02 12:50:57 +0100165
166 // The connection acknowledged command handler will automatically transition the state to "Active" once a
167 // valid "Connection Acknowledged" packet has been received
168
169 break;
170 case ProfilingState::Active:
171
Matteo Martincighe8485382019-10-10 14:08:21 +0100172 // The period counter capture thread is started by the Periodic Counter Selection command handler upon
173 // request by an external profiling service
174
Matteo Martincigh54fb9572019-10-02 12:50:57 +0100175 break;
176 default:
177 throw RuntimeException(boost::str(boost::format("Unknown profiling service state: %1")
178 % static_cast<int>(currentState)));
Sadik Armaganbd9e2c52019-09-26 23:13:31 +0100179 }
Keith Davis02356de2019-08-26 18:28:17 +0100180}
181
Jim Flynn53e46992019-10-14 12:31:10 +0100182void ProfilingService::Disconnect()
183{
184 ProfilingState currentState = m_StateMachine.GetCurrentState();
185 switch (currentState)
186 {
187 case ProfilingState::Uninitialised:
188 case ProfilingState::NotConnected:
189 case ProfilingState::WaitingForAck:
190 return; // NOP
191 case ProfilingState::Active:
192 // Stop the command thread (if running)
193 Stop();
194
195 break;
196 default:
197 throw RuntimeException(boost::str(boost::format("Unknown profiling service state: %1")
198 % static_cast<int>(currentState)));
199 }
200}
201
David Monahanc1536d62020-02-12 15:52:35 +0000202// Store a profiling context returned from a backend that support profiling, and register its counters
203void ProfilingService::AddBackendProfilingContext(const BackendId backendId,
204 std::shared_ptr<armnn::profiling::IBackendProfilingContext> profilingContext)
205{
206 BOOST_ASSERT(profilingContext != nullptr);
207 // Register the backend counters
208 m_MaxGlobalCounterId = profilingContext->RegisterCounters(m_MaxGlobalCounterId);
209 m_BackendProfilingContexts.emplace(backendId, std::move(profilingContext));
210}
FinnWilliamsArmce2d9d12019-09-18 10:28:16 +0100211const ICounterDirectory& ProfilingService::GetCounterDirectory() const
212{
213 return m_CounterDirectory;
214}
215
Jim Flynn97897022020-02-02 12:52:59 +0000216ICounterRegistry& ProfilingService::GetCounterRegistry()
217{
218 return m_CounterDirectory;
219}
220
Matteo Martincigha84edee2019-10-02 12:50:57 +0100221ProfilingState ProfilingService::GetCurrentState() const
FinnWilliamsArmf6e534a2019-09-16 15:45:42 +0100222{
Matteo Martincigha84edee2019-10-02 12:50:57 +0100223 return m_StateMachine.GetCurrentState();
FinnWilliamsArmf6e534a2019-09-16 15:45:42 +0100224}
225
226uint16_t ProfilingService::GetCounterCount() const
227{
228 return m_CounterDirectory.GetCounterCount();
229}
230
Matteo Martincighe8485382019-10-10 14:08:21 +0100231bool ProfilingService::IsCounterRegistered(uint16_t counterUid) const
232{
233 return counterUid < m_CounterIndex.size();
234}
235
Matteo Martincigha84edee2019-10-02 12:50:57 +0100236uint32_t ProfilingService::GetCounterValue(uint16_t counterUid) const
Keith Davis02356de2019-08-26 18:28:17 +0100237{
Matteo Martincighe8485382019-10-10 14:08:21 +0100238 CheckCounterUid(counterUid);
Matteo Martincigha84edee2019-10-02 12:50:57 +0100239 std::atomic<uint32_t>* counterValuePtr = m_CounterIndex.at(counterUid);
240 BOOST_ASSERT(counterValuePtr);
241 return counterValuePtr->load(std::memory_order::memory_order_relaxed);
Keith Davis02356de2019-08-26 18:28:17 +0100242}
FinnWilliamsArmce2d9d12019-09-18 10:28:16 +0100243
Jim Flynn8e0c7a62020-01-30 14:10:55 +0000244const ICounterMappings& ProfilingService::GetCounterMappings() const
245{
246 return m_CounterIdMap;
247}
248
Jim Flynn97897022020-02-02 12:52:59 +0000249IRegisterCounterMapping& ProfilingService::GetCounterMappingRegistry()
Jim Flynn8e0c7a62020-01-30 14:10:55 +0000250{
251 return m_CounterIdMap;
252}
253
James Conroy2dcd3fe2020-02-06 18:34:52 +0000254CaptureData ProfilingService::GetCaptureData()
255{
256 return m_Holder.GetCaptureData();
257}
258
Finn Williams032bc742020-02-12 11:02:34 +0000259void ProfilingService::SetCaptureData(uint32_t capturePeriod,
260 const std::vector<uint16_t>& counterIds,
261 const std::set<BackendId>& activeBackends)
James Conroy2dcd3fe2020-02-06 18:34:52 +0000262{
Finn Williams032bc742020-02-12 11:02:34 +0000263 m_Holder.SetCaptureData(capturePeriod, counterIds, activeBackends);
James Conroy2dcd3fe2020-02-06 18:34:52 +0000264}
265
Matteo Martincigha84edee2019-10-02 12:50:57 +0100266void ProfilingService::SetCounterValue(uint16_t counterUid, uint32_t value)
FinnWilliamsArmce2d9d12019-09-18 10:28:16 +0100267{
Matteo Martincighe8485382019-10-10 14:08:21 +0100268 CheckCounterUid(counterUid);
Matteo Martincigha84edee2019-10-02 12:50:57 +0100269 std::atomic<uint32_t>* counterValuePtr = m_CounterIndex.at(counterUid);
270 BOOST_ASSERT(counterValuePtr);
271 counterValuePtr->store(value, std::memory_order::memory_order_relaxed);
272}
273
274uint32_t ProfilingService::AddCounterValue(uint16_t counterUid, uint32_t value)
275{
Matteo Martincighe8485382019-10-10 14:08:21 +0100276 CheckCounterUid(counterUid);
Matteo Martincigha84edee2019-10-02 12:50:57 +0100277 std::atomic<uint32_t>* counterValuePtr = m_CounterIndex.at(counterUid);
278 BOOST_ASSERT(counterValuePtr);
279 return counterValuePtr->fetch_add(value, std::memory_order::memory_order_relaxed);
280}
281
282uint32_t ProfilingService::SubtractCounterValue(uint16_t counterUid, uint32_t value)
283{
Matteo Martincighe8485382019-10-10 14:08:21 +0100284 CheckCounterUid(counterUid);
Matteo Martincigha84edee2019-10-02 12:50:57 +0100285 std::atomic<uint32_t>* counterValuePtr = m_CounterIndex.at(counterUid);
286 BOOST_ASSERT(counterValuePtr);
287 return counterValuePtr->fetch_sub(value, std::memory_order::memory_order_relaxed);
288}
289
290uint32_t ProfilingService::IncrementCounterValue(uint16_t counterUid)
291{
Matteo Martincighe8485382019-10-10 14:08:21 +0100292 CheckCounterUid(counterUid);
Matteo Martincigha84edee2019-10-02 12:50:57 +0100293 std::atomic<uint32_t>* counterValuePtr = m_CounterIndex.at(counterUid);
294 BOOST_ASSERT(counterValuePtr);
295 return counterValuePtr->operator++(std::memory_order::memory_order_relaxed);
296}
297
Jim Flynn00f3aaf2019-10-24 11:58:06 +0100298ProfilingDynamicGuid ProfilingService::NextGuid()
299{
Sadik Armagan3184c902020-03-18 10:57:30 +0000300 return ProfilingService::GetNextGuid();
Jim Flynn00f3aaf2019-10-24 11:58:06 +0100301}
302
303ProfilingStaticGuid ProfilingService::GenerateStaticId(const std::string& str)
304{
Sadik Armagan3184c902020-03-18 10:57:30 +0000305 return ProfilingService::GetStaticId(str);
Jim Flynn00f3aaf2019-10-24 11:58:06 +0100306}
307
Jim Flynn8b200652019-10-24 18:07:44 +0100308std::unique_ptr<ISendTimelinePacket> ProfilingService::GetSendTimelinePacket() const
309{
310 return m_TimelinePacketWriterFactory.GetSendTimelinePacket();
311}
312
Matteo Martincigha84edee2019-10-02 12:50:57 +0100313void ProfilingService::Initialize()
314{
Matteo Martincigha84edee2019-10-02 12:50:57 +0100315 // Register a category for the basic runtime counters
316 if (!m_CounterDirectory.IsCategoryRegistered("ArmNN_Runtime"))
317 {
318 m_CounterDirectory.RegisterCategory("ArmNN_Runtime");
319 }
320
Keith Davise394bd92019-12-02 15:12:19 +0000321 // Register a counter for the number of Network loads
322 if (!m_CounterDirectory.IsCounterRegistered("Network loads"))
Matteo Martincigha84edee2019-10-02 12:50:57 +0100323 {
324 const Counter* loadedNetworksCounter =
Keith Davise394bd92019-12-02 15:12:19 +0000325 m_CounterDirectory.RegisterCounter(armnn::profiling::BACKEND_ID,
326 armnn::profiling::NETWORK_LOADS,
327 "ArmNN_Runtime",
Matteo Martincigha84edee2019-10-02 12:50:57 +0100328 0,
329 0,
330 1.f,
Keith Davise394bd92019-12-02 15:12:19 +0000331 "Network loads",
Matteo Martincigha84edee2019-10-02 12:50:57 +0100332 "The number of networks loaded at runtime",
333 std::string("networks"));
334 BOOST_ASSERT(loadedNetworksCounter);
335 InitializeCounterValue(loadedNetworksCounter->m_Uid);
336 }
Keith Davise394bd92019-12-02 15:12:19 +0000337 // Register a counter for the number of unloaded networks
338 if (!m_CounterDirectory.IsCounterRegistered("Network unloads"))
Matteo Martincigha84edee2019-10-02 12:50:57 +0100339 {
Keith Davise394bd92019-12-02 15:12:19 +0000340 const Counter* unloadedNetworksCounter =
341 m_CounterDirectory.RegisterCounter(armnn::profiling::BACKEND_ID,
342 armnn::profiling::NETWORK_UNLOADS,
343 "ArmNN_Runtime",
Matteo Martincigha84edee2019-10-02 12:50:57 +0100344 0,
345 0,
346 1.f,
Keith Davise394bd92019-12-02 15:12:19 +0000347 "Network unloads",
348 "The number of networks unloaded at runtime",
349 std::string("networks"));
350 BOOST_ASSERT(unloadedNetworksCounter);
351 InitializeCounterValue(unloadedNetworksCounter->m_Uid);
352 }
353 // Register a counter for the number of registered backends
354 if (!m_CounterDirectory.IsCounterRegistered("Backends registered"))
355 {
356 const Counter* registeredBackendsCounter =
357 m_CounterDirectory.RegisterCounter(armnn::profiling::BACKEND_ID,
358 armnn::profiling::REGISTERED_BACKENDS,
359 "ArmNN_Runtime",
360 0,
361 0,
362 1.f,
363 "Backends registered",
Matteo Martincigha84edee2019-10-02 12:50:57 +0100364 "The number of registered backends",
365 std::string("backends"));
366 BOOST_ASSERT(registeredBackendsCounter);
367 InitializeCounterValue(registeredBackendsCounter->m_Uid);
368 }
Keith Davise394bd92019-12-02 15:12:19 +0000369 // Register a counter for the number of registered backends
370 if (!m_CounterDirectory.IsCounterRegistered("Backends unregistered"))
371 {
372 const Counter* unregisteredBackendsCounter =
373 m_CounterDirectory.RegisterCounter(armnn::profiling::BACKEND_ID,
374 armnn::profiling::UNREGISTERED_BACKENDS,
375 "ArmNN_Runtime",
376 0,
377 0,
378 1.f,
379 "Backends unregistered",
380 "The number of unregistered backends",
381 std::string("backends"));
382 BOOST_ASSERT(unregisteredBackendsCounter);
383 InitializeCounterValue(unregisteredBackendsCounter->m_Uid);
384 }
Matteo Martincigha84edee2019-10-02 12:50:57 +0100385 // Register a counter for the number of inferences run
386 if (!m_CounterDirectory.IsCounterRegistered("Inferences run"))
387 {
388 const Counter* inferencesRunCounter =
Keith Davise394bd92019-12-02 15:12:19 +0000389 m_CounterDirectory.RegisterCounter(armnn::profiling::BACKEND_ID,
390 armnn::profiling::INFERENCES_RUN,
391 "ArmNN_Runtime",
Matteo Martincigha84edee2019-10-02 12:50:57 +0100392 0,
393 0,
394 1.f,
395 "Inferences run",
396 "The number of inferences run",
397 std::string("inferences"));
398 BOOST_ASSERT(inferencesRunCounter);
399 InitializeCounterValue(inferencesRunCounter->m_Uid);
400 }
FinnWilliamsArmce2d9d12019-09-18 10:28:16 +0100401}
FinnWilliamsArmf6e534a2019-09-16 15:45:42 +0100402
Matteo Martincigha84edee2019-10-02 12:50:57 +0100403void ProfilingService::InitializeCounterValue(uint16_t counterUid)
FinnWilliamsArmf6e534a2019-09-16 15:45:42 +0100404{
Matteo Martincigha84edee2019-10-02 12:50:57 +0100405 // Increase the size of the counter index if necessary
406 if (counterUid >= m_CounterIndex.size())
FinnWilliamsArmf6e534a2019-09-16 15:45:42 +0100407 {
Matteo Martincigha84edee2019-10-02 12:50:57 +0100408 m_CounterIndex.resize(boost::numeric_cast<size_t>(counterUid) + 1);
FinnWilliamsArmf6e534a2019-09-16 15:45:42 +0100409 }
Matteo Martincigha84edee2019-10-02 12:50:57 +0100410
411 // Create a new atomic counter and add it to the list
412 m_CounterValues.emplace_back(0);
413
414 // Register the new counter to the counter index for quick access
415 std::atomic<uint32_t>* counterValuePtr = &(m_CounterValues.back());
416 m_CounterIndex.at(counterUid) = counterValuePtr;
FinnWilliamsArmf6e534a2019-09-16 15:45:42 +0100417}
418
Matteo Martincigh54fb9572019-10-02 12:50:57 +0100419void ProfilingService::Reset()
420{
Matteo Martincigh8d9590e2019-10-15 09:35:29 +0100421 // Stop the profiling service...
Jim Flynn53e46992019-10-14 12:31:10 +0100422 Stop();
Matteo Martincigh8d9590e2019-10-15 09:35:29 +0100423
Jim Flynn53e46992019-10-14 12:31:10 +0100424 // ...then delete all the counter data and configuration...
425 m_CounterIndex.clear();
426 m_CounterValues.clear();
427 m_CounterDirectory.Clear();
Jim Flynn97897022020-02-02 12:52:59 +0000428 m_CounterIdMap.Reset();
Finn Williams09ad6f92019-12-19 17:05:18 +0000429 m_BufferManager.Reset();
Matteo Martincighd0613b52019-10-09 16:47:04 +0100430
Jim Flynn53e46992019-10-14 12:31:10 +0100431 // ...finally reset the profiling state machine
432 m_StateMachine.Reset();
Colm Donelan1aff3932020-02-05 17:48:59 +0000433 m_BackendProfilingContexts.clear();
David Monahanc1536d62020-02-12 15:52:35 +0000434 m_MaxGlobalCounterId = armnn::profiling::INFERENCES_RUN;
Jim Flynn53e46992019-10-14 12:31:10 +0100435}
436
437void ProfilingService::Stop()
438{
Matteo Martincighd0613b52019-10-09 16:47:04 +0100439 // The order in which we reset/stop the components is not trivial!
Finn Williams09ad6f92019-12-19 17:05:18 +0000440 // First stop the producing threads
441 // Command Handler first as it is responsible for launching then Periodic Counter capture thread
Matteo Martincigh54fb9572019-10-02 12:50:57 +0100442 m_CommandHandler.Stop();
Matteo Martincighe8485382019-10-10 14:08:21 +0100443 m_PeriodicCounterCapture.Stop();
Finn Williams09ad6f92019-12-19 17:05:18 +0000444 // The the consuming thread
Sadik Armagan3896b472020-02-10 12:24:15 +0000445 m_SendThread.Stop(false);
Matteo Martincighd0613b52019-10-09 16:47:04 +0100446
Matteo Martincigh8d9590e2019-10-15 09:35:29 +0100447 // ...then close and destroy the profiling connection...
Jim Flynn53e46992019-10-14 12:31:10 +0100448 if (m_ProfilingConnection != nullptr && m_ProfilingConnection->IsOpen())
449 {
450 m_ProfilingConnection->Close();
451 }
Matteo Martincighd0613b52019-10-09 16:47:04 +0100452 m_ProfilingConnection.reset();
453
Matteo Martincigh8d9590e2019-10-15 09:35:29 +0100454 // ...then move to the "NotConnected" state
Jim Flynn53e46992019-10-14 12:31:10 +0100455 m_StateMachine.TransitionToState(ProfilingState::NotConnected);
Matteo Martincigh54fb9572019-10-02 12:50:57 +0100456}
457
Matteo Martincighe8485382019-10-10 14:08:21 +0100458inline void ProfilingService::CheckCounterUid(uint16_t counterUid) const
459{
460 if (!IsCounterRegistered(counterUid))
461 {
462 throw InvalidArgumentException(boost::str(boost::format("Counter UID %1% is not registered") % counterUid));
463 }
464}
465
janeil01811ca552019-12-03 17:01:32 +0000466ProfilingService::~ProfilingService()
467{
468 Stop();
469}
470
Keith Davis02356de2019-08-26 18:28:17 +0100471} // namespace profiling
472
Matteo Martincigha84edee2019-10-02 12:50:57 +0100473} // namespace armnn