aboutsummaryrefslogtreecommitdiff
path: root/src/profiling/test/TimelineUtilityMethodsTests.cpp
diff options
context:
space:
mode:
authorMatteo Martincigh <matteo.martincigh@arm.com>2019-11-04 14:05:28 +0000
committerMatteo Martincigh <matteo.martincigh@arm.com>2019-11-06 15:50:10 +0000
commit5dc816e7d027170992e45d22ae11ae3000de9244 (patch)
treed96d8a759dd0bcd9b98df36698ded032caa13bd0 /src/profiling/test/TimelineUtilityMethodsTests.cpp
parent5edc8816118fcddb2681379db04c978041ce8b46 (diff)
downloadarmnn-5dc816e7d027170992e45d22ae11ae3000de9244.tar.gz
IVGCVSW-4065 Add a RecordEvent function
* Added RecordEvent utility function to the TimelineUtilityMethods class * Added new utility function to get a timestamp * Added unit tests Signed-off-by: Matteo Martincigh <matteo.martincigh@arm.com> Change-Id: Ia3f8fe7397915fa6c903ce0c0abab3047cea628c
Diffstat (limited to 'src/profiling/test/TimelineUtilityMethodsTests.cpp')
-rw-r--r--src/profiling/test/TimelineUtilityMethodsTests.cpp133
1 files changed, 129 insertions, 4 deletions
diff --git a/src/profiling/test/TimelineUtilityMethodsTests.cpp b/src/profiling/test/TimelineUtilityMethodsTests.cpp
index c2be6e5c46..3556a12a7b 100644
--- a/src/profiling/test/TimelineUtilityMethodsTests.cpp
+++ b/src/profiling/test/TimelineUtilityMethodsTests.cpp
@@ -262,9 +262,8 @@ void VerifyTimelineEntityBinaryPacket(Optional<ProfilingGuid> guid,
// Check the decl_id
offset += uint32_t_size;
- uint32_t entitytDecId = ReadUint32(readableData, offset);
-
- BOOST_CHECK(entitytDecId == uint32_t(1));
+ uint32_t entityDeclId = ReadUint32(readableData, offset);
+ BOOST_CHECK(entityDeclId == 1);
// Check the profiling GUID
offset += uint32_t_size;
@@ -282,6 +281,83 @@ void VerifyTimelineEntityBinaryPacket(Optional<ProfilingGuid> guid,
offset += uint64_t_size;
}
+void VerifyTimelineEventBinaryPacket(Optional<uint64_t> timestamp,
+ Optional<std::thread::id> threadId,
+ Optional<ProfilingGuid> eventGuid,
+ const unsigned char* readableData,
+ unsigned int& offset)
+{
+ BOOST_ASSERT(readableData);
+
+ // Utils
+ unsigned int uint32_t_size = sizeof(uint32_t);
+ unsigned int uint64_t_size = sizeof(uint64_t);
+ unsigned int threadId_size = sizeof(std::thread::id);
+
+ // Reading TimelineEventBinaryPacket
+ uint32_t entityBinaryPacketHeaderWord0 = ReadUint32(readableData, offset);
+ uint32_t entityBinaryPacketFamily = (entityBinaryPacketHeaderWord0 >> 26) & 0x0000003F;
+ uint32_t entityBinaryPacketClass = (entityBinaryPacketHeaderWord0 >> 19) & 0x0000007F;
+ uint32_t entityBinaryPacketType = (entityBinaryPacketHeaderWord0 >> 16) & 0x00000007;
+ uint32_t entityBinaryPacketStreamId = (entityBinaryPacketHeaderWord0 >> 0) & 0x00000007;
+
+ BOOST_CHECK(entityBinaryPacketFamily == 1);
+ BOOST_CHECK(entityBinaryPacketClass == 0);
+ BOOST_CHECK(entityBinaryPacketType == 1);
+ BOOST_CHECK(entityBinaryPacketStreamId == 0);
+
+ offset += uint32_t_size;
+ uint32_t entityBinaryPacketHeaderWord1 = ReadUint32(readableData, offset);
+ uint32_t entityBinaryPacketSequenceNumbered = (entityBinaryPacketHeaderWord1 >> 24) & 0x00000001;
+ uint32_t entityBinaryPacketDataLength = (entityBinaryPacketHeaderWord1 >> 0) & 0x00FFFFFF;
+ BOOST_CHECK(entityBinaryPacketSequenceNumbered == 0);
+ BOOST_CHECK(entityBinaryPacketDataLength == 20 + threadId_size);
+
+ // Check the decl_id
+ offset += uint32_t_size;
+ uint32_t entityDeclId = ReadUint32(readableData, offset);
+ BOOST_CHECK(entityDeclId == 4);
+
+ // Check the timestamp
+ offset += uint32_t_size;
+ uint64_t readTimestamp = ReadUint64(readableData, offset);
+ if (timestamp.has_value())
+ {
+ BOOST_CHECK(readTimestamp == timestamp.value());
+ }
+ else
+ {
+ BOOST_CHECK(readTimestamp != 0);
+ }
+
+ // Check the thread id
+ offset += uint64_t_size;
+ std::vector<uint8_t> readThreadId(threadId_size, 0);
+ ReadBytes(readableData, offset, threadId_size, readThreadId.data());
+ if (threadId.has_value())
+ {
+ BOOST_CHECK(readThreadId == threadId.value());
+ }
+ else
+ {
+ BOOST_CHECK(readThreadId == std::this_thread::get_id());
+ }
+
+ // Check the event GUID
+ offset += threadId_size;
+ uint64_t readEventGuid = ReadUint64(readableData, offset);
+ if (eventGuid.has_value())
+ {
+ BOOST_CHECK(readEventGuid == eventGuid.value());
+ }
+ else
+ {
+ BOOST_CHECK(readEventGuid != ProfilingGuid(0));
+ }
+
+ offset += uint64_t_size;
+}
+
} // Anonymous namespace
BOOST_AUTO_TEST_SUITE(TimelineUtilityMethodsTests)
@@ -518,7 +594,7 @@ BOOST_AUTO_TEST_CASE(CreateNameTypeEntityInvalidTest)
}
-BOOST_AUTO_TEST_CASE(CreateNameTypeEntitylTest)
+BOOST_AUTO_TEST_CASE(CreateNameTypeEntityTest)
{
MockBufferManager mockBufferManager(1024);
SendTimelinePacket sendTimelinePacket(mockBufferManager);
@@ -591,4 +667,53 @@ BOOST_AUTO_TEST_CASE(CreateNameTypeEntitylTest)
mockBufferManager.MarkRead(readableBuffer);
}
+BOOST_AUTO_TEST_CASE(RecordEventTest)
+{
+ MockBufferManager mockBufferManager(1024);
+ SendTimelinePacket sendTimelinePacket(mockBufferManager);
+ TimelineUtilityMethods timelineUtilityMethods(sendTimelinePacket);
+
+ ProfilingGuid entityGuid(123);
+ ProfilingStaticGuid eventClassGuid(456);
+ ProfilingDynamicGuid eventGuid(0);
+ BOOST_CHECK_NO_THROW(eventGuid = timelineUtilityMethods.RecordEvent(entityGuid, eventClassGuid));
+ BOOST_CHECK(eventGuid != ProfilingGuid(0));
+
+ // Commit all packets at once
+ sendTimelinePacket.Commit();
+
+ // Get the readable buffer
+ auto readableBuffer = mockBufferManager.GetReadableBuffer();
+ BOOST_CHECK(readableBuffer != nullptr);
+ unsigned int size = readableBuffer->GetSize();
+ BOOST_CHECK(size == 116);
+ const unsigned char* readableData = readableBuffer->GetReadableData();
+ BOOST_CHECK(readableData != nullptr);
+
+ // Utils
+ unsigned int offset = 0;
+
+ // First packet sent: TimelineEntityBinaryPacket
+ VerifyTimelineEventBinaryPacket(EmptyOptional(), EmptyOptional(), EmptyOptional(), readableData, offset);
+
+ // Second packet sent: TimelineRelationshipBinaryPacket
+ VerifyTimelineRelationshipBinaryPacket(ProfilingRelationshipType::ExecutionLink,
+ EmptyOptional(),
+ entityGuid,
+ EmptyOptional(),
+ readableData,
+ offset);
+
+ // Third packet sent: TimelineRelationshipBinaryPacket
+ VerifyTimelineRelationshipBinaryPacket(ProfilingRelationshipType::DataLink,
+ EmptyOptional(),
+ entityGuid,
+ eventClassGuid,
+ readableData,
+ offset);
+
+ // Mark the buffer as read
+ mockBufferManager.MarkRead(readableBuffer);
+}
+
BOOST_AUTO_TEST_SUITE_END()