blob: 377ca22cf5fe1dd71e7acf90a71b0a71442efc82 [file] [log] [blame]
David Monahanc1536d62020-02-12 15:52:35 +00001//
Jim Flynnbbfe6032020-07-20 16:57:44 +01002// Copyright © 2020 Arm Ltd and Contributors. All rights reserved.
David Monahanc1536d62020-02-12 15:52:35 +00003// SPDX-License-Identifier: MIT
4//
5
Finn Williams032bc742020-02-12 11:02:34 +00006#include "CounterDirectory.hpp"
7#include "CounterIdMap.hpp"
8#include "Holder.hpp"
David Monahanc1536d62020-02-12 15:52:35 +00009#include "MockBackend.hpp"
10#include "MockBackendId.hpp"
Finn Williams032bc742020-02-12 11:02:34 +000011#include "PeriodicCounterCapture.hpp"
12#include "PeriodicCounterSelectionCommandHandler.hpp"
13#include "ProfilingStateMachine.hpp"
14#include "ProfilingUtils.hpp"
15#include "RequestCounterDirectoryCommandHandler.hpp"
David Monahanc1536d62020-02-12 15:52:35 +000016
Sadik Armaganea41b572020-03-19 18:16:46 +000017#include <test/TestUtils.hpp>
Sadik Armagan3184c902020-03-18 10:57:30 +000018
Jan Eilers8eb25602020-03-09 12:13:48 +000019#include <armnn/utility/IgnoreUnused.hpp>
David Monahanc1536d62020-02-12 15:52:35 +000020#include <armnn/BackendId.hpp>
Finn Williams032bc742020-02-12 11:02:34 +000021#include <armnn/Logging.hpp>
Colm Donelanfcb802b2020-02-13 20:47:08 +000022#include <armnn/profiling/ISendTimelinePacket.hpp>
Finn Williams032bc742020-02-12 11:02:34 +000023
David Monahanc1536d62020-02-12 15:52:35 +000024#include <boost/test/unit_test.hpp>
25#include <vector>
26
Finn Williams032bc742020-02-12 11:02:34 +000027#include <cstdint>
28#include <limits>
29#include <backends/BackendProfiling.hpp>
30
31using namespace armnn::profiling;
32
33class ReadCounterVals : public IReadCounterValues
34{
35 virtual bool IsCounterRegistered(uint16_t counterUid) const override
36 {
37 return (counterUid > 4 && counterUid < 11);
38 }
39 virtual uint16_t GetCounterCount() const override
40 {
41 return 1;
42 }
Finn Williamsf3fcf322020-05-11 14:38:02 +010043 virtual uint32_t GetAbsoluteCounterValue(uint16_t counterUid) const override
44 {
45 return counterUid;
46 }
47 virtual uint32_t GetDeltaCounterValue(uint16_t counterUid) override
Finn Williams032bc742020-02-12 11:02:34 +000048 {
49 return counterUid;
50 }
51};
52
53class MockBackendSendCounterPacket : public ISendCounterPacket
54{
55public:
56 using IndexValuePairsVector = std::vector<CounterValue>;
57
58 /// Create and write a StreamMetaDataPacket in the buffer
59 virtual void SendStreamMetaDataPacket() {}
60
61 /// Create and write a CounterDirectoryPacket from the parameters to the buffer.
62 virtual void SendCounterDirectoryPacket(const ICounterDirectory& counterDirectory)
63 {
Jan Eilers8eb25602020-03-09 12:13:48 +000064 armnn::IgnoreUnused(counterDirectory);
Finn Williams032bc742020-02-12 11:02:34 +000065 }
66
67 /// Create and write a PeriodicCounterCapturePacket from the parameters to the buffer.
68 virtual void SendPeriodicCounterCapturePacket(uint64_t timestamp, const IndexValuePairsVector& values)
69 {
70 m_timestamps.emplace_back(Timestamp{timestamp, values});
71 }
72
73 /// Create and write a PeriodicCounterSelectionPacket from the parameters to the buffer.
74 virtual void SendPeriodicCounterSelectionPacket(uint32_t capturePeriod,
75 const std::vector<uint16_t>& selectedCounterIds)
76 {
Jan Eilers8eb25602020-03-09 12:13:48 +000077 armnn::IgnoreUnused(capturePeriod);
78 armnn::IgnoreUnused(selectedCounterIds);
Finn Williams032bc742020-02-12 11:02:34 +000079 }
80
81 std::vector<Timestamp> GetTimestamps()
82 {
83 return m_timestamps;
84 }
85
86 void ClearTimestamps()
87 {
88 m_timestamps.clear();
89 }
90
91private:
92 std::vector<Timestamp> m_timestamps;
93};
94
Jim Flynnbbfe6032020-07-20 16:57:44 +010095arm::pipe::Packet PacketWriter(uint32_t period, std::vector<uint16_t> countervalues)
Finn Williams032bc742020-02-12 11:02:34 +000096{
97 const uint32_t packetId = 0x40000;
98 uint32_t offset = 0;
99 uint32_t dataLength = static_cast<uint32_t>(4 + countervalues.size() * 2);
100 std::unique_ptr<unsigned char[]> uniqueData = std::make_unique<unsigned char[]>(dataLength);
101 unsigned char* data1 = reinterpret_cast<unsigned char*>(uniqueData.get());
102
103 WriteUint32(data1, offset, period);
104 offset += 4;
105 for (auto countervalue : countervalues)
106 {
107 WriteUint16(data1, offset, countervalue);
108 offset += 2;
109 }
110
111 return {packetId, dataLength, uniqueData};
112}
113
David Monahanc1536d62020-02-12 15:52:35 +0000114BOOST_AUTO_TEST_SUITE(BackendProfilingTestSuite)
115
116BOOST_AUTO_TEST_CASE(BackendProfilingCounterRegisterMockBackendTest)
117{
118 // Reset the profiling service to the uninitialized state
119 armnn::IRuntime::CreationOptions options;
Finn Williams45a73622020-05-15 18:41:05 +0100120 options.m_ProfilingOptions.m_EnableProfiling = true;
David Monahanc1536d62020-02-12 15:52:35 +0000121
122 armnn::MockBackendInitialiser initialiser;
123 // Create a runtime
Sadik Armagan3184c902020-03-18 10:57:30 +0000124 armnn::Runtime runtime(options);
David Monahanc1536d62020-02-12 15:52:35 +0000125
126 // Check if the MockBackends 3 dummy counters {0, 1, 2-5 (four cores)} are registered
127 armnn::BackendId mockId = armnn::MockBackendId();
Sadik Armagan3184c902020-03-18 10:57:30 +0000128 const armnn::profiling::ICounterMappings& counterMap = GetProfilingService(&runtime).GetCounterMappings();
David Monahanc1536d62020-02-12 15:52:35 +0000129 BOOST_CHECK(counterMap.GetGlobalId(0, mockId) == 5);
130 BOOST_CHECK(counterMap.GetGlobalId(1, mockId) == 6);
131 BOOST_CHECK(counterMap.GetGlobalId(2, mockId) == 7);
132 BOOST_CHECK(counterMap.GetGlobalId(3, mockId) == 8);
133 BOOST_CHECK(counterMap.GetGlobalId(4, mockId) == 9);
134 BOOST_CHECK(counterMap.GetGlobalId(5, mockId) == 10);
135 options.m_ProfilingOptions.m_EnableProfiling = false;
Sadik Armagan3184c902020-03-18 10:57:30 +0000136 GetProfilingService(&runtime).ResetExternalProfilingOptions(options.m_ProfilingOptions, true);
David Monahanc1536d62020-02-12 15:52:35 +0000137}
138
Finn Williams032bc742020-02-12 11:02:34 +0000139BOOST_AUTO_TEST_CASE(TestBackendCounters)
140{
141 Holder holder;
Jim Flynnbbfe6032020-07-20 16:57:44 +0100142 arm::pipe::PacketVersionResolver packetVersionResolver;
Finn Williams032bc742020-02-12 11:02:34 +0000143 ProfilingStateMachine stateMachine;
144 ReadCounterVals readCounterVals;
145 CounterIdMap counterIdMap;
146 MockBackendSendCounterPacket sendCounterPacket;
147
148 const armnn::BackendId cpuAccId(armnn::Compute::CpuAcc);
149 const armnn::BackendId gpuAccId(armnn::Compute::GpuAcc);
150
151 armnn::IRuntime::CreationOptions options;
152 options.m_ProfilingOptions.m_EnableProfiling = true;
153
Sadik Armagan3184c902020-03-18 10:57:30 +0000154 armnn::profiling::ProfilingService profilingService;
Finn Williams032bc742020-02-12 11:02:34 +0000155
156 std::unique_ptr<armnn::profiling::IBackendProfiling> cpuBackendProfilingPtr =
157 std::make_unique<BackendProfiling>(options, profilingService, cpuAccId);
158 std::unique_ptr<armnn::profiling::IBackendProfiling> gpuBackendProfilingPtr =
159 std::make_unique<BackendProfiling>(options, profilingService, gpuAccId);
160
161 std::shared_ptr<armnn::profiling::IBackendProfilingContext> cpuProfilingContextPtr =
162 std::make_shared<armnn::MockBackendProfilingContext>(cpuBackendProfilingPtr);
163 std::shared_ptr<armnn::profiling::IBackendProfilingContext> gpuProfilingContextPtr =
164 std::make_shared<armnn::MockBackendProfilingContext>(gpuBackendProfilingPtr);
165
166 std::unordered_map<armnn::BackendId,
167 std::shared_ptr<armnn::profiling::IBackendProfilingContext>> backendProfilingContexts;
168
169 backendProfilingContexts[cpuAccId] = cpuProfilingContextPtr;
170 backendProfilingContexts[gpuAccId] = gpuProfilingContextPtr;
171
172 uint16_t globalId = 5;
173
174 counterIdMap.RegisterMapping(globalId++, 0, cpuAccId);
175 counterIdMap.RegisterMapping(globalId++, 1, cpuAccId);
176 counterIdMap.RegisterMapping(globalId++, 2, cpuAccId);
177
178 counterIdMap.RegisterMapping(globalId++, 0, gpuAccId);
179 counterIdMap.RegisterMapping(globalId++, 1, gpuAccId);
180 counterIdMap.RegisterMapping(globalId++, 2, gpuAccId);
181
182 backendProfilingContexts[cpuAccId] = cpuProfilingContextPtr;
183 backendProfilingContexts[gpuAccId] = gpuProfilingContextPtr;
184
185 PeriodicCounterCapture periodicCounterCapture(holder, sendCounterPacket, readCounterVals,
186 counterIdMap, backendProfilingContexts);
187
188 uint16_t maxArmnnCounterId = 4;
189
190 PeriodicCounterSelectionCommandHandler periodicCounterSelectionCommandHandler(0,
191 4,
192 packetVersionResolver.ResolvePacketVersion(0, 4).GetEncodedValue(),
193 backendProfilingContexts,
194 counterIdMap,
195 holder,
196 maxArmnnCounterId,
197 periodicCounterCapture,
198 readCounterVals,
199 sendCounterPacket,
200 stateMachine);
201
202 stateMachine.TransitionToState(ProfilingState::NotConnected);
203 stateMachine.TransitionToState(ProfilingState::WaitingForAck);
204 stateMachine.TransitionToState(ProfilingState::Active);
205
206 uint32_t period = 12345u;
207
208 std::vector<uint16_t> cpuCounters{5, 6, 7};
209 std::vector<uint16_t> gpuCounters{8, 9, 10};
210
211 // Request only gpu counters
212 periodicCounterSelectionCommandHandler(PacketWriter(period, gpuCounters));
213 periodicCounterCapture.Stop();
214
215 std::set<armnn::BackendId> activeIds = holder.GetCaptureData().GetActiveBackends();
216 BOOST_CHECK(activeIds.size() == 1);
217 BOOST_CHECK(activeIds.find(gpuAccId) != activeIds.end());
218
219 std::vector<Timestamp> recievedTimestamp = sendCounterPacket.GetTimestamps();
220
221 BOOST_CHECK(recievedTimestamp[0].timestamp == period);
222 BOOST_CHECK(recievedTimestamp.size() == 1);
223 BOOST_CHECK(recievedTimestamp[0].counterValues.size() == gpuCounters.size());
224 for (unsigned long i=0; i< gpuCounters.size(); ++i)
225 {
226 BOOST_CHECK(recievedTimestamp[0].counterValues[i].counterId == gpuCounters[i]);
227 BOOST_CHECK(recievedTimestamp[0].counterValues[i].counterValue == i + 1u);
228 }
229 sendCounterPacket.ClearTimestamps();
230
231 // Request only cpu counters
232 periodicCounterSelectionCommandHandler(PacketWriter(period, cpuCounters));
233 periodicCounterCapture.Stop();
234
235 activeIds = holder.GetCaptureData().GetActiveBackends();
236 BOOST_CHECK(activeIds.size() == 1);
237 BOOST_CHECK(activeIds.find(cpuAccId) != activeIds.end());
238
239 recievedTimestamp = sendCounterPacket.GetTimestamps();
240
241 BOOST_CHECK(recievedTimestamp[0].timestamp == period);
242 BOOST_CHECK(recievedTimestamp.size() == 1);
243 BOOST_CHECK(recievedTimestamp[0].counterValues.size() == cpuCounters.size());
244 for (unsigned long i=0; i< cpuCounters.size(); ++i)
245 {
246 BOOST_CHECK(recievedTimestamp[0].counterValues[i].counterId == cpuCounters[i]);
247 BOOST_CHECK(recievedTimestamp[0].counterValues[i].counterValue == i + 1u);
248 }
249 sendCounterPacket.ClearTimestamps();
250
251 // Request combination of cpu & gpu counters with new period
252 period = 12222u;
253 periodicCounterSelectionCommandHandler(PacketWriter(period, {cpuCounters[0], gpuCounters[2],
254 gpuCounters[1], cpuCounters[1], gpuCounters[0]}));
255 periodicCounterCapture.Stop();
256
257 activeIds = holder.GetCaptureData().GetActiveBackends();
258 BOOST_CHECK(activeIds.size() == 2);
259 BOOST_CHECK(activeIds.find(cpuAccId) != activeIds.end());
260 BOOST_CHECK(activeIds.find(gpuAccId) != activeIds.end());
261
262 recievedTimestamp = sendCounterPacket.GetTimestamps();
263
264 BOOST_CHECK(recievedTimestamp[0].timestamp == period);
265 BOOST_CHECK(recievedTimestamp[1].timestamp == period);
266
267 BOOST_CHECK(recievedTimestamp.size() == 2);
268 BOOST_CHECK(recievedTimestamp[0].counterValues.size() == 2);
269 BOOST_CHECK(recievedTimestamp[1].counterValues.size() == gpuCounters.size());
270
271 BOOST_CHECK(recievedTimestamp[0].counterValues[0].counterId == cpuCounters[0]);
272 BOOST_CHECK(recievedTimestamp[0].counterValues[0].counterValue == 1u);
273 BOOST_CHECK(recievedTimestamp[0].counterValues[1].counterId == cpuCounters[1]);
274 BOOST_CHECK(recievedTimestamp[0].counterValues[1].counterValue == 2u);
275
276 for (unsigned long i=0; i< gpuCounters.size(); ++i)
277 {
278 BOOST_CHECK(recievedTimestamp[1].counterValues[i].counterId == gpuCounters[i]);
279 BOOST_CHECK(recievedTimestamp[1].counterValues[i].counterValue == i + 1u);
280 }
281
282 sendCounterPacket.ClearTimestamps();
283
284 // Request all counters
285 std::vector<uint16_t> counterValues;
286 counterValues.insert(counterValues.begin(), cpuCounters.begin(), cpuCounters.end());
287 counterValues.insert(counterValues.begin(), gpuCounters.begin(), gpuCounters.end());
288
289 periodicCounterSelectionCommandHandler(PacketWriter(period, counterValues));
290 periodicCounterCapture.Stop();
291
292 activeIds = holder.GetCaptureData().GetActiveBackends();
293 BOOST_CHECK(activeIds.size() == 2);
294 BOOST_CHECK(activeIds.find(cpuAccId) != activeIds.end());
295 BOOST_CHECK(activeIds.find(gpuAccId) != activeIds.end());
296
297 recievedTimestamp = sendCounterPacket.GetTimestamps();
298
299 BOOST_CHECK(recievedTimestamp[0].counterValues.size() == cpuCounters.size());
300 for (unsigned long i=0; i< cpuCounters.size(); ++i)
301 {
302 BOOST_CHECK(recievedTimestamp[0].counterValues[i].counterId == cpuCounters[i]);
303 BOOST_CHECK(recievedTimestamp[0].counterValues[i].counterValue == i + 1u);
304 }
305
306 BOOST_CHECK(recievedTimestamp[1].counterValues.size() == gpuCounters.size());
307 for (unsigned long i=0; i< gpuCounters.size(); ++i)
308 {
309 BOOST_CHECK(recievedTimestamp[1].counterValues[i].counterId == gpuCounters[i]);
310 BOOST_CHECK(recievedTimestamp[1].counterValues[i].counterValue == i + 1u);
311 }
312 sendCounterPacket.ClearTimestamps();
313
314 // Request random counters with duplicates and invalid counters
315 counterValues = {0, 0, 200, cpuCounters[2], gpuCounters[0],3 ,30, cpuCounters[0],cpuCounters[2], gpuCounters[1], 3,
316 90, 0, 30, gpuCounters[0], gpuCounters[0]};
317
318 periodicCounterSelectionCommandHandler(PacketWriter(period, counterValues));
319 periodicCounterCapture.Stop();
320
321 activeIds = holder.GetCaptureData().GetActiveBackends();
322 BOOST_CHECK(activeIds.size() == 2);
323 BOOST_CHECK(activeIds.find(cpuAccId) != activeIds.end());
324 BOOST_CHECK(activeIds.find(gpuAccId) != activeIds.end());
325
326 recievedTimestamp = sendCounterPacket.GetTimestamps();
327
328 BOOST_CHECK(recievedTimestamp.size() == 2);
329
330 BOOST_CHECK(recievedTimestamp[0].counterValues.size() == 2);
331
332 BOOST_CHECK(recievedTimestamp[0].counterValues[0].counterId == cpuCounters[0]);
333 BOOST_CHECK(recievedTimestamp[0].counterValues[0].counterValue == 1u);
334 BOOST_CHECK(recievedTimestamp[0].counterValues[1].counterId == cpuCounters[2]);
335 BOOST_CHECK(recievedTimestamp[0].counterValues[1].counterValue == 3u);
336
337 BOOST_CHECK(recievedTimestamp[1].counterValues.size() == 2);
338
339 BOOST_CHECK(recievedTimestamp[1].counterValues[0].counterId == gpuCounters[0]);
340 BOOST_CHECK(recievedTimestamp[1].counterValues[0].counterValue == 1u);
341 BOOST_CHECK(recievedTimestamp[1].counterValues[1].counterId == gpuCounters[1]);
342 BOOST_CHECK(recievedTimestamp[1].counterValues[1].counterValue == 2u);
343
344 sendCounterPacket.ClearTimestamps();
345
346 // Request no counters
347 periodicCounterSelectionCommandHandler(PacketWriter(period, {}));
348 periodicCounterCapture.Stop();
349
350 activeIds = holder.GetCaptureData().GetActiveBackends();
351 BOOST_CHECK(activeIds.size() == 0);
352
353 recievedTimestamp = sendCounterPacket.GetTimestamps();
354 BOOST_CHECK(recievedTimestamp.size() == 0);
355
356 sendCounterPacket.ClearTimestamps();
357
358 // Request period of zero
359 periodicCounterSelectionCommandHandler(PacketWriter(0, counterValues));
360 periodicCounterCapture.Stop();
361
362 activeIds = holder.GetCaptureData().GetActiveBackends();
363 BOOST_CHECK(activeIds.size() == 0);
364
365 recievedTimestamp = sendCounterPacket.GetTimestamps();
366 BOOST_CHECK(recievedTimestamp.size() == 0);
367}
368
369BOOST_AUTO_TEST_CASE(TestBackendCounterLogging)
370{
371 std::stringstream ss;
372
373 struct StreamRedirector
374 {
375 public:
376 StreamRedirector(std::ostream &stream, std::streambuf *newStreamBuffer)
377 : m_Stream(stream), m_BackupBuffer(m_Stream.rdbuf(newStreamBuffer))
378 {}
379
380 ~StreamRedirector()
381 { m_Stream.rdbuf(m_BackupBuffer); }
382
383 private:
384 std::ostream &m_Stream;
385 std::streambuf *m_BackupBuffer;
386 };
387
388 Holder holder;
Jim Flynnbbfe6032020-07-20 16:57:44 +0100389 arm::pipe::PacketVersionResolver packetVersionResolver;
Finn Williams032bc742020-02-12 11:02:34 +0000390 ProfilingStateMachine stateMachine;
391 ReadCounterVals readCounterVals;
392 StreamRedirector redirect(std::cout, ss.rdbuf());
393 CounterIdMap counterIdMap;
394 MockBackendSendCounterPacket sendCounterPacket;
395
396 const armnn::BackendId cpuAccId(armnn::Compute::CpuAcc);
397 const armnn::BackendId gpuAccId(armnn::Compute::GpuAcc);
398
399 armnn::IRuntime::CreationOptions options;
400 options.m_ProfilingOptions.m_EnableProfiling = true;
401
Sadik Armagan3184c902020-03-18 10:57:30 +0000402 armnn::profiling::ProfilingService profilingService;
Finn Williams032bc742020-02-12 11:02:34 +0000403
404 std::unique_ptr<armnn::profiling::IBackendProfiling> cpuBackendProfilingPtr =
405 std::make_unique<BackendProfiling>(options, profilingService, cpuAccId);
406
407 std::shared_ptr<armnn::profiling::IBackendProfilingContext> cpuProfilingContextPtr =
408 std::make_shared<armnn::MockBackendProfilingContext>(cpuBackendProfilingPtr);
409
410 std::unordered_map<armnn::BackendId,
411 std::shared_ptr<armnn::profiling::IBackendProfilingContext>> backendProfilingContexts;
412
413 uint16_t globalId = 5;
414 counterIdMap.RegisterMapping(globalId, 0, cpuAccId);
415 backendProfilingContexts[cpuAccId] = cpuProfilingContextPtr;
416
417 PeriodicCounterCapture periodicCounterCapture(holder, sendCounterPacket, readCounterVals,
418 counterIdMap, backendProfilingContexts);
419
420 uint16_t maxArmnnCounterId = 4;
421
422 PeriodicCounterSelectionCommandHandler periodicCounterSelectionCommandHandler(0,
423 4,
424 packetVersionResolver.ResolvePacketVersion(0, 4).GetEncodedValue(),
425 backendProfilingContexts,
426 counterIdMap,
427 holder,
428 maxArmnnCounterId,
429 periodicCounterCapture,
430 readCounterVals,
431 sendCounterPacket,
432 stateMachine);
433
434 stateMachine.TransitionToState(ProfilingState::NotConnected);
435 stateMachine.TransitionToState(ProfilingState::WaitingForAck);
436 stateMachine.TransitionToState(ProfilingState::Active);
437
438 uint32_t period = 15939u;
439
440 armnn::SetAllLoggingSinks(true, false, false);
441 SetLogFilter(armnn::LogSeverity::Warning);
442 periodicCounterSelectionCommandHandler(PacketWriter(period, {5}));
443 periodicCounterCapture.Stop();
444 SetLogFilter(armnn::LogSeverity::Fatal);
445
David Monahana8837bf2020-04-16 10:01:56 +0100446 BOOST_CHECK(ss.str().find("ActivateCounters example test error") != std::string::npos);
Finn Williams032bc742020-02-12 11:02:34 +0000447}
448
Colm Donelanfcb802b2020-02-13 20:47:08 +0000449BOOST_AUTO_TEST_CASE(BackendProfilingContextGetSendTimelinePacket)
450{
451 // Reset the profiling service to the uninitialized state
452 armnn::IRuntime::CreationOptions options;
453 options.m_ProfilingOptions.m_EnableProfiling = true;
Sadik Armagan3184c902020-03-18 10:57:30 +0000454 armnn::profiling::ProfilingService profilingService;
Colm Donelanfcb802b2020-02-13 20:47:08 +0000455 profilingService.ConfigureProfilingService(options.m_ProfilingOptions, true);
456
457 armnn::MockBackendInitialiser initialiser;
458 // Create a runtime. During this the mock backend will be registered and context returned.
459 armnn::IRuntimePtr runtime(armnn::IRuntime::Create(options));
460 armnn::MockBackendProfilingService mockProfilingService = armnn::MockBackendProfilingService::Instance();
461 armnn::MockBackendProfilingContext *mockBackEndProfilingContext = mockProfilingService.GetContext();
462 // Check that there is a valid context set.
463 BOOST_CHECK(mockBackEndProfilingContext);
464 armnn::IBackendInternal::IBackendProfilingPtr& backendProfilingIface =
465 mockBackEndProfilingContext->GetBackendProfiling();
466 BOOST_CHECK(backendProfilingIface);
467
468 // Now for the meat of the test. We're just going to send a random packet and make sure there
469 // are no exceptions or errors. The sending of packets is already tested in SendTimelinePacketTests.
470 std::unique_ptr<armnn::profiling::ISendTimelinePacket> timelinePacket =
471 backendProfilingIface->GetSendTimelinePacket();
472 // Send TimelineEntityClassBinaryPacket
473 const uint64_t entityBinaryPacketProfilingGuid = 123456u;
474 timelinePacket->SendTimelineEntityBinaryPacket(entityBinaryPacketProfilingGuid);
475 timelinePacket->Commit();
476
477 // Reset the profiling servie after the test.
478 options.m_ProfilingOptions.m_EnableProfiling = false;
479 profilingService.ResetExternalProfilingOptions(options.m_ProfilingOptions, true);
480}
481
482BOOST_AUTO_TEST_CASE(GetProfilingGuidGenerator)
483{
484 // Reset the profiling service to the uninitialized state
485 armnn::IRuntime::CreationOptions options;
486 options.m_ProfilingOptions.m_EnableProfiling = true;
Colm Donelanfcb802b2020-02-13 20:47:08 +0000487
488 armnn::MockBackendInitialiser initialiser;
489 // Create a runtime. During this the mock backend will be registered and context returned.
490 armnn::IRuntimePtr runtime(armnn::IRuntime::Create(options));
491 armnn::MockBackendProfilingService mockProfilingService = armnn::MockBackendProfilingService::Instance();
492 armnn::MockBackendProfilingContext *mockBackEndProfilingContext = mockProfilingService.GetContext();
493 // Check that there is a valid context set.
494 BOOST_CHECK(mockBackEndProfilingContext);
495 armnn::IBackendInternal::IBackendProfilingPtr& backendProfilingIface =
496 mockBackEndProfilingContext->GetBackendProfiling();
497 BOOST_CHECK(backendProfilingIface);
498
499 // Get the Guid generator and check the getting two Guid's results in the second being greater than the first.
500 armnn::profiling::IProfilingGuidGenerator& guidGenerator = backendProfilingIface->GetProfilingGuidGenerator();
Colm Donelanfcb802b2020-02-13 20:47:08 +0000501 const armnn::profiling::ProfilingDynamicGuid& firstGuid = guidGenerator.NextGuid();
Colm Donelanfcb802b2020-02-13 20:47:08 +0000502 const armnn::profiling::ProfilingDynamicGuid& secondGuid = guidGenerator.NextGuid();
503 BOOST_CHECK(secondGuid > firstGuid);
504
505 // Reset the profiling servie after the test.
506 options.m_ProfilingOptions.m_EnableProfiling = false;
Colm Donelanfcb802b2020-02-13 20:47:08 +0000507}
508
509BOOST_AUTO_TEST_SUITE_END()