11 #include <CounterDirectory.hpp> 12 #include <common/include/EncodeVersion.hpp> 21 #include <common/include/Constants.hpp> 25 #include <doctest/doctest.h> 35 uint16_t constexpr WAIT_UNTIL_READABLE_MS = 20;
53 CHECK_MESSAGE(
false,
"Invalid profiling state");
73 CHECK_MESSAGE(
false,
"Invalid profiling state");
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);
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")
158 uint32_t capturePeriod = 1000;
159 std::vector<uint16_t> selectedCounterIds;
168 auto readBuffer2 = mockBuffer2.GetReadableBuffer();
170 uint32_t headerWord0 =
ReadUint32(readBuffer2, 0);
171 uint32_t headerWord1 =
ReadUint32(readBuffer2, 4);
174 CHECK(((headerWord0 >> 26) & 0x3F) == 0);
175 CHECK(((headerWord0 >> 16) & 0x3FF) == 4);
176 CHECK(headerWord1 == 4);
177 CHECK(period == 1000);
183 selectedCounterIds.reserve(5);
184 selectedCounterIds.emplace_back(100);
185 selectedCounterIds.emplace_back(200);
186 selectedCounterIds.emplace_back(300);
187 selectedCounterIds.emplace_back(400);
188 selectedCounterIds.emplace_back(500);
196 CHECK(((headerWord0 >> 26) & 0x3F) == 0);
197 CHECK(((headerWord0 >> 16) & 0x3FF) == 4);
198 CHECK(headerWord1 == 14);
199 CHECK(period == 1000);
201 uint16_t counterId = 0;
202 uint32_t offset = 12;
205 for(
const uint16_t&
id : selectedCounterIds)
208 CHECK(counterId ==
id);
213 TEST_CASE(
"SendPeriodicCounterCapturePacketTest")
221 auto captureTimestamp = std::chrono::steady_clock::now();
222 uint64_t time =
static_cast<uint64_t
>(captureTimestamp.time_since_epoch().count());
223 std::vector<CounterValue> indexValuePairs;
233 auto readBuffer2 = mockBuffer2.GetReadableBuffer();
235 uint32_t headerWord0 =
ReadUint32(readBuffer2, 0);
236 uint32_t headerWord1 =
ReadUint32(readBuffer2, 4);
237 uint64_t readTimestamp =
ReadUint64(readBuffer2, 8);
239 CHECK(((headerWord0 >> 26) & 0x0000003F) == 3);
240 CHECK(((headerWord0 >> 19) & 0x0000007F) == 0);
241 CHECK(((headerWord0 >> 16) & 0x00000007) == 0);
242 CHECK(headerWord1 == 8);
243 CHECK(time == readTimestamp);
249 indexValuePairs.reserve(5);
260 uint64_t readTimestamp2 =
ReadUint64(readBuffer3, 8);
262 CHECK(((headerWord0 >> 26) & 0x0000003F) == 3);
263 CHECK(((headerWord0 >> 19) & 0x0000007F) == 0);
264 CHECK(((headerWord0 >> 16) & 0x00000007) == 0);
265 CHECK(headerWord1 == 38);
266 CHECK(time == readTimestamp2);
268 uint16_t counterIndex = 0;
269 uint32_t counterValue = 100;
270 uint32_t offset = 16;
273 for (
auto it = indexValuePairs.begin(), end = indexValuePairs.end(); it != end; ++it)
276 uint16_t readIndex =
ReadUint16(readBuffer3, offset);
277 CHECK(counterIndex == readIndex);
282 uint32_t readValue =
ReadUint32(readBuffer3, offset);
283 CHECK(counterValue == readValue);
290 TEST_CASE(
"SendStreamMetaDataPacketTest")
325 std::vector<std::pair<uint32_t, uint32_t>> packetVersions;
326 packetVersions.push_back(std::make_pair(
ConstructHeader(0, 0), arm::pipe::EncodeVersion(1, 0, 0)));
327 packetVersions.push_back(std::make_pair(
ConstructHeader(0, 1), arm::pipe::EncodeVersion(1, 0, 0)));
328 packetVersions.push_back(std::make_pair(
ConstructHeader(0, 2), arm::pipe::EncodeVersion(1, 0, 0)));
329 packetVersions.push_back(std::make_pair(
ConstructHeader(0, 3), arm::pipe::EncodeVersion(1, 0, 0)));
330 packetVersions.push_back(std::make_pair(
ConstructHeader(0, 4), arm::pipe::EncodeVersion(1, 0, 0)));
331 packetVersions.push_back(std::make_pair(
ConstructHeader(0, 5), arm::pipe::EncodeVersion(1, 0, 0)));
332 packetVersions.push_back(std::make_pair(
ConstructHeader(0, 6), arm::pipe::EncodeVersion(1, 0, 0)));
333 packetVersions.push_back(std::make_pair(
ConstructHeader(0, 7), arm::pipe::EncodeVersion(1, 0, 0)));
334 packetVersions.push_back(std::make_pair(
ConstructHeader(3, 0, 0), arm::pipe::EncodeVersion(1, 0, 0)));
335 packetVersions.push_back(std::make_pair(
ConstructHeader(3, 1, 0), arm::pipe::EncodeVersion(1, 0, 0)));
336 packetVersions.push_back(std::make_pair(
ConstructHeader(3, 1, 1), arm::pipe::EncodeVersion(1, 0, 0)));
337 packetVersions.push_back(std::make_pair(
ConstructHeader(1, 0, 0), arm::pipe::EncodeVersion(1, 0, 0)));
338 packetVersions.push_back(std::make_pair(
ConstructHeader(1, 0, 1), arm::pipe::EncodeVersion(1, 0, 0)));
340 uint32_t packetEntries =
static_cast<uint32_t
>(packetVersions.size());
347 uint32_t headerWord0 =
ReadUint32(readBuffer2, 0);
348 uint32_t headerWord1 =
ReadUint32(readBuffer2, sizeUint32);
350 CHECK(((headerWord0 >> 26) & 0x3F) == 0);
351 CHECK(((headerWord0 >> 16) & 0x3FF) == 0);
354 10 * sizeUint32 + infoSize +
355 hardwareVersionSize + softwareVersionSize +
356 processNameSize + sizeUint32 +
357 2 * packetEntries * sizeUint32);
359 CHECK(headerWord1 == totalLength - (2 * sizeUint32));
361 uint32_t offset = sizeUint32 * 2;
362 CHECK(
ReadUint32(readBuffer2, offset) == arm::pipe::PIPE_MAGIC);
363 offset += sizeUint32;
364 CHECK(
ReadUint32(readBuffer2, offset) == arm::pipe::EncodeVersion(1, 0, 0));
365 offset += sizeUint32;
367 offset += sizeUint32;
369 CHECK(
ReadUint32(readBuffer2, offset) == armnn::numeric_cast<uint32_t>(pid));
370 offset += sizeUint32;
371 uint32_t poolOffset = 10 * sizeUint32;
372 CHECK(
ReadUint32(readBuffer2, offset) == poolOffset);
373 offset += sizeUint32;
374 poolOffset += infoSize;
375 CHECK(
ReadUint32(readBuffer2, offset) == poolOffset);
376 offset += sizeUint32;
377 poolOffset += hardwareVersionSize;
378 CHECK(
ReadUint32(readBuffer2, offset) == poolOffset);
379 offset += sizeUint32;
380 poolOffset += softwareVersionSize;
381 CHECK(
ReadUint32(readBuffer2, offset) == poolOffset);
382 offset += sizeUint32;
383 poolOffset += processNameSize;
384 CHECK(
ReadUint32(readBuffer2, offset) == poolOffset);
385 offset += sizeUint32;
388 const unsigned char* readData2 = readBuffer2->GetReadableData();
390 offset += sizeUint32;
393 CHECK(strcmp(reinterpret_cast<const char *>(&readData2[offset]),
GetSoftwareInfo().c_str()) == 0);
397 if (hardwareVersionSize)
399 CHECK(strcmp(reinterpret_cast<const char *>(&readData2[offset]),
GetHardwareVersion().c_str()) == 0);
400 offset += hardwareVersionSize;
403 if (softwareVersionSize)
405 CHECK(strcmp(reinterpret_cast<const char *>(&readData2[offset]),
GetSoftwareVersion().c_str()) == 0);
406 offset += softwareVersionSize;
411 CHECK(strcmp(reinterpret_cast<const char *>(&readData2[offset]),
GetProcessName().c_str()) == 0);
412 offset += processNameSize;
417 uint32_t numberOfEntries =
ReadUint32(readBuffer2, offset);
418 CHECK((numberOfEntries >> 16) == packetEntries);
419 offset += sizeUint32;
420 for (std::pair<uint32_t, uint32_t>& packetVersion : packetVersions)
422 uint32_t readPacketId =
ReadUint32(readBuffer2, offset);
423 CHECK(packetVersion.first == readPacketId);
424 offset += sizeUint32;
425 uint32_t readVersion =
ReadUint32(readBuffer2, offset);
426 CHECK(packetVersion.second == readVersion);
427 offset += sizeUint32;
431 CHECK(offset == totalLength);
434 TEST_CASE(
"CreateDeviceRecordTest")
440 uint16_t deviceUid = 27;
441 const std::string deviceName =
"some_device";
442 uint16_t deviceCores = 3;
443 const DevicePtr device = std::make_unique<Device>(deviceUid, deviceName, deviceCores);
447 std::string errorMessage;
451 CHECK(errorMessage.empty());
452 CHECK(deviceRecord.size() == 6);
454 uint16_t deviceRecordWord0[]
456 static_cast<uint16_t
>(deviceRecord[0] >> 16),
457 static_cast<uint16_t>(deviceRecord[0])
459 CHECK(deviceRecordWord0[0] == deviceUid);
460 CHECK(deviceRecordWord0[1] == deviceCores);
461 CHECK(deviceRecord[1] == 8);
462 CHECK(deviceRecord[2] == deviceName.size() + 1);
463 CHECK(std::memcmp(deviceRecord.data() + 3, deviceName.data(), deviceName.size()) == 0);
466 TEST_CASE(
"CreateInvalidDeviceRecordTest")
472 uint16_t deviceUid = 27;
473 const std::string deviceName =
"some€£invalid‡device";
474 uint16_t deviceCores = 3;
475 const DevicePtr device = std::make_unique<Device>(deviceUid, deviceName, deviceCores);
479 std::string errorMessage;
483 CHECK(!errorMessage.empty());
484 CHECK(deviceRecord.empty());
487 TEST_CASE(
"CreateCounterSetRecordTest")
493 uint16_t counterSetUid = 27;
494 const std::string counterSetName =
"some_counter_set";
495 uint16_t counterSetCount = 3421;
496 const CounterSetPtr counterSet = std::make_unique<CounterSet>(counterSetUid, counterSetName, counterSetCount);
500 std::string errorMessage;
504 CHECK(errorMessage.empty());
505 CHECK(counterSetRecord.size() == 8);
507 uint16_t counterSetRecordWord0[]
509 static_cast<uint16_t
>(counterSetRecord[0] >> 16),
510 static_cast<uint16_t>(counterSetRecord[0])
512 CHECK(counterSetRecordWord0[0] == counterSetUid);
513 CHECK(counterSetRecordWord0[1] == counterSetCount);
514 CHECK(counterSetRecord[1] == 8);
515 CHECK(counterSetRecord[2] == counterSetName.size() + 1);
516 CHECK(std::memcmp(counterSetRecord.data() + 3, counterSetName.data(), counterSetName.size()) == 0);
519 TEST_CASE(
"CreateInvalidCounterSetRecordTest")
525 uint16_t counterSetUid = 27;
526 const std::string counterSetName =
"some invalid_counter€£set";
527 uint16_t counterSetCount = 3421;
528 const CounterSetPtr counterSet = std::make_unique<CounterSet>(counterSetUid, counterSetName, counterSetCount);
532 std::string errorMessage;
536 CHECK(!errorMessage.empty());
537 CHECK(counterSetRecord.empty());
540 TEST_CASE(
"CreateEventRecordTest")
546 uint16_t counterUid = 7256;
547 uint16_t maxCounterUid = 132;
548 uint16_t deviceUid = 132;
549 uint16_t counterSetUid = 4497;
550 uint16_t counterClass = 1;
551 uint16_t counterInterpolation = 1;
552 double counterMultiplier = 1234.567f;
553 const std::string counterName =
"some_valid_counter";
554 const std::string counterDescription =
"a_counter_for_testing";
555 const std::string counterUnits =
"Mrads2";
556 const CounterPtr counter = std::make_unique<Counter>(armnn::profiling::BACKEND_ID,
560 counterInterpolation,
571 std::string errorMessage;
575 CHECK(errorMessage.empty());
576 CHECK(eventRecord.size() == 24);
578 uint16_t eventRecordWord0[]
580 static_cast<uint16_t
>(eventRecord[0] >> 16),
581 static_cast<uint16_t>(eventRecord[0])
583 uint16_t eventRecordWord1[]
585 static_cast<uint16_t
>(eventRecord[1] >> 16),
586 static_cast<uint16_t>(eventRecord[1])
588 uint16_t eventRecordWord2[]
590 static_cast<uint16_t
>(eventRecord[2] >> 16),
591 static_cast<uint16_t>(eventRecord[2])
593 uint32_t eventRecordWord34[]
599 CHECK(eventRecordWord0[0] == maxCounterUid);
600 CHECK(eventRecordWord0[1] == counterUid);
601 CHECK(eventRecordWord1[0] == deviceUid);
603 CHECK(eventRecordWord1[1] == counterSetUid);
604 CHECK(eventRecordWord2[0] == counterClass);
605 CHECK(eventRecordWord2[1] == counterInterpolation);
606 CHECK(std::memcmp(eventRecordWord34, &counterMultiplier,
sizeof(counterMultiplier)) == 0);
609 uint32_t eventRecordBlockSize = 8u *
sizeof(uint32_t);
610 uint32_t counterNameOffset = eventRecordBlockSize;
611 uint32_t counterDescriptionOffset = counterNameOffset +
617 size_t counterUnitsOffset = counterDescriptionOffset +
619 counterDescription.size() +
625 CHECK(eventRecord[5] == counterNameOffset);
626 CHECK(eventRecord[6] == counterDescriptionOffset);
627 CHECK(eventRecord[7] == counterUnitsOffset);
630 auto eventRecordPool =
reinterpret_cast<unsigned char*
>(eventRecord.data());
634 CHECK(eventRecordPool[counterNameOffset] == counterName.size() + 1);
636 CHECK(std::memcmp(eventRecordPool +
640 counterName.size()) == 0);
642 CHECK(eventRecordPool[counterNameOffset + uint32_t_size + counterName.size()] ==
'\0');
645 CHECK(eventRecordPool[counterDescriptionOffset] == counterDescription.size() + 1);
647 CHECK(std::memcmp(eventRecordPool +
648 counterDescriptionOffset +
650 counterDescription.data(),
651 counterDescription.size()) == 0);
653 CHECK(eventRecordPool[counterDescriptionOffset + uint32_t_size + counterDescription.size()] ==
'\0');
656 CHECK(eventRecordPool[counterUnitsOffset] == counterUnits.size() + 1);
658 CHECK(std::memcmp(eventRecordPool +
662 counterUnits.size()) == 0);
664 CHECK(eventRecordPool[counterUnitsOffset + uint32_t_size + counterUnits.size()] ==
'\0');
667 TEST_CASE(
"CreateEventRecordNoUnitsTest")
673 uint16_t counterUid = 44312;
674 uint16_t maxCounterUid = 345;
675 uint16_t deviceUid = 101;
676 uint16_t counterSetUid = 34035;
677 uint16_t counterClass = 0;
678 uint16_t counterInterpolation = 1;
679 double counterMultiplier = 4435.0023f;
680 const std::string counterName =
"some_valid_counter";
681 const std::string counterDescription =
"a_counter_for_testing";
682 const CounterPtr counter = std::make_unique<Counter>(armnn::profiling::BACKEND_ID,
686 counterInterpolation,
697 std::string errorMessage;
701 CHECK(errorMessage.empty());
702 CHECK(eventRecord.size() == 21);
704 uint16_t eventRecordWord0[]
706 static_cast<uint16_t
>(eventRecord[0] >> 16),
707 static_cast<uint16_t>(eventRecord[0])
709 uint16_t eventRecordWord1[]
711 static_cast<uint16_t
>(eventRecord[1] >> 16),
712 static_cast<uint16_t>(eventRecord[1])
714 uint16_t eventRecordWord2[]
716 static_cast<uint16_t
>(eventRecord[2] >> 16),
717 static_cast<uint16_t>(eventRecord[2])
719 uint32_t eventRecordWord34[]
724 CHECK(eventRecordWord0[0] == maxCounterUid);
725 CHECK(eventRecordWord0[1] == counterUid);
726 CHECK(eventRecordWord1[0] == deviceUid);
727 CHECK(eventRecordWord1[1] == counterSetUid);
728 CHECK(eventRecordWord2[0] == counterClass);
729 CHECK(eventRecordWord2[1] == counterInterpolation);
730 CHECK(std::memcmp(eventRecordWord34, &counterMultiplier,
sizeof(counterMultiplier)) == 0);
733 uint32_t eventRecordBlockSize = 8u *
sizeof(uint32_t);
734 uint32_t counterNameOffset = eventRecordBlockSize;
735 uint32_t counterDescriptionOffset = counterNameOffset +
742 CHECK(eventRecord[5] == counterNameOffset);
743 CHECK(eventRecord[6] == counterDescriptionOffset);
744 CHECK(eventRecord[7] == 0);
747 auto eventRecordPool =
reinterpret_cast<unsigned char*
>(eventRecord.data());
751 CHECK(eventRecordPool[counterNameOffset] == counterName.size() + 1);
753 CHECK(std::memcmp(eventRecordPool +
757 counterName.size()) == 0);
759 CHECK(eventRecordPool[counterNameOffset + uint32_t_size + counterName.size()] ==
'\0');
762 CHECK(eventRecordPool[counterDescriptionOffset] == counterDescription.size() + 1);
764 CHECK(std::memcmp(eventRecordPool +
765 counterDescriptionOffset +
767 counterDescription.data(),
768 counterDescription.size()) == 0);
770 CHECK(eventRecordPool[counterDescriptionOffset + uint32_t_size + counterDescription.size()] ==
'\0');
773 TEST_CASE(
"CreateInvalidEventRecordTest1")
779 uint16_t counterUid = 7256;
780 uint16_t maxCounterUid = 132;
781 uint16_t deviceUid = 132;
782 uint16_t counterSetUid = 4497;
783 uint16_t counterClass = 1;
784 uint16_t counterInterpolation = 1;
785 double counterMultiplier = 1234.567f;
786 const std::string counterName =
"some_invalid_counter £££";
787 const std::string counterDescription =
"a_counter_for_testing";
788 const std::string counterUnits =
"Mrads2";
789 const CounterPtr counter = std::make_unique<Counter>(armnn::profiling::BACKEND_ID,
793 counterInterpolation,
804 std::string errorMessage;
808 CHECK(!errorMessage.empty());
809 CHECK(eventRecord.empty());
812 TEST_CASE(
"CreateInvalidEventRecordTest2")
818 uint16_t counterUid = 7256;
819 uint16_t maxCounterUid = 132;
820 uint16_t deviceUid = 132;
821 uint16_t counterSetUid = 4497;
822 uint16_t counterClass = 1;
823 uint16_t counterInterpolation = 1;
824 double counterMultiplier = 1234.567f;
825 const std::string counterName =
"some_invalid_counter";
826 const std::string counterDescription =
"an invalid d€scription";
827 const std::string counterUnits =
"Mrads2";
828 const CounterPtr counter = std::make_unique<Counter>(armnn::profiling::BACKEND_ID,
832 counterInterpolation,
843 std::string errorMessage;
847 CHECK(!errorMessage.empty());
848 CHECK(eventRecord.empty());
851 TEST_CASE(
"CreateInvalidEventRecordTest3")
857 uint16_t counterUid = 7256;
858 uint16_t maxCounterUid = 132;
859 uint16_t deviceUid = 132;
860 uint16_t counterSetUid = 4497;
861 uint16_t counterClass = 1;
862 uint16_t counterInterpolation = 1;
863 double counterMultiplier = 1234.567f;
864 const std::string counterName =
"some_invalid_counter";
865 const std::string counterDescription =
"a valid description";
866 const std::string counterUnits =
"Mrad s2";
867 const CounterPtr counter = std::make_unique<Counter>(armnn::profiling::BACKEND_ID,
871 counterInterpolation,
882 std::string errorMessage;
886 CHECK(!errorMessage.empty());
887 CHECK(eventRecord.empty());
890 TEST_CASE(
"CreateCategoryRecordTest")
896 const std::string categoryName =
"some_category";
897 const CategoryPtr category = std::make_unique<Category>(categoryName);
899 category->m_Counters = { 11u, 23u, 5670u };
903 counters.insert(std::make_pair<uint16_t, CounterPtr>(11,
915 counters.insert(std::make_pair<uint16_t, CounterPtr>(23,
923 "the second counter",
927 counters.insert(std::make_pair<uint16_t, CounterPtr>(5670,
934 "and this is number 3",
939 Counter* counter1 = counters.find(11)->second.get();
940 Counter* counter2 = counters.find(23)->second.get();
941 Counter* counter3 = counters.find(5670)->second.get();
949 std::string errorMessage;
953 CHECK(errorMessage.empty());
954 CHECK(categoryRecord.size() == 79);
957 uint16_t categoryRecordWord1[]
959 static_cast<uint16_t
>(categoryRecord[0] >> 16),
960 static_cast<uint16_t>(categoryRecord[0])
962 CHECK(categoryRecordWord1[0] == categoryEventCount);
963 CHECK(categoryRecordWord1[1] == 0);
969 uint32_t eventPointerTableOffset = categoryRecordBlockSize;
970 uint32_t categoryNameOffset = eventPointerTableOffset +
974 CHECK(categoryRecord[1] == eventPointerTableOffset);
975 CHECK(categoryRecord[2] == categoryNameOffset);
977 auto categoryRecordPool =
reinterpret_cast<unsigned char*
>(categoryRecord.data());
980 uint32_t eventRecord0Offset = categoryRecordPool[eventPointerTableOffset + 0 *
uint32_t_size];
981 uint32_t eventRecord1Offset = categoryRecordPool[eventPointerTableOffset + 1 *
uint32_t_size];
982 uint32_t eventRecord2Offset = categoryRecordPool[eventPointerTableOffset + 2 *
uint32_t_size];
983 CHECK(eventRecord0Offset == 32);
984 CHECK(eventRecord1Offset == 120);
985 CHECK(eventRecord2Offset == 200);
988 CHECK(categoryRecordPool[categoryNameOffset] == categoryName.size() + 1);
990 CHECK(std::memcmp(categoryRecordPool +
994 categoryName.size()) == 0);
996 CHECK(categoryRecordPool[categoryNameOffset + uint32_t_size + categoryName.size()] ==
'\0');
1002 uint16_t eventRecord0Word0[2] = { 0u, 0u };
1003 std::memcpy(eventRecord0Word0, categoryRecordPool + categoryRecordBlockSize + eventRecord0Offset,
1004 sizeof(eventRecord0Word0));
1005 CHECK(eventRecord0Word0[0] == counter1->
m_Uid);
1009 uint32_t counter1NameOffset = 0;
1010 std::memcpy(&counter1NameOffset, categoryRecordPool + eventRecord0Offset + 5u * uint32_t_size, uint32_t_size);
1011 CHECK(counter1NameOffset == 0);
1013 CHECK(categoryRecordPool[eventRecord0Offset +
1014 categoryRecordBlockSize +
1015 8u * uint32_t_size +
1017 ] == counter1->
m_Name.size() + 1);
1020 CHECK(std::memcmp(categoryRecordPool +
1021 categoryRecordBlockSize +
1022 eventRecord0Offset +
1023 8u * uint32_t_size +
1024 counter1NameOffset +
1027 counter1->
m_Name.size()) == 0);
1029 CHECK(categoryRecordPool[eventRecord0Offset +
1030 categoryRecordBlockSize +
1031 8u * uint32_t_size +
1032 counter1NameOffset +
1038 uint32_t counter2NameOffset = 0;
1039 std::memcpy(&counter2NameOffset, categoryRecordPool +
1040 categoryRecordBlockSize +
1041 eventRecord1Offset +
1044 CHECK(counter2NameOffset == 8u * uint32_t_size );
1047 CHECK(categoryRecordPool[eventRecord1Offset +
1048 categoryRecordBlockSize +
1050 ] == counter2->
m_Name.size() + 1);
1053 CHECK(std::memcmp(categoryRecordPool +
1054 categoryRecordBlockSize +
1055 eventRecord1Offset +
1056 counter2NameOffset +
1059 counter2->
m_Name.size()) == 0);
1063 CHECK(categoryRecordPool[eventRecord1Offset +
1064 categoryRecordBlockSize +
1065 counter2NameOffset +
1071 uint32_t counter3NameOffset = 0;
1072 std::memcpy(&counter3NameOffset, categoryRecordPool + eventRecord2Offset + 5u * uint32_t_size, uint32_t_size);
1073 CHECK(counter3NameOffset == 0);
1075 CHECK(categoryRecordPool[eventRecord2Offset +
1076 categoryRecordBlockSize +
1077 8u * uint32_t_size +
1079 ] == counter3->
m_Name.size() + 1);
1082 CHECK(std::memcmp(categoryRecordPool +
1083 categoryRecordBlockSize +
1084 eventRecord2Offset +
1085 8u * uint32_t_size +
1086 counter3NameOffset +
1089 counter3->
m_Name.size()) == 0);
1091 CHECK(categoryRecordPool[eventRecord2Offset +
1092 categoryRecordBlockSize +
1093 8u * uint32_t_size +
1094 counter3NameOffset +
1100 TEST_CASE(
"CreateInvalidCategoryRecordTest1")
1106 const std::string categoryName =
"some invalid category";
1107 const CategoryPtr category = std::make_unique<Category>(categoryName);
1113 std::string errorMessage;
1117 CHECK(!errorMessage.empty());
1118 CHECK(categoryRecord.empty());
1121 TEST_CASE(
"CreateInvalidCategoryRecordTest2")
1127 const std::string categoryName =
"some_category";
1128 const CategoryPtr category = std::make_unique<Category>(categoryName);
1130 category->m_Counters = { 11u, 23u, 5670u };
1134 counters.insert(std::make_pair<uint16_t, CounterPtr>(11,
1142 "the first counter",
1147 Counter* counter1 = counters.find(11)->second.get();
1152 std::string errorMessage;
1156 CHECK(!errorMessage.empty());
1157 CHECK(categoryRecord.empty());
1160 TEST_CASE(
"SendCounterDirectoryPacketTest1")
1166 const std::string device1Name =
"device1";
1167 const Device* device1 =
nullptr;
1168 CHECK_NOTHROW(device1 = counterDirectory.
RegisterDevice(device1Name, 3));
1173 const std::string device2Name =
"device2";
1174 const Device* device2 =
nullptr;
1175 CHECK_NOTHROW(device2 = counterDirectory.
RegisterDevice(device2Name));
1186 TEST_CASE(
"SendCounterDirectoryPacketTest2")
1192 const std::string device1Name =
"device1";
1193 const Device* device1 =
nullptr;
1194 CHECK_NOTHROW(device1 = counterDirectory.
RegisterDevice(device1Name, 3));
1199 const std::string device2Name =
"device2";
1200 const Device* device2 =
nullptr;
1201 CHECK_NOTHROW(device2 = counterDirectory.
RegisterDevice(device2Name));
1206 const std::string counterSet1Name =
"counterset1";
1213 const std::string category1Name =
"category1";
1214 const Category* category1 =
nullptr;
1215 CHECK_NOTHROW(category1 = counterDirectory.
RegisterCategory(category1Name));
1220 const std::string category2Name =
"category2";
1221 const Category* category2 =
nullptr;
1222 CHECK_NOTHROW(category2 = counterDirectory.
RegisterCategory(category2Name));
1226 uint16_t numberOfCores = 4;
1229 const Counter* counter1 =
nullptr;
1230 CHECK_NOTHROW(counter1 = counterDirectory.
RegisterCounter(armnn::profiling::BACKEND_ID,
1237 "counter1description",
1238 std::string(
"counter1units"),
1244 const Counter* counter2 =
nullptr;
1245 CHECK_NOTHROW(counter2 = counterDirectory.
RegisterCounter(armnn::profiling::BACKEND_ID,
1252 "counter2description",
1253 std::string(
"counter2units"),
1261 const Counter* counter3 =
nullptr;
1262 CHECK_NOTHROW(counter3 = counterDirectory.
RegisterCounter(armnn::profiling::BACKEND_ID,
1269 "counter3description",
1273 counterSet1->
m_Uid));
1286 const uint32_t packetHeaderWord0 =
ReadUint32(readBuffer, 0);
1287 const uint32_t packetHeaderWord1 =
ReadUint32(readBuffer, 4);
1288 CHECK(((packetHeaderWord0 >> 26) & 0x3F) == 0);
1289 CHECK(((packetHeaderWord0 >> 16) & 0x3FF) == 2);
1290 CHECK(packetHeaderWord1 == 432);
1293 const uint32_t bodyHeaderWord0 =
ReadUint32(readBuffer, 8);
1294 const uint32_t bodyHeaderWord1 =
ReadUint32(readBuffer, 12);
1295 const uint32_t bodyHeaderWord2 =
ReadUint32(readBuffer, 16);
1296 const uint32_t bodyHeaderWord3 =
ReadUint32(readBuffer, 20);
1297 const uint32_t bodyHeaderWord4 =
ReadUint32(readBuffer, 24);
1298 const uint32_t bodyHeaderWord5 =
ReadUint32(readBuffer, 28);
1299 const uint16_t deviceRecordCount =
static_cast<uint16_t
>(bodyHeaderWord0 >> 16);
1300 const uint16_t counterSetRecordCount =
static_cast<uint16_t
>(bodyHeaderWord2 >> 16);
1301 const uint16_t categoryRecordCount =
static_cast<uint16_t
>(bodyHeaderWord4 >> 16);
1302 CHECK(deviceRecordCount == 2);
1303 CHECK(bodyHeaderWord1 == bodyHeaderSize * 4);
1304 CHECK(counterSetRecordCount == 1);
1305 CHECK(bodyHeaderWord3 == 8 + bodyHeaderSize * 4);
1306 CHECK(categoryRecordCount == 2);
1307 CHECK(bodyHeaderWord5 == 12 + bodyHeaderSize * 4);
1310 const uint32_t deviceRecordOffset0 =
ReadUint32(readBuffer, 32);
1311 const uint32_t deviceRecordOffset1 =
ReadUint32(readBuffer, 36);
1312 CHECK(deviceRecordOffset0 == 20);
1313 CHECK(deviceRecordOffset1 == 40);
1316 const uint32_t counterSetRecordOffset0 =
ReadUint32(readBuffer, 40);
1317 CHECK(counterSetRecordOffset0 == 52);
1320 const uint32_t categoryRecordOffset0 =
ReadUint32(readBuffer, 44);
1321 const uint32_t categoryRecordOffset1 =
ReadUint32(readBuffer, 48);
1322 CHECK(categoryRecordOffset0 == 72);
1323 CHECK(categoryRecordOffset1 == 176);
1334 uint32_t name_offset;
1335 uint32_t name_length;
1338 std::vector<DeviceRecord> deviceRecords;
1339 const uint32_t deviceRecordsPointerTableOffset = packetHeaderSize +
1342 const unsigned char* readData = readBuffer->GetReadableData();
1344 uint32_t offset = 0;
1345 std::vector<uint32_t> data(800);
1353 std::vector<uint32_t> deviceRecordOffsets(deviceRecordCount);
1354 offset = deviceRecordsPointerTableOffset;
1355 for (uint32_t i = 0; i < deviceRecordCount; ++i)
1358 deviceRecordOffsets[i] =
ReadUint32(readBuffer, offset) + deviceRecordsPointerTableOffset;
1362 for (uint32_t i = 0; i < deviceRecordCount; i++)
1365 const uint32_t deviceRecordWord0 =
ReadUint32(readBuffer, deviceRecordOffsets[i] + 0 * uint32_t_size);
1366 const uint32_t deviceRecordWord1 =
ReadUint32(readBuffer, deviceRecordOffsets[i] + 1 * uint32_t_size);
1367 DeviceRecord deviceRecord;
1368 deviceRecord.uid =
static_cast<uint16_t
>(deviceRecordWord0 >> 16);
1369 deviceRecord.cores =
static_cast<uint16_t
>(deviceRecordWord0);
1370 deviceRecord.name_offset = deviceRecordWord1;
1372 uint32_t deviceRecordPoolOffset = deviceRecordOffsets[i] +
1373 deviceRecord.name_offset;
1374 uint32_t deviceRecordNameLength =
ReadUint32(readBuffer, deviceRecordPoolOffset);
1375 deviceRecord.name_length = deviceRecordNameLength;
1376 unsigned char deviceRecordNameNullTerminator =
1377 ReadUint8(readBuffer, deviceRecordPoolOffset + uint32_t_size + deviceRecordNameLength - 1);
1378 CHECK(deviceRecordNameNullTerminator ==
'\0');
1379 std::vector<unsigned char> deviceRecordNameBuffer(deviceRecord.name_length - 1);
1380 std::memcpy(deviceRecordNameBuffer.data(),
1381 readData + deviceRecordPoolOffset +
uint32_t_size, deviceRecordNameBuffer.size());
1382 deviceRecord.name.assign(deviceRecordNameBuffer.begin(), deviceRecordNameBuffer.end());
1384 deviceRecords.push_back(deviceRecord);
1388 CHECK(deviceRecords.size() == 2);
1389 for (
const DeviceRecord& deviceRecord : deviceRecords)
1393 CHECK(device->
m_Uid == deviceRecord.uid);
1394 CHECK(device->
m_Cores == deviceRecord.cores);
1395 CHECK(device->
m_Name == deviceRecord.name);
1400 struct CounterSetRecord
1404 uint32_t name_offset;
1405 uint32_t name_length;
1408 std::vector<CounterSetRecord> counterSetRecords;
1409 const uint32_t counterSetRecordsPointerTableOffset = 2u * uint32_t_size +
1412 offset = counterSetRecordsPointerTableOffset;
1413 std::vector<uint32_t> counterSetRecordOffsets(counterSetRecordCount);
1415 for (uint32_t i = 0; i < counterSetRecordCount; ++i)
1418 counterSetRecordOffsets[i] =
ReadUint32(readBuffer, offset) + counterSetRecordsPointerTableOffset;
1422 for (uint32_t i = 0; i < counterSetRecordCount; i++)
1425 const uint32_t counterSetRecordWord0 =
ReadUint32(readBuffer, counterSetRecordOffsets[i] + 0 * uint32_t_size);
1426 const uint32_t counterSetRecordWord1 =
ReadUint32(readBuffer, counterSetRecordOffsets[i] + 1 * uint32_t_size);
1427 CounterSetRecord counterSetRecord;
1428 counterSetRecord.uid =
static_cast<uint16_t
>(counterSetRecordWord0 >> 16);
1429 counterSetRecord.count =
static_cast<uint16_t
>(counterSetRecordWord0);
1430 counterSetRecord.name_offset = counterSetRecordWord1;
1432 uint32_t counterSetRecordPoolOffset = counterSetRecordOffsets[i] +
1433 counterSetRecord.name_offset;
1434 uint32_t counterSetRecordNameLength =
ReadUint32(readBuffer, counterSetRecordPoolOffset);
1435 counterSetRecord.name_length = counterSetRecordNameLength;
1436 unsigned char counterSetRecordNameNullTerminator =
1437 ReadUint8(readBuffer, counterSetRecordPoolOffset + uint32_t_size + counterSetRecordNameLength - 1);
1438 CHECK(counterSetRecordNameNullTerminator ==
'\0');
1439 std::vector<unsigned char> counterSetRecordNameBuffer(counterSetRecord.name_length - 1);
1440 std::memcpy(counterSetRecordNameBuffer.data(),
1441 readData + counterSetRecordPoolOffset +
uint32_t_size, counterSetRecordNameBuffer.size());
1442 counterSetRecord.name.assign(counterSetRecordNameBuffer.begin(), counterSetRecordNameBuffer.end());
1444 counterSetRecords.push_back(counterSetRecord);
1448 CHECK(counterSetRecords.size() == 1);
1449 for (
const CounterSetRecord& counterSetRecord : counterSetRecords)
1453 CHECK(counterSet->
m_Uid == counterSetRecord.uid);
1454 CHECK(counterSet->
m_Count == counterSetRecord.count);
1455 CHECK(counterSet->
m_Name == counterSetRecord.name);
1461 uint16_t counter_uid;
1462 uint16_t max_counter_uid;
1464 uint16_t counter_set;
1465 uint16_t counter_class;
1466 uint16_t interpolation;
1468 uint32_t name_offset;
1469 uint32_t name_length;
1471 uint32_t description_offset;
1472 uint32_t description_length;
1473 std::string description;
1474 uint32_t units_offset;
1475 uint32_t units_length;
1479 struct CategoryRecord
1481 uint16_t event_count;
1482 uint32_t event_pointer_table_offset;
1483 uint32_t name_offset;
1484 uint32_t name_length;
1486 std::vector<uint32_t> event_pointer_table;
1487 std::vector<EventRecord> event_records;
1489 std::vector<CategoryRecord> categoryRecords;
1490 const uint32_t categoryRecordsPointerTableOffset = 2u * uint32_t_size +
1493 offset = categoryRecordsPointerTableOffset;
1494 std::vector<uint32_t> categoryRecordOffsets(categoryRecordCount);
1495 for (uint32_t i = 0; i < categoryRecordCount; ++i)
1498 categoryRecordOffsets[i] =
ReadUint32(readBuffer, offset) + categoryRecordsPointerTableOffset;
1502 for (uint32_t i = 0; i < categoryRecordCount; i++)
1505 const uint32_t categoryRecordWord1 =
ReadUint32(readBuffer, categoryRecordOffsets[i] + 0 * uint32_t_size);
1506 const uint32_t categoryRecordWord2 =
ReadUint32(readBuffer, categoryRecordOffsets[i] + 1 * uint32_t_size);
1507 const uint32_t categoryRecordWord3 =
ReadUint32(readBuffer, categoryRecordOffsets[i] + 2 * uint32_t_size);
1508 CategoryRecord categoryRecord;
1509 categoryRecord.event_count =
static_cast<uint16_t
>(categoryRecordWord1 >> 16);
1510 categoryRecord.event_pointer_table_offset = categoryRecordWord2;
1511 categoryRecord.name_offset = categoryRecordWord3;
1513 uint32_t categoryRecordNameLength =
ReadUint32(readBuffer,
1514 categoryRecordOffsets[i] + categoryRecord.name_offset);
1515 categoryRecord.name_length = categoryRecordNameLength;
1516 unsigned char categoryRecordNameNullTerminator =
1518 categoryRecordOffsets[i] +
1519 categoryRecord.name_offset +
1521 categoryRecordNameLength - 1);
1522 CHECK(categoryRecordNameNullTerminator ==
'\0');
1523 std::vector<unsigned char> categoryRecordNameBuffer(categoryRecord.name_length - 1);
1524 std::memcpy(categoryRecordNameBuffer.data(),
1526 categoryRecordOffsets[i] +
1527 categoryRecord.name_offset +
1529 categoryRecordNameBuffer.size());
1530 categoryRecord.name.assign(categoryRecordNameBuffer.begin(), categoryRecordNameBuffer.end());
1532 categoryRecord.event_pointer_table.resize(categoryRecord.event_count);
1533 offset = categoryRecordOffsets[i] + categoryRecord.event_pointer_table_offset;
1534 for (uint32_t eventOffsetIndex = 0; eventOffsetIndex < categoryRecord.event_count; ++eventOffsetIndex)
1537 categoryRecord.event_pointer_table[eventOffsetIndex] =
ReadUint32(readBuffer, offset) +
1538 categoryRecordOffsets[i] +
1539 categoryRecord.event_pointer_table_offset;
1543 for (uint32_t eventIndex = 0; eventIndex < categoryRecord.event_count; eventIndex++)
1545 const uint32_t eventOffset = categoryRecord.event_pointer_table[eventIndex];
1547 const uint32_t eventRecordWord0 =
ReadUint32(readBuffer, eventOffset + 0 * uint32_t_size);
1548 const uint32_t eventRecordWord1 =
ReadUint32(readBuffer, eventOffset + 1 * uint32_t_size);
1549 const uint32_t eventRecordWord2 =
ReadUint32(readBuffer, eventOffset + 2 * uint32_t_size);
1550 const uint64_t eventRecordWord34 =
ReadUint64(readBuffer, eventOffset + 3 * uint32_t_size);
1551 const uint32_t eventRecordWord5 =
ReadUint32(readBuffer, eventOffset + 5 * uint32_t_size);
1552 const uint32_t eventRecordWord6 =
ReadUint32(readBuffer, eventOffset + 6 * uint32_t_size);
1553 const uint32_t eventRecordWord7 =
ReadUint32(readBuffer, eventOffset + 7 * uint32_t_size);
1555 EventRecord eventRecord;
1556 eventRecord.counter_uid =
static_cast<uint16_t
>(eventRecordWord0);
1557 eventRecord.max_counter_uid =
static_cast<uint16_t
>(eventRecordWord0 >> 16);
1558 eventRecord.device =
static_cast<uint16_t
>(eventRecordWord1 >> 16);
1559 eventRecord.counter_set =
static_cast<uint16_t
>(eventRecordWord1);
1560 eventRecord.counter_class =
static_cast<uint16_t
>(eventRecordWord2 >> 16);
1561 eventRecord.interpolation =
static_cast<uint16_t
>(eventRecordWord2);
1562 std::memcpy(&eventRecord.multiplier, &eventRecordWord34,
sizeof(eventRecord.multiplier));
1563 eventRecord.name_offset =
static_cast<uint32_t
>(eventRecordWord5);
1564 eventRecord.description_offset =
static_cast<uint32_t
>(eventRecordWord6);
1565 eventRecord.units_offset =
static_cast<uint32_t
>(eventRecordWord7);
1567 uint32_t eventRecordNameLength =
ReadUint32(readBuffer, eventOffset + eventRecord.name_offset);
1568 eventRecord.name_length = eventRecordNameLength;
1569 unsigned char eventRecordNameNullTerminator =
1572 eventRecord.name_offset +
1574 eventRecordNameLength - 1);
1575 CHECK(eventRecordNameNullTerminator ==
'\0');
1576 std::vector<unsigned char> eventRecordNameBuffer(eventRecord.name_length - 1);
1577 std::memcpy(eventRecordNameBuffer.data(),
1580 eventRecord.name_offset +
1582 eventRecordNameBuffer.size());
1583 eventRecord.name.assign(eventRecordNameBuffer.begin(), eventRecordNameBuffer.end());
1585 uint32_t eventRecordDescriptionLength =
ReadUint32(readBuffer,
1586 eventOffset + eventRecord.description_offset);
1587 eventRecord.description_length = eventRecordDescriptionLength;
1588 unsigned char eventRecordDescriptionNullTerminator =
1591 eventRecord.description_offset +
1593 eventRecordDescriptionLength - 1);
1594 CHECK(eventRecordDescriptionNullTerminator ==
'\0');
1595 std::vector<unsigned char> eventRecordDescriptionBuffer(eventRecord.description_length - 1);
1596 std::memcpy(eventRecordDescriptionBuffer.data(),
1599 eventRecord.description_offset +
1601 eventRecordDescriptionBuffer.size());
1602 eventRecord.description.assign(eventRecordDescriptionBuffer.begin(),
1603 eventRecordDescriptionBuffer.end());
1605 if (eventRecord.units_offset > 0)
1607 uint32_t eventRecordUnitsLength =
ReadUint32(readBuffer,
1608 eventOffset + eventRecord.units_offset);
1609 eventRecord.units_length = eventRecordUnitsLength;
1610 unsigned char eventRecordUnitsNullTerminator =
1613 eventRecord.units_offset +
1615 eventRecordUnitsLength - 1);
1616 CHECK(eventRecordUnitsNullTerminator ==
'\0');
1617 std::vector<unsigned char> eventRecordUnitsBuffer(eventRecord.units_length - 1);
1618 std::memcpy(eventRecordUnitsBuffer.data(),
1621 eventRecord.units_offset +
1623 eventRecordUnitsBuffer.size());
1624 eventRecord.units.assign(eventRecordUnitsBuffer.begin(), eventRecordUnitsBuffer.end());
1627 categoryRecord.event_records.push_back(eventRecord);
1630 categoryRecords.push_back(categoryRecord);
1634 CHECK(categoryRecords.size() == 2);
1635 for (
const CategoryRecord& categoryRecord : categoryRecords)
1639 CHECK(category->
m_Name == categoryRecord.name);
1640 CHECK(category->
m_Counters.size() == categoryRecord.event_count +
static_cast<size_t>(numberOfCores) -1);
1641 CHECK(category->
m_Counters.size() == categoryRecord.event_count +
static_cast<size_t>(numberOfCores) -1);
1644 for (
const EventRecord& eventRecord : categoryRecord.event_records)
1649 CHECK(counter->
m_DeviceUid == eventRecord.device);
1651 CHECK(counter->
m_Class == eventRecord.counter_class);
1653 CHECK(counter->
m_Multiplier == eventRecord.multiplier);
1654 CHECK(counter->
m_Name == eventRecord.name);
1656 CHECK(counter->
m_Units == eventRecord.units);
1661 TEST_CASE(
"SendCounterDirectoryPacketTest3")
1667 const std::string deviceName =
"inv@lid dev!c€";
1668 const Device* device =
nullptr;
1669 CHECK_NOTHROW(device = counterDirectory.
RegisterDevice(deviceName, 3));
1679 TEST_CASE(
"SendCounterDirectoryPacketTest4")
1685 const std::string counterSetName =
"inv@lid count€rs€t";
1697 TEST_CASE(
"SendCounterDirectoryPacketTest5")
1703 const std::string categoryName =
"c@t€gory";
1704 const Category* category =
nullptr;
1715 TEST_CASE(
"SendCounterDirectoryPacketTest6")
1721 const std::string deviceName =
"inv@lid dev!c€";
1722 const Device* device =
nullptr;
1723 CHECK_NOTHROW(device = counterDirectory.
RegisterDevice(deviceName, 3));
1728 const std::string counterSetName =
"inv@lid count€rs€t";
1735 const std::string categoryName =
"c@t€gory";
1736 const Category* category =
nullptr;
1747 TEST_CASE(
"SendCounterDirectoryPacketTest7")
1753 const std::string deviceName =
"valid device";
1754 const Device* device =
nullptr;
1755 CHECK_NOTHROW(device = counterDirectory.
RegisterDevice(deviceName, 3));
1760 const std::string counterSetName =
"valid counterset";
1767 const std::string categoryName =
"category";
1768 const Category* category =
nullptr;
1774 const Counter* counter =
nullptr;
1775 CHECK_NOTHROW(counter = counterDirectory.
RegisterCounter(armnn::profiling::BACKEND_ID,
1782 "counter description",
1783 std::string(
"invalid counter units"),
1786 counterSet->
m_Uid));
1796 TEST_CASE(
"SendThreadTest0")
1799 SetActiveProfilingState(profilingStateMachine);
1804 SendThread sendThread(profilingStateMachine, mockStreamCounterBuffer, sendCounterPacket);
1808 sendThread.
Start(mockProfilingConnection);
1810 sendThread.
Start(mockProfilingConnection);
1811 sendThread.
Start(mockProfilingConnection);
1812 sendThread.
Start(mockProfilingConnection);
1813 sendThread.
Start(mockProfilingConnection);
1820 TEST_CASE(
"SendThreadTest1")
1823 SetActiveProfilingState(profilingStateMachine);
1825 unsigned int totalWrittenSize = 0;
1830 SendThread sendThread(profilingStateMachine, mockStreamCounterBuffer, sendCounterPacket);
1831 sendThread.
Start(mockProfilingConnection);
1836 std::this_thread::sleep_for(std::chrono::milliseconds(WAIT_UNTIL_READABLE_MS));
1845 std::this_thread::sleep_for(std::chrono::milliseconds(WAIT_UNTIL_READABLE_MS));
1850 unsigned int counterDirectoryPacketSize = 32;
1851 totalWrittenSize += counterDirectoryPacketSize;
1855 std::this_thread::sleep_for(std::chrono::milliseconds(WAIT_UNTIL_READABLE_MS));
1864 unsigned int periodicCounterCapturePacketSize = 28;
1865 totalWrittenSize += periodicCounterCapturePacketSize;
1869 std::this_thread::sleep_for(std::chrono::milliseconds(WAIT_UNTIL_READABLE_MS));
1877 periodicCounterCapturePacketSize = 22;
1878 totalWrittenSize += periodicCounterCapturePacketSize;
1890 periodicCounterCapturePacketSize = 46;
1891 totalWrittenSize += periodicCounterCapturePacketSize;
1902 periodicCounterCapturePacketSize = 40;
1903 totalWrittenSize += periodicCounterCapturePacketSize;
1907 std::this_thread::sleep_for(std::chrono::milliseconds(WAIT_UNTIL_READABLE_MS));
1912 periodicCounterCapturePacketSize = 30;
1913 totalWrittenSize += periodicCounterCapturePacketSize;
1919 std::this_thread::sleep_for(std::chrono::milliseconds(WAIT_UNTIL_READABLE_MS));
1925 CHECK(mockStreamCounterBuffer.
GetReadSize() == totalWrittenSize);
1928 TEST_CASE(
"SendThreadTest2")
1931 SetActiveProfilingState(profilingStateMachine);
1933 unsigned int totalWrittenSize = 0;
1938 SendThread sendThread(profilingStateMachine, mockStreamCounterBuffer, sendCounterPacket);
1939 sendThread.
Start(mockProfilingConnection);
1944 std::this_thread::sleep_for(std::chrono::milliseconds(WAIT_UNTIL_READABLE_MS));
1955 std::this_thread::sleep_for(std::chrono::milliseconds(WAIT_UNTIL_READABLE_MS));
1960 unsigned int counterDirectoryPacketSize = 32;
1961 totalWrittenSize += counterDirectoryPacketSize;
1966 std::this_thread::sleep_for(std::chrono::milliseconds(WAIT_UNTIL_READABLE_MS));
1975 unsigned int periodicCounterCapturePacketSize = 28;
1976 totalWrittenSize += periodicCounterCapturePacketSize;
1980 std::this_thread::sleep_for(std::chrono::milliseconds(WAIT_UNTIL_READABLE_MS));
1986 std::this_thread::sleep_for(std::chrono::milliseconds(WAIT_UNTIL_READABLE_MS));
1995 periodicCounterCapturePacketSize = 22;
1996 totalWrittenSize += periodicCounterCapturePacketSize;
2008 periodicCounterCapturePacketSize = 46;
2009 totalWrittenSize += periodicCounterCapturePacketSize;
2021 periodicCounterCapturePacketSize = 40;
2022 totalWrittenSize += periodicCounterCapturePacketSize;
2027 std::this_thread::sleep_for(std::chrono::milliseconds(WAIT_UNTIL_READABLE_MS));
2032 periodicCounterCapturePacketSize = 30;
2033 totalWrittenSize += periodicCounterCapturePacketSize;
2043 CHECK(mockStreamCounterBuffer.
GetReadSize() == totalWrittenSize);
2046 TEST_CASE(
"SendThreadTest3")
2049 SetActiveProfilingState(profilingStateMachine);
2051 unsigned int totalWrittenSize = 0;
2056 SendThread sendThread(profilingStateMachine, mockStreamCounterBuffer, sendCounterPacket);
2057 sendThread.
Start(mockProfilingConnection);
2072 unsigned int counterDirectoryPacketSize =32;
2073 totalWrittenSize += counterDirectoryPacketSize;
2084 unsigned int periodicCounterCapturePacketSize = 28;
2085 totalWrittenSize += periodicCounterCapturePacketSize;
2098 periodicCounterCapturePacketSize = 22;
2099 totalWrittenSize += periodicCounterCapturePacketSize;
2111 periodicCounterCapturePacketSize = 46;
2112 totalWrittenSize += periodicCounterCapturePacketSize;
2125 periodicCounterCapturePacketSize = 40;
2126 totalWrittenSize += periodicCounterCapturePacketSize;
2133 periodicCounterCapturePacketSize = 30;
2134 totalWrittenSize += periodicCounterCapturePacketSize;
2144 CHECK(mockStreamCounterBuffer.
GetReadSize() <= totalWrittenSize);
2149 TEST_CASE(
"SendCounterPacketTestWithSendThread")
2152 SetWaitingForAckProfilingState(profilingStateMachine);
2157 SendThread sendThread(profilingStateMachine, bufferManager, sendCounterPacket, -1);
2158 sendThread.
Start(mockProfilingConnection);
2165 CHECK(mockProfilingConnection.
CheckForPacket({PacketType::StreamMetaData, streamMetadataPacketsize}) == 1);
2167 SetActiveProfilingState(profilingStateMachine);
2168 sendThread.
Start(mockProfilingConnection);
2175 unsigned int counterDirectoryPacketSize = 32;
2178 {PacketType::CounterDirectory, counterDirectoryPacketSize}) == 1);
2180 sendThread.
Start(mockProfilingConnection);
2191 unsigned int periodicCounterCapturePacketSize = 28;
2193 {PacketType::PeriodicCounterCapture, periodicCounterCapturePacketSize}) == 1);
2196 TEST_CASE(
"SendThreadBufferTest")
2199 SetActiveProfilingState(profilingStateMachine);
2204 SendThread sendThread(profilingStateMachine, bufferManager, sendCounterPacket, -1);
2205 sendThread.
Start(mockProfilingConnection);
2213 CHECK(packetBuffer.get());
2216 CHECK(packetBuffer->GetSize() == streamMetadataPacketsize);
2219 bufferManager.
Commit(packetBuffer, streamMetadataPacketsize);
2239 unsigned int reservedSize = 0;
2240 auto reservedBuffer = bufferManager.
Reserve(512, reservedSize);
2241 CHECK(reservedSize == 512);
2242 CHECK(reservedBuffer.get());
2245 const auto metaDataPacketCount =
2246 mockProfilingConnection.
CheckForPacket({PacketType::StreamMetaData, streamMetadataPacketsize});
2248 CHECK(metaDataPacketCount >= 1);
2249 CHECK(mockProfilingConnection.
CheckForPacket({PacketType::CounterDirectory, 32}) == 1);
2250 CHECK(mockProfilingConnection.
CheckForPacket({PacketType::PeriodicCounterCapture, 28}) == 1);
2252 CHECK(metaDataPacketCount + 2 == writtenDataSize);
2255 TEST_CASE(
"SendThreadSendStreamMetadataPacket1")
2262 SendThread sendThread(profilingStateMachine, bufferManager, sendCounterPacket);
2263 sendThread.
Start(mockProfilingConnection);
2269 TEST_CASE(
"SendThreadSendStreamMetadataPacket2")
2272 SetNotConnectedProfilingState(profilingStateMachine);
2277 SendThread sendThread(profilingStateMachine, bufferManager, sendCounterPacket);
2278 sendThread.
Start(mockProfilingConnection);
2284 TEST_CASE(
"SendThreadSendStreamMetadataPacket3")
2287 SetWaitingForAckProfilingState(profilingStateMachine);
2294 SendThread sendThread(profilingStateMachine, bufferManager, sendCounterPacket);
2295 sendThread.
Start(mockProfilingConnection);
2299 CHECK_NOTHROW(sendThread.
Stop());
2304 CHECK(writtenDataSize >= 1u);
2306 {PacketType::StreamMetaData, streamMetadataPacketsize}) == writtenDataSize);
2309 TEST_CASE(
"SendThreadSendStreamMetadataPacket4")
2312 SetWaitingForAckProfilingState(profilingStateMachine);
2319 SendThread sendThread(profilingStateMachine, bufferManager, sendCounterPacket);
2320 sendThread.
Start(mockProfilingConnection);
2326 sendThread.
Start(mockProfilingConnection);
2331 CHECK(mockProfilingConnection.
CheckForPacket({PacketType::StreamMetaData, streamMetadataPacketsize}) >= 1);
2333 mockProfilingConnection.
Clear();
2336 sendThread.
Start(mockProfilingConnection);
2342 CHECK_NOTHROW(sendThread.
Stop());
2350 CHECK(writtenDataSize >= 1u);
2352 {PacketType::StreamMetaData, streamMetadataPacketsize}) == writtenDataSize);
TEST_SUITE("TestConstTensorLayerVisitor")
bool CreateCounterSetRecordTest(const CounterSetPtr &counterSet, CounterSetRecord &counterSetRecord, std::string &errorMessage)
std::vector< uint32_t > CounterSetRecord
ProfilingState GetCurrentState() const
const Category * RegisterCategory(const std::string &categoryName) override
const Counter * RegisterCounter(const BackendId &backendId, const uint16_t uid, const std::string &parentCategoryName, uint16_t counterClass, uint16_t interpolation, double multiplier, const std::string &name, const std::string &description, const Optional< std::string > &units=EmptyOptional(), const Optional< uint16_t > &numberOfCores=EmptyOptional(), const Optional< uint16_t > &deviceUid=EmptyOptional(), const Optional< uint16_t > &counterSetUid=EmptyOptional()) override
std::vector< uint32_t > DeviceRecord
std::string GetHardwareVersion()
uint64_t ReadUint64(const IPacketBufferPtr &packetBuffer, unsigned int offset)
void SendCounterDirectoryPacket(const ICounterDirectory &counterDirectory) override
Create and write a CounterDirectoryPacket from the parameters to the buffer.
std::unordered_map< uint16_t, CounterPtr > Counters
void SendStreamMetaDataPacket() override
Create and write a StreamMetaDataPacket in the buffer.
#define ARMNN_NO_CONVERSION_WARN_END
void SendCounterDirectoryPacket(const ICounterDirectory &counterDirectory) override
Create and write a CounterDirectoryPacket from the parameters to the buffer.
uint32_t GetStreamMetaDataPacketSize()
std::unique_ptr< Device > DevicePtr
std::string GetProcessName()
unsigned int GetCommittedSize() const
void SendStreamMetaDataPacket() override
Create and write a StreamMetaDataPacket in the buffer.
const Device * GetDevice(uint16_t uid) const override
bool CreateDeviceRecordTest(const DevicePtr &device, DeviceRecord &deviceRecord, std::string &errorMessage)
std::unique_ptr< CounterSet > CounterSetPtr
uint16_t ReadUint16(const IPacketBufferPtr &packetBuffer, unsigned int offset)
uint16_t GetCounterSetCount() const override
uint8_t ReadUint8(const IPacketBufferPtr &packetBuffer, unsigned int offset)
unsigned long GetWrittenDataSize()
std::string GetSoftwareInfo()
void SendPeriodicCounterSelectionPacket(uint32_t capturePeriod, const std::vector< uint16_t > &selectedCounterIds) override
Create and write a PeriodicCounterSelectionPacket from the parameters to the buffer.
bool CreateEventRecordTest(const CounterPtr &counter, EventRecord &eventRecord, std::string &errorMessage)
const Counter * RegisterCounter(const BackendId &backendId, const uint16_t uid, const std::string &parentCategoryName, uint16_t counterClass, uint16_t interpolation, double multiplier, const std::string &name, const std::string &description, const armnn::Optional< std::string > &units=armnn::EmptyOptional(), const armnn::Optional< uint16_t > &numberOfCores=armnn::EmptyOptional(), const armnn::Optional< uint16_t > &deviceUid=armnn::EmptyOptional(), const armnn::Optional< uint16_t > &counterSetUid=armnn::EmptyOptional())
uint16_t GetDeviceCount() const override
std::vector< uint32_t > EventRecord
uint16_t GetCategoryCount() const override
void MarkRead(IPacketBufferPtr &packetBuffer) override
std::shared_ptr< Counter > CounterPtr
void Commit(IPacketBufferPtr &packetBuffer, unsigned int size, bool notifyConsumer=true) override
void SendPeriodicCounterCapturePacket(uint64_t timestamp, const IndexValuePairsVector &values) override
Create and write a PeriodicCounterCapturePacket from the parameters to the buffer.
const Device * RegisterDevice(const std::string &deviceName, uint16_t cores=0)
unsigned int GetReadableSize() const
IPacketBufferPtr GetReadableBuffer() override
#define ARMNN_FALLTHROUGH
uint32_t ConstructHeader(uint32_t packetFamily, uint32_t packetId)
#define ARMNN_ASSERT(COND)
IPacketBufferPtr Reserve(unsigned int requestedSize, unsigned int &reservedSize) override
uint16_t GetCategoryCount() const override
const Category * RegisterCategory(const std::string &categoryName)
void SendPeriodicCounterCapturePacket(uint64_t timestamp, const std::vector< CounterValue > &values) override
IPacketBufferPtr GetReadableBuffer() override
#define MAX_METADATA_PACKET_LENGTH
uint16_t GetCounterCount() const override
uint32_t ReadUint32(const IPacketBufferPtr &packetBuffer, unsigned int offset)
uint16_t GetCounterSetCount() const override
#define ARMNN_NO_CONVERSION_WARN_BEGIN
std::string GetSoftwareVersion()
std::vector< uint16_t > m_Counters
const Counter * GetCounter(uint16_t uid) const override
const Category * GetCategory(const std::string &name) const override
EmptyOptional is used to initialize the Optional class in case we want to have default value for an O...
void SetReadyToRead() override
Set a "ready to read" flag in the buffer to notify the reading thread to start reading it...
std::string m_Description
const Device * RegisterDevice(const std::string &deviceName, uint16_t cores=0, const Optional< std::string > &parentCategoryName=EmptyOptional()) override
bool CreateCategoryRecordTest(const CategoryPtr &category, const Counters &counters, CategoryRecord &categoryRecord, std::string &errorMessage)
void SendPeriodicCounterSelectionPacket(uint32_t capturePeriod, const std::vector< uint16_t > &selectedCounterIds) override
Create and write a PeriodicCounterSelectionPacket from the parameters to the buffer.
std::vector< uint32_t > CategoryRecord
std::unique_ptr< Category > CategoryPtr
std::enable_if_t< std::is_unsigned< Source >::value &&std::is_unsigned< Dest >::value, Dest > numeric_cast(Source source)
const CounterSet * RegisterCounterSet(const std::string &counterSetName, uint16_t count=0)
uint16_t GetCounterCount() const override
void TransitionToState(ProfilingState newState)
long CheckForPacket(const std::pair< PacketType, uint32_t > packetInfo)
const CounterSet * RegisterCounterSet(const std::string &counterSetName, uint16_t count=0, const Optional< std::string > &parentCategoryName=EmptyOptional()) override
const CounterSet * GetCounterSet(uint16_t uid) const override
void Stop(bool rethrowSendThreadExceptions=true) override
Stop the thread.
unsigned int GetReadSize() const
void Start(IProfilingConnection &profilingConnection) override
Start the thread.
uint16_t GetDeviceCount() const override