10 #include <client/src/BufferManager.hpp> 11 #include <client/src/ProfilingUtils.hpp> 12 #include <client/src/SendCounterPacket.hpp> 16 #include <common/include/Assert.hpp> 17 #include <common/include/Conversion.hpp> 18 #include <common/include/Constants.hpp> 19 #include <common/include/CounterDirectory.hpp> 20 #include <common/include/EncodeVersion.hpp> 21 #include <common/include/NumericCast.hpp> 22 #include <common/include/Processes.hpp> 23 #include <common/include/ProfilingException.hpp> 25 #include <doctest/doctest.h> 35 uint16_t constexpr WAIT_UNTIL_READABLE_MS = 20;
37 void SetNotConnectedProfilingState(ProfilingStateMachine& profilingStateMachine)
39 ProfilingState currentState = profilingStateMachine.GetCurrentState();
42 case ProfilingState::WaitingForAck:
43 profilingStateMachine.TransitionToState(ProfilingState::Active);
45 case ProfilingState::Uninitialised:
47 case ProfilingState::Active:
48 profilingStateMachine.TransitionToState(ProfilingState::NotConnected);
50 case ProfilingState::NotConnected:
53 CHECK_MESSAGE(
false,
"Invalid profiling state");
57 void SetWaitingForAckProfilingState(ProfilingStateMachine& profilingStateMachine)
59 ProfilingState currentState = profilingStateMachine.GetCurrentState();
62 case ProfilingState::Uninitialised:
64 case ProfilingState::Active:
65 profilingStateMachine.TransitionToState(ProfilingState::NotConnected);
67 case ProfilingState::NotConnected:
68 profilingStateMachine.TransitionToState(ProfilingState::WaitingForAck);
70 case ProfilingState::WaitingForAck:
73 CHECK_MESSAGE(
false,
"Invalid profiling state");
77 void SetActiveProfilingState(ProfilingStateMachine& profilingStateMachine)
79 ProfilingState currentState = profilingStateMachine.GetCurrentState();
82 case ProfilingState::Uninitialised:
83 profilingStateMachine.TransitionToState(ProfilingState::NotConnected);
85 case ProfilingState::NotConnected:
86 profilingStateMachine.TransitionToState(ProfilingState::WaitingForAck);
88 case ProfilingState::WaitingForAck:
89 profilingStateMachine.TransitionToState(ProfilingState::Active);
91 case ProfilingState::Active:
94 CHECK_MESSAGE(
false,
"Invalid profiling state");
104 TEST_CASE(
"MockSendCounterPacketTest")
112 const char* buffer =
reinterpret_cast<const char*
>(packetBuffer->GetReadableData());
114 CHECK(strcmp(buffer,
"SendStreamMetaDataPacket") == 0);
118 CounterDirectory counterDirectory;
122 buffer =
reinterpret_cast<const char*
>(packetBuffer->GetReadableData());
124 CHECK(strcmp(buffer,
"SendCounterDirectoryPacket") == 0);
128 uint64_t timestamp = 0;
129 std::vector<CounterValue> indexValuePairs;
134 buffer =
reinterpret_cast<const char*
>(packetBuffer->GetReadableData());
136 CHECK(strcmp(buffer,
"SendPeriodicCounterCapturePacket") == 0);
140 uint32_t capturePeriod = 0;
141 std::vector<uint16_t> selectedCounterIds;
145 buffer =
reinterpret_cast<const char*
>(packetBuffer->GetReadableData());
147 CHECK(strcmp(buffer,
"SendPeriodicCounterSelectionPacket") == 0);
152 TEST_CASE(
"SendPeriodicCounterSelectionPacketTest")
156 SendCounterPacket sendPacket1(mockBuffer1,
157 arm::pipe::ARMNN_SOFTWARE_INFO,
158 arm::pipe::ARMNN_SOFTWARE_VERSION,
159 arm::pipe::ARMNN_HARDWARE_VERSION);
161 uint32_t capturePeriod = 1000;
162 std::vector<uint16_t> selectedCounterIds;
163 CHECK_THROWS_AS(sendPacket1.SendPeriodicCounterSelectionPacket(
164 capturePeriod, selectedCounterIds),
169 SendCounterPacket sendPacket2(mockBuffer2,
170 arm::pipe::ARMNN_SOFTWARE_INFO,
171 arm::pipe::ARMNN_SOFTWARE_VERSION,
172 arm::pipe::ARMNN_HARDWARE_VERSION);
174 sendPacket2.SendPeriodicCounterSelectionPacket(capturePeriod, selectedCounterIds);
175 auto readBuffer2 = mockBuffer2.GetReadableBuffer();
177 uint32_t headerWord0 = ReadUint32(readBuffer2, 0);
178 uint32_t headerWord1 = ReadUint32(readBuffer2, 4);
179 uint32_t period = ReadUint32(readBuffer2, 8);
181 CHECK(((headerWord0 >> 26) & 0x3F) == 0);
182 CHECK(((headerWord0 >> 16) & 0x3FF) == 4);
183 CHECK(headerWord1 == 4);
184 CHECK(period == 1000);
188 SendCounterPacket sendPacket3(mockBuffer3,
189 arm::pipe::ARMNN_SOFTWARE_INFO,
190 arm::pipe::ARMNN_SOFTWARE_VERSION,
191 arm::pipe::ARMNN_HARDWARE_VERSION);
193 selectedCounterIds.reserve(5);
194 selectedCounterIds.emplace_back(100);
195 selectedCounterIds.emplace_back(200);
196 selectedCounterIds.emplace_back(300);
197 selectedCounterIds.emplace_back(400);
198 selectedCounterIds.emplace_back(500);
199 sendPacket3.SendPeriodicCounterSelectionPacket(capturePeriod, selectedCounterIds);
202 headerWord0 = ReadUint32(readBuffer3, 0);
203 headerWord1 = ReadUint32(readBuffer3, 4);
204 period = ReadUint32(readBuffer3, 8);
206 CHECK(((headerWord0 >> 26) & 0x3F) == 0);
207 CHECK(((headerWord0 >> 16) & 0x3FF) == 4);
208 CHECK(headerWord1 == 14);
209 CHECK(period == 1000);
211 uint16_t counterId = 0;
212 uint32_t offset = 12;
215 for(
const uint16_t&
id : selectedCounterIds)
217 counterId = ReadUint16(readBuffer3, offset);
218 CHECK(counterId ==
id);
223 TEST_CASE(
"SendPeriodicCounterCapturePacketTest")
225 ProfilingStateMachine profilingStateMachine;
229 SendCounterPacket sendPacket1(mockBuffer1,
230 arm::pipe::ARMNN_SOFTWARE_INFO,
231 arm::pipe::ARMNN_SOFTWARE_VERSION,
232 arm::pipe::ARMNN_HARDWARE_VERSION);
234 auto captureTimestamp = std::chrono::steady_clock::now();
235 uint64_t time =
static_cast<uint64_t
>(captureTimestamp.time_since_epoch().count());
236 std::vector<CounterValue> indexValuePairs;
238 CHECK_THROWS_AS(sendPacket1.SendPeriodicCounterCapturePacket(time, indexValuePairs),
243 SendCounterPacket sendPacket2(mockBuffer2,
244 arm::pipe::ARMNN_SOFTWARE_INFO,
245 arm::pipe::ARMNN_SOFTWARE_VERSION,
246 arm::pipe::ARMNN_HARDWARE_VERSION);
248 sendPacket2.SendPeriodicCounterCapturePacket(time, indexValuePairs);
249 auto readBuffer2 = mockBuffer2.GetReadableBuffer();
251 uint32_t headerWord0 = ReadUint32(readBuffer2, 0);
252 uint32_t headerWord1 = ReadUint32(readBuffer2, 4);
253 uint64_t readTimestamp = ReadUint64(readBuffer2, 8);
255 CHECK(((headerWord0 >> 26) & 0x0000003F) == 3);
256 CHECK(((headerWord0 >> 19) & 0x0000007F) == 0);
257 CHECK(((headerWord0 >> 16) & 0x00000007) == 0);
258 CHECK(headerWord1 == 8);
259 CHECK(time == readTimestamp);
263 SendCounterPacket sendPacket3(mockBuffer3,
264 arm::pipe::ARMNN_SOFTWARE_INFO,
265 arm::pipe::ARMNN_SOFTWARE_VERSION,
266 arm::pipe::ARMNN_HARDWARE_VERSION);
268 indexValuePairs.reserve(5);
269 indexValuePairs.emplace_back(CounterValue{0, 100});
270 indexValuePairs.emplace_back(CounterValue{1, 200});
271 indexValuePairs.emplace_back(CounterValue{2, 300});
272 indexValuePairs.emplace_back(CounterValue{3, 400});
273 indexValuePairs.emplace_back(CounterValue{4, 500});
274 sendPacket3.SendPeriodicCounterCapturePacket(time, indexValuePairs);
277 headerWord0 = ReadUint32(readBuffer3, 0);
278 headerWord1 = ReadUint32(readBuffer3, 4);
279 uint64_t readTimestamp2 = ReadUint64(readBuffer3, 8);
281 CHECK(((headerWord0 >> 26) & 0x0000003F) == 3);
282 CHECK(((headerWord0 >> 19) & 0x0000007F) == 0);
283 CHECK(((headerWord0 >> 16) & 0x00000007) == 0);
284 CHECK(headerWord1 == 38);
285 CHECK(time == readTimestamp2);
287 uint16_t counterIndex = 0;
288 uint32_t counterValue = 100;
289 uint32_t offset = 16;
292 for (
auto it = indexValuePairs.begin(), end = indexValuePairs.end(); it != end; ++it)
295 uint16_t readIndex = ReadUint16(readBuffer3, offset);
296 CHECK(counterIndex == readIndex);
301 uint32_t readValue = ReadUint32(readBuffer3, offset);
302 CHECK(counterValue == readValue);
309 TEST_CASE(
"SendStreamMetaDataPacketTest")
315 SendCounterPacket sendPacket1(mockBuffer1,
316 arm::pipe::ARMNN_SOFTWARE_INFO,
317 arm::pipe::ARMNN_SOFTWARE_VERSION,
318 arm::pipe::ARMNN_HARDWARE_VERSION);
319 CHECK_THROWS_AS(sendPacket1.SendStreamMetaDataPacket(), BufferExhaustion);
323 std::string processName = GetProcessName().substr(0, 60);
326 uint32_t hardwareVersionSize =
arm::pipe::numeric_cast<uint32_t>(arm::pipe::ARMNN_HARDWARE_VERSION.size()) + 1;
327 uint32_t softwareVersionSize =
arm::pipe::numeric_cast<uint32_t>(arm::pipe::ARMNN_SOFTWARE_VERSION.size()) + 1;
347 std::vector<std::pair<uint32_t, uint32_t>> packetVersions;
348 packetVersions.push_back(std::make_pair(ConstructHeader(0, 0), arm::pipe::EncodeVersion(1, 0, 0)));
349 packetVersions.push_back(std::make_pair(ConstructHeader(0, 1), arm::pipe::EncodeVersion(1, 0, 0)));
350 packetVersions.push_back(std::make_pair(ConstructHeader(0, 2), arm::pipe::EncodeVersion(1, 0, 0)));
351 packetVersions.push_back(std::make_pair(ConstructHeader(0, 3), arm::pipe::EncodeVersion(1, 0, 0)));
352 packetVersions.push_back(std::make_pair(ConstructHeader(0, 4), arm::pipe::EncodeVersion(1, 0, 0)));
353 packetVersions.push_back(std::make_pair(ConstructHeader(0, 5), arm::pipe::EncodeVersion(1, 0, 0)));
354 packetVersions.push_back(std::make_pair(ConstructHeader(0, 6), arm::pipe::EncodeVersion(1, 0, 0)));
355 packetVersions.push_back(std::make_pair(ConstructHeader(0, 7), arm::pipe::EncodeVersion(1, 0, 0)));
356 packetVersions.push_back(std::make_pair(ConstructHeader(3, 0, 0), arm::pipe::EncodeVersion(1, 0, 0)));
357 packetVersions.push_back(std::make_pair(ConstructHeader(3, 1, 0), arm::pipe::EncodeVersion(1, 0, 0)));
358 packetVersions.push_back(std::make_pair(ConstructHeader(3, 1, 1), arm::pipe::EncodeVersion(1, 0, 0)));
359 packetVersions.push_back(std::make_pair(ConstructHeader(1, 0, 0), arm::pipe::EncodeVersion(1, 0, 0)));
360 packetVersions.push_back(std::make_pair(ConstructHeader(1, 0, 1), arm::pipe::EncodeVersion(1, 0, 0)));
362 uint32_t packetEntries =
static_cast<uint32_t
>(packetVersions.size());
365 SendCounterPacket sendPacket2(mockBuffer2,
366 arm::pipe::ARMNN_SOFTWARE_INFO,
367 arm::pipe::ARMNN_SOFTWARE_VERSION,
368 arm::pipe::ARMNN_HARDWARE_VERSION);
369 sendPacket2.SendStreamMetaDataPacket();
372 uint32_t headerWord0 = ReadUint32(readBuffer2, 0);
373 uint32_t headerWord1 = ReadUint32(readBuffer2, sizeUint32);
375 CHECK(((headerWord0 >> 26) & 0x3F) == 0);
376 CHECK(((headerWord0 >> 16) & 0x3FF) == 0);
379 10 * sizeUint32 + infoSize +
380 hardwareVersionSize + softwareVersionSize +
381 processNameSize + sizeUint32 +
382 2 * packetEntries * sizeUint32);
384 CHECK(headerWord1 == totalLength - (2 * sizeUint32));
386 uint32_t offset = sizeUint32 * 2;
387 CHECK(ReadUint32(readBuffer2, offset) == arm::pipe::PIPE_MAGIC);
388 offset += sizeUint32;
389 CHECK(ReadUint32(readBuffer2, offset) == arm::pipe::EncodeVersion(1, 0, 0));
390 offset += sizeUint32;
391 CHECK(ReadUint32(readBuffer2, offset) == MAX_METADATA_PACKET_LENGTH);
392 offset += sizeUint32;
393 int pid = arm::pipe::GetCurrentProcessId();
394 CHECK(ReadUint32(readBuffer2, offset) == arm::pipe::numeric_cast<uint32_t>(pid));
395 offset += sizeUint32;
396 uint32_t poolOffset = 10 * sizeUint32;
397 CHECK(ReadUint32(readBuffer2, offset) == poolOffset);
398 offset += sizeUint32;
399 poolOffset += infoSize;
400 CHECK(ReadUint32(readBuffer2, offset) == poolOffset);
401 offset += sizeUint32;
402 poolOffset += hardwareVersionSize;
403 CHECK(ReadUint32(readBuffer2, offset) == poolOffset);
404 offset += sizeUint32;
405 poolOffset += softwareVersionSize;
406 CHECK(ReadUint32(readBuffer2, offset) == poolOffset);
407 offset += sizeUint32;
408 poolOffset += processNameSize;
409 CHECK(ReadUint32(readBuffer2, offset) == poolOffset);
410 offset += sizeUint32;
411 CHECK(ReadUint32(readBuffer2, offset) == 0);
413 const unsigned char* readData2 = readBuffer2->GetReadableData();
415 offset += sizeUint32;
418 CHECK(strcmp(reinterpret_cast<const char *>(&readData2[offset]),
419 arm::pipe::ARMNN_SOFTWARE_INFO.c_str()) == 0);
423 if (hardwareVersionSize)
425 CHECK(strcmp(reinterpret_cast<const char *>(&readData2[offset]),
426 arm::pipe::ARMNN_HARDWARE_VERSION.c_str()) == 0);
427 offset += hardwareVersionSize;
430 if (softwareVersionSize)
432 CHECK(strcmp(reinterpret_cast<const char *>(&readData2[offset]),
433 arm::pipe::ARMNN_SOFTWARE_VERSION.c_str()) == 0);
434 offset += softwareVersionSize;
439 CHECK(strcmp(reinterpret_cast<const char *>(&readData2[offset]), GetProcessName().c_str()) == 0);
440 offset += processNameSize;
445 uint32_t numberOfEntries = ReadUint32(readBuffer2, offset);
446 CHECK((numberOfEntries >> 16) == packetEntries);
447 offset += sizeUint32;
448 for (std::pair<uint32_t, uint32_t>& packetVersion : packetVersions)
450 uint32_t readPacketId = ReadUint32(readBuffer2, offset);
451 CHECK(packetVersion.first == readPacketId);
452 offset += sizeUint32;
453 uint32_t readVersion = ReadUint32(readBuffer2, offset);
454 CHECK(packetVersion.second == readVersion);
455 offset += sizeUint32;
459 CHECK(offset == totalLength);
462 TEST_CASE(
"CreateDeviceRecordTest")
468 uint16_t deviceUid = 27;
469 const std::string deviceName =
"some_device";
470 uint16_t deviceCores = 3;
471 const DevicePtr device = std::make_unique<Device>(deviceUid, deviceName, deviceCores);
474 SendCounterPacket::DeviceRecord deviceRecord;
475 std::string errorMessage;
479 CHECK(errorMessage.empty());
480 CHECK(deviceRecord.size() == 6);
482 uint16_t deviceRecordWord0[]
484 static_cast<uint16_t
>(deviceRecord[0] >> 16),
485 static_cast<uint16_t>(deviceRecord[0])
487 CHECK(deviceRecordWord0[0] == deviceUid);
488 CHECK(deviceRecordWord0[1] == deviceCores);
489 CHECK(deviceRecord[1] == 8);
490 CHECK(deviceRecord[2] == deviceName.size() + 1);
491 CHECK(std::memcmp(deviceRecord.data() + 3, deviceName.data(), deviceName.size()) == 0);
494 TEST_CASE(
"CreateInvalidDeviceRecordTest")
500 uint16_t deviceUid = 27;
501 const std::string deviceName =
"some€£invalid‡device";
502 uint16_t deviceCores = 3;
503 const DevicePtr device = std::make_unique<Device>(deviceUid, deviceName, deviceCores);
506 SendCounterPacket::DeviceRecord deviceRecord;
507 std::string errorMessage;
511 CHECK(!errorMessage.empty());
512 CHECK(deviceRecord.empty());
515 TEST_CASE(
"CreateCounterSetRecordTest")
521 uint16_t counterSetUid = 27;
522 const std::string counterSetName =
"some_counter_set";
523 uint16_t counterSetCount = 3421;
524 const CounterSetPtr counterSet = std::make_unique<CounterSet>(counterSetUid, counterSetName, counterSetCount);
527 SendCounterPacket::CounterSetRecord counterSetRecord;
528 std::string errorMessage;
532 CHECK(errorMessage.empty());
533 CHECK(counterSetRecord.size() == 8);
535 uint16_t counterSetRecordWord0[]
537 static_cast<uint16_t
>(counterSetRecord[0] >> 16),
538 static_cast<uint16_t>(counterSetRecord[0])
540 CHECK(counterSetRecordWord0[0] == counterSetUid);
541 CHECK(counterSetRecordWord0[1] == counterSetCount);
542 CHECK(counterSetRecord[1] == 8);
543 CHECK(counterSetRecord[2] == counterSetName.size() + 1);
544 CHECK(std::memcmp(counterSetRecord.data() + 3, counterSetName.data(), counterSetName.size()) == 0);
547 TEST_CASE(
"CreateInvalidCounterSetRecordTest")
553 uint16_t counterSetUid = 27;
554 const std::string counterSetName =
"some invalid_counter€£set";
555 uint16_t counterSetCount = 3421;
556 const CounterSetPtr counterSet = std::make_unique<CounterSet>(counterSetUid, counterSetName, counterSetCount);
559 SendCounterPacket::CounterSetRecord counterSetRecord;
560 std::string errorMessage;
564 CHECK(!errorMessage.empty());
565 CHECK(counterSetRecord.empty());
568 TEST_CASE(
"CreateEventRecordTest")
574 uint16_t counterUid = 7256;
575 uint16_t maxCounterUid = 132;
576 uint16_t deviceUid = 132;
577 uint16_t counterSetUid = 4497;
578 uint16_t counterClass = 1;
579 uint16_t counterInterpolation = 1;
580 double counterMultiplier = 1234.567f;
581 const std::string counterName =
"some_valid_counter";
582 const std::string counterDescription =
"a_counter_for_testing";
583 const std::string counterUnits =
"Mrads2";
584 const CounterPtr counter = std::make_unique<Counter>(armnn::profiling::BACKEND_ID,
588 counterInterpolation,
595 ARM_PIPE_ASSERT(counter);
598 SendCounterPacket::EventRecord eventRecord;
599 std::string errorMessage;
603 CHECK(errorMessage.empty());
604 CHECK(eventRecord.size() == 24);
606 uint16_t eventRecordWord0[]
608 static_cast<uint16_t
>(eventRecord[0] >> 16),
609 static_cast<uint16_t>(eventRecord[0])
611 uint16_t eventRecordWord1[]
613 static_cast<uint16_t
>(eventRecord[1] >> 16),
614 static_cast<uint16_t>(eventRecord[1])
616 uint16_t eventRecordWord2[]
618 static_cast<uint16_t
>(eventRecord[2] >> 16),
619 static_cast<uint16_t>(eventRecord[2])
621 uint32_t eventRecordWord34[]
627 CHECK(eventRecordWord0[0] == maxCounterUid);
628 CHECK(eventRecordWord0[1] == counterUid);
629 CHECK(eventRecordWord1[0] == deviceUid);
631 CHECK(eventRecordWord1[1] == counterSetUid);
632 CHECK(eventRecordWord2[0] == counterClass);
633 CHECK(eventRecordWord2[1] == counterInterpolation);
634 CHECK(std::memcmp(eventRecordWord34, &counterMultiplier,
sizeof(counterMultiplier)) == 0);
636 ARM_PIPE_NO_CONVERSION_WARN_BEGIN
637 uint32_t eventRecordBlockSize = 8u *
sizeof(uint32_t);
638 uint32_t counterNameOffset = eventRecordBlockSize;
639 uint32_t counterDescriptionOffset = counterNameOffset +
645 size_t counterUnitsOffset = counterDescriptionOffset +
647 counterDescription.size() +
651 ARM_PIPE_NO_CONVERSION_WARN_END
653 CHECK(eventRecord[5] == counterNameOffset);
654 CHECK(eventRecord[6] == counterDescriptionOffset);
655 CHECK(eventRecord[7] == counterUnitsOffset);
658 auto eventRecordPool =
reinterpret_cast<unsigned char*
>(eventRecord.data());
659 size_t uint32_t_size =
sizeof(uint32_t);
662 CHECK(eventRecordPool[counterNameOffset] == counterName.size() + 1);
664 CHECK(std::memcmp(eventRecordPool +
668 counterName.size()) == 0);
670 CHECK(eventRecordPool[counterNameOffset + uint32_t_size + counterName.size()] ==
'\0');
673 CHECK(eventRecordPool[counterDescriptionOffset] == counterDescription.size() + 1);
675 CHECK(std::memcmp(eventRecordPool +
676 counterDescriptionOffset +
678 counterDescription.data(),
679 counterDescription.size()) == 0);
681 CHECK(eventRecordPool[counterDescriptionOffset + uint32_t_size + counterDescription.size()] ==
'\0');
684 CHECK(eventRecordPool[counterUnitsOffset] == counterUnits.size() + 1);
686 CHECK(std::memcmp(eventRecordPool +
690 counterUnits.size()) == 0);
692 CHECK(eventRecordPool[counterUnitsOffset + uint32_t_size + counterUnits.size()] ==
'\0');
695 TEST_CASE(
"CreateEventRecordNoUnitsTest")
701 uint16_t counterUid = 44312;
702 uint16_t maxCounterUid = 345;
703 uint16_t deviceUid = 101;
704 uint16_t counterSetUid = 34035;
705 uint16_t counterClass = 0;
706 uint16_t counterInterpolation = 1;
707 double counterMultiplier = 4435.0023f;
708 const std::string counterName =
"some_valid_counter";
709 const std::string counterDescription =
"a_counter_for_testing";
710 const CounterPtr counter = std::make_unique<Counter>(armnn::profiling::BACKEND_ID,
714 counterInterpolation,
721 ARM_PIPE_ASSERT(counter);
724 SendCounterPacket::EventRecord eventRecord;
725 std::string errorMessage;
729 CHECK(errorMessage.empty());
730 CHECK(eventRecord.size() == 21);
732 uint16_t eventRecordWord0[]
734 static_cast<uint16_t
>(eventRecord[0] >> 16),
735 static_cast<uint16_t>(eventRecord[0])
737 uint16_t eventRecordWord1[]
739 static_cast<uint16_t
>(eventRecord[1] >> 16),
740 static_cast<uint16_t>(eventRecord[1])
742 uint16_t eventRecordWord2[]
744 static_cast<uint16_t
>(eventRecord[2] >> 16),
745 static_cast<uint16_t>(eventRecord[2])
747 uint32_t eventRecordWord34[]
752 CHECK(eventRecordWord0[0] == maxCounterUid);
753 CHECK(eventRecordWord0[1] == counterUid);
754 CHECK(eventRecordWord1[0] == deviceUid);
755 CHECK(eventRecordWord1[1] == counterSetUid);
756 CHECK(eventRecordWord2[0] == counterClass);
757 CHECK(eventRecordWord2[1] == counterInterpolation);
758 CHECK(std::memcmp(eventRecordWord34, &counterMultiplier,
sizeof(counterMultiplier)) == 0);
760 ARM_PIPE_NO_CONVERSION_WARN_BEGIN
761 uint32_t eventRecordBlockSize = 8u *
sizeof(uint32_t);
762 uint32_t counterNameOffset = eventRecordBlockSize;
763 uint32_t counterDescriptionOffset = counterNameOffset +
768 ARM_PIPE_NO_CONVERSION_WARN_END
770 CHECK(eventRecord[5] == counterNameOffset);
771 CHECK(eventRecord[6] == counterDescriptionOffset);
772 CHECK(eventRecord[7] == 0);
775 auto eventRecordPool =
reinterpret_cast<unsigned char*
>(eventRecord.data());
776 size_t uint32_t_size =
sizeof(uint32_t);
779 CHECK(eventRecordPool[counterNameOffset] == counterName.size() + 1);
781 CHECK(std::memcmp(eventRecordPool +
785 counterName.size()) == 0);
787 CHECK(eventRecordPool[counterNameOffset + uint32_t_size + counterName.size()] ==
'\0');
790 CHECK(eventRecordPool[counterDescriptionOffset] == counterDescription.size() + 1);
792 CHECK(std::memcmp(eventRecordPool +
793 counterDescriptionOffset +
795 counterDescription.data(),
796 counterDescription.size()) == 0);
798 CHECK(eventRecordPool[counterDescriptionOffset + uint32_t_size + counterDescription.size()] ==
'\0');
801 TEST_CASE(
"CreateInvalidEventRecordTest1")
807 uint16_t counterUid = 7256;
808 uint16_t maxCounterUid = 132;
809 uint16_t deviceUid = 132;
810 uint16_t counterSetUid = 4497;
811 uint16_t counterClass = 1;
812 uint16_t counterInterpolation = 1;
813 double counterMultiplier = 1234.567f;
814 const std::string counterName =
"some_invalid_counter £££";
815 const std::string counterDescription =
"a_counter_for_testing";
816 const std::string counterUnits =
"Mrads2";
817 const CounterPtr counter = std::make_unique<Counter>(armnn::profiling::BACKEND_ID,
821 counterInterpolation,
828 ARM_PIPE_ASSERT(counter);
831 SendCounterPacket::EventRecord eventRecord;
832 std::string errorMessage;
836 CHECK(!errorMessage.empty());
837 CHECK(eventRecord.empty());
840 TEST_CASE(
"CreateInvalidEventRecordTest2")
846 uint16_t counterUid = 7256;
847 uint16_t maxCounterUid = 132;
848 uint16_t deviceUid = 132;
849 uint16_t counterSetUid = 4497;
850 uint16_t counterClass = 1;
851 uint16_t counterInterpolation = 1;
852 double counterMultiplier = 1234.567f;
853 const std::string counterName =
"some_invalid_counter";
854 const std::string counterDescription =
"an invalid d€scription";
855 const std::string counterUnits =
"Mrads2";
856 const CounterPtr counter = std::make_unique<Counter>(armnn::profiling::BACKEND_ID,
860 counterInterpolation,
867 ARM_PIPE_ASSERT(counter);
870 SendCounterPacket::EventRecord eventRecord;
871 std::string errorMessage;
875 CHECK(!errorMessage.empty());
876 CHECK(eventRecord.empty());
879 TEST_CASE(
"CreateInvalidEventRecordTest3")
885 uint16_t counterUid = 7256;
886 uint16_t maxCounterUid = 132;
887 uint16_t deviceUid = 132;
888 uint16_t counterSetUid = 4497;
889 uint16_t counterClass = 1;
890 uint16_t counterInterpolation = 1;
891 double counterMultiplier = 1234.567f;
892 const std::string counterName =
"some_invalid_counter";
893 const std::string counterDescription =
"a valid description";
894 const std::string counterUnits =
"Mrad s2";
895 const CounterPtr counter = std::make_unique<Counter>(armnn::profiling::BACKEND_ID,
899 counterInterpolation,
906 ARM_PIPE_ASSERT(counter);
909 SendCounterPacket::EventRecord eventRecord;
910 std::string errorMessage;
914 CHECK(!errorMessage.empty());
915 CHECK(eventRecord.empty());
918 TEST_CASE(
"CreateCategoryRecordTest")
924 const std::string categoryName =
"some_category";
925 const CategoryPtr category = std::make_unique<Category>(categoryName);
926 ARM_PIPE_ASSERT(category);
927 category->m_Counters = { 11u, 23u, 5670u };
931 counters.insert(std::make_pair<uint16_t, CounterPtr>(11,
932 CounterPtr(
new Counter(armnn::profiling::BACKEND_ID,
943 counters.insert(std::make_pair<uint16_t, CounterPtr>(23,
944 CounterPtr(
new Counter(armnn::profiling::BACKEND_ID,
951 "the second counter",
955 counters.insert(std::make_pair<uint16_t, CounterPtr>(5670,
956 CounterPtr(
new Counter(armnn::profiling::BACKEND_ID,
962 "and this is number 3",
967 Counter* counter1 = counters.find(11)->second.get();
968 Counter* counter2 = counters.find(23)->second.get();
969 Counter* counter3 = counters.find(5670)->second.get();
970 ARM_PIPE_ASSERT(counter1);
971 ARM_PIPE_ASSERT(counter2);
972 ARM_PIPE_ASSERT(counter3);
976 SendCounterPacket::CategoryRecord categoryRecord;
977 std::string errorMessage;
981 CHECK(errorMessage.empty());
982 CHECK(categoryRecord.size() == 79);
985 uint16_t categoryRecordWord1[]
987 static_cast<uint16_t
>(categoryRecord[0] >> 16),
988 static_cast<uint16_t>(categoryRecord[0])
990 CHECK(categoryRecordWord1[0] == categoryEventCount);
991 CHECK(categoryRecordWord1[1] == 0);
993 size_t uint32_t_size =
sizeof(uint32_t);
995 ARM_PIPE_NO_CONVERSION_WARN_BEGIN
996 uint32_t categoryRecordBlockSize = 3u * uint32_t_size;
997 uint32_t eventPointerTableOffset = categoryRecordBlockSize;
998 uint32_t categoryNameOffset = eventPointerTableOffset +
999 categoryEventCount * uint32_t_size;
1000 ARM_PIPE_NO_CONVERSION_WARN_END
1002 CHECK(categoryRecord[1] == eventPointerTableOffset);
1003 CHECK(categoryRecord[2] == categoryNameOffset);
1005 auto categoryRecordPool =
reinterpret_cast<unsigned char*
>(categoryRecord.data());
1008 uint32_t eventRecord0Offset = categoryRecordPool[eventPointerTableOffset + 0 * uint32_t_size];
1009 uint32_t eventRecord1Offset = categoryRecordPool[eventPointerTableOffset + 1 * uint32_t_size];
1010 uint32_t eventRecord2Offset = categoryRecordPool[eventPointerTableOffset + 2 * uint32_t_size];
1011 CHECK(eventRecord0Offset == 32);
1012 CHECK(eventRecord1Offset == 120);
1013 CHECK(eventRecord2Offset == 200);
1016 CHECK(categoryRecordPool[categoryNameOffset] == categoryName.size() + 1);
1018 CHECK(std::memcmp(categoryRecordPool +
1019 categoryNameOffset +
1021 categoryName.data(),
1022 categoryName.size()) == 0);
1024 CHECK(categoryRecordPool[categoryNameOffset + uint32_t_size + categoryName.size()] ==
'\0');
1030 uint16_t eventRecord0Word0[2] = { 0u, 0u };
1031 std::memcpy(eventRecord0Word0, categoryRecordPool + categoryRecordBlockSize + eventRecord0Offset,
1032 sizeof(eventRecord0Word0));
1033 CHECK(eventRecord0Word0[0] == counter1->m_Uid);
1034 CHECK(eventRecord0Word0[1] == counter1->m_MaxCounterUid);
1037 uint32_t counter1NameOffset = 0;
1038 std::memcpy(&counter1NameOffset, categoryRecordPool + eventRecord0Offset + 5u * uint32_t_size, uint32_t_size);
1039 CHECK(counter1NameOffset == 0);
1041 CHECK(categoryRecordPool[eventRecord0Offset +
1042 categoryRecordBlockSize +
1043 8u * uint32_t_size +
1045 ] == counter1->m_Name.size() + 1);
1048 CHECK(std::memcmp(categoryRecordPool +
1049 categoryRecordBlockSize +
1050 eventRecord0Offset +
1051 8u * uint32_t_size +
1052 counter1NameOffset +
1054 counter1->m_Name.data(),
1055 counter1->m_Name.size()) == 0);
1057 CHECK(categoryRecordPool[eventRecord0Offset +
1058 categoryRecordBlockSize +
1059 8u * uint32_t_size +
1060 counter1NameOffset +
1062 counter1->m_Name.size()
1066 uint32_t counter2NameOffset = 0;
1067 std::memcpy(&counter2NameOffset, categoryRecordPool +
1068 categoryRecordBlockSize +
1069 eventRecord1Offset +
1072 CHECK(counter2NameOffset == 8u * uint32_t_size );
1075 CHECK(categoryRecordPool[eventRecord1Offset +
1076 categoryRecordBlockSize +
1078 ] == counter2->m_Name.size() + 1);
1081 CHECK(std::memcmp(categoryRecordPool +
1082 categoryRecordBlockSize +
1083 eventRecord1Offset +
1084 counter2NameOffset +
1086 counter2->m_Name.data(),
1087 counter2->m_Name.size()) == 0);
1091 CHECK(categoryRecordPool[eventRecord1Offset +
1092 categoryRecordBlockSize +
1093 counter2NameOffset +
1095 counter2->m_Name.size()
1099 uint32_t counter3NameOffset = 0;
1100 std::memcpy(&counter3NameOffset, categoryRecordPool + eventRecord2Offset + 5u * uint32_t_size, uint32_t_size);
1101 CHECK(counter3NameOffset == 0);
1103 CHECK(categoryRecordPool[eventRecord2Offset +
1104 categoryRecordBlockSize +
1105 8u * uint32_t_size +
1107 ] == counter3->m_Name.size() + 1);
1110 CHECK(std::memcmp(categoryRecordPool +
1111 categoryRecordBlockSize +
1112 eventRecord2Offset +
1113 8u * uint32_t_size +
1114 counter3NameOffset +
1116 counter3->m_Name.data(),
1117 counter3->m_Name.size()) == 0);
1119 CHECK(categoryRecordPool[eventRecord2Offset +
1120 categoryRecordBlockSize +
1121 8u * uint32_t_size +
1122 counter3NameOffset +
1124 counter3->m_Name.size()
1128 TEST_CASE(
"CreateInvalidCategoryRecordTest1")
1134 const std::string categoryName =
"some invalid category";
1135 const CategoryPtr category = std::make_unique<Category>(categoryName);
1140 SendCounterPacket::CategoryRecord categoryRecord;
1141 std::string errorMessage;
1145 CHECK(!errorMessage.empty());
1146 CHECK(categoryRecord.empty());
1149 TEST_CASE(
"CreateInvalidCategoryRecordTest2")
1155 const std::string categoryName =
"some_category";
1156 const CategoryPtr category = std::make_unique<Category>(categoryName);
1158 category->m_Counters = { 11u, 23u, 5670u };
1162 counters.insert(std::make_pair<uint16_t, CounterPtr>(11,
1163 CounterPtr(
new Counter(armnn::profiling::BACKEND_ID,
1170 "the first counter",
1175 Counter* counter1 = counters.find(11)->second.get();
1179 SendCounterPacket::CategoryRecord categoryRecord;
1180 std::string errorMessage;
1184 CHECK(!errorMessage.empty());
1185 CHECK(categoryRecord.empty());
1188 TEST_CASE(
"SendCounterDirectoryPacketTest1")
1191 CounterDirectory counterDirectory;
1194 const std::string device1Name =
"device1";
1195 const Device* device1 =
nullptr;
1196 CHECK_NOTHROW(device1 = counterDirectory.RegisterDevice(device1Name, 3));
1197 CHECK(counterDirectory.GetDeviceCount() == 1);
1201 const std::string device2Name =
"device2";
1202 const Device* device2 =
nullptr;
1203 CHECK_NOTHROW(device2 = counterDirectory.RegisterDevice(device2Name));
1204 CHECK(counterDirectory.GetDeviceCount() == 2);
1209 SendCounterPacket sendCounterPacket(mockBuffer,
1210 arm::pipe::ARMNN_SOFTWARE_INFO,
1211 arm::pipe::ARMNN_SOFTWARE_VERSION,
1212 arm::pipe::ARMNN_HARDWARE_VERSION);
1213 CHECK_THROWS_AS(sendCounterPacket.SendCounterDirectoryPacket(counterDirectory),
1217 TEST_CASE(
"SendCounterDirectoryPacketTest2")
1220 CounterDirectory counterDirectory;
1223 const std::string device1Name =
"device1";
1224 const Device* device1 =
nullptr;
1225 CHECK_NOTHROW(device1 = counterDirectory.RegisterDevice(device1Name, 3));
1226 CHECK(counterDirectory.GetDeviceCount() == 1);
1230 const std::string device2Name =
"device2";
1231 const Device* device2 =
nullptr;
1232 CHECK_NOTHROW(device2 = counterDirectory.RegisterDevice(device2Name));
1233 CHECK(counterDirectory.GetDeviceCount() == 2);
1237 const std::string counterSet1Name =
"counterset1";
1238 const CounterSet* counterSet1 =
nullptr;
1239 CHECK_NOTHROW(counterSet1 = counterDirectory.RegisterCounterSet(counterSet1Name));
1240 CHECK(counterDirectory.GetCounterSetCount() == 1);
1244 const std::string category1Name =
"category1";
1245 const Category* category1 =
nullptr;
1246 CHECK_NOTHROW(category1 = counterDirectory.RegisterCategory(category1Name));
1247 CHECK(counterDirectory.GetCategoryCount() == 1);
1251 const std::string category2Name =
"category2";
1252 const Category* category2 =
nullptr;
1253 CHECK_NOTHROW(category2 = counterDirectory.RegisterCategory(category2Name));
1254 CHECK(counterDirectory.GetCategoryCount() == 2);
1257 uint16_t numberOfCores = 4;
1260 const Counter* counter1 =
nullptr;
1261 CHECK_NOTHROW(counter1 = counterDirectory.RegisterCounter(armnn::profiling::BACKEND_ID,
1268 "counter1description",
1269 std::string(
"counter1units"),
1271 CHECK(counterDirectory.GetCounterCount() == 4);
1275 const Counter* counter2 =
nullptr;
1276 CHECK_NOTHROW(counter2 = counterDirectory.RegisterCounter(armnn::profiling::BACKEND_ID,
1283 "counter2description",
1284 std::string(
"counter2units"),
1285 arm::pipe::EmptyOptional(),
1288 CHECK(counterDirectory.GetCounterCount() == 5);
1292 const Counter* counter3 =
nullptr;
1293 CHECK_NOTHROW(counter3 = counterDirectory.RegisterCounter(armnn::profiling::BACKEND_ID,
1300 "counter3description",
1301 arm::pipe::EmptyOptional(),
1304 counterSet1->m_Uid));
1305 CHECK(counterDirectory.GetCounterCount() == 9);
1310 SendCounterPacket sendCounterPacket(mockBuffer,
1311 arm::pipe::ARMNN_SOFTWARE_INFO,
1312 arm::pipe::ARMNN_SOFTWARE_VERSION,
1313 arm::pipe::ARMNN_HARDWARE_VERSION);
1314 CHECK_NOTHROW(sendCounterPacket.SendCounterDirectoryPacket(counterDirectory));
1320 const uint32_t packetHeaderWord0 = ReadUint32(readBuffer, 0);
1321 const uint32_t packetHeaderWord1 = ReadUint32(readBuffer, 4);
1322 CHECK(((packetHeaderWord0 >> 26) & 0x3F) == 0);
1323 CHECK(((packetHeaderWord0 >> 16) & 0x3FF) == 2);
1324 CHECK(packetHeaderWord1 == 432);
1327 const uint32_t bodyHeaderWord0 = ReadUint32(readBuffer, 8);
1328 const uint32_t bodyHeaderWord1 = ReadUint32(readBuffer, 12);
1329 const uint32_t bodyHeaderWord2 = ReadUint32(readBuffer, 16);
1330 const uint32_t bodyHeaderWord3 = ReadUint32(readBuffer, 20);
1331 const uint32_t bodyHeaderWord4 = ReadUint32(readBuffer, 24);
1332 const uint32_t bodyHeaderWord5 = ReadUint32(readBuffer, 28);
1333 const uint16_t deviceRecordCount =
static_cast<uint16_t
>(bodyHeaderWord0 >> 16);
1334 const uint16_t counterSetRecordCount =
static_cast<uint16_t
>(bodyHeaderWord2 >> 16);
1335 const uint16_t categoryRecordCount =
static_cast<uint16_t
>(bodyHeaderWord4 >> 16);
1336 CHECK(deviceRecordCount == 2);
1337 CHECK(bodyHeaderWord1 == bodyHeaderSize * 4);
1338 CHECK(counterSetRecordCount == 1);
1339 CHECK(bodyHeaderWord3 == 8 + bodyHeaderSize * 4);
1340 CHECK(categoryRecordCount == 2);
1341 CHECK(bodyHeaderWord5 == 12 + bodyHeaderSize * 4);
1344 const uint32_t deviceRecordOffset0 = ReadUint32(readBuffer, 32);
1345 const uint32_t deviceRecordOffset1 = ReadUint32(readBuffer, 36);
1346 CHECK(deviceRecordOffset0 == 20);
1347 CHECK(deviceRecordOffset1 == 40);
1350 const uint32_t counterSetRecordOffset0 = ReadUint32(readBuffer, 40);
1351 CHECK(counterSetRecordOffset0 == 52);
1354 const uint32_t categoryRecordOffset0 = ReadUint32(readBuffer, 44);
1355 const uint32_t categoryRecordOffset1 = ReadUint32(readBuffer, 48);
1356 CHECK(categoryRecordOffset0 == 72);
1357 CHECK(categoryRecordOffset1 == 176);
1360 const uint32_t uint32_t_size =
sizeof(uint32_t);
1361 const uint32_t packetHeaderSize = 2u * uint32_t_size;
1368 uint32_t name_offset;
1369 uint32_t name_length;
1372 std::vector<DeviceRecord> deviceRecords;
1373 const uint32_t deviceRecordsPointerTableOffset = packetHeaderSize +
1376 const unsigned char* readData = readBuffer->GetReadableData();
1378 uint32_t offset = 0;
1379 std::vector<uint32_t> data(800);
1381 for (uint32_t i = 0; i < 800; i+=uint32_t_size)
1383 data[i] = ReadUint32(readBuffer, offset);
1384 offset += uint32_t_size;
1387 std::vector<uint32_t> deviceRecordOffsets(deviceRecordCount);
1388 offset = deviceRecordsPointerTableOffset;
1389 for (uint32_t i = 0; i < deviceRecordCount; ++i)
1392 deviceRecordOffsets[i] = ReadUint32(readBuffer, offset) + deviceRecordsPointerTableOffset;
1393 offset += uint32_t_size;
1396 for (uint32_t i = 0; i < deviceRecordCount; i++)
1399 const uint32_t deviceRecordWord0 = ReadUint32(readBuffer, deviceRecordOffsets[i] + 0 * uint32_t_size);
1400 const uint32_t deviceRecordWord1 = ReadUint32(readBuffer, deviceRecordOffsets[i] + 1 * uint32_t_size);
1401 DeviceRecord deviceRecord;
1402 deviceRecord.uid =
static_cast<uint16_t
>(deviceRecordWord0 >> 16);
1403 deviceRecord.cores =
static_cast<uint16_t
>(deviceRecordWord0);
1404 deviceRecord.name_offset = deviceRecordWord1;
1406 uint32_t deviceRecordPoolOffset = deviceRecordOffsets[i] +
1407 deviceRecord.name_offset;
1408 uint32_t deviceRecordNameLength = ReadUint32(readBuffer, deviceRecordPoolOffset);
1409 deviceRecord.name_length = deviceRecordNameLength;
1410 unsigned char deviceRecordNameNullTerminator =
1411 ReadUint8(readBuffer, deviceRecordPoolOffset + uint32_t_size + deviceRecordNameLength - 1);
1412 CHECK(deviceRecordNameNullTerminator ==
'\0');
1413 std::vector<unsigned char> deviceRecordNameBuffer(deviceRecord.name_length - 1);
1414 std::memcpy(deviceRecordNameBuffer.data(),
1415 readData + deviceRecordPoolOffset + uint32_t_size, deviceRecordNameBuffer.size());
1416 deviceRecord.name.assign(deviceRecordNameBuffer.begin(), deviceRecordNameBuffer.end());
1418 deviceRecords.push_back(deviceRecord);
1422 CHECK(deviceRecords.size() == 2);
1423 for (
const DeviceRecord& deviceRecord : deviceRecords)
1425 const Device* device = counterDirectory.GetDevice(deviceRecord.uid);
1427 CHECK(device->m_Uid == deviceRecord.uid);
1428 CHECK(device->m_Cores == deviceRecord.cores);
1429 CHECK(device->m_Name == deviceRecord.name);
1434 struct CounterSetRecord
1438 uint32_t name_offset;
1439 uint32_t name_length;
1442 std::vector<CounterSetRecord> counterSetRecords;
1443 const uint32_t counterSetRecordsPointerTableOffset = 2u * uint32_t_size +
1446 offset = counterSetRecordsPointerTableOffset;
1447 std::vector<uint32_t> counterSetRecordOffsets(counterSetRecordCount);
1449 for (uint32_t i = 0; i < counterSetRecordCount; ++i)
1452 counterSetRecordOffsets[i] = ReadUint32(readBuffer, offset) + counterSetRecordsPointerTableOffset;
1453 offset += uint32_t_size;
1456 for (uint32_t i = 0; i < counterSetRecordCount; i++)
1459 const uint32_t counterSetRecordWord0 = ReadUint32(readBuffer, counterSetRecordOffsets[i] + 0 * uint32_t_size);
1460 const uint32_t counterSetRecordWord1 = ReadUint32(readBuffer, counterSetRecordOffsets[i] + 1 * uint32_t_size);
1461 CounterSetRecord counterSetRecord;
1462 counterSetRecord.uid =
static_cast<uint16_t
>(counterSetRecordWord0 >> 16);
1463 counterSetRecord.count =
static_cast<uint16_t
>(counterSetRecordWord0);
1464 counterSetRecord.name_offset = counterSetRecordWord1;
1466 uint32_t counterSetRecordPoolOffset = counterSetRecordOffsets[i] +
1467 counterSetRecord.name_offset;
1468 uint32_t counterSetRecordNameLength = ReadUint32(readBuffer, counterSetRecordPoolOffset);
1469 counterSetRecord.name_length = counterSetRecordNameLength;
1470 unsigned char counterSetRecordNameNullTerminator =
1471 ReadUint8(readBuffer, counterSetRecordPoolOffset + uint32_t_size + counterSetRecordNameLength - 1);
1472 CHECK(counterSetRecordNameNullTerminator ==
'\0');
1473 std::vector<unsigned char> counterSetRecordNameBuffer(counterSetRecord.name_length - 1);
1474 std::memcpy(counterSetRecordNameBuffer.data(),
1475 readData + counterSetRecordPoolOffset + uint32_t_size, counterSetRecordNameBuffer.size());
1476 counterSetRecord.name.assign(counterSetRecordNameBuffer.begin(), counterSetRecordNameBuffer.end());
1478 counterSetRecords.push_back(counterSetRecord);
1482 CHECK(counterSetRecords.size() == 1);
1483 for (
const CounterSetRecord& counterSetRecord : counterSetRecords)
1485 const CounterSet* counterSet = counterDirectory.GetCounterSet(counterSetRecord.uid);
1487 CHECK(counterSet->m_Uid == counterSetRecord.uid);
1488 CHECK(counterSet->m_Count == counterSetRecord.count);
1489 CHECK(counterSet->m_Name == counterSetRecord.name);
1495 uint16_t counter_uid;
1496 uint16_t max_counter_uid;
1498 uint16_t counter_set;
1499 uint16_t counter_class;
1500 uint16_t interpolation;
1502 uint32_t name_offset;
1503 uint32_t name_length;
1505 uint32_t description_offset;
1506 uint32_t description_length;
1507 std::string description;
1508 uint32_t units_offset;
1509 uint32_t units_length;
1513 struct CategoryRecord
1515 uint16_t event_count;
1516 uint32_t event_pointer_table_offset;
1517 uint32_t name_offset;
1518 uint32_t name_length;
1520 std::vector<uint32_t> event_pointer_table;
1521 std::vector<EventRecord> event_records;
1523 std::vector<CategoryRecord> categoryRecords;
1524 const uint32_t categoryRecordsPointerTableOffset = 2u * uint32_t_size +
1527 offset = categoryRecordsPointerTableOffset;
1528 std::vector<uint32_t> categoryRecordOffsets(categoryRecordCount);
1529 for (uint32_t i = 0; i < categoryRecordCount; ++i)
1532 categoryRecordOffsets[i] = ReadUint32(readBuffer, offset) + categoryRecordsPointerTableOffset;
1533 offset += uint32_t_size;
1536 for (uint32_t i = 0; i < categoryRecordCount; i++)
1539 const uint32_t categoryRecordWord1 = ReadUint32(readBuffer, categoryRecordOffsets[i] + 0 * uint32_t_size);
1540 const uint32_t categoryRecordWord2 = ReadUint32(readBuffer, categoryRecordOffsets[i] + 1 * uint32_t_size);
1541 const uint32_t categoryRecordWord3 = ReadUint32(readBuffer, categoryRecordOffsets[i] + 2 * uint32_t_size);
1542 CategoryRecord categoryRecord;
1543 categoryRecord.event_count =
static_cast<uint16_t
>(categoryRecordWord1 >> 16);
1544 categoryRecord.event_pointer_table_offset = categoryRecordWord2;
1545 categoryRecord.name_offset = categoryRecordWord3;
1547 uint32_t categoryRecordNameLength = ReadUint32(readBuffer,
1548 categoryRecordOffsets[i] + categoryRecord.name_offset);
1549 categoryRecord.name_length = categoryRecordNameLength;
1550 unsigned char categoryRecordNameNullTerminator =
1551 ReadUint8(readBuffer,
1552 categoryRecordOffsets[i] +
1553 categoryRecord.name_offset +
1555 categoryRecordNameLength - 1);
1556 CHECK(categoryRecordNameNullTerminator ==
'\0');
1557 std::vector<unsigned char> categoryRecordNameBuffer(categoryRecord.name_length - 1);
1558 std::memcpy(categoryRecordNameBuffer.data(),
1560 categoryRecordOffsets[i] +
1561 categoryRecord.name_offset +
1563 categoryRecordNameBuffer.size());
1564 categoryRecord.name.assign(categoryRecordNameBuffer.begin(), categoryRecordNameBuffer.end());
1566 categoryRecord.event_pointer_table.resize(categoryRecord.event_count);
1567 offset = categoryRecordOffsets[i] + categoryRecord.event_pointer_table_offset;
1568 for (uint32_t eventOffsetIndex = 0; eventOffsetIndex < categoryRecord.event_count; ++eventOffsetIndex)
1571 categoryRecord.event_pointer_table[eventOffsetIndex] = ReadUint32(readBuffer, offset) +
1572 categoryRecordOffsets[i] +
1573 categoryRecord.event_pointer_table_offset;
1574 offset += uint32_t_size;
1577 for (uint32_t eventIndex = 0; eventIndex < categoryRecord.event_count; eventIndex++)
1579 const uint32_t eventOffset = categoryRecord.event_pointer_table[eventIndex];
1581 const uint32_t eventRecordWord0 = ReadUint32(readBuffer, eventOffset + 0 * uint32_t_size);
1582 const uint32_t eventRecordWord1 = ReadUint32(readBuffer, eventOffset + 1 * uint32_t_size);
1583 const uint32_t eventRecordWord2 = ReadUint32(readBuffer, eventOffset + 2 * uint32_t_size);
1584 const uint64_t eventRecordWord34 = ReadUint64(readBuffer, eventOffset + 3 * uint32_t_size);
1585 const uint32_t eventRecordWord5 = ReadUint32(readBuffer, eventOffset + 5 * uint32_t_size);
1586 const uint32_t eventRecordWord6 = ReadUint32(readBuffer, eventOffset + 6 * uint32_t_size);
1587 const uint32_t eventRecordWord7 = ReadUint32(readBuffer, eventOffset + 7 * uint32_t_size);
1589 EventRecord eventRecord;
1590 eventRecord.counter_uid =
static_cast<uint16_t
>(eventRecordWord0);
1591 eventRecord.max_counter_uid =
static_cast<uint16_t
>(eventRecordWord0 >> 16);
1592 eventRecord.device =
static_cast<uint16_t
>(eventRecordWord1 >> 16);
1593 eventRecord.counter_set =
static_cast<uint16_t
>(eventRecordWord1);
1594 eventRecord.counter_class =
static_cast<uint16_t
>(eventRecordWord2 >> 16);
1595 eventRecord.interpolation =
static_cast<uint16_t
>(eventRecordWord2);
1596 std::memcpy(&eventRecord.multiplier, &eventRecordWord34,
sizeof(eventRecord.multiplier));
1597 eventRecord.name_offset =
static_cast<uint32_t
>(eventRecordWord5);
1598 eventRecord.description_offset =
static_cast<uint32_t
>(eventRecordWord6);
1599 eventRecord.units_offset =
static_cast<uint32_t
>(eventRecordWord7);
1601 uint32_t eventRecordNameLength = ReadUint32(readBuffer, eventOffset + eventRecord.name_offset);
1602 eventRecord.name_length = eventRecordNameLength;
1603 unsigned char eventRecordNameNullTerminator =
1604 ReadUint8(readBuffer,
1606 eventRecord.name_offset +
1608 eventRecordNameLength - 1);
1609 CHECK(eventRecordNameNullTerminator ==
'\0');
1610 std::vector<unsigned char> eventRecordNameBuffer(eventRecord.name_length - 1);
1611 std::memcpy(eventRecordNameBuffer.data(),
1614 eventRecord.name_offset +
1616 eventRecordNameBuffer.size());
1617 eventRecord.name.assign(eventRecordNameBuffer.begin(), eventRecordNameBuffer.end());
1619 uint32_t eventRecordDescriptionLength = ReadUint32(readBuffer,
1620 eventOffset + eventRecord.description_offset);
1621 eventRecord.description_length = eventRecordDescriptionLength;
1622 unsigned char eventRecordDescriptionNullTerminator =
1623 ReadUint8(readBuffer,
1625 eventRecord.description_offset +
1627 eventRecordDescriptionLength - 1);
1628 CHECK(eventRecordDescriptionNullTerminator ==
'\0');
1629 std::vector<unsigned char> eventRecordDescriptionBuffer(eventRecord.description_length - 1);
1630 std::memcpy(eventRecordDescriptionBuffer.data(),
1633 eventRecord.description_offset +
1635 eventRecordDescriptionBuffer.size());
1636 eventRecord.description.assign(eventRecordDescriptionBuffer.begin(),
1637 eventRecordDescriptionBuffer.end());
1639 if (eventRecord.units_offset > 0)
1641 uint32_t eventRecordUnitsLength = ReadUint32(readBuffer,
1642 eventOffset + eventRecord.units_offset);
1643 eventRecord.units_length = eventRecordUnitsLength;
1644 unsigned char eventRecordUnitsNullTerminator =
1645 ReadUint8(readBuffer,
1647 eventRecord.units_offset +
1649 eventRecordUnitsLength - 1);
1650 CHECK(eventRecordUnitsNullTerminator ==
'\0');
1651 std::vector<unsigned char> eventRecordUnitsBuffer(eventRecord.units_length - 1);
1652 std::memcpy(eventRecordUnitsBuffer.data(),
1655 eventRecord.units_offset +
1657 eventRecordUnitsBuffer.size());
1658 eventRecord.units.assign(eventRecordUnitsBuffer.begin(), eventRecordUnitsBuffer.end());
1661 categoryRecord.event_records.push_back(eventRecord);
1664 categoryRecords.push_back(categoryRecord);
1668 CHECK(categoryRecords.size() == 2);
1669 for (
const CategoryRecord& categoryRecord : categoryRecords)
1671 const Category* category = counterDirectory.GetCategory(categoryRecord.name);
1673 CHECK(category->m_Name == categoryRecord.name);
1674 CHECK(category->m_Counters.size() == categoryRecord.event_count +
static_cast<size_t>(numberOfCores) -1);
1675 CHECK(category->m_Counters.size() == categoryRecord.event_count +
static_cast<size_t>(numberOfCores) -1);
1678 for (
const EventRecord& eventRecord : categoryRecord.event_records)
1680 const Counter* counter = counterDirectory.GetCounter(eventRecord.counter_uid);
1682 CHECK(counter->m_MaxCounterUid == eventRecord.max_counter_uid);
1683 CHECK(counter->m_DeviceUid == eventRecord.device);
1684 CHECK(counter->m_CounterSetUid == eventRecord.counter_set);
1685 CHECK(counter->m_Class == eventRecord.counter_class);
1686 CHECK(counter->m_Interpolation == eventRecord.interpolation);
1687 CHECK(counter->m_Multiplier == eventRecord.multiplier);
1688 CHECK(counter->m_Name == eventRecord.name);
1689 CHECK(counter->m_Description == eventRecord.description);
1690 CHECK(counter->m_Units == eventRecord.units);
1695 TEST_CASE(
"SendCounterDirectoryPacketTest3")
1701 const std::string deviceName =
"inv@lid dev!c€";
1702 const Device* device =
nullptr;
1703 CHECK_NOTHROW(device = counterDirectory.
RegisterDevice(deviceName, 3));
1709 SendCounterPacket sendCounterPacket(mockBuffer,
1710 arm::pipe::ARMNN_SOFTWARE_INFO,
1711 arm::pipe::ARMNN_SOFTWARE_VERSION,
1712 arm::pipe::ARMNN_HARDWARE_VERSION);
1713 CHECK_THROWS_AS(sendCounterPacket.SendCounterDirectoryPacket(counterDirectory), arm::pipe::ProfilingException);
1716 TEST_CASE(
"SendCounterDirectoryPacketTest4")
1722 const std::string counterSetName =
"inv@lid count€rs€t";
1723 const CounterSet* counterSet =
nullptr;
1730 SendCounterPacket sendCounterPacket(mockBuffer,
1731 arm::pipe::ARMNN_SOFTWARE_INFO,
1732 arm::pipe::ARMNN_SOFTWARE_VERSION,
1733 arm::pipe::ARMNN_HARDWARE_VERSION);
1734 CHECK_THROWS_AS(sendCounterPacket.SendCounterDirectoryPacket(counterDirectory), arm::pipe::ProfilingException);
1737 TEST_CASE(
"SendCounterDirectoryPacketTest5")
1743 const std::string categoryName =
"c@t€gory";
1744 const Category* category =
nullptr;
1751 SendCounterPacket sendCounterPacket(mockBuffer,
1752 arm::pipe::ARMNN_SOFTWARE_INFO,
1753 arm::pipe::ARMNN_SOFTWARE_VERSION,
1754 arm::pipe::ARMNN_HARDWARE_VERSION);
1755 CHECK_THROWS_AS(sendCounterPacket.SendCounterDirectoryPacket(counterDirectory), arm::pipe::ProfilingException);
1758 TEST_CASE(
"SendCounterDirectoryPacketTest6")
1764 const std::string deviceName =
"inv@lid dev!c€";
1765 const Device* device =
nullptr;
1766 CHECK_NOTHROW(device = counterDirectory.
RegisterDevice(deviceName, 3));
1771 const std::string counterSetName =
"inv@lid count€rs€t";
1772 const CounterSet* counterSet =
nullptr;
1778 const std::string categoryName =
"c@t€gory";
1779 const Category* category =
nullptr;
1786 SendCounterPacket sendCounterPacket(mockBuffer,
1787 arm::pipe::ARMNN_SOFTWARE_INFO,
1788 arm::pipe::ARMNN_SOFTWARE_VERSION,
1789 arm::pipe::ARMNN_HARDWARE_VERSION);
1790 CHECK_THROWS_AS(sendCounterPacket.SendCounterDirectoryPacket(counterDirectory), arm::pipe::ProfilingException);
1793 TEST_CASE(
"SendCounterDirectoryPacketTest7")
1799 const std::string deviceName =
"valid device";
1800 const Device* device =
nullptr;
1801 CHECK_NOTHROW(device = counterDirectory.
RegisterDevice(deviceName, 3));
1806 const std::string counterSetName =
"valid counterset";
1807 const CounterSet* counterSet =
nullptr;
1813 const std::string categoryName =
"category";
1814 const Category* category =
nullptr;
1820 const Counter* counter =
nullptr;
1821 CHECK_NOTHROW(counter = counterDirectory.
RegisterCounter(armnn::profiling::BACKEND_ID,
1828 "counter description",
1829 std::string(
"invalid counter units"),
1832 counterSet->m_Uid));
1838 SendCounterPacket sendCounterPacket(mockBuffer,
1839 arm::pipe::ARMNN_SOFTWARE_INFO,
1840 arm::pipe::ARMNN_SOFTWARE_VERSION,
1841 arm::pipe::ARMNN_HARDWARE_VERSION);
1842 CHECK_THROWS_AS(sendCounterPacket.SendCounterDirectoryPacket(counterDirectory), arm::pipe::ProfilingException);
1845 TEST_CASE(
"SendThreadTest0")
1847 ProfilingStateMachine profilingStateMachine;
1848 SetActiveProfilingState(profilingStateMachine);
1852 SendCounterPacket sendCounterPacket(mockStreamCounterBuffer,
1853 arm::pipe::ARMNN_SOFTWARE_INFO,
1854 arm::pipe::ARMNN_SOFTWARE_VERSION,
1855 arm::pipe::ARMNN_HARDWARE_VERSION);
1856 SendThread sendThread(profilingStateMachine, mockStreamCounterBuffer, sendCounterPacket);
1860 sendThread.Start(mockProfilingConnection);
1861 CHECK(sendThread.IsRunning());
1862 sendThread.Start(mockProfilingConnection);
1863 sendThread.Start(mockProfilingConnection);
1864 sendThread.Start(mockProfilingConnection);
1865 sendThread.Start(mockProfilingConnection);
1866 CHECK(sendThread.IsRunning());
1869 CHECK(!sendThread.IsRunning());
1872 TEST_CASE(
"SendThreadTest1")
1874 ProfilingStateMachine profilingStateMachine;
1875 SetActiveProfilingState(profilingStateMachine);
1877 unsigned int totalWrittenSize = 0;
1881 SendCounterPacket sendCounterPacket(mockStreamCounterBuffer,
1882 arm::pipe::ARMNN_SOFTWARE_INFO,
1883 arm::pipe::ARMNN_SOFTWARE_VERSION,
1884 arm::pipe::ARMNN_HARDWARE_VERSION);
1885 SendThread sendThread(profilingStateMachine, mockStreamCounterBuffer, sendCounterPacket);
1886 sendThread.Start(mockProfilingConnection);
1891 std::this_thread::sleep_for(std::chrono::milliseconds(WAIT_UNTIL_READABLE_MS));
1893 CounterDirectory counterDirectory;
1894 sendCounterPacket.SendStreamMetaDataPacket();
1898 sendThread.SetReadyToRead();
1900 std::this_thread::sleep_for(std::chrono::milliseconds(WAIT_UNTIL_READABLE_MS));
1902 sendCounterPacket.SendCounterDirectoryPacket(counterDirectory);
1905 unsigned int counterDirectoryPacketSize = 32;
1906 totalWrittenSize += counterDirectoryPacketSize;
1908 sendThread.SetReadyToRead();
1910 std::this_thread::sleep_for(std::chrono::milliseconds(WAIT_UNTIL_READABLE_MS));
1912 sendCounterPacket.SendPeriodicCounterCapturePacket(123u,
1919 unsigned int periodicCounterCapturePacketSize = 28;
1920 totalWrittenSize += periodicCounterCapturePacketSize;
1922 sendThread.SetReadyToRead();
1924 std::this_thread::sleep_for(std::chrono::milliseconds(WAIT_UNTIL_READABLE_MS));
1926 sendCounterPacket.SendPeriodicCounterCapturePacket(44u,
1932 periodicCounterCapturePacketSize = 22;
1933 totalWrittenSize += periodicCounterCapturePacketSize;
1935 sendCounterPacket.SendPeriodicCounterCapturePacket(1234u,
1945 periodicCounterCapturePacketSize = 46;
1946 totalWrittenSize += periodicCounterCapturePacketSize;
1948 sendCounterPacket.SendPeriodicCounterCapturePacket(997u,
1957 periodicCounterCapturePacketSize = 40;
1958 totalWrittenSize += periodicCounterCapturePacketSize;
1960 sendThread.SetReadyToRead();
1962 std::this_thread::sleep_for(std::chrono::milliseconds(WAIT_UNTIL_READABLE_MS));
1964 sendCounterPacket.SendPeriodicCounterSelectionPacket(1000u, { 1345u, 254u, 4536u, 408u, 54u, 6323u, 428u, 1u, 6u });
1967 periodicCounterCapturePacketSize = 30;
1968 totalWrittenSize += periodicCounterCapturePacketSize;
1970 sendThread.SetReadyToRead();
1974 std::this_thread::sleep_for(std::chrono::milliseconds(WAIT_UNTIL_READABLE_MS));
1980 CHECK(mockStreamCounterBuffer.
GetReadSize() == totalWrittenSize);
1983 TEST_CASE(
"SendThreadTest2")
1985 ProfilingStateMachine profilingStateMachine;
1986 SetActiveProfilingState(profilingStateMachine);
1988 unsigned int totalWrittenSize = 0;
1992 SendCounterPacket sendCounterPacket(mockStreamCounterBuffer,
1993 arm::pipe::ARMNN_SOFTWARE_INFO,
1994 arm::pipe::ARMNN_SOFTWARE_VERSION,
1995 arm::pipe::ARMNN_HARDWARE_VERSION);
1996 SendThread sendThread(profilingStateMachine, mockStreamCounterBuffer, sendCounterPacket);
1997 sendThread.Start(mockProfilingConnection);
2002 std::this_thread::sleep_for(std::chrono::milliseconds(WAIT_UNTIL_READABLE_MS));
2004 sendThread.SetReadyToRead();
2006 CounterDirectory counterDirectory;
2007 sendCounterPacket.SendStreamMetaDataPacket();
2011 sendThread.SetReadyToRead();
2013 std::this_thread::sleep_for(std::chrono::milliseconds(WAIT_UNTIL_READABLE_MS));
2015 sendCounterPacket.SendCounterDirectoryPacket(counterDirectory);
2018 unsigned int counterDirectoryPacketSize = 32;
2019 totalWrittenSize += counterDirectoryPacketSize;
2021 sendThread.SetReadyToRead();
2022 sendThread.SetReadyToRead();
2024 std::this_thread::sleep_for(std::chrono::milliseconds(WAIT_UNTIL_READABLE_MS));
2026 sendCounterPacket.SendPeriodicCounterCapturePacket(123u,
2033 unsigned int periodicCounterCapturePacketSize = 28;
2034 totalWrittenSize += periodicCounterCapturePacketSize;
2036 sendThread.SetReadyToRead();
2038 std::this_thread::sleep_for(std::chrono::milliseconds(WAIT_UNTIL_READABLE_MS));
2040 sendThread.SetReadyToRead();
2041 sendThread.SetReadyToRead();
2042 sendThread.SetReadyToRead();
2044 std::this_thread::sleep_for(std::chrono::milliseconds(WAIT_UNTIL_READABLE_MS));
2046 sendThread.SetReadyToRead();
2047 sendCounterPacket.SendPeriodicCounterCapturePacket(44u,
2053 periodicCounterCapturePacketSize = 22;
2054 totalWrittenSize += periodicCounterCapturePacketSize;
2056 sendCounterPacket.SendPeriodicCounterCapturePacket(1234u,
2066 periodicCounterCapturePacketSize = 46;
2067 totalWrittenSize += periodicCounterCapturePacketSize;
2069 sendThread.SetReadyToRead();
2070 sendCounterPacket.SendPeriodicCounterCapturePacket(997u,
2079 periodicCounterCapturePacketSize = 40;
2080 totalWrittenSize += periodicCounterCapturePacketSize;
2082 sendThread.SetReadyToRead();
2083 sendThread.SetReadyToRead();
2085 std::this_thread::sleep_for(std::chrono::milliseconds(WAIT_UNTIL_READABLE_MS));
2087 sendCounterPacket.SendPeriodicCounterSelectionPacket(1000u, { 1345u, 254u, 4536u, 408u, 54u, 6323u, 428u, 1u, 6u });
2090 periodicCounterCapturePacketSize = 30;
2091 totalWrittenSize += periodicCounterCapturePacketSize;
2093 sendThread.SetReadyToRead();
2101 CHECK(mockStreamCounterBuffer.
GetReadSize() == totalWrittenSize);
2104 TEST_CASE(
"SendThreadTest3")
2106 ProfilingStateMachine profilingStateMachine;
2107 SetActiveProfilingState(profilingStateMachine);
2109 unsigned int totalWrittenSize = 0;
2113 SendCounterPacket sendCounterPacket(mockStreamCounterBuffer,
2114 arm::pipe::ARMNN_SOFTWARE_INFO,
2115 arm::pipe::ARMNN_SOFTWARE_VERSION,
2116 arm::pipe::ARMNN_HARDWARE_VERSION);
2117 SendThread sendThread(profilingStateMachine, mockStreamCounterBuffer, sendCounterPacket);
2118 sendThread.Start(mockProfilingConnection);
2122 sendThread.SetReadyToRead();
2124 CounterDirectory counterDirectory;
2125 sendCounterPacket.SendStreamMetaDataPacket();
2129 sendThread.SetReadyToRead();
2130 sendCounterPacket.SendCounterDirectoryPacket(counterDirectory);
2133 unsigned int counterDirectoryPacketSize =32;
2134 totalWrittenSize += counterDirectoryPacketSize;
2136 sendThread.SetReadyToRead();
2137 sendThread.SetReadyToRead();
2138 sendCounterPacket.SendPeriodicCounterCapturePacket(123u,
2145 unsigned int periodicCounterCapturePacketSize = 28;
2146 totalWrittenSize += periodicCounterCapturePacketSize;
2148 sendThread.SetReadyToRead();
2149 sendThread.SetReadyToRead();
2150 sendThread.SetReadyToRead();
2151 sendThread.SetReadyToRead();
2152 sendThread.SetReadyToRead();
2153 sendCounterPacket.SendPeriodicCounterCapturePacket(44u,
2159 periodicCounterCapturePacketSize = 22;
2160 totalWrittenSize += periodicCounterCapturePacketSize;
2162 sendCounterPacket.SendPeriodicCounterCapturePacket(1234u,
2172 periodicCounterCapturePacketSize = 46;
2173 totalWrittenSize += periodicCounterCapturePacketSize;
2175 sendThread.SetReadyToRead();
2176 sendThread.SetReadyToRead();
2177 sendCounterPacket.SendPeriodicCounterCapturePacket(997u,
2186 periodicCounterCapturePacketSize = 40;
2187 totalWrittenSize += periodicCounterCapturePacketSize;
2189 sendThread.SetReadyToRead();
2190 sendThread.SetReadyToRead();
2191 sendCounterPacket.SendPeriodicCounterSelectionPacket(1000u, { 1345u, 254u, 4536u, 408u, 54u, 6323u, 428u, 1u, 6u });
2194 periodicCounterCapturePacketSize = 30;
2195 totalWrittenSize += periodicCounterCapturePacketSize;
2197 sendThread.SetReadyToRead();
2205 CHECK(mockStreamCounterBuffer.
GetReadSize() <= totalWrittenSize);
2210 TEST_CASE(
"SendCounterPacketTestWithSendThread")
2212 ProfilingStateMachine profilingStateMachine;
2213 SetWaitingForAckProfilingState(profilingStateMachine);
2216 BufferManager bufferManager(1, 1024);
2217 SendCounterPacket sendCounterPacket(bufferManager,
2218 arm::pipe::ARMNN_SOFTWARE_INFO,
2219 arm::pipe::ARMNN_SOFTWARE_VERSION,
2220 arm::pipe::ARMNN_HARDWARE_VERSION);
2221 SendThread sendThread(profilingStateMachine, bufferManager, sendCounterPacket, -1);
2222 sendThread.Start(mockProfilingConnection);
2229 CHECK(mockProfilingConnection.
CheckForPacket({PacketType::StreamMetaData, streamMetadataPacketsize}) == 1);
2231 SetActiveProfilingState(profilingStateMachine);
2232 sendThread.Start(mockProfilingConnection);
2235 CounterDirectory counterDirectory;
2236 sendCounterPacket.SendCounterDirectoryPacket(counterDirectory);
2239 unsigned int counterDirectoryPacketSize = 32;
2242 {PacketType::CounterDirectory, counterDirectoryPacketSize}) == 1);
2244 sendThread.Start(mockProfilingConnection);
2247 sendCounterPacket.SendPeriodicCounterCapturePacket(123u,
2255 unsigned int periodicCounterCapturePacketSize = 28;
2257 {PacketType::PeriodicCounterCapture, periodicCounterCapturePacketSize}) == 1);
2260 TEST_CASE(
"SendThreadBufferTest")
2262 ProfilingStateMachine profilingStateMachine;
2263 SetActiveProfilingState(profilingStateMachine);
2266 BufferManager bufferManager(3, 1024);
2267 SendCounterPacket sendCounterPacket(bufferManager,
2268 arm::pipe::ARMNN_SOFTWARE_INFO,
2269 arm::pipe::ARMNN_SOFTWARE_VERSION,
2270 arm::pipe::ARMNN_HARDWARE_VERSION);
2271 SendThread sendThread(profilingStateMachine, bufferManager, sendCounterPacket, -1);
2272 sendThread.Start(mockProfilingConnection);
2275 sendCounterPacket.SendStreamMetaDataPacket();
2279 auto packetBuffer = bufferManager.GetReadableBuffer();
2280 CHECK(packetBuffer.get());
2283 CHECK(packetBuffer->GetSize() == streamMetadataPacketsize);
2286 bufferManager.Commit(packetBuffer, streamMetadataPacketsize);
2289 CounterDirectory counterDirectory;
2290 sendCounterPacket.SendCounterDirectoryPacket(counterDirectory);
2293 sendCounterPacket.SendPeriodicCounterCapturePacket(123u,
2302 auto readBuffer = bufferManager.GetReadableBuffer();
2306 unsigned int reservedSize = 0;
2307 auto reservedBuffer = bufferManager.Reserve(512, reservedSize);
2308 CHECK(reservedSize == 512);
2309 CHECK(reservedBuffer.get());
2312 const auto metaDataPacketCount =
2313 mockProfilingConnection.
CheckForPacket({PacketType::StreamMetaData, streamMetadataPacketsize});
2315 CHECK(metaDataPacketCount >= 1);
2316 CHECK(mockProfilingConnection.
CheckForPacket({PacketType::CounterDirectory, 32}) == 1);
2317 CHECK(mockProfilingConnection.
CheckForPacket({PacketType::PeriodicCounterCapture, 28}) == 1);
2319 CHECK(metaDataPacketCount + 2 == writtenDataSize);
2322 TEST_CASE(
"SendThreadSendStreamMetadataPacket1")
2324 ProfilingStateMachine profilingStateMachine;
2327 BufferManager bufferManager(3, 1024);
2328 SendCounterPacket sendCounterPacket(bufferManager,
2329 arm::pipe::ARMNN_SOFTWARE_INFO,
2330 arm::pipe::ARMNN_SOFTWARE_VERSION,
2331 arm::pipe::ARMNN_HARDWARE_VERSION);
2332 SendThread sendThread(profilingStateMachine, bufferManager, sendCounterPacket);
2333 sendThread.Start(mockProfilingConnection);
2336 CHECK_THROWS_AS(sendThread.Stop(), arm::pipe::ProfilingException);
2339 TEST_CASE(
"SendThreadSendStreamMetadataPacket2")
2341 ProfilingStateMachine profilingStateMachine;
2342 SetNotConnectedProfilingState(profilingStateMachine);
2345 BufferManager bufferManager(3, 1024);
2346 SendCounterPacket sendCounterPacket(bufferManager,
2347 arm::pipe::ARMNN_SOFTWARE_INFO,
2348 arm::pipe::ARMNN_SOFTWARE_VERSION,
2349 arm::pipe::ARMNN_HARDWARE_VERSION);
2350 SendThread sendThread(profilingStateMachine, bufferManager, sendCounterPacket);
2351 sendThread.Start(mockProfilingConnection);
2354 CHECK_THROWS_AS(sendThread.Stop(), arm::pipe::ProfilingException);
2357 TEST_CASE(
"SendThreadSendStreamMetadataPacket3")
2359 ProfilingStateMachine profilingStateMachine;
2360 SetWaitingForAckProfilingState(profilingStateMachine);
2365 BufferManager bufferManager(3, 1024);
2366 SendCounterPacket sendCounterPacket(bufferManager,
2367 arm::pipe::ARMNN_SOFTWARE_INFO,
2368 arm::pipe::ARMNN_SOFTWARE_VERSION,
2369 arm::pipe::ARMNN_HARDWARE_VERSION);
2370 SendThread sendThread(profilingStateMachine, bufferManager, sendCounterPacket);
2371 sendThread.Start(mockProfilingConnection);
2375 CHECK_NOTHROW(sendThread.Stop());
2380 CHECK(writtenDataSize >= 1u);
2382 {PacketType::StreamMetaData, streamMetadataPacketsize}) == writtenDataSize);
2385 TEST_CASE(
"SendThreadSendStreamMetadataPacket4")
2387 ProfilingStateMachine profilingStateMachine;
2388 SetWaitingForAckProfilingState(profilingStateMachine);
2393 BufferManager bufferManager(3, 1024);
2394 SendCounterPacket sendCounterPacket(bufferManager,
2395 arm::pipe::ARMNN_SOFTWARE_INFO,
2396 arm::pipe::ARMNN_SOFTWARE_VERSION,
2397 arm::pipe::ARMNN_HARDWARE_VERSION);
2398 SendThread sendThread(profilingStateMachine, bufferManager, sendCounterPacket);
2399 sendThread.Start(mockProfilingConnection);
2405 sendThread.Start(mockProfilingConnection);
2407 CHECK((profilingStateMachine.GetCurrentState() == ProfilingState::WaitingForAck));
2410 CHECK(mockProfilingConnection.
CheckForPacket({PacketType::StreamMetaData, streamMetadataPacketsize}) >= 1);
2412 mockProfilingConnection.
Clear();
2415 sendThread.Start(mockProfilingConnection);
2418 sendThread.SetReadyToRead();
2421 CHECK_NOTHROW(sendThread.Stop());
2424 CHECK((profilingStateMachine.GetCurrentState() == ProfilingState::WaitingForAck));
2429 CHECK(writtenDataSize >= 1u);
2431 {PacketType::StreamMetaData, streamMetadataPacketsize}) == writtenDataSize);
void SendCounterDirectoryPacket(const ICounterDirectory &counterDirectory) override
const Category * RegisterCategory(const std::string &categoryName)
const Device * RegisterDevice(const std::string &deviceName, uint16_t cores=0)
uint16_t GetCounterCount() const override
bool CreateCategoryRecordTest(const CategoryPtr &category, const Counters &counters, CategoryRecord &categoryRecord, std::string &errorMessage)
uint32_t GetStreamMetaDataPacketSize()
long CheckForPacket(const std::pair< PacketType, uint32_t > packetInfo)
uint16_t GetDeviceCount() const override
TEST_SUITE("SendCounterPacketTests")
void MarkRead(IPacketBufferPtr &packetBuffer) override
unsigned int GetReadableSize() const
uint16_t GetCounterSetCount() const override
unsigned int GetReadSize() const
#define ARMNN_FALLTHROUGH
uint16_t GetCategoryCount() const override
void SendPeriodicCounterSelectionPacket(uint32_t capturePeriod, const std::vector< uint16_t > &selectedCounterIds) override
bool CreateDeviceRecordTest(const DevicePtr &device, DeviceRecord &deviceRecord, std::string &errorMessage)
bool CreateCounterSetRecordTest(const CounterSetPtr &counterSet, CounterSetRecord &counterSetRecord, std::string &errorMessage)
void SendPeriodicCounterCapturePacket(uint64_t timestamp, const std::vector< CounterValue > &values) override
bool CreateEventRecordTest(const CounterPtr &counter, EventRecord &eventRecord, std::string &errorMessage)
unsigned long GetWrittenDataSize()
unsigned int GetCommittedSize() const
void SendStreamMetaDataPacket() override
const CounterSet * RegisterCounterSet(const std::string &counterSetName, uint16_t count=0)
IPacketBufferPtr GetReadableBuffer() override
std::enable_if_t< std::is_unsigned< Source >::value &&std::is_unsigned< Dest >::value, Dest > numeric_cast(Source source)
const Counter * RegisterCounter(const std::string &backendId, const uint16_t uid, const std::string &parentCategoryName, uint16_t counterClass, uint16_t interpolation, double multiplier, const std::string &name, const std::string &description, const arm::pipe::Optional< std::string > &units=arm::pipe::EmptyOptional(), const arm::pipe::Optional< uint16_t > &numberOfCores=arm::pipe::EmptyOptional(), const arm::pipe::Optional< uint16_t > &deviceUid=arm::pipe::EmptyOptional(), const arm::pipe::Optional< uint16_t > &counterSetUid=arm::pipe::EmptyOptional())