11 #include <CounterDirectory.hpp> 12 #include <common/include/EncodeVersion.hpp> 21 #include <common/include/Constants.hpp> 23 #include <boost/test/unit_test.hpp> 33 uint16_t constexpr WAIT_UNTIL_READABLE_MS = 20;
51 BOOST_CHECK_MESSAGE(
false,
"Invalid profiling state");
71 BOOST_CHECK_MESSAGE(
false,
"Invalid profiling state");
92 BOOST_CHECK_MESSAGE(
false,
"Invalid profiling state");
110 const char* buffer =
reinterpret_cast<const char*
>(packetBuffer->GetReadableData());
112 BOOST_TEST(strcmp(buffer,
"SendStreamMetaDataPacket") == 0);
120 buffer =
reinterpret_cast<const char*
>(packetBuffer->GetReadableData());
122 BOOST_TEST(strcmp(buffer,
"SendCounterDirectoryPacket") == 0);
126 uint64_t timestamp = 0;
127 std::vector<CounterValue> indexValuePairs;
132 buffer =
reinterpret_cast<const char*
>(packetBuffer->GetReadableData());
134 BOOST_TEST(strcmp(buffer,
"SendPeriodicCounterCapturePacket") == 0);
138 uint32_t capturePeriod = 0;
139 std::vector<uint16_t> selectedCounterIds;
143 buffer =
reinterpret_cast<const char*
>(packetBuffer->GetReadableData());
145 BOOST_TEST(strcmp(buffer,
"SendPeriodicCounterSelectionPacket") == 0);
156 uint32_t capturePeriod = 1000;
157 std::vector<uint16_t> selectedCounterIds;
166 auto readBuffer2 = mockBuffer2.GetReadableBuffer();
168 uint32_t headerWord0 =
ReadUint32(readBuffer2, 0);
169 uint32_t headerWord1 =
ReadUint32(readBuffer2, 4);
172 BOOST_TEST(((headerWord0 >> 26) & 0x3F) == 0);
173 BOOST_TEST(((headerWord0 >> 16) & 0x3FF) == 4);
174 BOOST_TEST(headerWord1 == 4);
175 BOOST_TEST(period == 1000);
181 selectedCounterIds.reserve(5);
182 selectedCounterIds.emplace_back(100);
183 selectedCounterIds.emplace_back(200);
184 selectedCounterIds.emplace_back(300);
185 selectedCounterIds.emplace_back(400);
186 selectedCounterIds.emplace_back(500);
194 BOOST_TEST(((headerWord0 >> 26) & 0x3F) == 0);
195 BOOST_TEST(((headerWord0 >> 16) & 0x3FF) == 4);
196 BOOST_TEST(headerWord1 == 14);
197 BOOST_TEST(period == 1000);
199 uint16_t counterId = 0;
200 uint32_t offset = 12;
203 for(
const uint16_t&
id : selectedCounterIds)
206 BOOST_TEST(counterId ==
id);
219 auto captureTimestamp = std::chrono::steady_clock::now();
220 uint64_t time =
static_cast<uint64_t
>(captureTimestamp.time_since_epoch().count());
221 std::vector<CounterValue> indexValuePairs;
231 auto readBuffer2 = mockBuffer2.GetReadableBuffer();
233 uint32_t headerWord0 =
ReadUint32(readBuffer2, 0);
234 uint32_t headerWord1 =
ReadUint32(readBuffer2, 4);
235 uint64_t readTimestamp =
ReadUint64(readBuffer2, 8);
237 BOOST_TEST(((headerWord0 >> 26) & 0x0000003F) == 3);
238 BOOST_TEST(((headerWord0 >> 19) & 0x0000007F) == 0);
239 BOOST_TEST(((headerWord0 >> 16) & 0x00000007) == 0);
240 BOOST_TEST(headerWord1 == 8);
241 BOOST_TEST(time == readTimestamp);
247 indexValuePairs.reserve(5);
258 uint64_t readTimestamp2 =
ReadUint64(readBuffer3, 8);
260 BOOST_TEST(((headerWord0 >> 26) & 0x0000003F) == 3);
261 BOOST_TEST(((headerWord0 >> 19) & 0x0000007F) == 0);
262 BOOST_TEST(((headerWord0 >> 16) & 0x00000007) == 0);
263 BOOST_TEST(headerWord1 == 38);
264 BOOST_TEST(time == readTimestamp2);
266 uint16_t counterIndex = 0;
267 uint32_t counterValue = 100;
268 uint32_t offset = 16;
271 for (
auto it = indexValuePairs.begin(), end = indexValuePairs.end(); it != end; ++it)
274 uint16_t readIndex =
ReadUint16(readBuffer3, offset);
275 BOOST_TEST(counterIndex == readIndex);
280 uint32_t readValue =
ReadUint32(readBuffer3, offset);
281 BOOST_TEST(counterValue == readValue);
323 std::vector<std::pair<uint32_t, uint32_t>> packetVersions;
324 packetVersions.push_back(std::make_pair(
ConstructHeader(0, 0), arm::pipe::EncodeVersion(1, 0, 0)));
325 packetVersions.push_back(std::make_pair(
ConstructHeader(0, 1), arm::pipe::EncodeVersion(1, 0, 0)));
326 packetVersions.push_back(std::make_pair(
ConstructHeader(0, 2), arm::pipe::EncodeVersion(1, 0, 0)));
327 packetVersions.push_back(std::make_pair(
ConstructHeader(0, 3), arm::pipe::EncodeVersion(1, 0, 0)));
328 packetVersions.push_back(std::make_pair(
ConstructHeader(0, 4), arm::pipe::EncodeVersion(1, 0, 0)));
329 packetVersions.push_back(std::make_pair(
ConstructHeader(0, 5), arm::pipe::EncodeVersion(1, 0, 0)));
330 packetVersions.push_back(std::make_pair(
ConstructHeader(0, 6), arm::pipe::EncodeVersion(1, 0, 0)));
331 packetVersions.push_back(std::make_pair(
ConstructHeader(0, 7), arm::pipe::EncodeVersion(1, 0, 0)));
332 packetVersions.push_back(std::make_pair(
ConstructHeader(3, 0, 0), arm::pipe::EncodeVersion(1, 0, 0)));
333 packetVersions.push_back(std::make_pair(
ConstructHeader(3, 1, 0), arm::pipe::EncodeVersion(1, 0, 0)));
334 packetVersions.push_back(std::make_pair(
ConstructHeader(3, 1, 1), arm::pipe::EncodeVersion(1, 0, 0)));
335 packetVersions.push_back(std::make_pair(
ConstructHeader(1, 0, 0), arm::pipe::EncodeVersion(1, 0, 0)));
336 packetVersions.push_back(std::make_pair(
ConstructHeader(1, 0, 1), arm::pipe::EncodeVersion(1, 0, 0)));
338 uint32_t packetEntries =
static_cast<uint32_t
>(packetVersions.size());
345 uint32_t headerWord0 =
ReadUint32(readBuffer2, 0);
346 uint32_t headerWord1 =
ReadUint32(readBuffer2, sizeUint32);
348 BOOST_TEST(((headerWord0 >> 26) & 0x3F) == 0);
349 BOOST_TEST(((headerWord0 >> 16) & 0x3FF) == 0);
352 10 * sizeUint32 + infoSize +
353 hardwareVersionSize + softwareVersionSize +
354 processNameSize + sizeUint32 +
355 2 * packetEntries * sizeUint32);
357 BOOST_TEST(headerWord1 == totalLength - (2 * sizeUint32));
359 uint32_t offset = sizeUint32 * 2;
360 BOOST_TEST(
ReadUint32(readBuffer2, offset) == arm::pipe::PIPE_MAGIC);
361 offset += sizeUint32;
362 BOOST_TEST(
ReadUint32(readBuffer2, offset) == arm::pipe::EncodeVersion(1, 0, 0));
363 offset += sizeUint32;
365 offset += sizeUint32;
367 BOOST_TEST(
ReadUint32(readBuffer2, offset) == armnn::numeric_cast<uint32_t>(pid));
368 offset += sizeUint32;
369 uint32_t poolOffset = 10 * sizeUint32;
370 BOOST_TEST(
ReadUint32(readBuffer2, offset) == poolOffset);
371 offset += sizeUint32;
372 poolOffset += infoSize;
373 BOOST_TEST(
ReadUint32(readBuffer2, offset) == poolOffset);
374 offset += sizeUint32;
375 poolOffset += hardwareVersionSize;
376 BOOST_TEST(
ReadUint32(readBuffer2, offset) == poolOffset);
377 offset += sizeUint32;
378 poolOffset += softwareVersionSize;
379 BOOST_TEST(
ReadUint32(readBuffer2, offset) == poolOffset);
380 offset += sizeUint32;
381 poolOffset += processNameSize;
382 BOOST_TEST(
ReadUint32(readBuffer2, offset) == poolOffset);
383 offset += sizeUint32;
384 BOOST_TEST(
ReadUint32(readBuffer2, offset) == 0);
386 const unsigned char* readData2 = readBuffer2->GetReadableData();
388 offset += sizeUint32;
391 BOOST_TEST(strcmp(reinterpret_cast<const char *>(&readData2[offset]),
GetSoftwareInfo().c_str()) == 0);
395 if (hardwareVersionSize)
397 BOOST_TEST(strcmp(reinterpret_cast<const char *>(&readData2[offset]),
GetHardwareVersion().c_str()) == 0);
398 offset += hardwareVersionSize;
401 if (softwareVersionSize)
403 BOOST_TEST(strcmp(reinterpret_cast<const char *>(&readData2[offset]),
GetSoftwareVersion().c_str()) == 0);
404 offset += softwareVersionSize;
409 BOOST_TEST(strcmp(reinterpret_cast<const char *>(&readData2[offset]),
GetProcessName().c_str()) == 0);
410 offset += processNameSize;
415 uint32_t numberOfEntries =
ReadUint32(readBuffer2, offset);
416 BOOST_TEST((numberOfEntries >> 16) == packetEntries);
417 offset += sizeUint32;
418 for (std::pair<uint32_t, uint32_t>& packetVersion : packetVersions)
420 uint32_t readPacketId =
ReadUint32(readBuffer2, offset);
421 BOOST_TEST(packetVersion.first == readPacketId);
422 offset += sizeUint32;
423 uint32_t readVersion =
ReadUint32(readBuffer2, offset);
424 BOOST_TEST(packetVersion.second == readVersion);
425 offset += sizeUint32;
429 BOOST_TEST(offset == totalLength);
438 uint16_t deviceUid = 27;
439 const std::string deviceName =
"some_device";
440 uint16_t deviceCores = 3;
441 const DevicePtr device = std::make_unique<Device>(deviceUid, deviceName, deviceCores);
445 std::string errorMessage;
449 BOOST_CHECK(errorMessage.empty());
450 BOOST_CHECK(deviceRecord.size() == 6);
452 uint16_t deviceRecordWord0[]
454 static_cast<uint16_t
>(deviceRecord[0] >> 16),
455 static_cast<uint16_t>(deviceRecord[0])
457 BOOST_CHECK(deviceRecordWord0[0] == deviceUid);
458 BOOST_CHECK(deviceRecordWord0[1] == deviceCores);
459 BOOST_CHECK(deviceRecord[1] == 8);
460 BOOST_CHECK(deviceRecord[2] == deviceName.size() + 1);
461 BOOST_CHECK(std::memcmp(deviceRecord.data() + 3, deviceName.data(), deviceName.size()) == 0);
470 uint16_t deviceUid = 27;
471 const std::string deviceName =
"some€£invalid‡device";
472 uint16_t deviceCores = 3;
473 const DevicePtr device = std::make_unique<Device>(deviceUid, deviceName, deviceCores);
477 std::string errorMessage;
480 BOOST_CHECK(!result);
481 BOOST_CHECK(!errorMessage.empty());
482 BOOST_CHECK(deviceRecord.empty());
491 uint16_t counterSetUid = 27;
492 const std::string counterSetName =
"some_counter_set";
493 uint16_t counterSetCount = 3421;
494 const CounterSetPtr counterSet = std::make_unique<CounterSet>(counterSetUid, counterSetName, counterSetCount);
498 std::string errorMessage;
502 BOOST_CHECK(errorMessage.empty());
503 BOOST_CHECK(counterSetRecord.size() == 8);
505 uint16_t counterSetRecordWord0[]
507 static_cast<uint16_t
>(counterSetRecord[0] >> 16),
508 static_cast<uint16_t>(counterSetRecord[0])
510 BOOST_CHECK(counterSetRecordWord0[0] == counterSetUid);
511 BOOST_CHECK(counterSetRecordWord0[1] == counterSetCount);
512 BOOST_CHECK(counterSetRecord[1] == 8);
513 BOOST_CHECK(counterSetRecord[2] == counterSetName.size() + 1);
514 BOOST_CHECK(std::memcmp(counterSetRecord.data() + 3, counterSetName.data(), counterSetName.size()) == 0);
523 uint16_t counterSetUid = 27;
524 const std::string counterSetName =
"some invalid_counter€£set";
525 uint16_t counterSetCount = 3421;
526 const CounterSetPtr counterSet = std::make_unique<CounterSet>(counterSetUid, counterSetName, counterSetCount);
530 std::string errorMessage;
533 BOOST_CHECK(!result);
534 BOOST_CHECK(!errorMessage.empty());
535 BOOST_CHECK(counterSetRecord.empty());
544 uint16_t counterUid = 7256;
545 uint16_t maxCounterUid = 132;
546 uint16_t deviceUid = 132;
547 uint16_t counterSetUid = 4497;
548 uint16_t counterClass = 1;
549 uint16_t counterInterpolation = 1;
550 double counterMultiplier = 1234.567f;
551 const std::string counterName =
"some_valid_counter";
552 const std::string counterDescription =
"a_counter_for_testing";
553 const std::string counterUnits =
"Mrads2";
554 const CounterPtr counter = std::make_unique<Counter>(armnn::profiling::BACKEND_ID,
558 counterInterpolation,
569 std::string errorMessage;
573 BOOST_CHECK(errorMessage.empty());
574 BOOST_CHECK(eventRecord.size() == 24);
576 uint16_t eventRecordWord0[]
578 static_cast<uint16_t
>(eventRecord[0] >> 16),
579 static_cast<uint16_t>(eventRecord[0])
581 uint16_t eventRecordWord1[]
583 static_cast<uint16_t
>(eventRecord[1] >> 16),
584 static_cast<uint16_t>(eventRecord[1])
586 uint16_t eventRecordWord2[]
588 static_cast<uint16_t
>(eventRecord[2] >> 16),
589 static_cast<uint16_t>(eventRecord[2])
591 uint32_t eventRecordWord34[]
597 BOOST_CHECK(eventRecordWord0[0] == maxCounterUid);
598 BOOST_CHECK(eventRecordWord0[1] == counterUid);
599 BOOST_CHECK(eventRecordWord1[0] == deviceUid);
601 BOOST_CHECK(eventRecordWord1[1] == counterSetUid);
602 BOOST_CHECK(eventRecordWord2[0] == counterClass);
603 BOOST_CHECK(eventRecordWord2[1] == counterInterpolation);
604 BOOST_CHECK(std::memcmp(eventRecordWord34, &counterMultiplier,
sizeof(counterMultiplier)) == 0);
607 uint32_t eventRecordBlockSize = 8u *
sizeof(uint32_t);
608 uint32_t counterNameOffset = eventRecordBlockSize;
609 uint32_t counterDescriptionOffset = counterNameOffset +
615 size_t counterUnitsOffset = counterDescriptionOffset +
617 counterDescription.size() +
623 BOOST_CHECK(eventRecord[5] == counterNameOffset);
624 BOOST_CHECK(eventRecord[6] == counterDescriptionOffset);
625 BOOST_CHECK(eventRecord[7] == counterUnitsOffset);
628 auto eventRecordPool =
reinterpret_cast<unsigned char*
>(eventRecord.data());
632 BOOST_CHECK(eventRecordPool[counterNameOffset] == counterName.size() + 1);
634 BOOST_CHECK(std::memcmp(eventRecordPool +
638 counterName.size()) == 0);
640 BOOST_CHECK(eventRecordPool[counterNameOffset + uint32_t_size + counterName.size()] ==
'\0');
643 BOOST_CHECK(eventRecordPool[counterDescriptionOffset] == counterDescription.size() + 1);
645 BOOST_CHECK(std::memcmp(eventRecordPool +
646 counterDescriptionOffset +
648 counterDescription.data(),
649 counterDescription.size()) == 0);
651 BOOST_CHECK(eventRecordPool[counterDescriptionOffset + uint32_t_size + counterDescription.size()] ==
'\0');
654 BOOST_CHECK(eventRecordPool[counterUnitsOffset] == counterUnits.size() + 1);
656 BOOST_CHECK(std::memcmp(eventRecordPool +
660 counterUnits.size()) == 0);
662 BOOST_CHECK(eventRecordPool[counterUnitsOffset + uint32_t_size + counterUnits.size()] ==
'\0');
671 uint16_t counterUid = 44312;
672 uint16_t maxCounterUid = 345;
673 uint16_t deviceUid = 101;
674 uint16_t counterSetUid = 34035;
675 uint16_t counterClass = 0;
676 uint16_t counterInterpolation = 1;
677 double counterMultiplier = 4435.0023f;
678 const std::string counterName =
"some_valid_counter";
679 const std::string counterDescription =
"a_counter_for_testing";
680 const CounterPtr counter = std::make_unique<Counter>(armnn::profiling::BACKEND_ID,
684 counterInterpolation,
695 std::string errorMessage;
699 BOOST_CHECK(errorMessage.empty());
700 BOOST_CHECK(eventRecord.size() == 21);
702 uint16_t eventRecordWord0[]
704 static_cast<uint16_t
>(eventRecord[0] >> 16),
705 static_cast<uint16_t>(eventRecord[0])
707 uint16_t eventRecordWord1[]
709 static_cast<uint16_t
>(eventRecord[1] >> 16),
710 static_cast<uint16_t>(eventRecord[1])
712 uint16_t eventRecordWord2[]
714 static_cast<uint16_t
>(eventRecord[2] >> 16),
715 static_cast<uint16_t>(eventRecord[2])
717 uint32_t eventRecordWord34[]
722 BOOST_CHECK(eventRecordWord0[0] == maxCounterUid);
723 BOOST_CHECK(eventRecordWord0[1] == counterUid);
724 BOOST_CHECK(eventRecordWord1[0] == deviceUid);
725 BOOST_CHECK(eventRecordWord1[1] == counterSetUid);
726 BOOST_CHECK(eventRecordWord2[0] == counterClass);
727 BOOST_CHECK(eventRecordWord2[1] == counterInterpolation);
728 BOOST_CHECK(std::memcmp(eventRecordWord34, &counterMultiplier,
sizeof(counterMultiplier)) == 0);
731 uint32_t eventRecordBlockSize = 8u *
sizeof(uint32_t);
732 uint32_t counterNameOffset = eventRecordBlockSize;
733 uint32_t counterDescriptionOffset = counterNameOffset +
740 BOOST_CHECK(eventRecord[5] == counterNameOffset);
741 BOOST_CHECK(eventRecord[6] == counterDescriptionOffset);
742 BOOST_CHECK(eventRecord[7] == 0);
745 auto eventRecordPool =
reinterpret_cast<unsigned char*
>(eventRecord.data());
749 BOOST_CHECK(eventRecordPool[counterNameOffset] == counterName.size() + 1);
751 BOOST_CHECK(std::memcmp(eventRecordPool +
755 counterName.size()) == 0);
757 BOOST_CHECK(eventRecordPool[counterNameOffset + uint32_t_size + counterName.size()] ==
'\0');
760 BOOST_CHECK(eventRecordPool[counterDescriptionOffset] == counterDescription.size() + 1);
762 BOOST_CHECK(std::memcmp(eventRecordPool +
763 counterDescriptionOffset +
765 counterDescription.data(),
766 counterDescription.size()) == 0);
768 BOOST_CHECK(eventRecordPool[counterDescriptionOffset + uint32_t_size + counterDescription.size()] ==
'\0');
777 uint16_t counterUid = 7256;
778 uint16_t maxCounterUid = 132;
779 uint16_t deviceUid = 132;
780 uint16_t counterSetUid = 4497;
781 uint16_t counterClass = 1;
782 uint16_t counterInterpolation = 1;
783 double counterMultiplier = 1234.567f;
784 const std::string counterName =
"some_invalid_counter £££";
785 const std::string counterDescription =
"a_counter_for_testing";
786 const std::string counterUnits =
"Mrads2";
787 const CounterPtr counter = std::make_unique<Counter>(armnn::profiling::BACKEND_ID,
791 counterInterpolation,
802 std::string errorMessage;
805 BOOST_CHECK(!result);
806 BOOST_CHECK(!errorMessage.empty());
807 BOOST_CHECK(eventRecord.empty());
816 uint16_t counterUid = 7256;
817 uint16_t maxCounterUid = 132;
818 uint16_t deviceUid = 132;
819 uint16_t counterSetUid = 4497;
820 uint16_t counterClass = 1;
821 uint16_t counterInterpolation = 1;
822 double counterMultiplier = 1234.567f;
823 const std::string counterName =
"some_invalid_counter";
824 const std::string counterDescription =
"an invalid d€scription";
825 const std::string counterUnits =
"Mrads2";
826 const CounterPtr counter = std::make_unique<Counter>(armnn::profiling::BACKEND_ID,
830 counterInterpolation,
841 std::string errorMessage;
844 BOOST_CHECK(!result);
845 BOOST_CHECK(!errorMessage.empty());
846 BOOST_CHECK(eventRecord.empty());
855 uint16_t counterUid = 7256;
856 uint16_t maxCounterUid = 132;
857 uint16_t deviceUid = 132;
858 uint16_t counterSetUid = 4497;
859 uint16_t counterClass = 1;
860 uint16_t counterInterpolation = 1;
861 double counterMultiplier = 1234.567f;
862 const std::string counterName =
"some_invalid_counter";
863 const std::string counterDescription =
"a valid description";
864 const std::string counterUnits =
"Mrad s2";
865 const CounterPtr counter = std::make_unique<Counter>(armnn::profiling::BACKEND_ID,
869 counterInterpolation,
880 std::string errorMessage;
883 BOOST_CHECK(!result);
884 BOOST_CHECK(!errorMessage.empty());
885 BOOST_CHECK(eventRecord.empty());
894 const std::string categoryName =
"some_category";
895 const CategoryPtr category = std::make_unique<Category>(categoryName);
897 category->m_Counters = { 11u, 23u, 5670u };
901 counters.insert(std::make_pair<uint16_t, CounterPtr>(11,
913 counters.insert(std::make_pair<uint16_t, CounterPtr>(23,
921 "the second counter",
925 counters.insert(std::make_pair<uint16_t, CounterPtr>(5670,
932 "and this is number 3",
937 Counter* counter1 = counters.find(11)->second.get();
938 Counter* counter2 = counters.find(23)->second.get();
939 Counter* counter3 = counters.find(5670)->second.get();
947 std::string errorMessage;
951 BOOST_CHECK(errorMessage.empty());
952 BOOST_CHECK(categoryRecord.size() == 79);
955 uint16_t categoryRecordWord1[]
957 static_cast<uint16_t
>(categoryRecord[0] >> 16),
958 static_cast<uint16_t>(categoryRecord[0])
960 BOOST_CHECK(categoryRecordWord1[0] == categoryEventCount);
961 BOOST_CHECK(categoryRecordWord1[1] == 0);
967 uint32_t eventPointerTableOffset = categoryRecordBlockSize;
968 uint32_t categoryNameOffset = eventPointerTableOffset +
972 BOOST_CHECK(categoryRecord[1] == eventPointerTableOffset);
973 BOOST_CHECK(categoryRecord[2] == categoryNameOffset);
975 auto categoryRecordPool =
reinterpret_cast<unsigned char*
>(categoryRecord.data());
978 uint32_t eventRecord0Offset = categoryRecordPool[eventPointerTableOffset + 0 *
uint32_t_size];
979 uint32_t eventRecord1Offset = categoryRecordPool[eventPointerTableOffset + 1 *
uint32_t_size];
980 uint32_t eventRecord2Offset = categoryRecordPool[eventPointerTableOffset + 2 *
uint32_t_size];
981 BOOST_CHECK(eventRecord0Offset == 32);
982 BOOST_CHECK(eventRecord1Offset == 120);
983 BOOST_CHECK(eventRecord2Offset == 200);
986 BOOST_CHECK(categoryRecordPool[categoryNameOffset] == categoryName.size() + 1);
988 BOOST_CHECK(std::memcmp(categoryRecordPool +
992 categoryName.size()) == 0);
994 BOOST_CHECK(categoryRecordPool[categoryNameOffset + uint32_t_size + categoryName.size()] ==
'\0');
1000 uint16_t eventRecord0Word0[2] = { 0u, 0u };
1001 std::memcpy(eventRecord0Word0, categoryRecordPool + categoryRecordBlockSize + eventRecord0Offset,
1002 sizeof(eventRecord0Word0));
1003 BOOST_CHECK(eventRecord0Word0[0] == counter1->
m_Uid);
1007 uint32_t counter1NameOffset = 0;
1008 std::memcpy(&counter1NameOffset, categoryRecordPool + eventRecord0Offset + 5u * uint32_t_size, uint32_t_size);
1009 BOOST_CHECK(counter1NameOffset == 0);
1011 BOOST_CHECK(categoryRecordPool[eventRecord0Offset +
1012 categoryRecordBlockSize +
1013 8u * uint32_t_size +
1015 ] == counter1->
m_Name.size() + 1);
1018 BOOST_CHECK(std::memcmp(categoryRecordPool +
1019 categoryRecordBlockSize +
1020 eventRecord0Offset +
1021 8u * uint32_t_size +
1022 counter1NameOffset +
1025 counter1->
m_Name.size()) == 0);
1027 BOOST_CHECK(categoryRecordPool[eventRecord0Offset +
1028 categoryRecordBlockSize +
1029 8u * uint32_t_size +
1030 counter1NameOffset +
1036 uint32_t counter2NameOffset = 0;
1037 std::memcpy(&counter2NameOffset, categoryRecordPool +
1038 categoryRecordBlockSize +
1039 eventRecord1Offset +
1042 BOOST_CHECK(counter2NameOffset == 8u * uint32_t_size );
1045 BOOST_CHECK(categoryRecordPool[eventRecord1Offset +
1046 categoryRecordBlockSize +
1048 ] == counter2->
m_Name.size() + 1);
1051 BOOST_CHECK(std::memcmp(categoryRecordPool +
1052 categoryRecordBlockSize +
1053 eventRecord1Offset +
1054 counter2NameOffset +
1057 counter2->
m_Name.size()) == 0);
1061 BOOST_CHECK(categoryRecordPool[eventRecord1Offset +
1062 categoryRecordBlockSize +
1063 counter2NameOffset +
1069 uint32_t counter3NameOffset = 0;
1070 std::memcpy(&counter3NameOffset, categoryRecordPool + eventRecord2Offset + 5u * uint32_t_size, uint32_t_size);
1071 BOOST_CHECK(counter3NameOffset == 0);
1073 BOOST_CHECK(categoryRecordPool[eventRecord2Offset +
1074 categoryRecordBlockSize +
1075 8u * uint32_t_size +
1077 ] == counter3->
m_Name.size() + 1);
1080 BOOST_CHECK(std::memcmp(categoryRecordPool +
1081 categoryRecordBlockSize +
1082 eventRecord2Offset +
1083 8u * uint32_t_size +
1084 counter3NameOffset +
1087 counter3->
m_Name.size()) == 0);
1089 BOOST_CHECK(categoryRecordPool[eventRecord2Offset +
1090 categoryRecordBlockSize +
1091 8u * uint32_t_size +
1092 counter3NameOffset +
1104 const std::string categoryName =
"some invalid category";
1105 const CategoryPtr category = std::make_unique<Category>(categoryName);
1106 BOOST_CHECK(category);
1111 std::string errorMessage;
1114 BOOST_CHECK(!result);
1115 BOOST_CHECK(!errorMessage.empty());
1116 BOOST_CHECK(categoryRecord.empty());
1125 const std::string categoryName =
"some_category";
1126 const CategoryPtr category = std::make_unique<Category>(categoryName);
1127 BOOST_CHECK(category);
1128 category->m_Counters = { 11u, 23u, 5670u };
1132 counters.insert(std::make_pair<uint16_t, CounterPtr>(11,
1140 "the first counter",
1145 Counter* counter1 = counters.find(11)->second.get();
1146 BOOST_CHECK(counter1);
1150 std::string errorMessage;
1153 BOOST_CHECK(!result);
1154 BOOST_CHECK(!errorMessage.empty());
1155 BOOST_CHECK(categoryRecord.empty());
1164 const std::string device1Name =
"device1";
1165 const Device* device1 =
nullptr;
1166 BOOST_CHECK_NO_THROW(device1 = counterDirectory.
RegisterDevice(device1Name, 3));
1168 BOOST_CHECK(device1);
1171 const std::string device2Name =
"device2";
1172 const Device* device2 =
nullptr;
1173 BOOST_CHECK_NO_THROW(device2 = counterDirectory.
RegisterDevice(device2Name));
1175 BOOST_CHECK(device2);
1190 const std::string device1Name =
"device1";
1191 const Device* device1 =
nullptr;
1192 BOOST_CHECK_NO_THROW(device1 = counterDirectory.
RegisterDevice(device1Name, 3));
1194 BOOST_CHECK(device1);
1197 const std::string device2Name =
"device2";
1198 const Device* device2 =
nullptr;
1199 BOOST_CHECK_NO_THROW(device2 = counterDirectory.
RegisterDevice(device2Name));
1201 BOOST_CHECK(device2);
1204 const std::string counterSet1Name =
"counterset1";
1206 BOOST_CHECK_NO_THROW(counterSet1 = counterDirectory.
RegisterCounterSet(counterSet1Name));
1208 BOOST_CHECK(counterSet1);
1211 const std::string category1Name =
"category1";
1212 const Category* category1 =
nullptr;
1213 BOOST_CHECK_NO_THROW(category1 = counterDirectory.
RegisterCategory(category1Name));
1215 BOOST_CHECK(category1);
1218 const std::string category2Name =
"category2";
1219 const Category* category2 =
nullptr;
1220 BOOST_CHECK_NO_THROW(category2 = counterDirectory.
RegisterCategory(category2Name));
1222 BOOST_CHECK(category2);
1224 uint16_t numberOfCores = 4;
1227 const Counter* counter1 =
nullptr;
1228 BOOST_CHECK_NO_THROW(counter1 = counterDirectory.
RegisterCounter(armnn::profiling::BACKEND_ID,
1235 "counter1description",
1236 std::string(
"counter1units"),
1239 BOOST_CHECK(counter1);
1242 const Counter* counter2 =
nullptr;
1243 BOOST_CHECK_NO_THROW(counter2 = counterDirectory.
RegisterCounter(armnn::profiling::BACKEND_ID,
1250 "counter2description",
1251 std::string(
"counter2units"),
1256 BOOST_CHECK(counter2);
1259 const Counter* counter3 =
nullptr;
1260 BOOST_CHECK_NO_THROW(counter3 = counterDirectory.
RegisterCounter(armnn::profiling::BACKEND_ID,
1267 "counter3description",
1271 counterSet1->
m_Uid));
1273 BOOST_CHECK(counter3);
1284 const uint32_t packetHeaderWord0 =
ReadUint32(readBuffer, 0);
1285 const uint32_t packetHeaderWord1 =
ReadUint32(readBuffer, 4);
1286 BOOST_TEST(((packetHeaderWord0 >> 26) & 0x3F) == 0);
1287 BOOST_TEST(((packetHeaderWord0 >> 16) & 0x3FF) == 2);
1288 BOOST_TEST(packetHeaderWord1 == 432);
1291 const uint32_t bodyHeaderWord0 =
ReadUint32(readBuffer, 8);
1292 const uint32_t bodyHeaderWord1 =
ReadUint32(readBuffer, 12);
1293 const uint32_t bodyHeaderWord2 =
ReadUint32(readBuffer, 16);
1294 const uint32_t bodyHeaderWord3 =
ReadUint32(readBuffer, 20);
1295 const uint32_t bodyHeaderWord4 =
ReadUint32(readBuffer, 24);
1296 const uint32_t bodyHeaderWord5 =
ReadUint32(readBuffer, 28);
1297 const uint16_t deviceRecordCount =
static_cast<uint16_t
>(bodyHeaderWord0 >> 16);
1298 const uint16_t counterSetRecordCount =
static_cast<uint16_t
>(bodyHeaderWord2 >> 16);
1299 const uint16_t categoryRecordCount =
static_cast<uint16_t
>(bodyHeaderWord4 >> 16);
1300 BOOST_TEST(deviceRecordCount == 2);
1301 BOOST_TEST(bodyHeaderWord1 == bodyHeaderSize * 4);
1302 BOOST_TEST(counterSetRecordCount == 1);
1303 BOOST_TEST(bodyHeaderWord3 == 8 + bodyHeaderSize * 4);
1304 BOOST_TEST(categoryRecordCount == 2);
1305 BOOST_TEST(bodyHeaderWord5 == 12 + bodyHeaderSize * 4);
1308 const uint32_t deviceRecordOffset0 =
ReadUint32(readBuffer, 32);
1309 const uint32_t deviceRecordOffset1 =
ReadUint32(readBuffer, 36);
1310 BOOST_TEST(deviceRecordOffset0 == 20);
1311 BOOST_TEST(deviceRecordOffset1 == 40);
1314 const uint32_t counterSetRecordOffset0 =
ReadUint32(readBuffer, 40);
1315 BOOST_TEST(counterSetRecordOffset0 == 52);
1318 const uint32_t categoryRecordOffset0 =
ReadUint32(readBuffer, 44);
1319 const uint32_t categoryRecordOffset1 =
ReadUint32(readBuffer, 48);
1320 BOOST_TEST(categoryRecordOffset0 == 72);
1321 BOOST_TEST(categoryRecordOffset1 == 176);
1332 uint32_t name_offset;
1333 uint32_t name_length;
1336 std::vector<DeviceRecord> deviceRecords;
1337 const uint32_t deviceRecordsPointerTableOffset = packetHeaderSize +
1340 const unsigned char* readData = readBuffer->GetReadableData();
1342 uint32_t offset = 0;
1343 std::vector<uint32_t> data(800);
1351 std::vector<uint32_t> deviceRecordOffsets(deviceRecordCount);
1352 offset = deviceRecordsPointerTableOffset;
1353 for (uint32_t i = 0; i < deviceRecordCount; ++i)
1356 deviceRecordOffsets[i] =
ReadUint32(readBuffer, offset) + deviceRecordsPointerTableOffset;
1360 for (uint32_t i = 0; i < deviceRecordCount; i++)
1363 const uint32_t deviceRecordWord0 =
ReadUint32(readBuffer, deviceRecordOffsets[i] + 0 * uint32_t_size);
1364 const uint32_t deviceRecordWord1 =
ReadUint32(readBuffer, deviceRecordOffsets[i] + 1 * uint32_t_size);
1365 DeviceRecord deviceRecord;
1366 deviceRecord.uid =
static_cast<uint16_t
>(deviceRecordWord0 >> 16);
1367 deviceRecord.cores =
static_cast<uint16_t
>(deviceRecordWord0);
1368 deviceRecord.name_offset = deviceRecordWord1;
1370 uint32_t deviceRecordPoolOffset = deviceRecordOffsets[i] +
1371 deviceRecord.name_offset;
1372 uint32_t deviceRecordNameLength =
ReadUint32(readBuffer, deviceRecordPoolOffset);
1373 deviceRecord.name_length = deviceRecordNameLength;
1374 unsigned char deviceRecordNameNullTerminator =
1375 ReadUint8(readBuffer, deviceRecordPoolOffset + uint32_t_size + deviceRecordNameLength - 1);
1376 BOOST_CHECK(deviceRecordNameNullTerminator ==
'\0');
1377 std::vector<unsigned char> deviceRecordNameBuffer(deviceRecord.name_length - 1);
1378 std::memcpy(deviceRecordNameBuffer.data(),
1379 readData + deviceRecordPoolOffset +
uint32_t_size, deviceRecordNameBuffer.size());
1380 deviceRecord.name.assign(deviceRecordNameBuffer.begin(), deviceRecordNameBuffer.end());
1382 deviceRecords.push_back(deviceRecord);
1386 BOOST_CHECK(deviceRecords.size() == 2);
1387 for (
const DeviceRecord& deviceRecord : deviceRecords)
1390 BOOST_CHECK(device);
1391 BOOST_CHECK(device->
m_Uid == deviceRecord.uid);
1392 BOOST_CHECK(device->
m_Cores == deviceRecord.cores);
1393 BOOST_CHECK(device->
m_Name == deviceRecord.name);
1398 struct CounterSetRecord
1402 uint32_t name_offset;
1403 uint32_t name_length;
1406 std::vector<CounterSetRecord> counterSetRecords;
1407 const uint32_t counterSetRecordsPointerTableOffset = 2u * uint32_t_size +
1410 offset = counterSetRecordsPointerTableOffset;
1411 std::vector<uint32_t> counterSetRecordOffsets(counterSetRecordCount);
1413 for (uint32_t i = 0; i < counterSetRecordCount; ++i)
1416 counterSetRecordOffsets[i] =
ReadUint32(readBuffer, offset) + counterSetRecordsPointerTableOffset;
1420 for (uint32_t i = 0; i < counterSetRecordCount; i++)
1423 const uint32_t counterSetRecordWord0 =
ReadUint32(readBuffer, counterSetRecordOffsets[i] + 0 * uint32_t_size);
1424 const uint32_t counterSetRecordWord1 =
ReadUint32(readBuffer, counterSetRecordOffsets[i] + 1 * uint32_t_size);
1425 CounterSetRecord counterSetRecord;
1426 counterSetRecord.uid =
static_cast<uint16_t
>(counterSetRecordWord0 >> 16);
1427 counterSetRecord.count =
static_cast<uint16_t
>(counterSetRecordWord0);
1428 counterSetRecord.name_offset = counterSetRecordWord1;
1430 uint32_t counterSetRecordPoolOffset = counterSetRecordOffsets[i] +
1431 counterSetRecord.name_offset;
1432 uint32_t counterSetRecordNameLength =
ReadUint32(readBuffer, counterSetRecordPoolOffset);
1433 counterSetRecord.name_length = counterSetRecordNameLength;
1434 unsigned char counterSetRecordNameNullTerminator =
1435 ReadUint8(readBuffer, counterSetRecordPoolOffset + uint32_t_size + counterSetRecordNameLength - 1);
1436 BOOST_CHECK(counterSetRecordNameNullTerminator ==
'\0');
1437 std::vector<unsigned char> counterSetRecordNameBuffer(counterSetRecord.name_length - 1);
1438 std::memcpy(counterSetRecordNameBuffer.data(),
1439 readData + counterSetRecordPoolOffset +
uint32_t_size, counterSetRecordNameBuffer.size());
1440 counterSetRecord.name.assign(counterSetRecordNameBuffer.begin(), counterSetRecordNameBuffer.end());
1442 counterSetRecords.push_back(counterSetRecord);
1446 BOOST_CHECK(counterSetRecords.size() == 1);
1447 for (
const CounterSetRecord& counterSetRecord : counterSetRecords)
1450 BOOST_CHECK(counterSet);
1451 BOOST_CHECK(counterSet->
m_Uid == counterSetRecord.uid);
1452 BOOST_CHECK(counterSet->
m_Count == counterSetRecord.count);
1453 BOOST_CHECK(counterSet->
m_Name == counterSetRecord.name);
1459 uint16_t counter_uid;
1460 uint16_t max_counter_uid;
1462 uint16_t counter_set;
1463 uint16_t counter_class;
1464 uint16_t interpolation;
1466 uint32_t name_offset;
1467 uint32_t name_length;
1469 uint32_t description_offset;
1470 uint32_t description_length;
1471 std::string description;
1472 uint32_t units_offset;
1473 uint32_t units_length;
1477 struct CategoryRecord
1479 uint16_t event_count;
1480 uint32_t event_pointer_table_offset;
1481 uint32_t name_offset;
1482 uint32_t name_length;
1484 std::vector<uint32_t> event_pointer_table;
1485 std::vector<EventRecord> event_records;
1487 std::vector<CategoryRecord> categoryRecords;
1488 const uint32_t categoryRecordsPointerTableOffset = 2u * uint32_t_size +
1491 offset = categoryRecordsPointerTableOffset;
1492 std::vector<uint32_t> categoryRecordOffsets(categoryRecordCount);
1493 for (uint32_t i = 0; i < categoryRecordCount; ++i)
1496 categoryRecordOffsets[i] =
ReadUint32(readBuffer, offset) + categoryRecordsPointerTableOffset;
1500 for (uint32_t i = 0; i < categoryRecordCount; i++)
1503 const uint32_t categoryRecordWord1 =
ReadUint32(readBuffer, categoryRecordOffsets[i] + 0 * uint32_t_size);
1504 const uint32_t categoryRecordWord2 =
ReadUint32(readBuffer, categoryRecordOffsets[i] + 1 * uint32_t_size);
1505 const uint32_t categoryRecordWord3 =
ReadUint32(readBuffer, categoryRecordOffsets[i] + 2 * uint32_t_size);
1506 CategoryRecord categoryRecord;
1507 categoryRecord.event_count =
static_cast<uint16_t
>(categoryRecordWord1 >> 16);
1508 categoryRecord.event_pointer_table_offset = categoryRecordWord2;
1509 categoryRecord.name_offset = categoryRecordWord3;
1511 uint32_t categoryRecordNameLength =
ReadUint32(readBuffer,
1512 categoryRecordOffsets[i] + categoryRecord.name_offset);
1513 categoryRecord.name_length = categoryRecordNameLength;
1514 unsigned char categoryRecordNameNullTerminator =
1516 categoryRecordOffsets[i] +
1517 categoryRecord.name_offset +
1519 categoryRecordNameLength - 1);
1520 BOOST_CHECK(categoryRecordNameNullTerminator ==
'\0');
1521 std::vector<unsigned char> categoryRecordNameBuffer(categoryRecord.name_length - 1);
1522 std::memcpy(categoryRecordNameBuffer.data(),
1524 categoryRecordOffsets[i] +
1525 categoryRecord.name_offset +
1527 categoryRecordNameBuffer.size());
1528 categoryRecord.name.assign(categoryRecordNameBuffer.begin(), categoryRecordNameBuffer.end());
1530 categoryRecord.event_pointer_table.resize(categoryRecord.event_count);
1531 offset = categoryRecordOffsets[i] + categoryRecord.event_pointer_table_offset;
1532 for (uint32_t eventOffsetIndex = 0; eventOffsetIndex < categoryRecord.event_count; ++eventOffsetIndex)
1535 categoryRecord.event_pointer_table[eventOffsetIndex] =
ReadUint32(readBuffer, offset) +
1536 categoryRecordOffsets[i] +
1537 categoryRecord.event_pointer_table_offset;
1541 for (uint32_t eventIndex = 0; eventIndex < categoryRecord.event_count; eventIndex++)
1543 const uint32_t eventOffset = categoryRecord.event_pointer_table[eventIndex];
1545 const uint32_t eventRecordWord0 =
ReadUint32(readBuffer, eventOffset + 0 * uint32_t_size);
1546 const uint32_t eventRecordWord1 =
ReadUint32(readBuffer, eventOffset + 1 * uint32_t_size);
1547 const uint32_t eventRecordWord2 =
ReadUint32(readBuffer, eventOffset + 2 * uint32_t_size);
1548 const uint64_t eventRecordWord34 =
ReadUint64(readBuffer, eventOffset + 3 * uint32_t_size);
1549 const uint32_t eventRecordWord5 =
ReadUint32(readBuffer, eventOffset + 5 * uint32_t_size);
1550 const uint32_t eventRecordWord6 =
ReadUint32(readBuffer, eventOffset + 6 * uint32_t_size);
1551 const uint32_t eventRecordWord7 =
ReadUint32(readBuffer, eventOffset + 7 * uint32_t_size);
1553 EventRecord eventRecord;
1554 eventRecord.counter_uid =
static_cast<uint16_t
>(eventRecordWord0);
1555 eventRecord.max_counter_uid =
static_cast<uint16_t
>(eventRecordWord0 >> 16);
1556 eventRecord.device =
static_cast<uint16_t
>(eventRecordWord1 >> 16);
1557 eventRecord.counter_set =
static_cast<uint16_t
>(eventRecordWord1);
1558 eventRecord.counter_class =
static_cast<uint16_t
>(eventRecordWord2 >> 16);
1559 eventRecord.interpolation =
static_cast<uint16_t
>(eventRecordWord2);
1560 std::memcpy(&eventRecord.multiplier, &eventRecordWord34,
sizeof(eventRecord.multiplier));
1561 eventRecord.name_offset =
static_cast<uint32_t
>(eventRecordWord5);
1562 eventRecord.description_offset =
static_cast<uint32_t
>(eventRecordWord6);
1563 eventRecord.units_offset =
static_cast<uint32_t
>(eventRecordWord7);
1565 uint32_t eventRecordNameLength =
ReadUint32(readBuffer, eventOffset + eventRecord.name_offset);
1566 eventRecord.name_length = eventRecordNameLength;
1567 unsigned char eventRecordNameNullTerminator =
1570 eventRecord.name_offset +
1572 eventRecordNameLength - 1);
1573 BOOST_CHECK(eventRecordNameNullTerminator ==
'\0');
1574 std::vector<unsigned char> eventRecordNameBuffer(eventRecord.name_length - 1);
1575 std::memcpy(eventRecordNameBuffer.data(),
1578 eventRecord.name_offset +
1580 eventRecordNameBuffer.size());
1581 eventRecord.name.assign(eventRecordNameBuffer.begin(), eventRecordNameBuffer.end());
1583 uint32_t eventRecordDescriptionLength =
ReadUint32(readBuffer,
1584 eventOffset + eventRecord.description_offset);
1585 eventRecord.description_length = eventRecordDescriptionLength;
1586 unsigned char eventRecordDescriptionNullTerminator =
1589 eventRecord.description_offset +
1591 eventRecordDescriptionLength - 1);
1592 BOOST_CHECK(eventRecordDescriptionNullTerminator ==
'\0');
1593 std::vector<unsigned char> eventRecordDescriptionBuffer(eventRecord.description_length - 1);
1594 std::memcpy(eventRecordDescriptionBuffer.data(),
1597 eventRecord.description_offset +
1599 eventRecordDescriptionBuffer.size());
1600 eventRecord.description.assign(eventRecordDescriptionBuffer.begin(),
1601 eventRecordDescriptionBuffer.end());
1603 if (eventRecord.units_offset > 0)
1605 uint32_t eventRecordUnitsLength =
ReadUint32(readBuffer,
1606 eventOffset + eventRecord.units_offset);
1607 eventRecord.units_length = eventRecordUnitsLength;
1608 unsigned char eventRecordUnitsNullTerminator =
1611 eventRecord.units_offset +
1613 eventRecordUnitsLength - 1);
1614 BOOST_CHECK(eventRecordUnitsNullTerminator ==
'\0');
1615 std::vector<unsigned char> eventRecordUnitsBuffer(eventRecord.units_length - 1);
1616 std::memcpy(eventRecordUnitsBuffer.data(),
1619 eventRecord.units_offset +
1621 eventRecordUnitsBuffer.size());
1622 eventRecord.units.assign(eventRecordUnitsBuffer.begin(), eventRecordUnitsBuffer.end());
1625 categoryRecord.event_records.push_back(eventRecord);
1628 categoryRecords.push_back(categoryRecord);
1632 BOOST_CHECK(categoryRecords.size() == 2);
1633 for (
const CategoryRecord& categoryRecord : categoryRecords)
1636 BOOST_CHECK(category);
1637 BOOST_CHECK(category->
m_Name == categoryRecord.name);
1638 BOOST_CHECK(category->
m_Counters.size() == categoryRecord.event_count +
static_cast<size_t>(numberOfCores) -1);
1639 BOOST_CHECK(category->
m_Counters.size() == categoryRecord.event_count +
static_cast<size_t>(numberOfCores) -1);
1642 for (
const EventRecord& eventRecord : categoryRecord.event_records)
1645 BOOST_CHECK(counter);
1647 BOOST_CHECK(counter->
m_DeviceUid == eventRecord.device);
1649 BOOST_CHECK(counter->
m_Class == eventRecord.counter_class);
1651 BOOST_CHECK(counter->
m_Multiplier == eventRecord.multiplier);
1652 BOOST_CHECK(counter->
m_Name == eventRecord.name);
1653 BOOST_CHECK(counter->
m_Description == eventRecord.description);
1654 BOOST_CHECK(counter->
m_Units == eventRecord.units);
1665 const std::string deviceName =
"inv@lid dev!c€";
1666 const Device* device =
nullptr;
1667 BOOST_CHECK_NO_THROW(device = counterDirectory.
RegisterDevice(deviceName, 3));
1669 BOOST_CHECK(device);
1683 const std::string counterSetName =
"inv@lid count€rs€t";
1685 BOOST_CHECK_NO_THROW(counterSet = counterDirectory.
RegisterCounterSet(counterSetName));
1687 BOOST_CHECK(counterSet);
1701 const std::string categoryName =
"c@t€gory";
1702 const Category* category =
nullptr;
1703 BOOST_CHECK_NO_THROW(category = counterDirectory.
RegisterCategory(categoryName));
1705 BOOST_CHECK(category);
1719 const std::string deviceName =
"inv@lid dev!c€";
1720 const Device* device =
nullptr;
1721 BOOST_CHECK_NO_THROW(device = counterDirectory.
RegisterDevice(deviceName, 3));
1723 BOOST_CHECK(device);
1726 const std::string counterSetName =
"inv@lid count€rs€t";
1728 BOOST_CHECK_NO_THROW(counterSet = counterDirectory.
RegisterCounterSet(counterSetName));
1730 BOOST_CHECK(counterSet);
1733 const std::string categoryName =
"c@t€gory";
1734 const Category* category =
nullptr;
1735 BOOST_CHECK_NO_THROW(category = counterDirectory.
RegisterCategory(categoryName));
1737 BOOST_CHECK(category);
1751 const std::string deviceName =
"valid device";
1752 const Device* device =
nullptr;
1753 BOOST_CHECK_NO_THROW(device = counterDirectory.
RegisterDevice(deviceName, 3));
1755 BOOST_CHECK(device);
1758 const std::string counterSetName =
"valid counterset";
1760 BOOST_CHECK_NO_THROW(counterSet = counterDirectory.
RegisterCounterSet(counterSetName));
1762 BOOST_CHECK(counterSet);
1765 const std::string categoryName =
"category";
1766 const Category* category =
nullptr;
1767 BOOST_CHECK_NO_THROW(category = counterDirectory.
RegisterCategory(categoryName));
1769 BOOST_CHECK(category);
1772 const Counter* counter =
nullptr;
1773 BOOST_CHECK_NO_THROW(counter = counterDirectory.
RegisterCounter(armnn::profiling::BACKEND_ID,
1780 "counter description",
1781 std::string(
"invalid counter units"),
1784 counterSet->
m_Uid));
1786 BOOST_CHECK(counter);
1797 SetActiveProfilingState(profilingStateMachine);
1802 SendThread sendThread(profilingStateMachine, mockStreamCounterBuffer, sendCounterPacket);
1806 sendThread.
Start(mockProfilingConnection);
1808 sendThread.
Start(mockProfilingConnection);
1809 sendThread.
Start(mockProfilingConnection);
1810 sendThread.
Start(mockProfilingConnection);
1811 sendThread.
Start(mockProfilingConnection);
1821 SetActiveProfilingState(profilingStateMachine);
1823 unsigned int totalWrittenSize = 0;
1828 SendThread sendThread(profilingStateMachine, mockStreamCounterBuffer, sendCounterPacket);
1829 sendThread.
Start(mockProfilingConnection);
1834 std::this_thread::sleep_for(std::chrono::milliseconds(WAIT_UNTIL_READABLE_MS));
1843 std::this_thread::sleep_for(std::chrono::milliseconds(WAIT_UNTIL_READABLE_MS));
1848 unsigned int counterDirectoryPacketSize = 32;
1849 totalWrittenSize += counterDirectoryPacketSize;
1853 std::this_thread::sleep_for(std::chrono::milliseconds(WAIT_UNTIL_READABLE_MS));
1862 unsigned int periodicCounterCapturePacketSize = 28;
1863 totalWrittenSize += periodicCounterCapturePacketSize;
1867 std::this_thread::sleep_for(std::chrono::milliseconds(WAIT_UNTIL_READABLE_MS));
1875 periodicCounterCapturePacketSize = 22;
1876 totalWrittenSize += periodicCounterCapturePacketSize;
1888 periodicCounterCapturePacketSize = 46;
1889 totalWrittenSize += periodicCounterCapturePacketSize;
1900 periodicCounterCapturePacketSize = 40;
1901 totalWrittenSize += periodicCounterCapturePacketSize;
1905 std::this_thread::sleep_for(std::chrono::milliseconds(WAIT_UNTIL_READABLE_MS));
1910 periodicCounterCapturePacketSize = 30;
1911 totalWrittenSize += periodicCounterCapturePacketSize;
1917 std::this_thread::sleep_for(std::chrono::milliseconds(WAIT_UNTIL_READABLE_MS));
1921 BOOST_CHECK(mockStreamCounterBuffer.
GetCommittedSize() == totalWrittenSize);
1922 BOOST_CHECK(mockStreamCounterBuffer.
GetReadableSize() == totalWrittenSize);
1923 BOOST_CHECK(mockStreamCounterBuffer.
GetReadSize() == totalWrittenSize);
1929 SetActiveProfilingState(profilingStateMachine);
1931 unsigned int totalWrittenSize = 0;
1936 SendThread sendThread(profilingStateMachine, mockStreamCounterBuffer, sendCounterPacket);
1937 sendThread.
Start(mockProfilingConnection);
1942 std::this_thread::sleep_for(std::chrono::milliseconds(WAIT_UNTIL_READABLE_MS));
1953 std::this_thread::sleep_for(std::chrono::milliseconds(WAIT_UNTIL_READABLE_MS));
1958 unsigned int counterDirectoryPacketSize = 32;
1959 totalWrittenSize += counterDirectoryPacketSize;
1964 std::this_thread::sleep_for(std::chrono::milliseconds(WAIT_UNTIL_READABLE_MS));
1973 unsigned int periodicCounterCapturePacketSize = 28;
1974 totalWrittenSize += periodicCounterCapturePacketSize;
1978 std::this_thread::sleep_for(std::chrono::milliseconds(WAIT_UNTIL_READABLE_MS));
1984 std::this_thread::sleep_for(std::chrono::milliseconds(WAIT_UNTIL_READABLE_MS));
1993 periodicCounterCapturePacketSize = 22;
1994 totalWrittenSize += periodicCounterCapturePacketSize;
2006 periodicCounterCapturePacketSize = 46;
2007 totalWrittenSize += periodicCounterCapturePacketSize;
2019 periodicCounterCapturePacketSize = 40;
2020 totalWrittenSize += periodicCounterCapturePacketSize;
2025 std::this_thread::sleep_for(std::chrono::milliseconds(WAIT_UNTIL_READABLE_MS));
2030 periodicCounterCapturePacketSize = 30;
2031 totalWrittenSize += periodicCounterCapturePacketSize;
2039 BOOST_CHECK(mockStreamCounterBuffer.
GetCommittedSize() == totalWrittenSize);
2040 BOOST_CHECK(mockStreamCounterBuffer.
GetReadableSize() == totalWrittenSize);
2041 BOOST_CHECK(mockStreamCounterBuffer.
GetReadSize() == totalWrittenSize);
2047 SetActiveProfilingState(profilingStateMachine);
2049 unsigned int totalWrittenSize = 0;
2054 SendThread sendThread(profilingStateMachine, mockStreamCounterBuffer, sendCounterPacket);
2055 sendThread.
Start(mockProfilingConnection);
2070 unsigned int counterDirectoryPacketSize =32;
2071 totalWrittenSize += counterDirectoryPacketSize;
2082 unsigned int periodicCounterCapturePacketSize = 28;
2083 totalWrittenSize += periodicCounterCapturePacketSize;
2096 periodicCounterCapturePacketSize = 22;
2097 totalWrittenSize += periodicCounterCapturePacketSize;
2109 periodicCounterCapturePacketSize = 46;
2110 totalWrittenSize += periodicCounterCapturePacketSize;
2123 periodicCounterCapturePacketSize = 40;
2124 totalWrittenSize += periodicCounterCapturePacketSize;
2131 periodicCounterCapturePacketSize = 30;
2132 totalWrittenSize += periodicCounterCapturePacketSize;
2140 BOOST_CHECK(mockStreamCounterBuffer.
GetCommittedSize() == totalWrittenSize);
2141 BOOST_CHECK(mockStreamCounterBuffer.
GetReadableSize() <= totalWrittenSize);
2142 BOOST_CHECK(mockStreamCounterBuffer.
GetReadSize() <= totalWrittenSize);
2150 SetWaitingForAckProfilingState(profilingStateMachine);
2155 SendThread sendThread(profilingStateMachine, bufferManager, sendCounterPacket, -1);
2156 sendThread.
Start(mockProfilingConnection);
2163 BOOST_CHECK(mockProfilingConnection.
CheckForPacket({PacketType::StreamMetaData, streamMetadataPacketsize}) == 1);
2165 SetActiveProfilingState(profilingStateMachine);
2166 sendThread.
Start(mockProfilingConnection);
2173 unsigned int counterDirectoryPacketSize = 32;
2176 {PacketType::CounterDirectory, counterDirectoryPacketSize}) == 1);
2178 sendThread.
Start(mockProfilingConnection);
2189 unsigned int periodicCounterCapturePacketSize = 28;
2191 {PacketType::PeriodicCounterCapture, periodicCounterCapturePacketSize}) == 1);
2197 SetActiveProfilingState(profilingStateMachine);
2202 SendThread sendThread(profilingStateMachine, bufferManager, sendCounterPacket, -1);
2203 sendThread.
Start(mockProfilingConnection);
2211 BOOST_TEST(packetBuffer.get());
2214 BOOST_TEST(packetBuffer->GetSize() == streamMetadataPacketsize);
2217 bufferManager.
Commit(packetBuffer, streamMetadataPacketsize);
2234 BOOST_TEST(!readBuffer);
2237 unsigned int reservedSize = 0;
2238 auto reservedBuffer = bufferManager.
Reserve(512, reservedSize);
2239 BOOST_TEST(reservedSize == 512);
2240 BOOST_TEST(reservedBuffer.get());
2243 const auto metaDataPacketCount =
2244 mockProfilingConnection.
CheckForPacket({PacketType::StreamMetaData, streamMetadataPacketsize});
2246 BOOST_TEST(metaDataPacketCount >= 1);
2247 BOOST_TEST(mockProfilingConnection.
CheckForPacket({PacketType::CounterDirectory, 32}) == 1);
2248 BOOST_TEST(mockProfilingConnection.
CheckForPacket({PacketType::PeriodicCounterCapture, 28}) == 1);
2250 BOOST_TEST(metaDataPacketCount + 2 == writtenDataSize);
2260 SendThread sendThread(profilingStateMachine, bufferManager, sendCounterPacket);
2261 sendThread.
Start(mockProfilingConnection);
2270 SetNotConnectedProfilingState(profilingStateMachine);
2275 SendThread sendThread(profilingStateMachine, bufferManager, sendCounterPacket);
2276 sendThread.
Start(mockProfilingConnection);
2285 SetWaitingForAckProfilingState(profilingStateMachine);
2292 SendThread sendThread(profilingStateMachine, bufferManager, sendCounterPacket);
2293 sendThread.
Start(mockProfilingConnection);
2297 BOOST_CHECK_NO_THROW(sendThread.
Stop());
2302 BOOST_TEST(writtenDataSize >= 1u);
2304 {PacketType::StreamMetaData, streamMetadataPacketsize}) == writtenDataSize);
2310 SetWaitingForAckProfilingState(profilingStateMachine);
2317 SendThread sendThread(profilingStateMachine, bufferManager, sendCounterPacket);
2318 sendThread.
Start(mockProfilingConnection);
2324 sendThread.
Start(mockProfilingConnection);
2329 BOOST_TEST(mockProfilingConnection.
CheckForPacket({PacketType::StreamMetaData, streamMetadataPacketsize}) >= 1);
2331 mockProfilingConnection.
Clear();
2334 sendThread.
Start(mockProfilingConnection);
2340 BOOST_CHECK_NO_THROW(sendThread.
Stop());
2348 BOOST_TEST(writtenDataSize >= 1u);
2350 {PacketType::StreamMetaData, streamMetadataPacketsize}) == writtenDataSize);
BOOST_AUTO_TEST_SUITE(TensorflowLiteParser)
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)
BOOST_AUTO_TEST_CASE(CheckConvolution2dLayer)
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
BOOST_AUTO_TEST_SUITE_END()
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