61 TEST_CASE(
"CheckCommandHandlerKeyComparisons")
63 arm::pipe::CommandHandlerKey testKey1_0(1, 1, 1);
64 arm::pipe::CommandHandlerKey testKey1_1(1, 1, 1);
65 arm::pipe::CommandHandlerKey testKey1_2(1, 2, 1);
67 arm::pipe::CommandHandlerKey testKey0(0, 1, 1);
68 arm::pipe::CommandHandlerKey testKey1(0, 1, 1);
69 arm::pipe::CommandHandlerKey testKey2(0, 1, 1);
70 arm::pipe::CommandHandlerKey testKey3(0, 0, 0);
71 arm::pipe::CommandHandlerKey testKey4(0, 2, 2);
72 arm::pipe::CommandHandlerKey testKey5(0, 0, 2);
74 CHECK(testKey1_0 > testKey0);
75 CHECK(testKey1_0 == testKey1_1);
76 CHECK(testKey1_0 < testKey1_2);
78 CHECK(testKey1 < testKey4);
79 CHECK(testKey1 > testKey3);
80 CHECK(testKey1 <= testKey4);
81 CHECK(testKey1 >= testKey3);
82 CHECK(testKey1 <= testKey2);
83 CHECK(testKey1 >= testKey2);
84 CHECK(testKey1 == testKey2);
85 CHECK(testKey1 == testKey1);
87 CHECK(!(testKey1 == testKey5));
88 CHECK(!(testKey1 != testKey1));
89 CHECK(testKey1 != testKey5);
91 CHECK((testKey1 == testKey2 && testKey2 == testKey1));
92 CHECK((testKey0 == testKey1 && testKey1 == testKey2 && testKey0 == testKey2));
94 CHECK(testKey1.GetPacketId() == 1);
95 CHECK(testKey1.GetVersion() == 1);
97 std::vector<arm::pipe::CommandHandlerKey> vect = {
98 arm::pipe::CommandHandlerKey(0, 0, 1), arm::pipe::CommandHandlerKey(0, 2, 0),
99 arm::pipe::CommandHandlerKey(0, 1, 0), arm::pipe::CommandHandlerKey(0, 2, 1),
100 arm::pipe::CommandHandlerKey(0, 1, 1), arm::pipe::CommandHandlerKey(0, 0, 1),
101 arm::pipe::CommandHandlerKey(0, 2, 0), arm::pipe::CommandHandlerKey(0, 0, 0) };
103 std::sort(vect.begin(), vect.end());
105 std::vector<arm::pipe::CommandHandlerKey> expectedVect = {
106 arm::pipe::CommandHandlerKey(0, 0, 0), arm::pipe::CommandHandlerKey(0, 0, 1),
107 arm::pipe::CommandHandlerKey(0, 0, 1), arm::pipe::CommandHandlerKey(0, 1, 0),
108 arm::pipe::CommandHandlerKey(0, 1, 1), arm::pipe::CommandHandlerKey(0, 2, 0),
109 arm::pipe::CommandHandlerKey(0, 2, 0), arm::pipe::CommandHandlerKey(0, 2, 1) };
111 CHECK(vect == expectedVect);
114 TEST_CASE(
"CheckPacketKeyComparisons")
116 arm::pipe::PacketKey key0(0, 0);
117 arm::pipe::PacketKey key1(0, 0);
118 arm::pipe::PacketKey key2(0, 1);
119 arm::pipe::PacketKey key3(0, 2);
120 arm::pipe::PacketKey key4(1, 0);
121 arm::pipe::PacketKey key5(1, 0);
122 arm::pipe::PacketKey key6(1, 1);
124 CHECK(!(key0 < key1));
125 CHECK(!(key0 > key1));
139 TEST_CASE(
"CheckCommandHandler")
141 LogLevelSwapper logLevelSwapper(arm::pipe::LogSeverity::Fatal);
143 arm::pipe::PacketVersionResolver packetVersionResolver;
144 ProfilingStateMachine profilingStateMachine;
149 CounterDirectory counterDirectory;
151 SendCounterPacket sendCounterPacket(mockBuffer,
152 arm::pipe::ARMNN_SOFTWARE_INFO,
153 arm::pipe::ARMNN_SOFTWARE_VERSION,
154 arm::pipe::ARMNN_HARDWARE_VERSION);
155 SendThread sendThread(profilingStateMachine, mockBuffer, sendCounterPacket);
156 SendTimelinePacket sendTimelinePacket(mockBuffer);
159 ConnectionAcknowledgedCommandHandler connectionAcknowledgedCommandHandler(0, 1, 4194304, counterDirectory,
160 sendCounterPacket, sendTimelinePacket,
161 profilingStateMachine,
162 mockProfilingServiceStatus);
163 arm::pipe::CommandHandlerRegistry commandHandlerRegistry;
165 commandHandlerRegistry.RegisterFunctor(&connectionAcknowledgedCommandHandler);
167 profilingStateMachine.TransitionToState(ProfilingState::NotConnected);
168 profilingStateMachine.TransitionToState(ProfilingState::WaitingForAck);
170 CommandHandler commandHandler0(1,
true, commandHandlerRegistry, packetVersionResolver);
174 commandHandler0.Start(testProfilingConnectionBase);
176 commandHandler0.Start(testProfilingConnectionBase);
179 for (
int i = 0; i < 10; i++)
181 if (profilingStateMachine.GetCurrentState() == ProfilingState::Active)
185 std::this_thread::sleep_for(std::chrono::milliseconds(2));
188 CHECK(profilingStateMachine.GetCurrentState() == ProfilingState::Active);
191 commandHandler0.Stop();
193 profilingStateMachine.TransitionToState(ProfilingState::NotConnected);
194 profilingStateMachine.TransitionToState(ProfilingState::WaitingForAck);
198 CommandHandler commandHandler1(1,
true, commandHandlerRegistry, packetVersionResolver);
200 commandHandler1.Start(testProfilingConnectionTimeOutError);
202 for (
int i = 0; i < 10; i++)
208 std::this_thread::sleep_for(std::chrono::milliseconds(2));
213 uint32_t timeout = 50;
214 uint32_t timeSlept = 0;
215 while (commandHandler1.IsRunning())
217 if (timeSlept >= timeout)
219 FAIL(
"Timeout: The command handler loop did not stop after the timeout");
221 std::this_thread::sleep_for(std::chrono::milliseconds(1));
225 commandHandler1.Stop();
227 CHECK(profilingStateMachine.GetCurrentState() == ProfilingState::WaitingForAck);
231 commandHandler1.Start(testProfilingConnectionBadAckPacket);
232 commandHandler1.Stop();
234 CHECK(profilingStateMachine.GetCurrentState() == ProfilingState::WaitingForAck);
237 commandHandler1.SetStopAfterTimeout(
false);
239 commandHandler1.Start(testProfilingConnectionTimeOutError);
242 for (
int i = 0; i < 10; i++)
248 std::this_thread::sleep_for(std::chrono::milliseconds(2));
250 commandHandler1.Stop();
253 CHECK(profilingStateMachine.GetCurrentState() == ProfilingState::Active);
256 CommandHandler commandHandler2(1,
false, commandHandlerRegistry, packetVersionResolver);
258 commandHandler2.Start(testProfilingConnectionArmnnError);
261 for (
int i = 0; i < 10; i++)
267 std::this_thread::sleep_for(std::chrono::milliseconds(2));
270 CHECK(commandHandler2.IsRunning());
271 commandHandler2.Stop();
274 TEST_CASE(
"CheckEncodeVersion")
276 arm::pipe::Version version1(12);
278 CHECK(version1.GetMajor() == 0);
279 CHECK(version1.GetMinor() == 0);
280 CHECK(version1.GetPatch() == 12);
282 arm::pipe::Version version2(4108);
284 CHECK(version2.GetMajor() == 0);
285 CHECK(version2.GetMinor() == 1);
286 CHECK(version2.GetPatch() == 12);
288 arm::pipe::Version version3(4198412);
290 CHECK(version3.GetMajor() == 1);
291 CHECK(version3.GetMinor() == 1);
292 CHECK(version3.GetPatch() == 12);
294 arm::pipe::Version version4(0);
296 CHECK(version4.GetMajor() == 0);
297 CHECK(version4.GetMinor() == 0);
298 CHECK(version4.GetPatch() == 0);
300 arm::pipe::Version version5(1, 0, 0);
301 CHECK(version5.GetEncodedValue() == 4194304);
304 TEST_CASE(
"CheckPacketClass")
307 std::unique_ptr<unsigned char[]> packetData0 = std::make_unique<unsigned char[]>(length);
308 std::unique_ptr<unsigned char[]> packetData1 = std::make_unique<unsigned char[]>(0);
309 std::unique_ptr<unsigned char[]> nullPacketData;
311 arm::pipe::Packet packetTest0(472580096, length, packetData0);
313 CHECK(packetTest0.GetHeader() == 472580096);
314 CHECK(packetTest0.GetPacketFamily() == 7);
315 CHECK(packetTest0.GetPacketId() == 43);
316 CHECK(packetTest0.GetLength() == length);
317 CHECK(packetTest0.GetPacketType() == 3);
318 CHECK(packetTest0.GetPacketClass() == 5);
320 CHECK_THROWS_AS(arm::pipe::Packet packetTest1(472580096, 0, packetData1), arm::pipe::InvalidArgumentException);
321 CHECK_NOTHROW(arm::pipe::Packet packetTest2(472580096, 0, nullPacketData));
323 arm::pipe::Packet packetTest3(472580096, 0, nullPacketData);
324 CHECK(packetTest3.GetLength() == 0);
325 CHECK(packetTest3.GetData() ==
nullptr);
327 const unsigned char* packetTest0Data = packetTest0.GetData();
328 arm::pipe::Packet packetTest4(std::move(packetTest0));
330 CHECK(packetTest0.GetData() ==
nullptr);
331 CHECK(packetTest4.GetData() == packetTest0Data);
333 CHECK(packetTest4.GetHeader() == 472580096);
334 CHECK(packetTest4.GetPacketFamily() == 7);
335 CHECK(packetTest4.GetPacketId() == 43);
336 CHECK(packetTest4.GetLength() == length);
337 CHECK(packetTest4.GetPacketType() == 3);
338 CHECK(packetTest4.GetPacketClass() == 5);
341 TEST_CASE(
"CheckCommandHandlerFunctor")
344 uint32_t version = 1;
350 arm::pipe::CommandHandlerKey keyA(
351 testFunctorA.GetFamilyId(), testFunctorA.GetPacketId(), testFunctorA.GetVersion());
352 arm::pipe::CommandHandlerKey keyB(
353 testFunctorB.GetFamilyId(), testFunctorB.GetPacketId(), testFunctorB.GetVersion());
354 arm::pipe::CommandHandlerKey keyC(
355 testFunctorC.GetFamilyId(), testFunctorC.GetPacketId(), testFunctorC.GetVersion());
358 std::map<arm::pipe::CommandHandlerKey, arm::pipe::CommandHandlerFunctor*> registry;
360 registry.insert(std::make_pair(keyB, &testFunctorB));
361 registry.insert(std::make_pair(keyA, &testFunctorA));
362 registry.insert(std::make_pair(keyC, &testFunctorC));
365 auto it = registry.begin();
366 CHECK(it->first == keyC);
368 CHECK(it->first == keyA);
370 CHECK(it->first == keyB);
372 std::unique_ptr<unsigned char[]> packetDataA;
373 std::unique_ptr<unsigned char[]> packetDataB;
374 std::unique_ptr<unsigned char[]> packetDataC;
376 arm::pipe::Packet packetA(500000000, 0, packetDataA);
377 arm::pipe::Packet packetB(600000000, 0, packetDataB);
378 arm::pipe::Packet packetC(400000000, 0, packetDataC);
381 registry.at(arm::pipe::CommandHandlerKey(
382 packetA.GetPacketFamily(), packetA.GetPacketId(), version))->operator()(packetA);
383 CHECK(testFunctorA.GetCount() == 1);
384 CHECK(testFunctorB.GetCount() == 0);
385 CHECK(testFunctorC.GetCount() == 0);
387 registry.at(arm::pipe::CommandHandlerKey(
388 packetB.GetPacketFamily(), packetB.GetPacketId(), version))->operator()(packetB);
389 CHECK(testFunctorA.GetCount() == 1);
390 CHECK(testFunctorB.GetCount() == 1);
391 CHECK(testFunctorC.GetCount() == 0);
393 registry.at(arm::pipe::CommandHandlerKey(
394 packetC.GetPacketFamily(), packetC.GetPacketId(), version))->operator()(packetC);
395 CHECK(testFunctorA.GetCount() == 1);
396 CHECK(testFunctorB.GetCount() == 1);
397 CHECK(testFunctorC.GetCount() == 1);
400 TEST_CASE(
"CheckCommandHandlerRegistry")
403 uint32_t version = 1;
410 arm::pipe::CommandHandlerRegistry registry;
413 registry.RegisterFunctor(&testFunctorA);
414 registry.RegisterFunctor(&testFunctorB);
415 registry.RegisterFunctor(&testFunctorC);
417 std::unique_ptr<unsigned char[]> packetDataA;
418 std::unique_ptr<unsigned char[]> packetDataB;
419 std::unique_ptr<unsigned char[]> packetDataC;
421 arm::pipe::Packet packetA(500000000, 0, packetDataA);
422 arm::pipe::Packet packetB(600000000, 0, packetDataB);
423 arm::pipe::Packet packetC(400000000, 0, packetDataC);
426 registry.GetFunctor(packetA.GetPacketFamily(), packetA.GetPacketId(), version)->
operator()(packetA);
427 CHECK(testFunctorA.GetCount() == 1);
428 CHECK(testFunctorB.GetCount() == 0);
429 CHECK(testFunctorC.GetCount() == 0);
431 registry.GetFunctor(packetB.GetPacketFamily(), packetB.GetPacketId(), version)->
operator()(packetB);
432 CHECK(testFunctorA.GetCount() == 1);
433 CHECK(testFunctorB.GetCount() == 1);
434 CHECK(testFunctorC.GetCount() == 0);
436 registry.GetFunctor(packetC.GetPacketFamily(), packetC.GetPacketId(), version)->
operator()(packetC);
437 CHECK(testFunctorA.GetCount() == 1);
438 CHECK(testFunctorB.GetCount() == 1);
439 CHECK(testFunctorC.GetCount() == 1);
442 registry.RegisterFunctor(&testFunctorC, testFunctorA.GetFamilyId(), testFunctorA.GetPacketId(), version);
443 registry.GetFunctor(packetA.GetPacketFamily(), packetA.GetPacketId(), version)->
operator()(packetC);
444 CHECK(testFunctorA.GetCount() == 1);
445 CHECK(testFunctorB.GetCount() == 1);
446 CHECK(testFunctorC.GetCount() == 2);
449 CHECK_THROWS_AS(registry.GetFunctor(0, 0, 0), arm::pipe::ProfilingException);
452 TEST_CASE(
"CheckPacketVersionResolver")
455 std::random_device device;
456 std::mt19937 generator(device());
457 std::uniform_int_distribution<uint32_t> distribution(std::numeric_limits<uint32_t>::min(),
458 std::numeric_limits<uint32_t>::max());
461 const arm::pipe::Version expectedVersion(1, 0, 0);
463 arm::pipe::PacketVersionResolver packetVersionResolver;
465 constexpr
unsigned int numTests = 10u;
467 for (
unsigned int i = 0u; i < numTests; ++i)
469 const uint32_t familyId = distribution(generator);
470 const uint32_t packetId = distribution(generator);
471 arm::pipe::Version resolvedVersion = packetVersionResolver.ResolvePacketVersion(familyId, packetId);
473 CHECK(resolvedVersion == expectedVersion);
477 void ProfilingCurrentStateThreadImpl(ProfilingStateMachine& states)
479 ProfilingState newState = ProfilingState::NotConnected;
480 states.GetCurrentState();
481 states.TransitionToState(newState);
484 TEST_CASE(
"CheckProfilingStateMachine")
486 ProfilingStateMachine profilingState1(ProfilingState::Uninitialised);
487 profilingState1.TransitionToState(ProfilingState::Uninitialised);
488 CHECK(profilingState1.GetCurrentState() == ProfilingState::Uninitialised);
490 ProfilingStateMachine profilingState2(ProfilingState::Uninitialised);
491 profilingState2.TransitionToState(ProfilingState::NotConnected);
492 CHECK(profilingState2.GetCurrentState() == ProfilingState::NotConnected);
494 ProfilingStateMachine profilingState3(ProfilingState::NotConnected);
495 profilingState3.TransitionToState(ProfilingState::NotConnected);
496 CHECK(profilingState3.GetCurrentState() == ProfilingState::NotConnected);
498 ProfilingStateMachine profilingState4(ProfilingState::NotConnected);
499 profilingState4.TransitionToState(ProfilingState::WaitingForAck);
500 CHECK(profilingState4.GetCurrentState() == ProfilingState::WaitingForAck);
502 ProfilingStateMachine profilingState5(ProfilingState::WaitingForAck);
503 profilingState5.TransitionToState(ProfilingState::WaitingForAck);
504 CHECK(profilingState5.GetCurrentState() == ProfilingState::WaitingForAck);
506 ProfilingStateMachine profilingState6(ProfilingState::WaitingForAck);
507 profilingState6.TransitionToState(ProfilingState::Active);
508 CHECK(profilingState6.GetCurrentState() == ProfilingState::Active);
510 ProfilingStateMachine profilingState7(ProfilingState::Active);
511 profilingState7.TransitionToState(ProfilingState::NotConnected);
512 CHECK(profilingState7.GetCurrentState() == ProfilingState::NotConnected);
514 ProfilingStateMachine profilingState8(ProfilingState::Active);
515 profilingState8.TransitionToState(ProfilingState::Active);
516 CHECK(profilingState8.GetCurrentState() == ProfilingState::Active);
518 ProfilingStateMachine profilingState9(ProfilingState::Uninitialised);
519 CHECK_THROWS_AS(profilingState9.TransitionToState(ProfilingState::WaitingForAck), arm::pipe::ProfilingException);
521 ProfilingStateMachine profilingState10(ProfilingState::Uninitialised);
522 CHECK_THROWS_AS(profilingState10.TransitionToState(ProfilingState::Active), arm::pipe::ProfilingException);
524 ProfilingStateMachine profilingState11(ProfilingState::NotConnected);
525 CHECK_THROWS_AS(profilingState11.TransitionToState(ProfilingState::Uninitialised), arm::pipe::ProfilingException);
527 ProfilingStateMachine profilingState12(ProfilingState::NotConnected);
528 CHECK_THROWS_AS(profilingState12.TransitionToState(ProfilingState::Active), arm::pipe::ProfilingException);
530 ProfilingStateMachine profilingState13(ProfilingState::WaitingForAck);
531 CHECK_THROWS_AS(profilingState13.TransitionToState(ProfilingState::Uninitialised), arm::pipe::ProfilingException);
533 ProfilingStateMachine profilingState14(ProfilingState::WaitingForAck);
534 profilingState14.TransitionToState(ProfilingState::NotConnected);
535 CHECK(profilingState14.GetCurrentState() == ProfilingState::NotConnected);
537 ProfilingStateMachine profilingState15(ProfilingState::Active);
538 CHECK_THROWS_AS(profilingState15.TransitionToState(ProfilingState::Uninitialised), arm::pipe::ProfilingException);
540 ProfilingStateMachine profilingState16(ProfilingState::Active);
541 CHECK_THROWS_AS(profilingState16.TransitionToState(ProfilingState::WaitingForAck), arm::pipe::ProfilingException);
543 ProfilingStateMachine profilingState17(ProfilingState::Uninitialised);
545 std::vector<std::thread> threads;
546 for (
unsigned int i = 0; i < 5; ++i)
548 threads.push_back(std::thread(ProfilingCurrentStateThreadImpl, std::ref(profilingState17)));
550 std::for_each(threads.begin(), threads.end(), [](std::thread& theThread)
555 CHECK((profilingState17.GetCurrentState() == ProfilingState::NotConnected));
558 void CaptureDataWriteThreadImpl(Holder& holder, uint32_t capturePeriod,
const std::vector<uint16_t>& counterIds)
560 holder.SetCaptureData(capturePeriod, counterIds, {});
563 void CaptureDataReadThreadImpl(
const Holder& holder, CaptureData& captureData)
565 captureData = holder.GetCaptureData();
568 TEST_CASE(
"CheckCaptureDataHolder")
570 std::map<uint32_t, std::vector<uint16_t>> periodIdMap;
571 std::vector<uint16_t> counterIds;
572 uint32_t numThreads = 10;
573 for (uint32_t i = 0; i < numThreads; ++i)
575 counterIds.emplace_back(i);
576 periodIdMap.insert(std::make_pair(i, counterIds));
582 CHECK((holder.GetCaptureData()).GetCapturePeriod() == 0);
583 CHECK(((holder.GetCaptureData()).GetCounterIds()).empty());
586 std::thread thread1(CaptureDataWriteThreadImpl, std::ref(holder), 2, std::ref(periodIdMap[2]));
588 CHECK((holder.GetCaptureData()).GetCapturePeriod() == 2);
589 CHECK((holder.GetCaptureData()).GetCounterIds() == periodIdMap[2]);
596 CaptureData captureData;
597 std::thread thread2(CaptureDataReadThreadImpl, std::ref(holder), std::ref(captureData));
599 CHECK(captureData.GetCapturePeriod() == 2);
600 CHECK(captureData.GetCounterIds() == periodIdMap[2]);
602 std::map<uint32_t, CaptureData> captureDataIdMap;
603 for (uint32_t i = 0; i < numThreads; ++i)
605 CaptureData perThreadCaptureData;
606 captureDataIdMap.insert(std::make_pair(i, perThreadCaptureData));
609 std::vector<std::thread> threadsVect;
610 std::vector<std::thread> readThreadsVect;
611 for (uint32_t i = 0; i < numThreads; ++i)
613 threadsVect.emplace_back(
614 std::thread(CaptureDataWriteThreadImpl, std::ref(holder), i, std::ref(periodIdMap[i])));
617 CHECK(captureDataIdMap.at(i).GetCapturePeriod() == 0);
618 CHECK(captureDataIdMap.at(i).GetCounterIds().empty());
619 readThreadsVect.emplace_back(
620 std::thread(CaptureDataReadThreadImpl, std::ref(holder), std::ref(captureDataIdMap.at(i))));
623 for (uint32_t i = 0; i < numThreads; ++i)
625 threadsVect[i].join();
626 readThreadsVect[i].join();
631 for (uint32_t i = 0; i < numThreads; ++i)
633 CaptureData perThreadCaptureData = captureDataIdMap.at(i);
634 CHECK(perThreadCaptureData.GetCounterIds() == periodIdMap.at(perThreadCaptureData.GetCapturePeriod()));
638 TEST_CASE(
"CaptureDataMethods")
641 std::vector<uint16_t> counterIds = { 42, 29, 13 };
642 CaptureData captureData;
643 CHECK(captureData.GetCapturePeriod() == 0);
644 CHECK((captureData.GetCounterIds()).empty());
645 captureData.SetCapturePeriod(150);
646 captureData.SetCounterIds(counterIds);
647 CHECK(captureData.GetCapturePeriod() == 150);
648 CHECK(captureData.GetCounterIds() == counterIds);
651 CaptureData secondCaptureData;
653 secondCaptureData = captureData;
654 CHECK(secondCaptureData.GetCapturePeriod() == 150);
655 CHECK(secondCaptureData.GetCounterIds() == counterIds);
658 CaptureData copyConstructedCaptureData(captureData);
660 CHECK(copyConstructedCaptureData.GetCapturePeriod() == 150);
661 CHECK(copyConstructedCaptureData.GetCounterIds() == counterIds);
664 TEST_CASE(
"CheckProfilingServiceDisabled")
666 ProfilingOptions options;
668 ProfilingService profilingService(arm::pipe::MAX_ARMNN_COUNTER,
670 arm::pipe::ARMNN_SOFTWARE_INFO,
671 arm::pipe::ARMNN_SOFTWARE_VERSION,
672 arm::pipe::ARMNN_HARDWARE_VERSION);
673 profilingService.ResetExternalProfilingOptions(options,
true);
674 CHECK(profilingService.GetCurrentState() == ProfilingState::Uninitialised);
675 profilingService.Update();
676 CHECK(profilingService.GetCurrentState() == ProfilingState::Uninitialised);
679 TEST_CASE(
"CheckProfilingServiceCounterDirectory")
681 ProfilingOptions options;
683 ProfilingService profilingService(arm::pipe::MAX_ARMNN_COUNTER,
685 arm::pipe::ARMNN_SOFTWARE_INFO,
686 arm::pipe::ARMNN_SOFTWARE_VERSION,
687 arm::pipe::ARMNN_HARDWARE_VERSION);
688 profilingService.ResetExternalProfilingOptions(options,
true);
690 const ICounterDirectory& counterDirectory0 = profilingService.GetCounterDirectory();
691 CHECK(counterDirectory0.GetCounterCount() == 0);
692 profilingService.Update();
693 CHECK(counterDirectory0.GetCounterCount() == 0);
695 options.m_EnableProfiling =
true;
696 profilingService.ResetExternalProfilingOptions(options);
698 const ICounterDirectory& counterDirectory1 = profilingService.GetCounterDirectory();
699 CHECK(counterDirectory1.GetCounterCount() == 0);
700 profilingService.Update();
701 CHECK(counterDirectory1.GetCounterCount() != 0);
703 options.m_EnableProfiling =
false;
704 profilingService.ResetExternalProfilingOptions(options,
true);
707 TEST_CASE(
"CheckProfilingServiceCounterValues")
709 ProfilingOptions options;
710 options.m_EnableProfiling =
true;
712 ProfilingService profilingService(arm::pipe::MAX_ARMNN_COUNTER,
714 arm::pipe::ARMNN_SOFTWARE_INFO,
715 arm::pipe::ARMNN_SOFTWARE_VERSION,
716 arm::pipe::ARMNN_HARDWARE_VERSION);
717 profilingService.ResetExternalProfilingOptions(options,
true);
719 profilingService.Update();
720 const ICounterDirectory& counterDirectory = profilingService.GetCounterDirectory();
721 const Counters& counters = counterDirectory.GetCounters();
722 CHECK(!counters.empty());
724 std::vector<std::thread> writers;
726 CHECK(!counters.empty());
727 uint16_t inferencesRun = INFERENCES_RUN;
730 for (
int i = 0; i < 4; ++i)
733 writers.push_back(std::thread([&profilingService, inferencesRun]()
735 for (
int i = 0; i < 250; ++i)
737 profilingService.IncrementCounterValue(inferencesRun);
741 writers.push_back(std::thread([&profilingService, inferencesRun]()
743 for (
int i = 0; i < 200; ++i)
745 profilingService.AddCounterValue(inferencesRun, 10);
749 writers.push_back(std::thread([&profilingService, inferencesRun]()
751 for (
int i = 0; i < 200; ++i)
753 profilingService.SubtractCounterValue(inferencesRun, 5);
757 std::for_each(writers.begin(), writers.end(), mem_fn(&std::thread::join));
759 uint32_t absoluteCounterValue = 0;
761 CHECK_NOTHROW(absoluteCounterValue = profilingService.GetAbsoluteCounterValue(INFERENCES_RUN));
762 CHECK(absoluteCounterValue == 5000);
765 CHECK_NOTHROW(profilingService.SetCounterValue(INFERENCES_RUN, 0));
766 CHECK_NOTHROW(absoluteCounterValue = profilingService.GetAbsoluteCounterValue(INFERENCES_RUN));
767 CHECK(absoluteCounterValue == 0);
771 uint32_t deltaCounterValue = 0;
773 std::thread reader([&profilingService, inferencesRun](uint32_t& deltaCounterValue)
775 for (
int i = 0; i < 300; ++i)
777 deltaCounterValue += profilingService.GetDeltaCounterValue(inferencesRun);
779 }, std::ref(deltaCounterValue));
781 for (
int i = 0; i < 4; ++i)
784 writers.push_back(std::thread([&profilingService, inferencesRun]()
786 for (
int i = 0; i < 250; ++i)
788 profilingService.IncrementCounterValue(inferencesRun);
792 writers.push_back(std::thread([&profilingService, inferencesRun]()
794 for (
int i = 0; i < 200; ++i)
796 profilingService.AddCounterValue(inferencesRun, 10);
800 writers.push_back(std::thread([&profilingService, inferencesRun]()
802 for (
int i = 0; i < 200; ++i)
804 profilingService.SubtractCounterValue(inferencesRun, 5);
809 std::for_each(writers.begin(), writers.end(), mem_fn(&std::thread::join));
813 deltaCounterValue += profilingService.GetDeltaCounterValue(INFERENCES_RUN);
814 CHECK(deltaCounterValue == 5000);
817 options.m_EnableProfiling =
false;
818 profilingService.ResetExternalProfilingOptions(options,
true);
821 TEST_CASE(
"CheckProfilingObjectUids")
824 CHECK_NOTHROW(uid = GetNextUid());
827 uint16_t nextUid = 0;
828 CHECK_NOTHROW(nextUid = GetNextUid());
829 CHECK(nextUid > uid);
831 std::vector<uint16_t> counterUids;
832 CHECK_NOTHROW(counterUids = GetNextCounterUids(uid,0));
833 CHECK(counterUids.size() == 1);
835 std::vector<uint16_t> nextCounterUids;
836 CHECK_NOTHROW(nextCounterUids = GetNextCounterUids(nextUid, 2));
837 CHECK(nextCounterUids.size() == 2);
838 CHECK(nextCounterUids[0] > counterUids[0]);
840 std::vector<uint16_t> counterUidsMultiCore;
841 uint16_t thirdUid = nextCounterUids[0];
842 uint16_t numberOfCores = 13;
843 CHECK_NOTHROW(counterUidsMultiCore = GetNextCounterUids(thirdUid, numberOfCores));
844 CHECK(counterUidsMultiCore.size() == numberOfCores);
845 CHECK(counterUidsMultiCore.front() >= nextCounterUids[0]);
846 for (
size_t i = 1; i < numberOfCores; i++)
848 CHECK(counterUidsMultiCore[i] == counterUidsMultiCore[i - 1] + 1);
850 CHECK(counterUidsMultiCore.back() == counterUidsMultiCore.front() + numberOfCores - 1);
853 TEST_CASE(
"CheckCounterDirectoryRegisterCategory")
855 CounterDirectory counterDirectory;
856 CHECK(counterDirectory.GetCategoryCount() == 0);
857 CHECK(counterDirectory.GetDeviceCount() == 0);
858 CHECK(counterDirectory.GetCounterSetCount() == 0);
859 CHECK(counterDirectory.GetCounterCount() == 0);
862 const Category* noCategory =
nullptr;
863 CHECK_THROWS_AS(noCategory = counterDirectory.RegisterCategory(
""), arm::pipe::InvalidArgumentException);
864 CHECK(counterDirectory.GetCategoryCount() == 0);
868 CHECK_THROWS_AS(noCategory = counterDirectory.RegisterCategory(
"invalid category"),
869 arm::pipe::InvalidArgumentException);
870 CHECK(counterDirectory.GetCategoryCount() == 0);
874 const std::string categoryName =
"some_category";
875 const Category* category =
nullptr;
876 CHECK_NOTHROW(category = counterDirectory.RegisterCategory(categoryName));
877 CHECK(counterDirectory.GetCategoryCount() == 1);
879 CHECK(category->m_Name == categoryName);
880 CHECK(category->m_Counters.empty());
883 const Category* registeredCategory = counterDirectory.GetCategory(categoryName);
884 CHECK(counterDirectory.GetCategoryCount() == 1);
885 CHECK(registeredCategory);
886 CHECK(registeredCategory == category);
889 const Category* notRegisteredCategory = counterDirectory.GetCategory(
"not_registered_category");
890 CHECK(counterDirectory.GetCategoryCount() == 1);
891 CHECK(!notRegisteredCategory);
894 const Category* anotherCategory =
nullptr;
895 CHECK_THROWS_AS(anotherCategory = counterDirectory.RegisterCategory(categoryName),
896 arm::pipe::InvalidArgumentException);
897 CHECK(counterDirectory.GetCategoryCount() == 1);
898 CHECK(!anotherCategory);
901 const std::string deviceName =
"some_device";
902 const Device* device =
nullptr;
903 CHECK_NOTHROW(device = counterDirectory.RegisterDevice(deviceName));
904 CHECK(counterDirectory.GetDeviceCount() == 1);
906 CHECK(device->m_Uid >= 1);
907 CHECK(device->m_Name == deviceName);
908 CHECK(device->m_Cores == 0);
911 const std::string categoryWoDeviceName =
"some_category_without_device";
912 const Category* categoryWoDevice =
nullptr;
913 CHECK_NOTHROW(categoryWoDevice = counterDirectory.RegisterCategory(categoryWoDeviceName));
914 CHECK(counterDirectory.GetCategoryCount() == 2);
915 CHECK(categoryWoDevice);
916 CHECK(categoryWoDevice->m_Name == categoryWoDeviceName);
917 CHECK(categoryWoDevice->m_Counters.empty());
920 const Category* categoryInvalidDeviceName =
nullptr;
921 CHECK_THROWS_AS(categoryInvalidDeviceName =
922 counterDirectory.RegisterCategory(categoryWoDeviceName),
923 arm::pipe::InvalidArgumentException);
924 CHECK(counterDirectory.GetCategoryCount() == 2);
925 CHECK(!categoryInvalidDeviceName);
928 const std::string categoryWValidDeviceName =
"some_category_with_valid_device";
929 const Category* categoryWValidDevice =
nullptr;
930 CHECK_NOTHROW(categoryWValidDevice =
931 counterDirectory.RegisterCategory(categoryWValidDeviceName));
932 CHECK(counterDirectory.GetCategoryCount() == 3);
933 CHECK(categoryWValidDevice);
934 CHECK(categoryWValidDevice != category);
935 CHECK(categoryWValidDevice->m_Name == categoryWValidDeviceName);
938 const std::string counterSetName =
"some_counter_set";
939 const CounterSet* counterSet =
nullptr;
940 CHECK_NOTHROW(counterSet = counterDirectory.RegisterCounterSet(counterSetName));
941 CHECK(counterDirectory.GetCounterSetCount() == 1);
943 CHECK(counterSet->m_Uid >= 1);
944 CHECK(counterSet->m_Name == counterSetName);
945 CHECK(counterSet->m_Count == 0);
948 const std::string categoryWoCounterSetName =
"some_category_without_counter_set";
949 const Category* categoryWoCounterSet =
nullptr;
950 CHECK_NOTHROW(categoryWoCounterSet =
951 counterDirectory.RegisterCategory(categoryWoCounterSetName));
952 CHECK(counterDirectory.GetCategoryCount() == 4);
953 CHECK(categoryWoCounterSet);
954 CHECK(categoryWoCounterSet->m_Name == categoryWoCounterSetName);
957 const std::string categoryWValidCounterSetName =
"some_category_with_valid_counter_set";
958 const Category* categoryWValidCounterSet =
nullptr;
959 CHECK_NOTHROW(categoryWValidCounterSet = counterDirectory.RegisterCategory(categoryWValidCounterSetName));
960 CHECK(counterDirectory.GetCategoryCount() == 5);
961 CHECK(categoryWValidCounterSet);
962 CHECK(categoryWValidCounterSet != category);
963 CHECK(categoryWValidCounterSet->m_Name == categoryWValidCounterSetName);
966 const std::string categoryWValidDeviceAndValidCounterSetName =
"some_category_with_valid_device_and_counter_set";
967 const Category* categoryWValidDeviceAndValidCounterSet =
nullptr;
968 CHECK_NOTHROW(categoryWValidDeviceAndValidCounterSet = counterDirectory.RegisterCategory(
969 categoryWValidDeviceAndValidCounterSetName));
970 CHECK(counterDirectory.GetCategoryCount() == 6);
971 CHECK(categoryWValidDeviceAndValidCounterSet);
972 CHECK(categoryWValidDeviceAndValidCounterSet != category);
973 CHECK(categoryWValidDeviceAndValidCounterSet->m_Name == categoryWValidDeviceAndValidCounterSetName);
976 TEST_CASE(
"CheckCounterDirectoryRegisterDevice")
978 CounterDirectory counterDirectory;
979 CHECK(counterDirectory.GetCategoryCount() == 0);
980 CHECK(counterDirectory.GetDeviceCount() == 0);
981 CHECK(counterDirectory.GetCounterSetCount() == 0);
982 CHECK(counterDirectory.GetCounterCount() == 0);
985 const Device* noDevice =
nullptr;
986 CHECK_THROWS_AS(noDevice = counterDirectory.RegisterDevice(
""), arm::pipe::InvalidArgumentException);
987 CHECK(counterDirectory.GetDeviceCount() == 0);
991 CHECK_THROWS_AS(noDevice = counterDirectory.RegisterDevice(
"inv@lid nam€"), arm::pipe::InvalidArgumentException);
992 CHECK(counterDirectory.GetDeviceCount() == 0);
996 const std::string deviceName =
"some_device";
997 const Device* device =
nullptr;
998 CHECK_NOTHROW(device = counterDirectory.RegisterDevice(deviceName));
999 CHECK(counterDirectory.GetDeviceCount() == 1);
1001 CHECK(device->m_Name == deviceName);
1002 CHECK(device->m_Uid >= 1);
1003 CHECK(device->m_Cores == 0);
1006 const Device* unregisteredDevice = counterDirectory.GetDevice(9999);
1007 CHECK(!unregisteredDevice);
1010 const Device* registeredDevice = counterDirectory.GetDevice(device->m_Uid);
1011 CHECK(counterDirectory.GetDeviceCount() == 1);
1012 CHECK(registeredDevice);
1013 CHECK(registeredDevice == device);
1016 const Device* deviceSameName =
nullptr;
1017 CHECK_THROWS_AS(deviceSameName = counterDirectory.RegisterDevice(deviceName),
1018 arm::pipe::InvalidArgumentException);
1019 CHECK(counterDirectory.GetDeviceCount() == 1);
1020 CHECK(!deviceSameName);
1023 const std::string deviceWCoresName =
"some_device_with_cores";
1024 const Device* deviceWCores =
nullptr;
1025 CHECK_NOTHROW(deviceWCores = counterDirectory.RegisterDevice(deviceWCoresName, 2));
1026 CHECK(counterDirectory.GetDeviceCount() == 2);
1027 CHECK(deviceWCores);
1028 CHECK(deviceWCores->m_Name == deviceWCoresName);
1029 CHECK(deviceWCores->m_Uid >= 1);
1030 CHECK(deviceWCores->m_Uid > device->m_Uid);
1031 CHECK(deviceWCores->m_Cores == 2);
1034 const Device* registeredDeviceWCores = counterDirectory.GetDevice(deviceWCores->m_Uid);
1035 CHECK(counterDirectory.GetDeviceCount() == 2);
1036 CHECK(registeredDeviceWCores);
1037 CHECK(registeredDeviceWCores == deviceWCores);
1038 CHECK(registeredDeviceWCores != device);
1041 const std::string deviceWCoresWInvalidParentCategoryName =
"some_device_with_cores_with_invalid_parent_category";
1042 const Device* deviceWCoresWInvalidParentCategory =
nullptr;
1043 CHECK_THROWS_AS(deviceWCoresWInvalidParentCategory =
1044 counterDirectory.RegisterDevice(deviceWCoresWInvalidParentCategoryName, 3, std::string(
"")),
1045 arm::pipe::InvalidArgumentException);
1046 CHECK(counterDirectory.GetDeviceCount() == 2);
1047 CHECK(!deviceWCoresWInvalidParentCategory);
1050 const std::string deviceWCoresWInvalidParentCategoryName2 =
"some_device_with_cores_with_invalid_parent_category2";
1051 const Device* deviceWCoresWInvalidParentCategory2 =
nullptr;
1052 CHECK_THROWS_AS(deviceWCoresWInvalidParentCategory2 = counterDirectory.RegisterDevice(
1053 deviceWCoresWInvalidParentCategoryName2, 3, std::string(
"invalid_parent_category")),
1054 arm::pipe::InvalidArgumentException);
1055 CHECK(counterDirectory.GetDeviceCount() == 2);
1056 CHECK(!deviceWCoresWInvalidParentCategory2);
1059 const std::string categoryName =
"some_category";
1060 const Category* category =
nullptr;
1061 CHECK_NOTHROW(category = counterDirectory.RegisterCategory(categoryName));
1062 CHECK(counterDirectory.GetCategoryCount() == 1);
1064 CHECK(category->m_Name == categoryName);
1065 CHECK(category->m_Counters.empty());
1068 const std::string deviceWCoresWValidParentCategoryName =
"some_device_with_cores_with_valid_parent_category";
1069 const Device* deviceWCoresWValidParentCategory =
nullptr;
1070 CHECK_NOTHROW(deviceWCoresWValidParentCategory =
1071 counterDirectory.RegisterDevice(deviceWCoresWValidParentCategoryName, 4, categoryName));
1072 CHECK(counterDirectory.GetDeviceCount() == 3);
1073 CHECK(deviceWCoresWValidParentCategory);
1074 CHECK(deviceWCoresWValidParentCategory->m_Name == deviceWCoresWValidParentCategoryName);
1075 CHECK(deviceWCoresWValidParentCategory->m_Uid >= 1);
1076 CHECK(deviceWCoresWValidParentCategory->m_Uid > device->m_Uid);
1077 CHECK(deviceWCoresWValidParentCategory->m_Uid > deviceWCores->m_Uid);
1078 CHECK(deviceWCoresWValidParentCategory->m_Cores == 4);
1081 TEST_CASE(
"CheckCounterDirectoryRegisterCounterSet")
1083 CounterDirectory counterDirectory;
1084 CHECK(counterDirectory.GetCategoryCount() == 0);
1085 CHECK(counterDirectory.GetDeviceCount() == 0);
1086 CHECK(counterDirectory.GetCounterSetCount() == 0);
1087 CHECK(counterDirectory.GetCounterCount() == 0);
1090 const CounterSet* noCounterSet =
nullptr;
1091 CHECK_THROWS_AS(noCounterSet = counterDirectory.RegisterCounterSet(
""), arm::pipe::InvalidArgumentException);
1092 CHECK(counterDirectory.GetCounterSetCount() == 0);
1093 CHECK(!noCounterSet);
1096 CHECK_THROWS_AS(noCounterSet = counterDirectory.RegisterCounterSet(
"invalid name"),
1097 arm::pipe::InvalidArgumentException);
1098 CHECK(counterDirectory.GetCounterSetCount() == 0);
1099 CHECK(!noCounterSet);
1102 const std::string counterSetName =
"some_counter_set";
1103 const CounterSet* counterSet =
nullptr;
1104 CHECK_NOTHROW(counterSet = counterDirectory.RegisterCounterSet(counterSetName));
1105 CHECK(counterDirectory.GetCounterSetCount() == 1);
1107 CHECK(counterSet->m_Name == counterSetName);
1108 CHECK(counterSet->m_Uid >= 1);
1109 CHECK(counterSet->m_Count == 0);
1112 const CounterSet* unregisteredCounterSet = counterDirectory.GetCounterSet(9999);
1113 CHECK(!unregisteredCounterSet);
1116 const CounterSet* registeredCounterSet = counterDirectory.GetCounterSet(counterSet->m_Uid);
1117 CHECK(counterDirectory.GetCounterSetCount() == 1);
1118 CHECK(registeredCounterSet);
1119 CHECK(registeredCounterSet == counterSet);
1122 const CounterSet* counterSetSameName =
nullptr;
1123 CHECK_THROWS_AS(counterSetSameName = counterDirectory.RegisterCounterSet(counterSetName),
1124 arm::pipe::InvalidArgumentException);
1125 CHECK(counterDirectory.GetCounterSetCount() == 1);
1126 CHECK(!counterSetSameName);
1129 const std::string counterSetWCountName =
"some_counter_set_with_count";
1130 const CounterSet* counterSetWCount =
nullptr;
1131 CHECK_NOTHROW(counterSetWCount = counterDirectory.RegisterCounterSet(counterSetWCountName, 37));
1132 CHECK(counterDirectory.GetCounterSetCount() == 2);
1133 CHECK(counterSetWCount);
1134 CHECK(counterSetWCount->m_Name == counterSetWCountName);
1135 CHECK(counterSetWCount->m_Uid >= 1);
1136 CHECK(counterSetWCount->m_Uid > counterSet->m_Uid);
1137 CHECK(counterSetWCount->m_Count == 37);
1140 const CounterSet* registeredCounterSetWCount = counterDirectory.GetCounterSet(counterSetWCount->m_Uid);
1141 CHECK(counterDirectory.GetCounterSetCount() == 2);
1142 CHECK(registeredCounterSetWCount);
1143 CHECK(registeredCounterSetWCount == counterSetWCount);
1144 CHECK(registeredCounterSetWCount != counterSet);
1147 const std::string counterSetWCountWInvalidParentCategoryName =
"some_counter_set_with_count_" 1148 "with_invalid_parent_category";
1149 const CounterSet* counterSetWCountWInvalidParentCategory =
nullptr;
1150 CHECK_THROWS_AS(counterSetWCountWInvalidParentCategory = counterDirectory.RegisterCounterSet(
1151 counterSetWCountWInvalidParentCategoryName, 42, std::string(
"")),
1152 arm::pipe::InvalidArgumentException);
1153 CHECK(counterDirectory.GetCounterSetCount() == 2);
1154 CHECK(!counterSetWCountWInvalidParentCategory);
1157 const std::string counterSetWCountWInvalidParentCategoryName2 =
"some_counter_set_with_count_" 1158 "with_invalid_parent_category2";
1159 const CounterSet* counterSetWCountWInvalidParentCategory2 =
nullptr;
1160 CHECK_THROWS_AS(counterSetWCountWInvalidParentCategory2 = counterDirectory.RegisterCounterSet(
1161 counterSetWCountWInvalidParentCategoryName2, 42, std::string(
"invalid_parent_category")),
1162 arm::pipe::InvalidArgumentException);
1163 CHECK(counterDirectory.GetCounterSetCount() == 2);
1164 CHECK(!counterSetWCountWInvalidParentCategory2);
1167 const std::string categoryName =
"some_category";
1168 const Category* category =
nullptr;
1169 CHECK_NOTHROW(category = counterDirectory.RegisterCategory(categoryName));
1170 CHECK(counterDirectory.GetCategoryCount() == 1);
1172 CHECK(category->m_Name == categoryName);
1173 CHECK(category->m_Counters.empty());
1176 const std::string counterSetWCountWValidParentCategoryName =
"some_counter_set_with_count_" 1177 "with_valid_parent_category";
1178 const CounterSet* counterSetWCountWValidParentCategory =
nullptr;
1179 CHECK_NOTHROW(counterSetWCountWValidParentCategory = counterDirectory.RegisterCounterSet(
1180 counterSetWCountWValidParentCategoryName, 42, categoryName));
1181 CHECK(counterDirectory.GetCounterSetCount() == 3);
1182 CHECK(counterSetWCountWValidParentCategory);
1183 CHECK(counterSetWCountWValidParentCategory->m_Name == counterSetWCountWValidParentCategoryName);
1184 CHECK(counterSetWCountWValidParentCategory->m_Uid >= 1);
1185 CHECK(counterSetWCountWValidParentCategory->m_Uid > counterSet->m_Uid);
1186 CHECK(counterSetWCountWValidParentCategory->m_Uid > counterSetWCount->m_Uid);
1187 CHECK(counterSetWCountWValidParentCategory->m_Count == 42);
1190 const std::string counterSetSameCategoryName =
"some_counter_set_with_invalid_parent_category";
1191 const std::string invalidCategoryName =
"";
1192 const CounterSet* counterSetSameCategory =
nullptr;
1193 CHECK_THROWS_AS(counterSetSameCategory =
1194 counterDirectory.RegisterCounterSet(counterSetSameCategoryName, 0, invalidCategoryName),
1195 arm::pipe::InvalidArgumentException);
1196 CHECK(counterDirectory.GetCounterSetCount() == 3);
1197 CHECK(!counterSetSameCategory);
1200 TEST_CASE(
"CheckCounterDirectoryRegisterCounter")
1202 CounterDirectory counterDirectory;
1203 CHECK(counterDirectory.GetCategoryCount() == 0);
1204 CHECK(counterDirectory.GetDeviceCount() == 0);
1205 CHECK(counterDirectory.GetCounterSetCount() == 0);
1206 CHECK(counterDirectory.GetCounterCount() == 0);
1209 const Counter* noCounter =
nullptr;
1210 CHECK_THROWS_AS(noCounter =
1211 counterDirectory.RegisterCounter(armnn::profiling::BACKEND_ID,
1219 arm::pipe::InvalidArgumentException);
1220 CHECK(counterDirectory.GetCounterCount() == 0);
1224 CHECK_THROWS_AS(noCounter = counterDirectory.RegisterCounter(armnn::profiling::BACKEND_ID,
1226 "invalid parent category",
1231 "valid description"),
1232 arm::pipe::InvalidArgumentException);
1233 CHECK(counterDirectory.GetCounterCount() == 0);
1237 CHECK_THROWS_AS(noCounter = counterDirectory.RegisterCounter(armnn::profiling::BACKEND_ID,
1239 "valid_parent_category",
1245 "valid description"),
1246 arm::pipe::InvalidArgumentException);
1247 CHECK(counterDirectory.GetCounterCount() == 0);
1251 CHECK_THROWS_AS(noCounter = counterDirectory.RegisterCounter(armnn::profiling::BACKEND_ID,
1253 "valid_parent_category",
1259 "valid description"),
1260 arm::pipe::InvalidArgumentException);
1261 CHECK(counterDirectory.GetCounterCount() == 0);
1265 CHECK_THROWS_AS(noCounter = counterDirectory.RegisterCounter(armnn::profiling::BACKEND_ID,
1267 "valid_parent_category",
1273 "valid description"),
1274 arm::pipe::InvalidArgumentException);
1275 CHECK(counterDirectory.GetCounterCount() == 0);
1280 noCounter = counterDirectory.RegisterCounter(armnn::profiling::BACKEND_ID,
1282 "valid_parent_category",
1287 "valid description"),
1288 arm::pipe::InvalidArgumentException);
1289 CHECK(counterDirectory.GetCounterCount() == 0);
1293 CHECK_THROWS_AS(noCounter = counterDirectory.RegisterCounter(armnn::profiling::BACKEND_ID,
1295 "valid_parent_category",
1300 "valid description"),
1301 arm::pipe::InvalidArgumentException);
1302 CHECK(counterDirectory.GetCounterCount() == 0);
1306 CHECK_THROWS_AS(noCounter =
1307 counterDirectory.RegisterCounter(armnn::profiling::BACKEND_ID,
1309 "valid_parent_category",
1315 arm::pipe::InvalidArgumentException);
1316 CHECK(counterDirectory.GetCounterCount() == 0);
1320 CHECK_THROWS_AS(noCounter = counterDirectory.RegisterCounter(armnn::profiling::BACKEND_ID,
1322 "valid_parent_category",
1328 "inv@lid description"),
1329 arm::pipe::InvalidArgumentException);
1330 CHECK(counterDirectory.GetCounterCount() == 0);
1334 CHECK_THROWS_AS(noCounter = counterDirectory.RegisterCounter(armnn::profiling::BACKEND_ID,
1336 "valid_parent_category",
1341 "valid description",
1342 std::string(
"Mb/s2")),
1343 arm::pipe::InvalidArgumentException);
1344 CHECK(counterDirectory.GetCounterCount() == 0);
1348 CHECK_THROWS_AS(noCounter = counterDirectory.RegisterCounter(armnn::profiling::BACKEND_ID,
1350 "invalid_parent_category",
1355 "valid description"),
1356 arm::pipe::InvalidArgumentException);
1357 CHECK(counterDirectory.GetCounterCount() == 0);
1361 const Counter* unregisteredCounter = counterDirectory.GetCounter(9999);
1362 CHECK(!unregisteredCounter);
1365 const std::string categoryName =
"some_category";
1366 const Category* category =
nullptr;
1367 CHECK_NOTHROW(category = counterDirectory.RegisterCategory(categoryName));
1368 CHECK(counterDirectory.GetCategoryCount() == 1);
1370 CHECK(category->m_Name == categoryName);
1371 CHECK(category->m_Counters.empty());
1374 const Counter* counter =
nullptr;
1376 counter = counterDirectory.RegisterCounter(armnn::profiling::BACKEND_ID,
1383 "valid description"));
1384 CHECK(counterDirectory.GetCounterCount() == 1);
1386 CHECK(counter->m_MaxCounterUid == counter->m_Uid);
1387 CHECK(counter->m_Class == 0);
1388 CHECK(counter->m_Interpolation == 1);
1389 CHECK(counter->m_Multiplier == 123.45f);
1390 CHECK(counter->m_Name ==
"valid name");
1391 CHECK(counter->m_Description ==
"valid description");
1392 CHECK(counter->m_Units ==
"");
1393 CHECK(counter->m_DeviceUid == 0);
1394 CHECK(counter->m_CounterSetUid == 0);
1395 CHECK(category->m_Counters.size() == 1);
1396 CHECK(category->m_Counters.back() == counter->m_Uid);
1399 const Counter* counterSameName =
nullptr;
1400 CHECK_THROWS_AS(counterSameName =
1401 counterDirectory.RegisterCounter(armnn::profiling::BACKEND_ID,
1408 "valid description",
1409 std::string(
"description")),
1410 arm::pipe::InvalidArgumentException);
1411 CHECK(counterDirectory.GetCounterCount() == 1);
1412 CHECK(!counterSameName);
1415 const Counter* counterWUnits =
nullptr;
1416 CHECK_NOTHROW(counterWUnits = counterDirectory.RegisterCounter(armnn::profiling::BACKEND_ID,
1423 "valid description",
1424 std::string(
"Mnnsq2")));
1425 CHECK(counterDirectory.GetCounterCount() == 2);
1426 CHECK(counterWUnits);
1427 CHECK(counterWUnits->m_Uid > counter->m_Uid);
1428 CHECK(counterWUnits->m_MaxCounterUid == counterWUnits->m_Uid);
1429 CHECK(counterWUnits->m_Class == 0);
1430 CHECK(counterWUnits->m_Interpolation == 1);
1431 CHECK(counterWUnits->m_Multiplier == 123.45f);
1432 CHECK(counterWUnits->m_Name ==
"valid name 2");
1433 CHECK(counterWUnits->m_Description ==
"valid description");
1434 CHECK(counterWUnits->m_Units ==
"Mnnsq2");
1435 CHECK(counterWUnits->m_DeviceUid == 0);
1436 CHECK(counterWUnits->m_CounterSetUid == 0);
1437 CHECK(category->m_Counters.size() == 2);
1438 CHECK(category->m_Counters.back() == counterWUnits->m_Uid);
1441 const Counter* counterWoDevice =
nullptr;
1442 CHECK_NOTHROW(counterWoDevice = counterDirectory.RegisterCounter(armnn::profiling::BACKEND_ID,
1449 "valid description",
1450 arm::pipe::EmptyOptional(),
1451 arm::pipe::EmptyOptional(),
1453 CHECK(counterDirectory.GetCounterCount() == 3);
1454 CHECK(counterWoDevice);
1455 CHECK(counterWoDevice->m_Uid > counter->m_Uid);
1456 CHECK(counterWoDevice->m_MaxCounterUid == counterWoDevice->m_Uid);
1457 CHECK(counterWoDevice->m_Class == 0);
1458 CHECK(counterWoDevice->m_Interpolation == 1);
1459 CHECK(counterWoDevice->m_Multiplier == 123.45f);
1460 CHECK(counterWoDevice->m_Name ==
"valid name 3");
1461 CHECK(counterWoDevice->m_Description ==
"valid description");
1462 CHECK(counterWoDevice->m_Units ==
"");
1463 CHECK(counterWoDevice->m_DeviceUid == 0);
1464 CHECK(counterWoDevice->m_CounterSetUid == 0);
1465 CHECK(category->m_Counters.size() == 3);
1466 CHECK(category->m_Counters.back() == counterWoDevice->m_Uid);
1469 CHECK_THROWS_AS(noCounter = counterDirectory.RegisterCounter(armnn::profiling::BACKEND_ID,
1476 "valid description",
1477 arm::pipe::EmptyOptional(),
1478 arm::pipe::EmptyOptional(),
1480 arm::pipe::InvalidArgumentException);
1481 CHECK(counterDirectory.GetCounterCount() == 3);
1485 const std::string deviceName =
"some_device";
1486 const Device* device =
nullptr;
1487 CHECK_NOTHROW(device = counterDirectory.RegisterDevice(deviceName));
1488 CHECK(counterDirectory.GetDeviceCount() == 1);
1490 CHECK(device->m_Name == deviceName);
1491 CHECK(device->m_Uid >= 1);
1492 CHECK(device->m_Cores == 0);
1495 const Counter* counterWDevice =
nullptr;
1496 CHECK_NOTHROW(counterWDevice = counterDirectory.RegisterCounter(armnn::profiling::BACKEND_ID,
1503 std::string(
"valid description"),
1504 arm::pipe::EmptyOptional(),
1505 arm::pipe::EmptyOptional(),
1507 CHECK(counterDirectory.GetCounterCount() == 4);
1508 CHECK(counterWDevice);
1509 CHECK(counterWDevice->m_Uid > counter->m_Uid);
1510 CHECK(counterWDevice->m_MaxCounterUid == counterWDevice->m_Uid);
1511 CHECK(counterWDevice->m_Class == 0);
1512 CHECK(counterWDevice->m_Interpolation == 1);
1513 CHECK(counterWDevice->m_Multiplier == 123.45f);
1514 CHECK(counterWDevice->m_Name ==
"valid name 5");
1515 CHECK(counterWDevice->m_Description ==
"valid description");
1516 CHECK(counterWDevice->m_Units ==
"");
1517 CHECK(counterWDevice->m_DeviceUid == device->m_Uid);
1518 CHECK(counterWDevice->m_CounterSetUid == 0);
1519 CHECK(category->m_Counters.size() == 4);
1520 CHECK(category->m_Counters.back() == counterWDevice->m_Uid);
1523 const Counter* counterWoCounterSet =
nullptr;
1524 CHECK_NOTHROW(counterWoCounterSet = counterDirectory.RegisterCounter(armnn::profiling::BACKEND_ID,
1531 "valid description",
1532 arm::pipe::EmptyOptional(),
1533 arm::pipe::EmptyOptional(),
1534 arm::pipe::EmptyOptional(),
1536 CHECK(counterDirectory.GetCounterCount() == 5);
1537 CHECK(counterWoCounterSet);
1538 CHECK(counterWoCounterSet->m_Uid > counter->m_Uid);
1539 CHECK(counterWoCounterSet->m_MaxCounterUid == counterWoCounterSet->m_Uid);
1540 CHECK(counterWoCounterSet->m_Class == 0);
1541 CHECK(counterWoCounterSet->m_Interpolation == 1);
1542 CHECK(counterWoCounterSet->m_Multiplier == 123.45f);
1543 CHECK(counterWoCounterSet->m_Name ==
"valid name 6");
1544 CHECK(counterWoCounterSet->m_Description ==
"valid description");
1545 CHECK(counterWoCounterSet->m_Units ==
"");
1546 CHECK(counterWoCounterSet->m_DeviceUid == 0);
1547 CHECK(counterWoCounterSet->m_CounterSetUid == 0);
1548 CHECK(category->m_Counters.size() == 5);
1549 CHECK(category->m_Counters.back() == counterWoCounterSet->m_Uid);
1552 CHECK_THROWS_AS(noCounter = counterDirectory.RegisterCounter(armnn::profiling::BACKEND_ID,
1560 std::string(
"valid description"),
1561 arm::pipe::EmptyOptional(),
1562 arm::pipe::EmptyOptional(),
1564 arm::pipe::InvalidArgumentException);
1565 CHECK(counterDirectory.GetCounterCount() == 5);
1569 const Counter* counterWNumberOfCores =
nullptr;
1570 uint16_t numberOfCores = 15;
1571 CHECK_NOTHROW(counterWNumberOfCores = counterDirectory.RegisterCounter(
1572 armnn::profiling::BACKEND_ID, 50,
1573 categoryName, 0, 1, 123.45f,
"valid name 8",
"valid description",
1574 arm::pipe::EmptyOptional(),
1576 arm::pipe::EmptyOptional(),
1577 arm::pipe::EmptyOptional()));
1578 CHECK(counterDirectory.GetCounterCount() == 20);
1579 CHECK(counterWNumberOfCores);
1580 CHECK(counterWNumberOfCores->m_Uid > counter->m_Uid);
1581 CHECK(counterWNumberOfCores->m_MaxCounterUid == counterWNumberOfCores->m_Uid + numberOfCores - 1);
1582 CHECK(counterWNumberOfCores->m_Class == 0);
1583 CHECK(counterWNumberOfCores->m_Interpolation == 1);
1584 CHECK(counterWNumberOfCores->m_Multiplier == 123.45f);
1585 CHECK(counterWNumberOfCores->m_Name ==
"valid name 8");
1586 CHECK(counterWNumberOfCores->m_Description ==
"valid description");
1587 CHECK(counterWNumberOfCores->m_Units ==
"");
1588 CHECK(counterWNumberOfCores->m_DeviceUid == 0);
1589 CHECK(counterWNumberOfCores->m_CounterSetUid == 0);
1590 CHECK(category->m_Counters.size() == 20);
1591 for (
size_t i = 0; i < numberOfCores; i++)
1593 CHECK(category->m_Counters[category->m_Counters.size() - numberOfCores + i] ==
1594 counterWNumberOfCores->m_Uid + i);
1598 const std::string multiCoreDeviceName =
"some_multi_core_device";
1599 const Device* multiCoreDevice =
nullptr;
1600 CHECK_NOTHROW(multiCoreDevice = counterDirectory.RegisterDevice(multiCoreDeviceName, 4));
1601 CHECK(counterDirectory.GetDeviceCount() == 2);
1602 CHECK(multiCoreDevice);
1603 CHECK(multiCoreDevice->m_Name == multiCoreDeviceName);
1604 CHECK(multiCoreDevice->m_Uid >= 1);
1605 CHECK(multiCoreDevice->m_Cores == 4);
1608 const Counter* counterWMultiCoreDevice =
nullptr;
1609 CHECK_NOTHROW(counterWMultiCoreDevice = counterDirectory.RegisterCounter(
1610 armnn::profiling::BACKEND_ID, 19, categoryName, 0, 1,
1611 123.45f,
"valid name 9",
"valid description",
1612 arm::pipe::EmptyOptional(),
1613 arm::pipe::EmptyOptional(),
1614 multiCoreDevice->m_Uid,
1615 arm::pipe::EmptyOptional()));
1616 CHECK(counterDirectory.GetCounterCount() == 24);
1617 CHECK(counterWMultiCoreDevice);
1618 CHECK(counterWMultiCoreDevice->m_Uid > counter->m_Uid);
1619 CHECK(counterWMultiCoreDevice->m_MaxCounterUid ==
1620 counterWMultiCoreDevice->m_Uid + multiCoreDevice->m_Cores - 1);
1621 CHECK(counterWMultiCoreDevice->m_Class == 0);
1622 CHECK(counterWMultiCoreDevice->m_Interpolation == 1);
1623 CHECK(counterWMultiCoreDevice->m_Multiplier == 123.45f);
1624 CHECK(counterWMultiCoreDevice->m_Name ==
"valid name 9");
1625 CHECK(counterWMultiCoreDevice->m_Description ==
"valid description");
1626 CHECK(counterWMultiCoreDevice->m_Units ==
"");
1627 CHECK(counterWMultiCoreDevice->m_DeviceUid == multiCoreDevice->m_Uid);
1628 CHECK(counterWMultiCoreDevice->m_CounterSetUid == 0);
1629 CHECK(category->m_Counters.size() == 24);
1630 for (
size_t i = 0; i < 4; i++)
1632 CHECK(category->m_Counters[category->m_Counters.size() - 4 + i] == counterWMultiCoreDevice->m_Uid + i);
1636 const std::string multiCoreDeviceNameWParentCategory =
"some_multi_core_device_with_parent_category";
1637 const Device* multiCoreDeviceWParentCategory =
nullptr;
1638 CHECK_NOTHROW(multiCoreDeviceWParentCategory =
1639 counterDirectory.RegisterDevice(multiCoreDeviceNameWParentCategory, 2, categoryName));
1640 CHECK(counterDirectory.GetDeviceCount() == 3);
1641 CHECK(multiCoreDeviceWParentCategory);
1642 CHECK(multiCoreDeviceWParentCategory->m_Name == multiCoreDeviceNameWParentCategory);
1643 CHECK(multiCoreDeviceWParentCategory->m_Uid >= 1);
1644 CHECK(multiCoreDeviceWParentCategory->m_Cores == 2);
1648 const Counter* counterWMultiCoreDeviceWParentCategory =
nullptr;
1649 uint16_t numberOfCourse = multiCoreDeviceWParentCategory->m_Cores;
1650 CHECK_NOTHROW(counterWMultiCoreDeviceWParentCategory =
1651 counterDirectory.RegisterCounter(
1652 armnn::profiling::BACKEND_ID,
1659 "valid description",
1660 arm::pipe::EmptyOptional(),
1662 arm::pipe::EmptyOptional(),
1663 arm::pipe::EmptyOptional()));
1664 CHECK(counterDirectory.GetCounterCount() == 26);
1665 CHECK(counterWMultiCoreDeviceWParentCategory);
1666 CHECK(counterWMultiCoreDeviceWParentCategory->m_Uid > counter->m_Uid);
1667 CHECK(counterWMultiCoreDeviceWParentCategory->m_MaxCounterUid ==
1668 counterWMultiCoreDeviceWParentCategory->m_Uid + multiCoreDeviceWParentCategory->m_Cores - 1);
1669 CHECK(counterWMultiCoreDeviceWParentCategory->m_Class == 0);
1670 CHECK(counterWMultiCoreDeviceWParentCategory->m_Interpolation == 1);
1671 CHECK(counterWMultiCoreDeviceWParentCategory->m_Multiplier == 123.45f);
1672 CHECK(counterWMultiCoreDeviceWParentCategory->m_Name ==
"valid name 10");
1673 CHECK(counterWMultiCoreDeviceWParentCategory->m_Description ==
"valid description");
1674 CHECK(counterWMultiCoreDeviceWParentCategory->m_Units ==
"");
1675 CHECK(category->m_Counters.size() == 26);
1676 for (
size_t i = 0; i < 2; i++)
1678 CHECK(category->m_Counters[category->m_Counters.size() - 2 + i] ==
1679 counterWMultiCoreDeviceWParentCategory->m_Uid + i);
1683 const std::string counterSetName =
"some_counter_set";
1684 const CounterSet* counterSet =
nullptr;
1685 CHECK_NOTHROW(counterSet = counterDirectory.RegisterCounterSet(counterSetName));
1686 CHECK(counterDirectory.GetCounterSetCount() == 1);
1688 CHECK(counterSet->m_Name == counterSetName);
1689 CHECK(counterSet->m_Uid >= 1);
1690 CHECK(counterSet->m_Count == 0);
1693 const Counter* counterWCounterSet =
nullptr;
1694 CHECK_NOTHROW(counterWCounterSet = counterDirectory.RegisterCounter(
1695 armnn::profiling::BACKEND_ID, 300,
1696 categoryName, 0, 1, 123.45f,
"valid name 11",
"valid description",
1697 arm::pipe::EmptyOptional(),
1699 arm::pipe::EmptyOptional(),
1700 counterSet->m_Uid));
1701 CHECK(counterDirectory.GetCounterCount() == 27);
1702 CHECK(counterWCounterSet);
1703 CHECK(counterWCounterSet->m_Uid > counter->m_Uid);
1704 CHECK(counterWCounterSet->m_MaxCounterUid == counterWCounterSet->m_Uid);
1705 CHECK(counterWCounterSet->m_Class == 0);
1706 CHECK(counterWCounterSet->m_Interpolation == 1);
1707 CHECK(counterWCounterSet->m_Multiplier == 123.45f);
1708 CHECK(counterWCounterSet->m_Name ==
"valid name 11");
1709 CHECK(counterWCounterSet->m_Description ==
"valid description");
1710 CHECK(counterWCounterSet->m_Units ==
"");
1711 CHECK(counterWCounterSet->m_DeviceUid == 0);
1712 CHECK(counterWCounterSet->m_CounterSetUid == counterSet->m_Uid);
1713 CHECK(category->m_Counters.size() == 27);
1714 CHECK(category->m_Counters.back() == counterWCounterSet->m_Uid);
1717 const Counter* counterWDeviceWCounterSet =
nullptr;
1718 CHECK_NOTHROW(counterWDeviceWCounterSet = counterDirectory.RegisterCounter(
1719 armnn::profiling::BACKEND_ID, 23,
1720 categoryName, 0, 1, 123.45f,
"valid name 12",
"valid description",
1721 arm::pipe::EmptyOptional(),
1724 counterSet->m_Uid));
1725 CHECK(counterDirectory.GetCounterCount() == 28);
1726 CHECK(counterWDeviceWCounterSet);
1727 CHECK(counterWDeviceWCounterSet->m_Uid > counter->m_Uid);
1728 CHECK(counterWDeviceWCounterSet->m_MaxCounterUid == counterWDeviceWCounterSet->m_Uid);
1729 CHECK(counterWDeviceWCounterSet->m_Class == 0);
1730 CHECK(counterWDeviceWCounterSet->m_Interpolation == 1);
1731 CHECK(counterWDeviceWCounterSet->m_Multiplier == 123.45f);
1732 CHECK(counterWDeviceWCounterSet->m_Name ==
"valid name 12");
1733 CHECK(counterWDeviceWCounterSet->m_Description ==
"valid description");
1734 CHECK(counterWDeviceWCounterSet->m_Units ==
"");
1735 CHECK(counterWDeviceWCounterSet->m_DeviceUid == device->m_Uid);
1736 CHECK(counterWDeviceWCounterSet->m_CounterSetUid == counterSet->m_Uid);
1737 CHECK(category->m_Counters.size() == 28);
1738 CHECK(category->m_Counters.back() == counterWDeviceWCounterSet->m_Uid);
1741 const std::string anotherCategoryName =
"some_other_category";
1742 const Category* anotherCategory =
nullptr;
1743 CHECK_NOTHROW(anotherCategory = counterDirectory.RegisterCategory(anotherCategoryName));
1744 CHECK(counterDirectory.GetCategoryCount() == 2);
1745 CHECK(anotherCategory);
1746 CHECK(anotherCategory != category);
1747 CHECK(anotherCategory->m_Name == anotherCategoryName);
1748 CHECK(anotherCategory->m_Counters.empty());
1751 const Counter* anotherCounter =
nullptr;
1752 CHECK_NOTHROW(anotherCounter = counterDirectory.RegisterCounter(armnn::profiling::BACKEND_ID, 24,
1753 anotherCategoryName, 1, 0, .00043f,
1754 "valid name",
"valid description",
1755 arm::pipe::EmptyOptional(),
1756 arm::pipe::EmptyOptional(),
1758 counterSet->m_Uid));
1759 CHECK(counterDirectory.GetCounterCount() == 29);
1760 CHECK(anotherCounter);
1761 CHECK(anotherCounter->m_MaxCounterUid == anotherCounter->m_Uid);
1762 CHECK(anotherCounter->m_Class == 1);
1763 CHECK(anotherCounter->m_Interpolation == 0);
1764 CHECK(anotherCounter->m_Multiplier == .00043f);
1765 CHECK(anotherCounter->m_Name ==
"valid name");
1766 CHECK(anotherCounter->m_Description ==
"valid description");
1767 CHECK(anotherCounter->m_Units ==
"");
1768 CHECK(anotherCounter->m_DeviceUid == device->m_Uid);
1769 CHECK(anotherCounter->m_CounterSetUid == counterSet->m_Uid);
1770 CHECK(anotherCategory->m_Counters.size() == 1);
1771 CHECK(anotherCategory->m_Counters.back() == anotherCounter->m_Uid);
1774 TEST_CASE(
"CounterSelectionCommandHandlerParseData")
1776 ProfilingStateMachine profilingStateMachine;
1778 class TestCaptureThread :
public IPeriodicCounterCapture
1780 void Start()
override 1782 void Stop()
override 1786 class TestReadCounterValues :
public IReadCounterValues
1788 bool IsCounterRegistered(uint16_t counterUid)
const override 1793 bool IsCounterRegistered(
const std::string& counterName)
const override 1798 uint16_t GetCounterCount()
const override 1802 uint32_t GetAbsoluteCounterValue(uint16_t counterUid)
const override 1807 uint32_t GetDeltaCounterValue(uint16_t counterUid)
override 1813 const uint32_t familyId = 0;
1814 const uint32_t packetId = 0x40000;
1816 uint32_t version = 1;
1817 const std::unordered_map<std::string,
1818 std::shared_ptr<IBackendProfilingContext>> backendProfilingContext;
1819 CounterIdMap counterIdMap;
1821 TestCaptureThread captureThread;
1822 TestReadCounterValues readCounterValues;
1824 SendCounterPacket sendCounterPacket(mockBuffer,
1825 arm::pipe::ARMNN_SOFTWARE_INFO,
1826 arm::pipe::ARMNN_SOFTWARE_VERSION,
1827 arm::pipe::ARMNN_HARDWARE_VERSION);
1828 SendThread sendThread(profilingStateMachine, mockBuffer, sendCounterPacket);
1835 uint32_t dataLength1 = 8;
1836 uint32_t offset = 0;
1838 std::unique_ptr<unsigned char[]> uniqueData1 = std::make_unique<unsigned char[]>(dataLength1);
1839 unsigned char* data1 =
reinterpret_cast<unsigned char*
>(uniqueData1.get());
1841 WriteUint32(data1, offset, period1);
1842 offset += sizeOfUint32;
1843 WriteUint16(data1, offset, 4000);
1844 offset += sizeOfUint16;
1845 WriteUint16(data1, offset, 5000);
1847 arm::pipe::Packet packetA(packetId, dataLength1, uniqueData1);
1849 PeriodicCounterSelectionCommandHandler commandHandler(familyId, packetId, version, backendProfilingContext,
1850 counterIdMap, holder, 10000u, captureThread,
1851 readCounterValues, sendCounterPacket, profilingStateMachine);
1853 profilingStateMachine.TransitionToState(ProfilingState::Uninitialised);
1854 CHECK_THROWS_AS(commandHandler(packetA), arm::pipe::ProfilingException);
1855 profilingStateMachine.TransitionToState(ProfilingState::NotConnected);
1856 CHECK_THROWS_AS(commandHandler(packetA), arm::pipe::ProfilingException);
1857 profilingStateMachine.TransitionToState(ProfilingState::WaitingForAck);
1858 CHECK_THROWS_AS(commandHandler(packetA), arm::pipe::ProfilingException);
1859 profilingStateMachine.TransitionToState(ProfilingState::Active);
1860 CHECK_NOTHROW(commandHandler(packetA));
1862 const std::vector<uint16_t> counterIdsA = holder.GetCaptureData().GetCounterIds();
1864 CHECK(holder.GetCaptureData().GetCapturePeriod() == period1);
1865 CHECK(counterIdsA.size() == 2);
1866 CHECK(counterIdsA[0] == 4000);
1867 CHECK(counterIdsA[1] == 5000);
1869 auto readBuffer = mockBuffer.GetReadableBuffer();
1873 uint32_t headerWord0 = ReadUint32(readBuffer, offset);
1874 offset += sizeOfUint32;
1875 uint32_t headerWord1 = ReadUint32(readBuffer, offset);
1876 offset += sizeOfUint32;
1877 uint32_t period = ReadUint32(readBuffer, offset);
1879 CHECK(((headerWord0 >> 26) & 0x3F) == 0);
1880 CHECK(((headerWord0 >> 16) & 0x3FF) == 4);
1881 CHECK(headerWord1 == 8);
1884 uint16_t counterId = 0;
1885 offset += sizeOfUint32;
1886 counterId = ReadUint16(readBuffer, offset);
1887 CHECK(counterId == 4000);
1888 offset += sizeOfUint16;
1889 counterId = ReadUint16(readBuffer, offset);
1890 CHECK(counterId == 5000);
1892 mockBuffer.MarkRead(readBuffer);
1895 uint32_t period2 = 9000;
1896 uint32_t dataLength2 = 4;
1898 std::unique_ptr<unsigned char[]> uniqueData2 = std::make_unique<unsigned char[]>(dataLength2);
1900 WriteUint32(reinterpret_cast<unsigned char*>(uniqueData2.get()), 0, period2);
1902 arm::pipe::Packet packetB(packetId, dataLength2, uniqueData2);
1904 commandHandler(packetB);
1906 const std::vector<uint16_t> counterIdsB = holder.GetCaptureData().GetCounterIds();
1910 CHECK(counterIdsB.size() == 0);
1912 readBuffer = mockBuffer.GetReadableBuffer();
1916 headerWord0 = ReadUint32(readBuffer, offset);
1917 offset += sizeOfUint32;
1918 headerWord1 = ReadUint32(readBuffer, offset);
1919 offset += sizeOfUint32;
1920 period = ReadUint32(readBuffer, offset);
1922 CHECK(((headerWord0 >> 26) & 0x3F) == 0);
1923 CHECK(((headerWord0 >> 16) & 0x3FF) == 4);
1924 CHECK(headerWord1 == 4);
1928 TEST_CASE(
"CheckTimelineActivationAndDeactivation")
1933 virtual void ReportStructure(arm::pipe::IProfilingService& profilingService)
override 1936 m_ReportStructureCalled =
true;
1939 bool m_ReportStructureCalled =
false;
1942 class TestNotifyBackends :
public INotifyBackends
1945 TestNotifyBackends() : m_timelineReporting(false) {}
1946 virtual void NotifyBackendsForTimelineReporting()
override 1948 m_TestNotifyBackendsCalled = m_timelineReporting.load();
1951 bool m_TestNotifyBackendsCalled =
false;
1952 std::atomic<bool> m_timelineReporting;
1955 arm::pipe::PacketVersionResolver packetVersionResolver;
1957 BufferManager bufferManager(512);
1958 SendTimelinePacket sendTimelinePacket(bufferManager);
1959 ProfilingStateMachine stateMachine;
1960 TestReportStructure testReportStructure;
1961 TestNotifyBackends testNotifyBackends;
1963 ProfilingService profilingService(arm::pipe::MAX_ARMNN_COUNTER,
1965 arm::pipe::ARMNN_SOFTWARE_INFO,
1966 arm::pipe::ARMNN_SOFTWARE_VERSION,
1967 arm::pipe::ARMNN_HARDWARE_VERSION);
1970 ActivateTimelineReportingCommandHandler activateTimelineReportingCommandHandler(0,
1972 packetVersionResolver.ResolvePacketVersion(0, 6)
1976 testReportStructure,
1977 testNotifyBackends.m_timelineReporting,
1983 const uint32_t packetFamily1 = 0;
1984 const uint32_t packetId1 = 6;
1985 uint32_t packetHeader1 = ConstructHeader(packetFamily1, packetId1);
1988 arm::pipe::Packet ActivateTimelineReportingPacket(packetHeader1);
1991 activateTimelineReportingCommandHandler.operator()(ActivateTimelineReportingPacket),
1992 arm::pipe::ProfilingException);
1994 stateMachine.TransitionToState(ProfilingState::NotConnected);
1996 activateTimelineReportingCommandHandler.operator()(ActivateTimelineReportingPacket),
1997 arm::pipe::ProfilingException);
1999 stateMachine.TransitionToState(ProfilingState::WaitingForAck);
2001 activateTimelineReportingCommandHandler.operator()(ActivateTimelineReportingPacket),
2002 arm::pipe::ProfilingException);
2004 stateMachine.TransitionToState(ProfilingState::Active);
2005 activateTimelineReportingCommandHandler.operator()(ActivateTimelineReportingPacket);
2007 CHECK(testReportStructure.m_ReportStructureCalled);
2008 CHECK(testNotifyBackends.m_TestNotifyBackendsCalled);
2009 CHECK(testNotifyBackends.m_timelineReporting.load());
2011 DeactivateTimelineReportingCommandHandler deactivateTimelineReportingCommandHandler(0,
2013 packetVersionResolver.ResolvePacketVersion(0, 7).GetEncodedValue(),
2014 testNotifyBackends.m_timelineReporting,
2016 testNotifyBackends);
2018 const uint32_t packetFamily2 = 0;
2019 const uint32_t packetId2 = 7;
2020 uint32_t packetHeader2 = ConstructHeader(packetFamily2, packetId2);
2023 arm::pipe::Packet deactivateTimelineReportingPacket(packetHeader2);
2025 stateMachine.Reset();
2027 deactivateTimelineReportingCommandHandler.operator()(deactivateTimelineReportingPacket),
2028 arm::pipe::ProfilingException);
2030 stateMachine.TransitionToState(ProfilingState::NotConnected);
2032 deactivateTimelineReportingCommandHandler.operator()(deactivateTimelineReportingPacket),
2033 arm::pipe::ProfilingException);
2035 stateMachine.TransitionToState(ProfilingState::WaitingForAck);
2037 deactivateTimelineReportingCommandHandler.operator()(deactivateTimelineReportingPacket),
2038 arm::pipe::ProfilingException);
2040 stateMachine.TransitionToState(ProfilingState::Active);
2041 deactivateTimelineReportingCommandHandler.operator()(deactivateTimelineReportingPacket);
2043 CHECK(!testNotifyBackends.m_TestNotifyBackendsCalled);
2044 CHECK(!testNotifyBackends.m_timelineReporting.load());
2047 TEST_CASE(
"CheckProfilingServiceNotActive")
2049 using namespace armnn;
2059 profilingServiceHelper.ForceTransitionToState(ProfilingState::NotConnected);
2060 profilingServiceHelper.ForceTransitionToState(ProfilingState::WaitingForAck);
2061 profilingServiceHelper.ForceTransitionToState(ProfilingState::Active);
2063 BufferManager& bufferManager = profilingServiceHelper.GetProfilingBufferManager();
2064 auto readableBuffer = bufferManager.GetReadableBuffer();
2067 CHECK(readableBuffer ==
nullptr);
2070 TEST_CASE(
"CheckConnectionAcknowledged")
2072 const uint32_t packetFamilyId = 0;
2073 const uint32_t connectionPacketId = 0x10000;
2074 const uint32_t version = 1;
2080 uint32_t period1 = 10;
2081 uint32_t dataLength1 = 8;
2082 uint32_t offset = 0;
2084 std::unique_ptr<unsigned char[]> uniqueData1 = std::make_unique<unsigned char[]>(dataLength1);
2085 unsigned char* data1 =
reinterpret_cast<unsigned char*
>(uniqueData1.get());
2087 WriteUint32(data1, offset, period1);
2088 offset += sizeOfUint32;
2089 WriteUint16(data1, offset, 4000);
2090 offset += sizeOfUint16;
2091 WriteUint16(data1, offset, 5000);
2093 arm::pipe::Packet packetA(connectionPacketId, dataLength1, uniqueData1);
2095 ProfilingStateMachine profilingState(ProfilingState::Uninitialised);
2096 CHECK(profilingState.GetCurrentState() == ProfilingState::Uninitialised);
2097 CounterDirectory counterDirectory;
2099 SendCounterPacket sendCounterPacket(mockBuffer,
2100 arm::pipe::ARMNN_SOFTWARE_INFO,
2101 arm::pipe::ARMNN_SOFTWARE_VERSION,
2102 arm::pipe::ARMNN_HARDWARE_VERSION);
2103 SendThread sendThread(profilingState, mockBuffer, sendCounterPacket);
2104 SendTimelinePacket sendTimelinePacket(mockBuffer);
2107 ConnectionAcknowledgedCommandHandler commandHandler(packetFamilyId,
2114 mockProfilingServiceStatus);
2117 CHECK_THROWS_AS(commandHandler(packetA), arm::pipe::ProfilingException);
2119 profilingState.TransitionToState(ProfilingState::NotConnected);
2120 CHECK(profilingState.GetCurrentState() == ProfilingState::NotConnected);
2122 CHECK_THROWS_AS(commandHandler(packetA), arm::pipe::ProfilingException);
2124 profilingState.TransitionToState(ProfilingState::WaitingForAck);
2125 CHECK(profilingState.GetCurrentState() == ProfilingState::WaitingForAck);
2127 CHECK_NOTHROW(commandHandler(packetA));
2128 CHECK(profilingState.GetCurrentState() == ProfilingState::Active);
2131 CHECK_NOTHROW(commandHandler(packetA));
2132 CHECK(profilingState.GetCurrentState() == ProfilingState::Active);
2135 const uint32_t differentPacketId = 0x40000;
2136 arm::pipe::Packet packetB(differentPacketId, dataLength1, uniqueData1);
2137 profilingState.TransitionToState(ProfilingState::NotConnected);
2138 profilingState.TransitionToState(ProfilingState::WaitingForAck);
2139 ConnectionAcknowledgedCommandHandler differentCommandHandler(packetFamilyId,
2146 mockProfilingServiceStatus);
2147 CHECK_THROWS_AS(differentCommandHandler(packetB), arm::pipe::ProfilingException);
2150 TEST_CASE(
"CheckSocketConnectionException")
2153 CHECK_THROWS_AS(
new SocketProfilingConnection(), arm::pipe::SocketConnectionException);
2156 TEST_CASE(
"CheckSocketConnectionException2")
2160 new SocketProfilingConnection();
2162 catch (
const arm::pipe::SocketConnectionException& ex)
2164 CHECK(ex.GetSocketFd() == 0);
2165 CHECK(ex.GetErrorNo() == ECONNREFUSED);
2167 == std::string(
"SocketProfilingConnection: Cannot connect to stream socket: Connection refused"));
2171 TEST_CASE(
"SwTraceIsValidCharTest")
2174 for (
unsigned char c = 0; c < 128; c++)
2176 CHECK(arm::pipe::SwTraceCharPolicy::IsValidChar(c));
2180 for (
unsigned char c = 255; c >= 128; c++)
2182 CHECK(!arm::pipe::SwTraceCharPolicy::IsValidChar(c));
2186 TEST_CASE(
"SwTraceIsValidNameCharTest")
2189 const unsigned char validChars[] =
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_";
2190 for (
unsigned char i = 0; i <
sizeof(validChars) /
sizeof(validChars[0]) - 1; i++)
2192 CHECK(arm::pipe::SwTraceNameCharPolicy::IsValidChar(validChars[i]));
2196 for (
unsigned char c = 0; c < 48; c++)
2198 CHECK(!arm::pipe::SwTraceNameCharPolicy::IsValidChar(c));
2200 for (
unsigned char c = 58; c < 65; c++)
2202 CHECK(!arm::pipe::SwTraceNameCharPolicy::IsValidChar(c));
2204 for (
unsigned char c = 91; c < 95; c++)
2206 CHECK(!arm::pipe::SwTraceNameCharPolicy::IsValidChar(c));
2208 for (
unsigned char c = 96; c < 97; c++)
2210 CHECK(!arm::pipe::SwTraceNameCharPolicy::IsValidChar(c));
2212 for (
unsigned char c = 123; c < 128; c++)
2214 CHECK(!arm::pipe::SwTraceNameCharPolicy::IsValidChar(c));
2218 for (
unsigned char c = 255; c >= 128; c++)
2220 CHECK(!arm::pipe::SwTraceNameCharPolicy::IsValidChar(c));
2224 TEST_CASE(
"IsValidSwTraceStringTest")
2227 CHECK(arm::pipe::IsValidSwTraceString<arm::pipe::SwTraceCharPolicy>(
""));
2228 CHECK(arm::pipe::IsValidSwTraceString<arm::pipe::SwTraceCharPolicy>(
"_"));
2229 CHECK(arm::pipe::IsValidSwTraceString<arm::pipe::SwTraceCharPolicy>(
"0123"));
2230 CHECK(arm::pipe::IsValidSwTraceString<arm::pipe::SwTraceCharPolicy>(
"valid_string"));
2231 CHECK(arm::pipe::IsValidSwTraceString<arm::pipe::SwTraceCharPolicy>(
"VALID_string_456"));
2232 CHECK(arm::pipe::IsValidSwTraceString<arm::pipe::SwTraceCharPolicy>(
" "));
2233 CHECK(arm::pipe::IsValidSwTraceString<arm::pipe::SwTraceCharPolicy>(
"valid string"));
2234 CHECK(arm::pipe::IsValidSwTraceString<arm::pipe::SwTraceCharPolicy>(
"!$%"));
2235 CHECK(arm::pipe::IsValidSwTraceString<arm::pipe::SwTraceCharPolicy>(
"valid|\\~string#123"));
2238 CHECK(!arm::pipe::IsValidSwTraceString<arm::pipe::SwTraceCharPolicy>(
"€£"));
2239 CHECK(!arm::pipe::IsValidSwTraceString<arm::pipe::SwTraceCharPolicy>(
"invalid‡string"));
2240 CHECK(!arm::pipe::IsValidSwTraceString<arm::pipe::SwTraceCharPolicy>(
"12Ž34"));
2243 TEST_CASE(
"IsValidSwTraceNameStringTest")
2246 CHECK(arm::pipe::IsValidSwTraceString<arm::pipe::SwTraceNameCharPolicy>(
""));
2247 CHECK(arm::pipe::IsValidSwTraceString<arm::pipe::SwTraceNameCharPolicy>(
"_"));
2248 CHECK(arm::pipe::IsValidSwTraceString<arm::pipe::SwTraceNameCharPolicy>(
"0123"));
2249 CHECK(arm::pipe::IsValidSwTraceString<arm::pipe::SwTraceNameCharPolicy>(
"valid_string"));
2250 CHECK(arm::pipe::IsValidSwTraceString<arm::pipe::SwTraceNameCharPolicy>(
"VALID_string_456"));
2253 CHECK(!arm::pipe::IsValidSwTraceString<arm::pipe::SwTraceNameCharPolicy>(
" "));
2254 CHECK(!arm::pipe::IsValidSwTraceString<arm::pipe::SwTraceNameCharPolicy>(
"invalid string"));
2255 CHECK(!arm::pipe::IsValidSwTraceString<arm::pipe::SwTraceNameCharPolicy>(
"!$%"));
2256 CHECK(!arm::pipe::IsValidSwTraceString<arm::pipe::SwTraceNameCharPolicy>(
"invalid|\\~string#123"));
2257 CHECK(!arm::pipe::IsValidSwTraceString<arm::pipe::SwTraceNameCharPolicy>(
"€£"));
2258 CHECK(!arm::pipe::IsValidSwTraceString<arm::pipe::SwTraceNameCharPolicy>(
"invalid‡string"));
2259 CHECK(!arm::pipe::IsValidSwTraceString<arm::pipe::SwTraceNameCharPolicy>(
"12Ž34"));
2262 template <
typename SwTracePolicy>
2263 void StringToSwTraceStringTestHelper(
const std::string& testString, std::vector<uint32_t> buffer,
size_t expectedSize)
2266 CHECK(arm::pipe::StringToSwTraceString<SwTracePolicy>(testString, buffer));
2269 CHECK(!buffer.empty());
2272 CHECK(buffer.size() == expectedSize);
2275 CHECK(buffer[0] == testString.size() + 1);
2278 CHECK(std::memcmp(testString.data(), buffer.data() + 1, testString.size()) == 0);
2281 size_t nullTerminatorIndex =
sizeof(uint32_t) + testString.size();
2282 CHECK(reinterpret_cast<unsigned char*>(buffer.data())[nullTerminatorIndex] ==
'\0');
2285 TEST_CASE(
"StringToSwTraceStringTest")
2287 std::vector<uint32_t> buffer;
2290 StringToSwTraceStringTestHelper<arm::pipe::SwTraceCharPolicy>(
"", buffer, 2);
2291 StringToSwTraceStringTestHelper<arm::pipe::SwTraceCharPolicy>(
"_", buffer, 2);
2292 StringToSwTraceStringTestHelper<arm::pipe::SwTraceCharPolicy>(
"0123", buffer, 3);
2293 StringToSwTraceStringTestHelper<arm::pipe::SwTraceCharPolicy>(
"valid_string", buffer, 5);
2294 StringToSwTraceStringTestHelper<arm::pipe::SwTraceCharPolicy>(
"VALID_string_456", buffer, 6);
2295 StringToSwTraceStringTestHelper<arm::pipe::SwTraceCharPolicy>(
" ", buffer, 2);
2296 StringToSwTraceStringTestHelper<arm::pipe::SwTraceCharPolicy>(
"valid string", buffer, 5);
2297 StringToSwTraceStringTestHelper<arm::pipe::SwTraceCharPolicy>(
"!$%", buffer, 2);
2298 StringToSwTraceStringTestHelper<arm::pipe::SwTraceCharPolicy>(
"valid|\\~string#123", buffer, 6);
2301 CHECK(!arm::pipe::StringToSwTraceString<arm::pipe::SwTraceCharPolicy>(
"€£", buffer));
2302 CHECK(buffer.empty());
2303 CHECK(!arm::pipe::StringToSwTraceString<arm::pipe::SwTraceCharPolicy>(
"invalid‡string", buffer));
2304 CHECK(buffer.empty());
2305 CHECK(!arm::pipe::StringToSwTraceString<arm::pipe::SwTraceCharPolicy>(
"12Ž34", buffer));
2306 CHECK(buffer.empty());
2309 TEST_CASE(
"StringToSwTraceNameStringTest")
2311 std::vector<uint32_t> buffer;
2314 StringToSwTraceStringTestHelper<arm::pipe::SwTraceNameCharPolicy>(
"", buffer, 2);
2315 StringToSwTraceStringTestHelper<arm::pipe::SwTraceNameCharPolicy>(
"_", buffer, 2);
2316 StringToSwTraceStringTestHelper<arm::pipe::SwTraceNameCharPolicy>(
"0123", buffer, 3);
2317 StringToSwTraceStringTestHelper<arm::pipe::SwTraceNameCharPolicy>(
"valid_string", buffer, 5);
2318 StringToSwTraceStringTestHelper<arm::pipe::SwTraceNameCharPolicy>(
"VALID_string_456", buffer, 6);
2321 CHECK(!arm::pipe::StringToSwTraceString<arm::pipe::SwTraceNameCharPolicy>(
" ", buffer));
2322 CHECK(buffer.empty());
2323 CHECK(!arm::pipe::StringToSwTraceString<arm::pipe::SwTraceNameCharPolicy>(
"invalid string", buffer));
2324 CHECK(buffer.empty());
2325 CHECK(!arm::pipe::StringToSwTraceString<arm::pipe::SwTraceNameCharPolicy>(
"!$%", buffer));
2326 CHECK(buffer.empty());
2327 CHECK(!arm::pipe::StringToSwTraceString<arm::pipe::SwTraceNameCharPolicy>(
"invalid|\\~string#123", buffer));
2328 CHECK(buffer.empty());
2329 CHECK(!arm::pipe::StringToSwTraceString<arm::pipe::SwTraceNameCharPolicy>(
"€£", buffer));
2330 CHECK(buffer.empty());
2331 CHECK(!arm::pipe::StringToSwTraceString<arm::pipe::SwTraceNameCharPolicy>(
"invalid‡string", buffer));
2332 CHECK(buffer.empty());
2333 CHECK(!arm::pipe::StringToSwTraceString<arm::pipe::SwTraceNameCharPolicy>(
"12Ž34", buffer));
2334 CHECK(buffer.empty());
2337 TEST_CASE(
"CheckPeriodicCounterCaptureThread")
2339 class CaptureReader :
public IReadCounterValues
2342 CaptureReader(uint16_t counterSize)
2344 for (uint16_t i = 0; i < counterSize; ++i)
2348 m_CounterSize = counterSize;
2351 bool IsCounterRegistered(uint16_t counterUid)
const override 2356 bool IsCounterRegistered(
const std::string& counterName)
const override 2361 uint16_t GetCounterCount()
const override 2363 return m_CounterSize;
2366 uint32_t GetAbsoluteCounterValue(uint16_t counterUid)
const override 2368 if (counterUid > m_CounterSize)
2370 FAIL(
"Invalid counter Uid");
2372 return m_Data.at(counterUid).load();
2375 uint32_t GetDeltaCounterValue(uint16_t counterUid)
override 2377 if (counterUid > m_CounterSize)
2379 FAIL(
"Invalid counter Uid");
2381 return m_Data.at(counterUid).load();
2384 void SetCounterValue(uint16_t counterUid, uint32_t value)
2386 if (counterUid > m_CounterSize)
2388 FAIL(
"Invalid counter Uid");
2390 m_Data.at(counterUid).store(value);
2394 std::unordered_map<uint16_t, std::atomic<uint32_t>> m_Data;
2395 uint16_t m_CounterSize;
2398 ProfilingStateMachine profilingStateMachine;
2400 const std::unordered_map<std::string,
2401 std::shared_ptr<IBackendProfilingContext>> backendProfilingContext;
2402 CounterIdMap counterIdMap;
2404 std::vector<uint16_t> captureIds1 = { 0, 1 };
2405 std::vector<uint16_t> captureIds2;
2408 SendCounterPacket sendCounterPacket(mockBuffer,
2409 arm::pipe::ARMNN_SOFTWARE_INFO,
2410 arm::pipe::ARMNN_SOFTWARE_VERSION,
2411 arm::pipe::ARMNN_HARDWARE_VERSION);
2412 SendThread sendThread(profilingStateMachine, mockBuffer, sendCounterPacket);
2414 std::vector<uint16_t> counterIds;
2415 CaptureReader captureReader(2);
2417 unsigned int valueA = 10;
2418 unsigned int valueB = 15;
2419 unsigned int numSteps = 5;
2421 PeriodicCounterCapture periodicCounterCapture(std::ref(data), std::ref(sendCounterPacket), captureReader,
2422 counterIdMap, backendProfilingContext);
2424 for (
unsigned int i = 0; i < numSteps; ++i)
2426 data.SetCaptureData(1, captureIds1, {});
2427 captureReader.SetCounterValue(0, valueA * (i + 1));
2428 captureReader.SetCounterValue(1, valueB * (i + 1));
2430 periodicCounterCapture.Start();
2431 periodicCounterCapture.Stop();
2434 auto buffer = mockBuffer.GetReadableBuffer();
2436 uint32_t headerWord0 = ReadUint32(buffer, 0);
2437 uint32_t headerWord1 = ReadUint32(buffer, 4);
2439 CHECK(((headerWord0 >> 26) & 0x0000003F) == 3);
2440 CHECK(((headerWord0 >> 19) & 0x0000007F) == 0);
2441 CHECK(((headerWord0 >> 16) & 0x00000007) == 0);
2442 CHECK(headerWord1 == 20);
2444 uint32_t offset = 16;
2445 uint16_t readIndex = ReadUint16(buffer, offset);
2446 CHECK(0 == readIndex);
2449 uint32_t readValue = ReadUint32(buffer, offset);
2450 CHECK((valueA * numSteps) == readValue);
2453 readIndex = ReadUint16(buffer, offset);
2454 CHECK(1 == readIndex);
2457 readValue = ReadUint32(buffer, offset);
2458 CHECK((valueB * numSteps) == readValue);
2461 TEST_CASE(
"RequestCounterDirectoryCommandHandlerTest1")
2463 const uint32_t familyId = 0;
2464 const uint32_t packetId = 3;
2465 const uint32_t version = 1;
2466 ProfilingStateMachine profilingStateMachine;
2467 CounterDirectory counterDirectory;
2469 SendCounterPacket sendCounterPacket(mockBuffer1,
2470 arm::pipe::ARMNN_SOFTWARE_INFO,
2471 arm::pipe::ARMNN_SOFTWARE_VERSION,
2472 arm::pipe::ARMNN_HARDWARE_VERSION);
2473 SendThread sendThread(profilingStateMachine, mockBuffer1, sendCounterPacket);
2475 SendTimelinePacket sendTimelinePacket(mockBuffer2);
2476 RequestCounterDirectoryCommandHandler commandHandler(familyId, packetId, version, counterDirectory,
2477 sendCounterPacket, sendTimelinePacket, profilingStateMachine);
2479 const uint32_t wrongPacketId = 47;
2480 const uint32_t wrongHeader = (wrongPacketId & 0x000003FF) << 16;
2482 arm::pipe::Packet wrongPacket(wrongHeader);
2484 profilingStateMachine.TransitionToState(ProfilingState::Uninitialised);
2485 CHECK_THROWS_AS(commandHandler(wrongPacket), arm::pipe::ProfilingException);
2486 profilingStateMachine.TransitionToState(ProfilingState::NotConnected);
2487 CHECK_THROWS_AS(commandHandler(wrongPacket), arm::pipe::ProfilingException);
2488 profilingStateMachine.TransitionToState(ProfilingState::WaitingForAck);
2489 CHECK_THROWS_AS(commandHandler(wrongPacket), arm::pipe::ProfilingException);
2490 profilingStateMachine.TransitionToState(ProfilingState::Active);
2491 CHECK_THROWS_AS(commandHandler(wrongPacket), arm::pipe::InvalidArgumentException);
2493 const uint32_t rightHeader = (packetId & 0x000003FF) << 16;
2495 arm::pipe::Packet rightPacket(rightHeader);
2497 CHECK_NOTHROW(commandHandler(rightPacket));
2499 auto readBuffer1 = mockBuffer1.GetReadableBuffer();
2501 uint32_t header1Word0 = ReadUint32(readBuffer1, 0);
2502 uint32_t header1Word1 = ReadUint32(readBuffer1, 4);
2505 CHECK(((header1Word0 >> 26) & 0x0000003F) == 0);
2506 CHECK(((header1Word0 >> 16) & 0x000003FF) == 2);
2507 CHECK(header1Word1 == 24);
2509 uint32_t bodyHeader1Word0 = ReadUint32(readBuffer1, 8);
2511 CHECK(deviceRecordCount == 0);
2513 auto readBuffer2 = mockBuffer2.GetReadableBuffer();
2515 uint32_t header2Word0 = ReadUint32(readBuffer2, 0);
2516 uint32_t header2Word1 = ReadUint32(readBuffer2, 4);
2519 CHECK(((header2Word0 >> 26) & 0x0000003F) == 1);
2520 CHECK(((header2Word0 >> 16) & 0x000003FF) == 0);
2521 CHECK(header2Word1 == 443);
2524 TEST_CASE(
"RequestCounterDirectoryCommandHandlerTest2")
2526 const uint32_t familyId = 0;
2527 const uint32_t packetId = 3;
2528 const uint32_t version = 1;
2529 ProfilingStateMachine profilingStateMachine;
2530 CounterDirectory counterDirectory;
2532 SendCounterPacket sendCounterPacket(mockBuffer1,
2533 arm::pipe::ARMNN_SOFTWARE_INFO,
2534 arm::pipe::ARMNN_SOFTWARE_VERSION,
2535 arm::pipe::ARMNN_HARDWARE_VERSION);
2536 SendThread sendThread(profilingStateMachine, mockBuffer1, sendCounterPacket);
2538 SendTimelinePacket sendTimelinePacket(mockBuffer2);
2539 RequestCounterDirectoryCommandHandler commandHandler(familyId, packetId, version, counterDirectory,
2540 sendCounterPacket, sendTimelinePacket, profilingStateMachine);
2541 const uint32_t header = (packetId & 0x000003FF) << 16;
2542 const arm::pipe::Packet packet(header);
2544 const Device* device = counterDirectory.RegisterDevice(
"deviceA", 1);
2545 CHECK(device !=
nullptr);
2546 const CounterSet* counterSet = counterDirectory.RegisterCounterSet(
"countersetA");
2547 CHECK(counterSet !=
nullptr);
2548 counterDirectory.RegisterCategory(
"categoryA");
2549 counterDirectory.RegisterCounter(armnn::profiling::BACKEND_ID, 24,
2550 "categoryA", 0, 1, 2.0f,
"counterA",
"descA");
2551 counterDirectory.RegisterCounter(armnn::profiling::BACKEND_ID, 25,
2552 "categoryA", 1, 1, 3.0f,
"counterB",
"descB");
2554 profilingStateMachine.TransitionToState(ProfilingState::Uninitialised);
2555 CHECK_THROWS_AS(commandHandler(packet), arm::pipe::ProfilingException);
2556 profilingStateMachine.TransitionToState(ProfilingState::NotConnected);
2557 CHECK_THROWS_AS(commandHandler(packet), arm::pipe::ProfilingException);
2558 profilingStateMachine.TransitionToState(ProfilingState::WaitingForAck);
2559 CHECK_THROWS_AS(commandHandler(packet), arm::pipe::ProfilingException);
2560 profilingStateMachine.TransitionToState(ProfilingState::Active);
2561 CHECK_NOTHROW(commandHandler(packet));
2563 auto readBuffer1 = mockBuffer1.GetReadableBuffer();
2565 const uint32_t header1Word0 = ReadUint32(readBuffer1, 0);
2566 const uint32_t header1Word1 = ReadUint32(readBuffer1, 4);
2568 CHECK(((header1Word0 >> 26) & 0x0000003F) == 0);
2569 CHECK(((header1Word0 >> 16) & 0x000003FF) == 2);
2570 CHECK(header1Word1 == 236);
2572 const uint32_t bodyHeaderSizeBytes = bodyHeaderSize *
sizeof(uint32_t);
2574 const uint32_t bodyHeader1Word0 = ReadUint32(readBuffer1, 8);
2575 const uint32_t bodyHeader1Word1 = ReadUint32(readBuffer1, 12);
2576 const uint32_t bodyHeader1Word2 = ReadUint32(readBuffer1, 16);
2577 const uint32_t bodyHeader1Word3 = ReadUint32(readBuffer1, 20);
2578 const uint32_t bodyHeader1Word4 = ReadUint32(readBuffer1, 24);
2579 const uint32_t bodyHeader1Word5 = ReadUint32(readBuffer1, 28);
2583 CHECK(deviceRecordCount == 1);
2584 CHECK(bodyHeader1Word1 == 0 + bodyHeaderSizeBytes);
2585 CHECK(counterSetRecordCount == 1);
2586 CHECK(bodyHeader1Word3 == 4 + bodyHeaderSizeBytes);
2587 CHECK(categoryRecordCount == 1);
2588 CHECK(bodyHeader1Word5 == 8 + bodyHeaderSizeBytes);
2590 const uint32_t deviceRecordOffset = ReadUint32(readBuffer1, 32);
2591 CHECK(deviceRecordOffset == 12);
2593 const uint32_t counterSetRecordOffset = ReadUint32(readBuffer1, 36);
2594 CHECK(counterSetRecordOffset == 28);
2596 const uint32_t categoryRecordOffset = ReadUint32(readBuffer1, 40);
2597 CHECK(categoryRecordOffset == 48);
2599 auto readBuffer2 = mockBuffer2.GetReadableBuffer();
2601 const uint32_t header2Word0 = ReadUint32(readBuffer2, 0);
2602 const uint32_t header2Word1 = ReadUint32(readBuffer2, 4);
2605 CHECK(((header2Word0 >> 26) & 0x0000003F) == 1);
2606 CHECK(((header2Word0 >> 16) & 0x000003FF) == 0);
2607 CHECK(header2Word1 == 443);
2610 TEST_CASE(
"CheckProfilingServiceGoodConnectionAcknowledgedPacket")
2615 ProfilingOptions options;
2616 options.m_EnableProfiling =
true;
2618 ProfilingService profilingService(arm::pipe::MAX_ARMNN_COUNTER,
2620 arm::pipe::ARMNN_SOFTWARE_INFO,
2621 arm::pipe::ARMNN_SOFTWARE_VERSION,
2622 arm::pipe::ARMNN_HARDWARE_VERSION);
2623 profilingService.ResetExternalProfilingOptions(options,
true);
2629 CHECK(profilingService.GetCurrentState() == ProfilingState::Uninitialised);
2630 profilingService.Update();
2631 CHECK(profilingService.GetCurrentState() == ProfilingState::NotConnected);
2632 profilingService.Update();
2636 CHECK(mockProfilingConnection);
2639 mockProfilingConnection->
Clear();
2641 CHECK(profilingService.GetCurrentState() == ProfilingState::WaitingForAck);
2642 profilingService.Update();
2645 CHECK(helper.WaitForPacketsSent(
2646 mockProfilingConnection, PacketType::StreamMetaData, streamMetadataPacketsize) >= 1);
2656 uint32_t packetFamily = 0;
2657 uint32_t packetId = 1;
2658 uint32_t header = ((packetFamily & 0x0000003F) << 26) | ((packetId & 0x000003FF) << 16);
2661 arm::pipe::Packet connectionAcknowledgedPacket(header);
2664 mockProfilingConnection->
WritePacket(std::move(connectionAcknowledgedPacket));
2667 CHECK(helper.WaitForPacketsSent(mockProfilingConnection, PacketType::CounterDirectory) == 1);
2670 CHECK(profilingService.GetCurrentState() == ProfilingState::Active);
2673 options.m_EnableProfiling =
false;
2674 profilingService.ResetExternalProfilingOptions(options,
true);
2677 TEST_CASE(
"CheckProfilingServiceGoodRequestCounterDirectoryPacket")
2680 ProfilingOptions options;
2681 options.m_EnableProfiling =
true;
2683 ProfilingService profilingService(arm::pipe::MAX_ARMNN_COUNTER,
2685 arm::pipe::ARMNN_SOFTWARE_INFO,
2686 arm::pipe::ARMNN_SOFTWARE_VERSION,
2687 arm::pipe::ARMNN_HARDWARE_VERSION);
2688 profilingService.ResetExternalProfilingOptions(options,
true);
2694 CHECK(profilingService.GetCurrentState() == ProfilingState::Uninitialised);
2695 profilingService.Update();
2696 CHECK(profilingService.GetCurrentState() == ProfilingState::NotConnected);
2697 profilingService.Update();
2698 CHECK(profilingService.GetCurrentState() == ProfilingState::WaitingForAck);
2699 profilingService.Update();
2703 CHECK(mockProfilingConnection);
2706 helper.ForceTransitionToState(ProfilingState::Active);
2707 CHECK(profilingService.GetCurrentState() == ProfilingState::Active);
2717 uint32_t packetFamily = 0;
2718 uint32_t packetId = 3;
2719 uint32_t header = ((packetFamily & 0x0000003F) << 26) | ((packetId & 0x000003FF) << 16);
2722 arm::pipe::Packet requestCounterDirectoryPacket(header);
2725 mockProfilingConnection->
WritePacket(std::move(requestCounterDirectoryPacket));
2729 CHECK(helper.WaitForPacketsSent(mockProfilingConnection, PacketType::CounterDirectory, 652) == 1);
2730 CHECK(helper.WaitForPacketsSent(mockProfilingConnection, PacketType::TimelineMessageDirectory, 451) == 1);
2733 CHECK(profilingService.GetCurrentState() == ProfilingState::Active);
2736 options.m_EnableProfiling =
false;
2737 profilingService.ResetExternalProfilingOptions(options,
true);
2740 TEST_CASE(
"CheckProfilingServiceBadPeriodicCounterSelectionPacketInvalidCounterUid")
2743 ProfilingOptions options;
2744 options.m_EnableProfiling =
true;
2746 ProfilingService profilingService(arm::pipe::MAX_ARMNN_COUNTER,
2748 arm::pipe::ARMNN_SOFTWARE_INFO,
2749 arm::pipe::ARMNN_SOFTWARE_VERSION,
2750 arm::pipe::ARMNN_HARDWARE_VERSION);
2751 profilingService.ResetExternalProfilingOptions(options,
true);
2757 CHECK(profilingService.GetCurrentState() == ProfilingState::Uninitialised);
2758 profilingService.Update();
2759 CHECK(profilingService.GetCurrentState() == ProfilingState::NotConnected);
2760 profilingService.Update();
2761 CHECK(profilingService.GetCurrentState() == ProfilingState::WaitingForAck);
2762 profilingService.Update();
2766 CHECK(mockProfilingConnection);
2769 helper.ForceTransitionToState(ProfilingState::Active);
2770 CHECK(profilingService.GetCurrentState() == ProfilingState::Active);
2773 mockProfilingConnection->
Clear();
2783 uint32_t packetFamily = 0;
2784 uint32_t packetId = 4;
2785 uint32_t header = ((packetFamily & 0x0000003F) << 26) | ((packetId & 0x000003FF) << 16);
2787 uint32_t capturePeriod = 123456;
2790 const ICounterDirectory& counterDirectory = profilingService.GetCounterDirectory();
2791 const Counters& counters = counterDirectory.GetCounters();
2792 CHECK(counters.size() > 1);
2793 uint16_t counterUidA = counters.begin()->first;
2794 uint16_t counterUidB = 9999;
2796 uint32_t length = 8;
2798 auto data = std::make_unique<unsigned char[]>(length);
2799 WriteUint32(data.get(), 0, capturePeriod);
2800 WriteUint16(data.get(), 4, counterUidA);
2801 WriteUint16(data.get(), 6, counterUidB);
2805 arm::pipe::Packet periodicCounterSelectionPacket(header, length, data);
2809 mockProfilingConnection->
WritePacket(std::move(periodicCounterSelectionPacket));
2813 CHECK(helper.WaitForPacketsSent(mockProfilingConnection, PacketType::PeriodicCounterSelection, 14) == 1);
2814 CHECK(helper.WaitForPacketsSent(mockProfilingConnection, PacketType::PeriodicCounterCapture, 22) >= 1);
2817 CHECK(profilingService.GetCurrentState() == ProfilingState::Active);
2820 options.m_EnableProfiling =
false;
2821 profilingService.ResetExternalProfilingOptions(options,
true);
2824 TEST_CASE(
"CheckProfilingServiceGoodPeriodicCounterSelectionPacketNoCounters")
2827 ProfilingOptions options;
2828 options.m_EnableProfiling =
true;
2830 ProfilingService profilingService(arm::pipe::MAX_ARMNN_COUNTER,
2832 arm::pipe::ARMNN_SOFTWARE_INFO,
2833 arm::pipe::ARMNN_SOFTWARE_VERSION,
2834 arm::pipe::ARMNN_HARDWARE_VERSION);
2835 profilingService.ResetExternalProfilingOptions(options,
true);
2841 CHECK(profilingService.GetCurrentState() == ProfilingState::Uninitialised);
2842 profilingService.Update();
2843 CHECK(profilingService.GetCurrentState() == ProfilingState::NotConnected);
2844 profilingService.Update();
2845 CHECK(profilingService.GetCurrentState() == ProfilingState::WaitingForAck);
2846 profilingService.Update();
2850 CHECK(mockProfilingConnection);
2854 helper.WaitForPacketsSent(mockProfilingConnection, PacketType::StreamMetaData);
2857 helper.ForceTransitionToState(ProfilingState::Active);
2858 CHECK(profilingService.GetCurrentState() == ProfilingState::Active);
2868 uint32_t packetFamily = 0;
2869 uint32_t packetId = 4;
2870 uint32_t header = ((packetFamily & 0x0000003F) << 26) | ((packetId & 0x000003FF) << 16);
2874 arm::pipe::Packet periodicCounterSelectionPacket(header);
2877 mockProfilingConnection->
WritePacket(std::move(periodicCounterSelectionPacket));
2881 CHECK(helper.WaitForPacketsSent(mockProfilingConnection, PacketType::PeriodicCounterSelection, 12) == 1);
2884 CHECK(profilingService.GetCurrentState() == ProfilingState::Active);
2887 CHECK(helper.WaitForPacketsSent(mockProfilingConnection, PacketType::PeriodicCounterCapture, 0, 0) == 0);
2890 options.m_EnableProfiling =
false;
2891 profilingService.ResetExternalProfilingOptions(options,
true);
2894 TEST_CASE(
"CheckProfilingServiceGoodPeriodicCounterSelectionPacketSingleCounter")
2897 ProfilingOptions options;
2898 options.m_EnableProfiling =
true;
2900 ProfilingService profilingService(arm::pipe::MAX_ARMNN_COUNTER,
2902 arm::pipe::ARMNN_SOFTWARE_INFO,
2903 arm::pipe::ARMNN_SOFTWARE_VERSION,
2904 arm::pipe::ARMNN_HARDWARE_VERSION);
2905 profilingService.ResetExternalProfilingOptions(options,
true);
2911 CHECK(profilingService.GetCurrentState() == ProfilingState::Uninitialised);
2912 profilingService.Update();
2913 CHECK(profilingService.GetCurrentState() == ProfilingState::NotConnected);
2914 profilingService.Update();
2915 CHECK(profilingService.GetCurrentState() == ProfilingState::WaitingForAck);
2916 profilingService.Update();
2920 CHECK(mockProfilingConnection);
2924 helper.WaitForPacketsSent(mockProfilingConnection, PacketType::StreamMetaData);
2927 helper.ForceTransitionToState(ProfilingState::Active);
2928 CHECK(profilingService.GetCurrentState() == ProfilingState::Active);
2938 uint32_t packetFamily = 0;
2939 uint32_t packetId = 4;
2940 uint32_t header = ((packetFamily & 0x0000003F) << 26) | ((packetId & 0x000003FF) << 16);
2942 uint32_t capturePeriod = 123456;
2945 const ICounterDirectory& counterDirectory = profilingService.GetCounterDirectory();
2946 const Counters& counters = counterDirectory.GetCounters();
2947 CHECK(!counters.empty());
2948 uint16_t counterUid = counters.begin()->first;
2950 uint32_t length = 6;
2952 auto data = std::make_unique<unsigned char[]>(length);
2953 WriteUint32(data.get(), 0, capturePeriod);
2954 WriteUint16(data.get(), 4, counterUid);
2958 arm::pipe::Packet periodicCounterSelectionPacket(header, length, data);
2961 mockProfilingConnection->
WritePacket(std::move(periodicCounterSelectionPacket));
2965 CHECK(helper.WaitForPacketsSent(mockProfilingConnection, PacketType::PeriodicCounterSelection, 14) == 1);
2966 CHECK(helper.WaitForPacketsSent(mockProfilingConnection, PacketType::PeriodicCounterCapture, 22) >= 1);
2969 CHECK(profilingService.GetCurrentState() == ProfilingState::Active);
2972 options.m_EnableProfiling =
false;
2973 profilingService.ResetExternalProfilingOptions(options,
true);
2976 TEST_CASE(
"CheckProfilingServiceGoodPeriodicCounterSelectionPacketMultipleCounters")
2979 ProfilingOptions options;
2980 options.m_EnableProfiling =
true;
2982 ProfilingService profilingService(arm::pipe::MAX_ARMNN_COUNTER,
2984 arm::pipe::ARMNN_SOFTWARE_INFO,
2985 arm::pipe::ARMNN_SOFTWARE_VERSION,
2986 arm::pipe::ARMNN_HARDWARE_VERSION);
2987 profilingService.ResetExternalProfilingOptions(options,
true);
2993 CHECK(profilingService.GetCurrentState() == ProfilingState::Uninitialised);
2994 profilingService.Update();
2995 CHECK(profilingService.GetCurrentState() == ProfilingState::NotConnected);
2996 profilingService.Update();
2997 CHECK(profilingService.GetCurrentState() == ProfilingState::WaitingForAck);
2998 profilingService.Update();
3002 CHECK(mockProfilingConnection);
3006 helper.WaitForPacketsSent(mockProfilingConnection, PacketType::StreamMetaData);
3009 helper.ForceTransitionToState(ProfilingState::Active);
3010 CHECK(profilingService.GetCurrentState() == ProfilingState::Active);
3020 uint32_t packetFamily = 0;
3021 uint32_t packetId = 4;
3022 uint32_t header = ((packetFamily & 0x0000003F) << 26) | ((packetId & 0x000003FF) << 16);
3024 uint32_t capturePeriod = 123456;
3027 const ICounterDirectory& counterDirectory = profilingService.GetCounterDirectory();
3028 const Counters& counters = counterDirectory.GetCounters();
3029 CHECK(counters.size() > 1);
3030 uint16_t counterUidA = counters.begin()->first;
3031 uint16_t counterUidB = (counters.begin()++)->first;
3033 uint32_t length = 8;
3035 auto data = std::make_unique<unsigned char[]>(length);
3036 WriteUint32(data.get(), 0, capturePeriod);
3037 WriteUint16(data.get(), 4, counterUidA);
3038 WriteUint16(data.get(), 6, counterUidB);
3042 arm::pipe::Packet periodicCounterSelectionPacket(header, length, data);
3045 mockProfilingConnection->
WritePacket(std::move(periodicCounterSelectionPacket));
3049 CHECK(helper.WaitForPacketsSent(mockProfilingConnection, PacketType::PeriodicCounterSelection, 16) == 1);
3050 CHECK(helper.WaitForPacketsSent(mockProfilingConnection, PacketType::PeriodicCounterCapture, 28) >= 1);
3053 CHECK(profilingService.GetCurrentState() == ProfilingState::Active);
3056 options.m_EnableProfiling =
false;
3057 profilingService.ResetExternalProfilingOptions(options,
true);
3060 TEST_CASE(
"CheckProfilingServiceDisconnect")
3063 ProfilingOptions options;
3064 options.m_EnableProfiling =
true;
3066 ProfilingService profilingService(arm::pipe::MAX_ARMNN_COUNTER,
3068 arm::pipe::ARMNN_SOFTWARE_INFO,
3069 arm::pipe::ARMNN_SOFTWARE_VERSION,
3070 arm::pipe::ARMNN_HARDWARE_VERSION);
3071 profilingService.ResetExternalProfilingOptions(options,
true);
3077 CHECK(profilingService.GetCurrentState() == ProfilingState::Uninitialised);
3078 profilingService.Disconnect();
3079 CHECK(profilingService.GetCurrentState() == ProfilingState::Uninitialised);
3082 profilingService.Update();
3083 CHECK(profilingService.GetCurrentState() == ProfilingState::NotConnected);
3084 profilingService.Disconnect();
3085 CHECK(profilingService.GetCurrentState() == ProfilingState::NotConnected);
3088 profilingService.Update();
3089 CHECK(profilingService.GetCurrentState() == ProfilingState::WaitingForAck);
3090 profilingService.Disconnect();
3091 CHECK(profilingService.GetCurrentState() == ProfilingState::WaitingForAck);
3094 profilingService.Update();
3098 CHECK(mockProfilingConnection);
3102 helper.WaitForPacketsSent(mockProfilingConnection, PacketType::StreamMetaData);
3105 helper.ForceTransitionToState(ProfilingState::Active);
3106 CHECK(profilingService.GetCurrentState() == ProfilingState::Active);
3109 CHECK(mockProfilingConnection->
IsOpen());
3111 profilingService.Disconnect();
3112 CHECK(profilingService.GetCurrentState() == ProfilingState::NotConnected);
3115 mockProfilingConnection = helper.GetMockProfilingConnection();
3116 CHECK(mockProfilingConnection ==
nullptr);
3119 options.m_EnableProfiling =
false;
3120 profilingService.ResetExternalProfilingOptions(options,
true);
3123 TEST_CASE(
"CheckProfilingServiceGoodPerJobCounterSelectionPacket")
3126 ProfilingOptions options;
3127 options.m_EnableProfiling =
true;
3129 ProfilingService profilingService(arm::pipe::MAX_ARMNN_COUNTER,
3131 arm::pipe::ARMNN_SOFTWARE_INFO,
3132 arm::pipe::ARMNN_SOFTWARE_VERSION,
3133 arm::pipe::ARMNN_HARDWARE_VERSION);
3134 profilingService.ResetExternalProfilingOptions(options,
true);
3140 CHECK(profilingService.GetCurrentState() == ProfilingState::Uninitialised);
3141 profilingService.Update();
3142 CHECK(profilingService.GetCurrentState() == ProfilingState::NotConnected);
3143 profilingService.Update();
3144 CHECK(profilingService.GetCurrentState() == ProfilingState::WaitingForAck);
3145 profilingService.Update();
3149 CHECK(mockProfilingConnection);
3153 helper.WaitForPacketsSent(mockProfilingConnection, PacketType::StreamMetaData);
3156 helper.ForceTransitionToState(ProfilingState::Active);
3157 CHECK(profilingService.GetCurrentState() == ProfilingState::Active);
3167 uint32_t packetFamily = 0;
3168 uint32_t packetId = 5;
3169 uint32_t header = ((packetFamily & 0x0000003F) << 26) | ((packetId & 0x000003FF) << 16);
3173 arm::pipe::Packet periodicCounterSelectionPacket(header);
3176 mockProfilingConnection->
WritePacket(std::move(periodicCounterSelectionPacket));
3180 std::this_thread::sleep_for(std::chrono::milliseconds(5));
3183 CHECK(profilingService.GetCurrentState() == ProfilingState::Active);
3187 const auto StreamMetaDataSize =
static_cast<unsigned long>(
3188 helper.WaitForPacketsSent(mockProfilingConnection, PacketType::StreamMetaData, 0, 0));
3192 options.m_EnableProfiling =
false;
3193 profilingService.ResetExternalProfilingOptions(options,
true);
3196 TEST_CASE(
"CheckConfigureProfilingServiceOn")
3198 ProfilingOptions options;
3199 options.m_EnableProfiling =
true;
3201 ProfilingService profilingService(arm::pipe::MAX_ARMNN_COUNTER,
3203 arm::pipe::ARMNN_SOFTWARE_INFO,
3204 arm::pipe::ARMNN_SOFTWARE_VERSION,
3205 arm::pipe::ARMNN_HARDWARE_VERSION);
3206 CHECK(profilingService.GetCurrentState() == ProfilingState::Uninitialised);
3207 profilingService.ConfigureProfilingService(options);
3209 CHECK(profilingService.GetCurrentState() == ProfilingState::NotConnected);
3211 options.m_EnableProfiling =
false;
3212 profilingService.ResetExternalProfilingOptions(options,
true);
3215 TEST_CASE(
"CheckConfigureProfilingServiceOff")
3217 ProfilingOptions options;
3219 ProfilingService profilingService(arm::pipe::MAX_ARMNN_COUNTER,
3221 arm::pipe::ARMNN_SOFTWARE_INFO,
3222 arm::pipe::ARMNN_SOFTWARE_VERSION,
3223 arm::pipe::ARMNN_HARDWARE_VERSION);
3224 CHECK(profilingService.GetCurrentState() == ProfilingState::Uninitialised);
3225 profilingService.ConfigureProfilingService(options);
3227 CHECK(profilingService.GetCurrentState() == ProfilingState::Uninitialised);
3229 options.m_EnableProfiling =
false;
3230 profilingService.ResetExternalProfilingOptions(options,
true);
3233 TEST_CASE(
"CheckProfilingServiceEnabled")
3236 LogLevelSwapper logLevelSwapper(arm::pipe::LogSeverity::Warning);
3239 std::stringstream ss;
3242 ProfilingOptions options;
3243 options.m_EnableProfiling =
true;
3245 ProfilingService profilingService(arm::pipe::MAX_ARMNN_COUNTER,
3247 arm::pipe::ARMNN_SOFTWARE_INFO,
3248 arm::pipe::ARMNN_SOFTWARE_VERSION,
3249 arm::pipe::ARMNN_HARDWARE_VERSION);
3250 profilingService.ResetExternalProfilingOptions(options,
true);
3251 CHECK(profilingService.GetCurrentState() == ProfilingState::Uninitialised);
3252 profilingService.Update();
3253 CHECK(profilingService.GetCurrentState() == ProfilingState::NotConnected);
3255 profilingService.Update();
3258 options.m_EnableProfiling =
false;
3259 profilingService.ResetExternalProfilingOptions(options,
true);
3261 streamRedirector.CancelRedirect();
3264 if (ss.str().find(
"Cannot connect to stream socket: Connection refused") == std::string::npos)
3266 std::cout << ss.str();
3267 FAIL(
"Expected string not found.");
3271 TEST_CASE(
"CheckProfilingServiceEnabledRuntime")
3274 LogLevelSwapper logLevelSwapper(arm::pipe::LogSeverity::Warning);
3277 std::stringstream ss;
3280 ProfilingOptions options;
3282 ProfilingService profilingService(arm::pipe::MAX_ARMNN_COUNTER,
3284 arm::pipe::ARMNN_SOFTWARE_INFO,
3285 arm::pipe::ARMNN_SOFTWARE_VERSION,
3286 arm::pipe::ARMNN_HARDWARE_VERSION);
3287 profilingService.ResetExternalProfilingOptions(options,
true);
3288 CHECK(profilingService.GetCurrentState() == ProfilingState::Uninitialised);
3289 profilingService.Update();
3290 CHECK(profilingService.GetCurrentState() == ProfilingState::Uninitialised);
3291 options.m_EnableProfiling =
true;
3292 profilingService.ResetExternalProfilingOptions(options);
3293 CHECK(profilingService.GetCurrentState() == ProfilingState::Uninitialised);
3294 profilingService.Update();
3295 CHECK(profilingService.GetCurrentState() == ProfilingState::NotConnected);
3297 profilingService.Update();
3300 options.m_EnableProfiling =
false;
3301 profilingService.ResetExternalProfilingOptions(options,
true);
3303 streamRedirector.CancelRedirect();
3306 if (ss.str().find(
"Cannot connect to stream socket: Connection refused") == std::string::npos)
3308 std::cout << ss.str();
3309 FAIL(
"Expected string not found.");
3313 TEST_CASE(
"CheckProfilingServiceBadConnectionAcknowledgedPacket")
3316 LogLevelSwapper logLevelSwapper(arm::pipe::LogSeverity::Warning);
3319 std::stringstream ss;
3323 ProfilingOptions options;
3324 options.m_EnableProfiling =
true;
3326 ProfilingService profilingService(arm::pipe::MAX_ARMNN_COUNTER,
3328 arm::pipe::ARMNN_SOFTWARE_INFO,
3329 arm::pipe::ARMNN_SOFTWARE_VERSION,
3330 arm::pipe::ARMNN_HARDWARE_VERSION);
3331 profilingService.ResetExternalProfilingOptions(options,
true);
3337 CHECK(profilingService.GetCurrentState() == ProfilingState::Uninitialised);
3338 profilingService.Update();
3339 CHECK(profilingService.GetCurrentState() == ProfilingState::NotConnected);
3340 profilingService.Update();
3344 CHECK(mockProfilingConnection);
3346 CHECK(profilingService.GetCurrentState() == ProfilingState::WaitingForAck);
3353 uint32_t packetFamily = 0;
3354 uint32_t packetId = 37;
3355 uint32_t header = ((packetFamily & 0x0000003F) << 26) | ((packetId & 0x000003FF) << 16);
3358 arm::pipe::Packet connectionAcknowledgedPacket(header);
3361 mockProfilingConnection->
WritePacket(std::move(connectionAcknowledgedPacket));
3364 profilingService.Update();
3367 options.m_EnableProfiling =
false;
3368 profilingService.ResetExternalProfilingOptions(options,
true);
3370 streamRedirector.CancelRedirect();
3373 if (ss.str().find(
"Functor with requested PacketId=37 and Version=4194304 does not exist") == std::string::npos)
3375 std::cout << ss.str();
3376 FAIL(
"Expected string not found.");
3380 TEST_CASE(
"CheckProfilingServiceBadRequestCounterDirectoryPacket")
3383 LogLevelSwapper logLevelSwapper(arm::pipe::LogSeverity::Warning);
3386 std::stringstream ss;
3390 ProfilingOptions options;
3391 options.m_EnableProfiling =
true;
3393 ProfilingService profilingService(arm::pipe::MAX_ARMNN_COUNTER,
3395 arm::pipe::ARMNN_SOFTWARE_INFO,
3396 arm::pipe::ARMNN_SOFTWARE_VERSION,
3397 arm::pipe::ARMNN_HARDWARE_VERSION);
3398 profilingService.ResetExternalProfilingOptions(options,
true);
3404 CHECK(profilingService.GetCurrentState() == ProfilingState::Uninitialised);
3405 helper.ForceTransitionToState(ProfilingState::NotConnected);
3406 CHECK(profilingService.GetCurrentState() == ProfilingState::NotConnected);
3407 profilingService.Update();
3408 CHECK(profilingService.GetCurrentState() == ProfilingState::WaitingForAck);
3412 CHECK(mockProfilingConnection);
3422 uint32_t packetFamily = 0;
3423 uint32_t packetId = 123;
3424 uint32_t header = ((packetFamily & 0x0000003F) << 26) | ((packetId & 0x000003FF) << 16);
3427 arm::pipe::Packet requestCounterDirectoryPacket(header);
3430 mockProfilingConnection->WritePacket(std::move(requestCounterDirectoryPacket));
3433 profilingService.Update();
3436 options.m_EnableProfiling =
false;
3437 profilingService.ResetExternalProfilingOptions(options,
true);
3439 streamRedirector.CancelRedirect();
3442 if (ss.str().find(
"Functor with requested PacketId=123 and Version=4194304 does not exist") == std::string::npos)
3444 std::cout << ss.str();
3445 FAIL(
"Expected string not found.");
3449 TEST_CASE(
"CheckProfilingServiceBadPeriodicCounterSelectionPacket")
3452 LogLevelSwapper logLevelSwapper(arm::pipe::LogSeverity::Warning);
3455 std::stringstream ss;
3459 ProfilingOptions options;
3460 options.m_EnableProfiling =
true;
3462 ProfilingService profilingService(arm::pipe::MAX_ARMNN_COUNTER,
3464 arm::pipe::ARMNN_SOFTWARE_INFO,
3465 arm::pipe::ARMNN_SOFTWARE_VERSION,
3466 arm::pipe::ARMNN_HARDWARE_VERSION);
3467 profilingService.ResetExternalProfilingOptions(options,
true);
3473 CHECK(profilingService.GetCurrentState() == ProfilingState::Uninitialised);
3474 profilingService.Update();
3475 CHECK(profilingService.GetCurrentState() == ProfilingState::NotConnected);
3476 profilingService.Update();
3477 CHECK(profilingService.GetCurrentState() == ProfilingState::WaitingForAck);
3478 profilingService.Update();
3482 CHECK(mockProfilingConnection);
3492 uint32_t packetFamily = 0;
3493 uint32_t packetId = 999;
3494 uint32_t header = ((packetFamily & 0x0000003F) << 26) | ((packetId & 0x000003FF) << 16);
3498 arm::pipe::Packet periodicCounterSelectionPacket(header);
3501 mockProfilingConnection->
WritePacket(std::move(periodicCounterSelectionPacket));
3502 profilingService.Update();
3505 options.m_EnableProfiling =
false;
3506 profilingService.ResetExternalProfilingOptions(options,
true);
3509 streamRedirector.CancelRedirect();
3512 if (ss.str().find(
"Functor with requested PacketId=999 and Version=4194304 does not exist") == std::string::npos)
3514 std::cout << ss.str();
3515 FAIL(
"Expected string not found.");
3519 TEST_CASE(
"CheckCounterIdMap")
3521 CounterIdMap counterIdMap;
3522 CHECK_THROWS_AS(counterIdMap.GetBackendId(0), arm::pipe::ProfilingException);
3523 CHECK_THROWS_AS(counterIdMap.GetGlobalId(0, armnn::profiling::BACKEND_ID), arm::pipe::ProfilingException);
3525 uint16_t globalCounterIds = 0;
3530 std::vector<uint16_t> cpuRefCounters = {0, 1, 2, 3};
3531 std::vector<uint16_t> cpuAccCounters = {0, 1};
3533 for (uint16_t backendCounterId : cpuRefCounters)
3535 counterIdMap.RegisterMapping(globalCounterIds, backendCounterId, cpuRefId);
3538 for (uint16_t backendCounterId : cpuAccCounters)
3540 counterIdMap.RegisterMapping(globalCounterIds, backendCounterId, cpuAccId);
3544 CHECK(counterIdMap.GetBackendId(0) == (std::pair<uint16_t, std::string>(0, cpuRefId)));
3545 CHECK(counterIdMap.GetBackendId(1) == (std::pair<uint16_t, std::string>(1, cpuRefId)));
3546 CHECK(counterIdMap.GetBackendId(2) == (std::pair<uint16_t, std::string>(2, cpuRefId)));
3547 CHECK(counterIdMap.GetBackendId(3) == (std::pair<uint16_t, std::string>(3, cpuRefId)));
3548 CHECK(counterIdMap.GetBackendId(4) == (std::pair<uint16_t, std::string>(0, cpuAccId)));
3549 CHECK(counterIdMap.GetBackendId(5) == (std::pair<uint16_t, std::string>(1, cpuAccId)));
3551 CHECK(counterIdMap.GetGlobalId(0, cpuRefId) == 0);
3552 CHECK(counterIdMap.GetGlobalId(1, cpuRefId) == 1);
3553 CHECK(counterIdMap.GetGlobalId(2, cpuRefId) == 2);
3554 CHECK(counterIdMap.GetGlobalId(3, cpuRefId) == 3);
3555 CHECK(counterIdMap.GetGlobalId(0, cpuAccId) == 4);
3556 CHECK(counterIdMap.GetGlobalId(1, cpuAccId) == 5);
3559 TEST_CASE(
"CheckRegisterBackendCounters")
3561 uint16_t globalCounterIds = INFERENCES_RUN;
3565 ProfilingOptions options;
3566 options.m_EnableProfiling =
true;
3568 ProfilingService profilingService(arm::pipe::MAX_ARMNN_COUNTER,
3570 arm::pipe::ARMNN_SOFTWARE_INFO,
3571 arm::pipe::ARMNN_SOFTWARE_VERSION,
3572 arm::pipe::ARMNN_HARDWARE_VERSION);
3573 profilingService.ResetExternalProfilingOptions(options,
true);
3575 RegisterBackendCounters registerBackendCounters(globalCounterIds, cpuRefId, profilingService);
3579 CHECK(profilingService.GetCounterDirectory().GetCategories().empty());
3580 registerBackendCounters.RegisterCategory(
"categoryOne");
3581 auto categoryOnePtr = profilingService.GetCounterDirectory().GetCategory(
"categoryOne");
3582 CHECK(categoryOnePtr);
3584 CHECK(profilingService.GetCounterDirectory().GetDevices().empty());
3585 globalCounterIds = registerBackendCounters.RegisterDevice(
"deviceOne");
3586 auto deviceOnePtr = profilingService.GetCounterDirectory().GetDevice(globalCounterIds);
3587 CHECK(deviceOnePtr);
3588 CHECK(deviceOnePtr->m_Name ==
"deviceOne");
3590 CHECK(profilingService.GetCounterDirectory().GetCounterSets().empty());
3591 globalCounterIds = registerBackendCounters.RegisterCounterSet(
"counterSetOne");
3592 auto counterSetOnePtr = profilingService.GetCounterDirectory().GetCounterSet(globalCounterIds);
3593 CHECK(counterSetOnePtr);
3594 CHECK(counterSetOnePtr->m_Name ==
"counterSetOne");
3596 uint16_t newGlobalCounterId = registerBackendCounters.RegisterCounter(0,
3602 "first test counter");
3603 CHECK((newGlobalCounterId = INFERENCES_RUN + 1));
3604 uint16_t mappedGlobalId = profilingService.GetCounterMappings().GetGlobalId(0, cpuRefId);
3605 CHECK(mappedGlobalId == newGlobalCounterId);
3606 auto backendMapping = profilingService.GetCounterMappings().GetBackendId(newGlobalCounterId);
3607 CHECK(backendMapping.first == 0);
3608 CHECK(backendMapping.second == cpuRefId);
3611 options.m_EnableProfiling =
false;
3612 profilingService.ResetExternalProfilingOptions(options,
true);
3615 TEST_CASE(
"CheckCounterStatusQuery")
3617 ProfilingOptions options;
3618 options.m_EnableProfiling =
true;
3622 ProfilingService profilingService(arm::pipe::MAX_ARMNN_COUNTER,
3624 arm::pipe::ARMNN_SOFTWARE_INFO,
3625 arm::pipe::ARMNN_SOFTWARE_VERSION,
3626 arm::pipe::ARMNN_HARDWARE_VERSION);
3627 profilingService.ResetExternalProfilingOptions(options,
true);
3633 BackendProfiling backendProfilingCpuRef(options, profilingService, cpuRefId);
3634 BackendProfiling backendProfilingCpuAcc(options, profilingService, cpuAccId);
3636 uint16_t initialNumGlobalCounterIds = INFERENCES_RUN;
3639 RegisterBackendCounters registerBackendCountersCpuRef(initialNumGlobalCounterIds, cpuRefId, profilingService);
3642 CHECK(profilingService.GetCounterDirectory().GetCategories().empty());
3643 registerBackendCountersCpuRef.RegisterCategory(
"testCategory");
3644 auto categoryOnePtr = profilingService.GetCounterDirectory().GetCategory(
"testCategory");
3645 CHECK(categoryOnePtr);
3653 std::vector<uint16_t> cpuRefCounters = {0, 1};
3654 std::vector<uint16_t> cpuAccCounters = {0};
3657 uint16_t currentNumGlobalCounterIds = registerBackendCountersCpuRef.RegisterCounter(
3658 0,
"testCategory", 0, 0, 1.f,
"CpuRefCounter0",
"Zeroth CpuRef Counter");
3659 CHECK(currentNumGlobalCounterIds == initialNumGlobalCounterIds + 1);
3660 uint16_t mappedGlobalId = profilingService.GetCounterMappings().GetGlobalId(0, cpuRefId);
3661 CHECK(mappedGlobalId == currentNumGlobalCounterIds);
3662 auto backendMapping = profilingService.GetCounterMappings().GetBackendId(currentNumGlobalCounterIds);
3663 CHECK(backendMapping.first == 0);
3664 CHECK(backendMapping.second == cpuRefId);
3666 currentNumGlobalCounterIds = registerBackendCountersCpuRef.RegisterCounter(
3667 1,
"testCategory", 0, 0, 1.f,
"CpuRefCounter1",
"First CpuRef Counter");
3668 CHECK(currentNumGlobalCounterIds == initialNumGlobalCounterIds + 2);
3669 mappedGlobalId = profilingService.GetCounterMappings().GetGlobalId(1, cpuRefId);
3670 CHECK(mappedGlobalId == currentNumGlobalCounterIds);
3671 backendMapping = profilingService.GetCounterMappings().GetBackendId(currentNumGlobalCounterIds);
3672 CHECK(backendMapping.first == 1);
3673 CHECK(backendMapping.second == cpuRefId);
3676 RegisterBackendCounters registerBackendCountersCpuAcc(currentNumGlobalCounterIds, cpuAccId, profilingService);
3679 currentNumGlobalCounterIds = registerBackendCountersCpuAcc.RegisterCounter(
3680 0,
"testCategory", 0, 0, 1.f,
"CpuAccCounter0",
"Zeroth CpuAcc Counter");
3681 CHECK(currentNumGlobalCounterIds == initialNumGlobalCounterIds + 3);
3682 mappedGlobalId = profilingService.GetCounterMappings().GetGlobalId(0, cpuAccId);
3683 CHECK(mappedGlobalId == currentNumGlobalCounterIds);
3684 backendMapping = profilingService.GetCounterMappings().GetBackendId(currentNumGlobalCounterIds);
3685 CHECK(backendMapping.first == 0);
3686 CHECK(backendMapping.second == cpuAccId);
3689 const std::vector<uint16_t> activeGlobalCounterIds = {5};
3690 const std::vector<uint16_t> newActiveGlobalCounterIds = {6, 7};
3692 const uint32_t capturePeriod = 200;
3693 const uint32_t newCapturePeriod = 100;
3696 profilingService.SetCaptureData(capturePeriod, activeGlobalCounterIds, {});
3699 std::vector<CounterStatus> cpuRefCounterStatus = backendProfilingCpuRef.GetActiveCounters();
3700 std::vector<CounterStatus> cpuAccCounterStatus = backendProfilingCpuAcc.GetActiveCounters();
3701 CHECK_EQ(cpuRefCounterStatus.size(), 1);
3702 CHECK_EQ(cpuAccCounterStatus.size(), 0);
3705 CHECK_EQ(cpuRefCounterStatus[0].m_GlobalCounterId, activeGlobalCounterIds[0]);
3706 CHECK_EQ(cpuRefCounterStatus[0].m_BackendCounterId, cpuRefCounters[0]);
3707 CHECK_EQ(cpuRefCounterStatus[0].m_SamplingRateInMicroseconds, capturePeriod);
3708 CHECK_EQ(cpuRefCounterStatus[0].m_Enabled,
true);
3711 CounterStatus inactiveCpuRefCounter = backendProfilingCpuRef.GetCounterStatus(cpuRefCounters[1]);
3712 CHECK_EQ(inactiveCpuRefCounter.m_GlobalCounterId, 6);
3713 CHECK_EQ(inactiveCpuRefCounter.m_BackendCounterId, cpuRefCounters[1]);
3714 CHECK_EQ(inactiveCpuRefCounter.m_SamplingRateInMicroseconds, 0);
3715 CHECK_EQ(inactiveCpuRefCounter.m_Enabled,
false);
3718 CounterStatus inactiveCpuAccCounter = backendProfilingCpuAcc.GetCounterStatus(cpuAccCounters[0]);
3719 CHECK_EQ(inactiveCpuAccCounter.m_GlobalCounterId, 7);
3720 CHECK_EQ(inactiveCpuAccCounter.m_BackendCounterId, cpuAccCounters[0]);
3721 CHECK_EQ(inactiveCpuAccCounter.m_SamplingRateInMicroseconds, 0);
3722 CHECK_EQ(inactiveCpuAccCounter.m_Enabled,
false);
3725 profilingService.SetCaptureData(newCapturePeriod, newActiveGlobalCounterIds, {});
3728 cpuRefCounterStatus = backendProfilingCpuRef.GetActiveCounters();
3729 cpuAccCounterStatus = backendProfilingCpuAcc.GetActiveCounters();
3730 CHECK_EQ(cpuRefCounterStatus.size(), 1);
3731 CHECK_EQ(cpuAccCounterStatus.size(), 1);
3734 CHECK_EQ(cpuRefCounterStatus[0].m_GlobalCounterId, newActiveGlobalCounterIds[0]);
3735 CHECK_EQ(cpuRefCounterStatus[0].m_BackendCounterId, cpuRefCounters[1]);
3736 CHECK_EQ(cpuRefCounterStatus[0].m_SamplingRateInMicroseconds, newCapturePeriod);
3737 CHECK_EQ(cpuRefCounterStatus[0].m_Enabled,
true);
3740 CHECK_EQ(cpuAccCounterStatus[0].m_GlobalCounterId, newActiveGlobalCounterIds[1]);
3741 CHECK_EQ(cpuAccCounterStatus[0].m_BackendCounterId, cpuAccCounters[0]);
3742 CHECK_EQ(cpuAccCounterStatus[0].m_SamplingRateInMicroseconds, newCapturePeriod);
3743 CHECK_EQ(cpuAccCounterStatus[0].m_Enabled,
true);
3746 inactiveCpuRefCounter = backendProfilingCpuRef.GetCounterStatus(cpuRefCounters[0]);
3747 CHECK_EQ(inactiveCpuRefCounter.m_GlobalCounterId, 5);
3748 CHECK_EQ(inactiveCpuRefCounter.m_BackendCounterId, cpuRefCounters[0]);
3749 CHECK_EQ(inactiveCpuRefCounter.m_SamplingRateInMicroseconds, 0);
3750 CHECK_EQ(inactiveCpuRefCounter.m_Enabled,
false);
3753 options.m_EnableProfiling =
false;
3754 profilingService.ResetExternalProfilingOptions(options,
true);
3757 TEST_CASE(
"CheckRegisterCounters")
3759 ProfilingOptions options;
3760 options.m_EnableProfiling =
true;
3763 CaptureData captureData;
3767 arm::pipe::MAX_ARMNN_COUNTER, initialiser, mockBuffer, options.m_EnableProfiling, captureData);
3770 mockProfilingService.RegisterMapping(6, 0, cpuRefId);
3771 mockProfilingService.RegisterMapping(7, 1, cpuRefId);
3772 mockProfilingService.RegisterMapping(8, 2, cpuRefId);
3774 BackendProfiling backendProfiling(options,
3775 mockProfilingService,
3778 Timestamp timestamp;
3779 timestamp.timestamp = 1000998;
3780 timestamp.counterValues.emplace_back(0, 700);
3781 timestamp.counterValues.emplace_back(2, 93);
3782 std::vector<Timestamp> timestamps;
3783 timestamps.push_back(timestamp);
3784 backendProfiling.ReportCounters(timestamps);
3786 auto readBuffer = mockBuffer.GetReadableBuffer();
3788 uint32_t headerWord0 = ReadUint32(readBuffer, 0);
3789 uint32_t headerWord1 = ReadUint32(readBuffer, 4);
3790 uint64_t readTimestamp = ReadUint64(readBuffer, 8);
3792 CHECK(((headerWord0 >> 26) & 0x0000003F) == 3);
3793 CHECK(((headerWord0 >> 19) & 0x0000007F) == 0);
3794 CHECK(((headerWord0 >> 16) & 0x00000007) == 0);
3795 CHECK(headerWord1 == 20);
3796 CHECK(1000998 == readTimestamp);
3798 uint32_t offset = 16;
3800 uint16_t readIndex = ReadUint16(readBuffer, offset);
3801 CHECK(6 == readIndex);
3805 uint32_t readValue = ReadUint32(readBuffer, offset);
3806 CHECK(700 == readValue);
3810 readIndex = ReadUint16(readBuffer, offset);
3811 CHECK(8 == readIndex);
3815 readValue = ReadUint32(readBuffer, offset);
3816 CHECK(93 == readValue);
3819 TEST_CASE(
"CheckFileFormat") {
3821 LogLevelSwapper logLevelSwapper(arm::pipe::LogSeverity::Warning);
3824 std::stringstream ss;
3828 ProfilingOptions options;
3829 options.m_EnableProfiling =
true;
3831 CHECK(options.m_FileFormat ==
"binary");
3834 options.m_FileFormat =
"json";
3837 ProfilingService profilingService(arm::pipe::MAX_ARMNN_COUNTER,
3839 arm::pipe::ARMNN_SOFTWARE_INFO,
3840 arm::pipe::ARMNN_SOFTWARE_VERSION,
3841 arm::pipe::ARMNN_HARDWARE_VERSION);
3842 profilingService.ResetExternalProfilingOptions(options,
true);
3844 profilingService.Update();
3845 CHECK(profilingService.GetCurrentState()==ProfilingState::NotConnected);
3849 profilingService.Update();
3851 streamRedirector.CancelRedirect();
3854 if (ss.str().find(
"Unsupported profiling file format, only binary is supported") == std::string::npos)
3856 std::cout << ss.str();
3857 FAIL(
"Expected string not found.");
bool IsOpen() const override
CPU Execution: Reference C++ kernels.
uint32_t GetStreamMetaDataPacketSize()
Copyright (c) 2021 ARM Limited and Contributors.
void IgnoreUnused(Ts &&...)
bool m_EnableProfiling
Indicates whether external profiling is enabled or not.
arm::pipe::IReportStructure IReportStructure
bool WritePacket(const unsigned char *buffer, uint32_t length) override
constexpr char const * GetComputeDeviceAsCString(Compute compute)
Deprecated function that will be removed together with the Compute enum.
constexpr unsigned int LOWEST_CAPTURE_PERIOD
The lowest performance data capture interval we support is 10 miliseconds.
unsigned long GetWrittenDataSize()
CPU Execution: NEON: ArmCompute.
std::enable_if_t< std::is_unsigned< Source >::value &&std::is_unsigned< Dest >::value, Dest > numeric_cast(Source source)
ExternalProfilingOptions m_ProfilingOptions
arm::pipe::IProfilingService & GetProfilingService(armnn::RuntimeImpl *runtime)