From 34a407d4a95830ff9fad05e2bff34dcfc631c931 Mon Sep 17 00:00:00 2001 From: Matteo Martincigh Date: Wed, 6 Nov 2019 15:30:54 +0000 Subject: IVGCVSW-4072 Add stream header to Timeline Message Directory packet * Refactored the WriteTimelineMessageDirectoryPacket function * Added the stream header to the packet * Updated decoders/parsers * Updated unit tests accordingly * Minor refactoring Signed-off-by: Matteo Martincigh Change-Id: I58f15fde54adc6414ca9fd5fb8d6157cad867339 --- src/profiling/ProfilingUtils.cpp | 213 ++++++++++++--------- src/profiling/ProfilingUtils.hpp | 61 +++++- src/profiling/test/SendTimelinePacketTests.cpp | 110 ++++++----- src/profiling/test/TimelinePacketTests.cpp | 22 ++- .../TimelineDirectoryCaptureCommandHandler.cpp | 33 ++-- .../TimelineDirectoryCaptureCommandHandler.hpp | 8 +- .../timelineDecoder/tests/TimelineTests.cpp | 40 ++-- 7 files changed, 314 insertions(+), 173 deletions(-) diff --git a/src/profiling/ProfilingUtils.cpp b/src/profiling/ProfilingUtils.cpp index 4dde235ecc..8a7d9147cc 100644 --- a/src/profiling/ProfilingUtils.cpp +++ b/src/profiling/ProfilingUtils.cpp @@ -134,6 +134,13 @@ void WriteUint16(const IPacketBufferPtr& packetBuffer, unsigned int offset, uint WriteUint16(packetBuffer->GetWritableData(), offset, value); } +void WriteUint8(const IPacketBufferPtr& packetBuffer, unsigned int offset, uint8_t value) +{ + BOOST_ASSERT(packetBuffer); + + WriteUint8(packetBuffer->GetWritableData(), offset, value); +} + void WriteBytes(unsigned char* buffer, unsigned int offset, const void* value, unsigned int valueSize) { BOOST_ASSERT(buffer); @@ -177,6 +184,13 @@ void WriteUint16(unsigned char* buffer, unsigned int offset, uint16_t value) buffer[offset + 1] = static_cast((value >> 8) & 0xFF); } +void WriteUint8(unsigned char* buffer, unsigned int offset, uint8_t value) +{ + BOOST_ASSERT(buffer); + + buffer[offset] = static_cast(value); +} + void ReadBytes(const IPacketBufferPtr& packetBuffer, unsigned int offset, unsigned int valueSize, uint8_t outValue[]) { BOOST_ASSERT(packetBuffer); @@ -294,46 +308,6 @@ std::string GetProcessName() return name; } -/// Creates a timeline packet header -/// -/// \params -/// packetFamiliy Timeline Packet Family -/// packetClass Timeline Packet Class -/// packetType Timeline Packet Type -/// streamId Stream identifier -/// seqeunceNumbered When non-zero the 4 bytes following the header is a u32 sequence number -/// dataLength Unsigned 24-bit integer. Length of data, in bytes. Zero is permitted -/// -/// \returns -/// Pair of uint32_t containing word0 and word1 of the header -std::pair CreateTimelinePacketHeader(uint32_t packetFamily, - uint32_t packetClass, - uint32_t packetType, - uint32_t streamId, - uint32_t sequenceNumbered, - uint32_t dataLength) -{ - // Packet header word 0: - // 26:31 [6] packet_family: timeline Packet Family, value 0b000001 - // 19:25 [7] packet_class: packet class - // 16:18 [3] packet_type: packet type - // 8:15 [8] reserved: all zeros - // 0:7 [8] stream_id: stream identifier - uint32_t packetHeaderWord0 = ((packetFamily & 0x0000003F) << 26) | - ((packetClass & 0x0000007F) << 19) | - ((packetType & 0x00000007) << 16) | - ((streamId & 0x00000007) << 0); - - // Packet header word 1: - // 25:31 [7] reserved: all zeros - // 24 [1] sequence_numbered: when non-zero the 4 bytes following the header is a u32 sequence number - // 0:23 [24] data_length: unsigned 24-bit integer. Length of data, in bytes. Zero is permitted - uint32_t packetHeaderWord1 = ((sequenceNumbered & 0x00000001) << 24) | - ((dataLength & 0x00FFFFFF) << 0); - - return std::make_pair(packetHeaderWord0, packetHeaderWord1); -} - // Calculate the actual length an SwString will be including the terminating null character // padding to bring it to the next uint32_t boundary but minus the leading uint32_t encoding // the size to allow the offset to be correctly updated when decoding a binary packet. @@ -357,7 +331,7 @@ SwTraceMessage ReadSwTraceMessage(const unsigned char* packetBuffer, unsigned in // Read the decl_id uint32_t readDeclId = ReadUint32(packetBuffer, offset); - swTraceMessage.id = readDeclId; + swTraceMessage.m_Id = readDeclId; // SWTrace "namestring" format // length of the string (first 4 bytes) + string + null terminator @@ -371,10 +345,10 @@ SwTraceMessage ReadSwTraceMessage(const unsigned char* packetBuffer, unsigned in std::memcpy(swTraceStringBuffer.data(), packetBuffer + offset, swTraceStringBuffer.size()); - swTraceMessage.name.assign(swTraceStringBuffer.begin(), swTraceStringBuffer.end()); // name + swTraceMessage.m_Name.assign(swTraceStringBuffer.begin(), swTraceStringBuffer.end()); // name // Check the ui_name - offset += CalculateSizeOfPaddedSwString(swTraceMessage.name); + offset += CalculateSizeOfPaddedSwString(swTraceMessage.m_Name); uint32_t swTraceUINameLength = ReadUint32(packetBuffer, offset); offset += uint32_t_size; @@ -382,10 +356,10 @@ SwTraceMessage ReadSwTraceMessage(const unsigned char* packetBuffer, unsigned in std::memcpy(swTraceStringBuffer.data(), packetBuffer + offset, swTraceStringBuffer.size()); - swTraceMessage.uiName.assign(swTraceStringBuffer.begin(), swTraceStringBuffer.end()); // ui_name + swTraceMessage.m_UiName.assign(swTraceStringBuffer.begin(), swTraceStringBuffer.end()); // ui_name // Check arg_types - offset += CalculateSizeOfPaddedSwString(swTraceMessage.uiName); + offset += CalculateSizeOfPaddedSwString(swTraceMessage.m_UiName); uint32_t swTraceArgTypesLength = ReadUint32(packetBuffer, offset); offset += uint32_t_size; @@ -393,7 +367,7 @@ SwTraceMessage ReadSwTraceMessage(const unsigned char* packetBuffer, unsigned in std::memcpy(swTraceStringBuffer.data(), packetBuffer + offset, swTraceStringBuffer.size()); - swTraceMessage.argTypes.assign(swTraceStringBuffer.begin(), swTraceStringBuffer.end()); // arg_types + swTraceMessage.m_ArgTypes.assign(swTraceStringBuffer.begin(), swTraceStringBuffer.end()); // arg_types std::string swTraceString(swTraceStringBuffer.begin(), swTraceStringBuffer.end()); @@ -411,7 +385,7 @@ SwTraceMessage ReadSwTraceMessage(const unsigned char* packetBuffer, unsigned in std::string argName; while (std::getline(stringStream, argName, ',')) { - swTraceMessage.argNames.push_back(argName); + swTraceMessage.m_ArgNames.push_back(argName); } offset += CalculateSizeOfPaddedSwString(swTraceString); @@ -419,6 +393,46 @@ SwTraceMessage ReadSwTraceMessage(const unsigned char* packetBuffer, unsigned in return swTraceMessage; } +/// Creates a timeline packet header +/// +/// \params +/// packetFamiliy Timeline Packet Family +/// packetClass Timeline Packet Class +/// packetType Timeline Packet Type +/// streamId Stream identifier +/// seqeunceNumbered When non-zero the 4 bytes following the header is a u32 sequence number +/// dataLength Unsigned 24-bit integer. Length of data, in bytes. Zero is permitted +/// +/// \returns +/// Pair of uint32_t containing word0 and word1 of the header +std::pair CreateTimelinePacketHeader(uint32_t packetFamily, + uint32_t packetClass, + uint32_t packetType, + uint32_t streamId, + uint32_t sequenceNumbered, + uint32_t dataLength) +{ + // Packet header word 0: + // 26:31 [6] packet_family: timeline Packet Family, value 0b000001 + // 19:25 [7] packet_class: packet class + // 16:18 [3] packet_type: packet type + // 8:15 [8] reserved: all zeros + // 0:7 [8] stream_id: stream identifier + uint32_t packetHeaderWord0 = ((packetFamily & 0x0000003F) << 26) | + ((packetClass & 0x0000007F) << 19) | + ((packetType & 0x00000007) << 16) | + ((streamId & 0x00000007) << 0); + + // Packet header word 1: + // 25:31 [7] reserved: all zeros + // 24 [1] sequence_numbered: when non-zero the 4 bytes following the header is a u32 sequence number + // 0:23 [24] data_length: unsigned 24-bit integer. Length of data, in bytes. Zero is permitted + uint32_t packetHeaderWord1 = ((sequenceNumbered & 0x00000001) << 24) | + ((dataLength & 0x00FFFFFF) << 0); + + return std::make_pair(packetHeaderWord0, packetHeaderWord1); +} + /// Creates a packet header for the timeline messages: /// * declareLabel /// * declareEntity @@ -675,11 +689,15 @@ TimelinePacketStatus WriteTimelineMessageDirectoryPackage(unsigned char* buffer, } // Utils + unsigned int uint8_t_size = sizeof(uint8_t); unsigned int uint32_t_size = sizeof(uint32_t); + unsigned int uint64_t_size = sizeof(uint64_t); + unsigned int threadId_size = sizeof(std::thread::id); // The payload/data of the packet consists of swtrace event definitions encoded according // to the swtrace directory specification. The messages being the five defined below: - // | decl_id | decl_name | ui_name | arg_types | arg_names | + // + // | decl_id | decl_name | ui_name | arg_types | arg_names | // |-----------|---------------------|-----------------------|-------------|-------------------------------------| // | 0 | declareLabel | declare label | ps | guid,value | // | 1 | declareEntity | declare entity | p | guid | @@ -687,42 +705,50 @@ TimelinePacketStatus WriteTimelineMessageDirectoryPackage(unsigned char* buffer, // | 3 | declareRelationship | declare relationship | Ippp | relationshipType,relationshipGuid, | // | | | | | headGuid,tailGuid | // | 4 | declareEvent | declare event | @tp | timestamp,threadId,eventGuid | - std::vector> timelineDirectoryMessages { - {"declareLabel", "declare label", "ps", "guid,value"}, - {"declareEntity", "declare entity", "p", "guid"}, - {"declareEventClass", "declare event class", "p", "guid"}, - {"declareRelationship", "declare relationship", "Ippp", "relationshipType,relationshipGuid,headGuid,tailGuid"}, - {"declareEvent", "declare event", "@tp", "timestamp,threadId,eventGuid"} + { "0", "declareLabel", "declare label", "ps", "guid,value" }, + { "1", "declareEntity", "declare entity", "p", "guid" }, + { "2", "declareEventClass", "declare event class", "p", "guid" }, + { "3", "declareRelationship", "declare relationship", "Ippp", + "relationshipType,relationshipGuid,headGuid,tailGuid" }, + { "4", "declareEvent", "declare event", "@tp", "timestamp,threadId,eventGuid" } }; - unsigned int messagesDataLength = 0u; - std::vector>> swTraceTimelineDirectoryMessages; - - for (const auto& timelineDirectoryMessage : timelineDirectoryMessages) + // Build the message declarations + std::vector swTraceBuffer; + for (const auto& directoryComponent : timelineDirectoryMessages) { - messagesDataLength += uint32_t_size; // decl_id - - std::vector> swTraceStringsVector; - for (const auto& label : timelineDirectoryMessage) + // decl_id + uint32_t declId = 0; + try + { + declId = boost::numeric_cast(std::stoul(directoryComponent[0])); + } + catch (const std::exception&) { - std::vector swTraceString; - bool result = StringToSwTraceString(label, swTraceString); - if (!result) - { - return TimelinePacketStatus::Error; - } - - messagesDataLength += boost::numeric_cast(swTraceString.size()) * uint32_t_size; - swTraceStringsVector.push_back(swTraceString); + return TimelinePacketStatus::Error; + } + swTraceBuffer.push_back(declId); + + bool result = true; + result &= ConvertDirectoryComponent(directoryComponent[1], swTraceBuffer); // decl_name + result &= ConvertDirectoryComponent (directoryComponent[2], swTraceBuffer); // ui_name + result &= ConvertDirectoryComponent(directoryComponent[3], swTraceBuffer); // arg_types + result &= ConvertDirectoryComponent (directoryComponent[4], swTraceBuffer); // arg_names + if (!result) + { + return TimelinePacketStatus::Error; } - swTraceTimelineDirectoryMessages.push_back(swTraceStringsVector); } + unsigned int dataLength = 3 * uint8_t_size + // Stream header (3 bytes) + boost::numeric_cast(swTraceBuffer.size()) * + uint32_t_size; // Trace directory (5 messages) + // Calculate the timeline directory binary packet size (in bytes) unsigned int timelineDirectoryPacketSize = 2 * uint32_t_size + // Header (2 words) - messagesDataLength; // 5 messages length + dataLength; // Payload // Check whether the timeline directory binary packet fits in the given buffer if (timelineDirectoryPacketSize > bufferSize) @@ -731,8 +757,7 @@ TimelinePacketStatus WriteTimelineMessageDirectoryPackage(unsigned char* buffer, } // Create packet header - uint32_t dataLength = boost::numeric_cast(messagesDataLength); - std::pair packetHeader = CreateTimelinePacketHeader(1, 0, 0, 0, 0, dataLength); + auto packetHeader = CreateTimelinePacketHeader(1, 0, 0, 0, 0, boost::numeric_cast(dataLength)); // Initialize the offset for writing in the buffer unsigned int offset = 0; @@ -743,23 +768,33 @@ TimelinePacketStatus WriteTimelineMessageDirectoryPackage(unsigned char* buffer, WriteUint32(buffer, offset, packetHeader.second); offset += uint32_t_size; - WriteUint32(buffer, offset, static_cast(swTraceTimelineDirectoryMessages.size())); + // Write the stream header + uint8_t streamVersion = 4; + uint8_t pointerBytes = boost::numeric_cast(uint64_t_size); // All GUIDs are uint64_t + uint8_t threadIdBytes = boost::numeric_cast(threadId_size); + switch (threadIdBytes) + { + case 4: // Typically Windows and Android + case 8: // Typically Linux + break; // Valid values + default: + return TimelinePacketStatus::Error; // Invalid value + } + WriteUint8(buffer, offset, streamVersion); + offset += uint8_t_size; + WriteUint8(buffer, offset, pointerBytes); + offset += uint8_t_size; + WriteUint8(buffer, offset, threadIdBytes); + offset += uint8_t_size; + + // Write the SWTrace directory + uint32_t numberOfDeclarations = boost::numeric_cast(timelineDirectoryMessages.size()); + WriteUint32(buffer, offset, numberOfDeclarations); // Number of declarations offset += uint32_t_size; - - for (unsigned int i = 0u; i < swTraceTimelineDirectoryMessages.size(); ++i) + for (uint32_t i : swTraceBuffer) { - // Write the timeline binary packet payload to the buffer - WriteUint32(buffer, offset, i); // decl_id + WriteUint32(buffer, offset, i); // Message declarations offset += uint32_t_size; - - for (std::vector swTraceString : swTraceTimelineDirectoryMessages[i]) - { - for (uint32_t swTraceDeclStringWord : swTraceString) - { - WriteUint32(buffer, offset, swTraceDeclStringWord); - offset += uint32_t_size; - } - } } // Update the number of bytes written diff --git a/src/profiling/ProfilingUtils.hpp b/src/profiling/ProfilingUtils.hpp index f7b46be972..4427140ece 100644 --- a/src/profiling/ProfilingUtils.hpp +++ b/src/profiling/ProfilingUtils.hpp @@ -25,13 +25,20 @@ namespace armnn namespace profiling { +struct SwTraceHeader +{ + uint8_t m_StreamVersion; + uint8_t m_PointerBytes; + uint8_t m_ThreadIdBytes; +}; + struct SwTraceMessage { - uint32_t id; - std::string name; - std::string uiName; - std::vector argTypes; - std::vector argNames; + uint32_t m_Id; + std::string m_Name; + std::string m_UiName; + std::vector m_ArgTypes; + std::vector m_ArgNames; }; struct SwTraceCharPolicy @@ -52,6 +59,29 @@ struct SwTraceNameCharPolicy } }; +struct SwTraceTypeCharPolicy +{ + static bool IsValidChar(unsigned char c) + { + // Check that the given character is among the allowed ones + switch (c) + { + case '@': + case 't': + case 'i': + case 'I': + case 'l': + case 'L': + case 'F': + case 'p': + case 's': + return true; // Valid char + default: + return false; // Invalid char + } + } +}; + template bool IsValidSwTraceString(const std::string& s) { @@ -87,6 +117,23 @@ bool StringToSwTraceString(const std::string& s, std::vector& outputBu return true; } +template > +bool ConvertDirectoryComponent(const std::string& directoryComponent, SwTraceBuffer& swTraceBuffer) +{ + // Convert the directory component using the given policy + SwTraceBuffer tempSwTraceBuffer; + bool result = StringToSwTraceString(directoryComponent, tempSwTraceBuffer); + if (!result) + { + return false; + } + + swTraceBuffer.insert(swTraceBuffer.end(), tempSwTraceBuffer.begin(), tempSwTraceBuffer.end()); + + return true; +} + uint16_t GetNextUid(bool peekOnly = false); std::vector GetNextCounterUids(uint16_t cores); @@ -103,6 +150,8 @@ void WriteUint32(const IPacketBufferPtr& packetBuffer, unsigned int offset, uint void WriteUint16(const IPacketBufferPtr& packetBuffer, unsigned int offset, uint16_t value); +void WriteUint8(const IPacketBufferPtr& packetBuffer, unsigned int offset, uint8_t value); + void WriteBytes(unsigned char* buffer, unsigned int offset, const void* value, unsigned int valueSize); void WriteUint64(unsigned char* buffer, unsigned int offset, uint64_t value); @@ -111,6 +160,8 @@ void WriteUint32(unsigned char* buffer, unsigned int offset, uint32_t value); void WriteUint16(unsigned char* buffer, unsigned int offset, uint16_t value); +void WriteUint8(unsigned char* buffer, unsigned int offset, uint8_t value); + void ReadBytes(const IPacketBufferPtr& packetBuffer, unsigned int offset, unsigned int valueSize, uint8_t outValue[]); uint64_t ReadUint64(const IPacketBufferPtr& packetBuffer, unsigned int offset); diff --git a/src/profiling/test/SendTimelinePacketTests.cpp b/src/profiling/test/SendTimelinePacketTests.cpp index 7f3094918d..26b49dfb18 100644 --- a/src/profiling/test/SendTimelinePacketTests.cpp +++ b/src/profiling/test/SendTimelinePacketTests.cpp @@ -31,7 +31,11 @@ BOOST_AUTO_TEST_CASE(SendTimelineMessageDirectoryPackageTest) // Get the readable buffer auto packetBuffer = mockBuffer.GetReadableBuffer(); + unsigned int uint8_t_size = sizeof(uint8_t); unsigned int uint32_t_size = sizeof(uint32_t); + unsigned int uint64_t_size = sizeof(uint64_t); + unsigned int threadId_size = sizeof(std::thread::id); + // Check the packet header unsigned int offset = 0; uint32_t packetHeaderWord0 = ReadUint32(packetBuffer, offset); @@ -50,74 +54,84 @@ BOOST_AUTO_TEST_CASE(SendTimelineMessageDirectoryPackageTest) uint32_t sequenceNumbered = (packetHeaderWord1 >> 24) & 0x00000001; uint32_t dataLength = (packetHeaderWord1 >> 0) & 0x00FFFFFF; BOOST_CHECK(sequenceNumbered == 0); - BOOST_CHECK(dataLength == 416); + BOOST_CHECK(dataLength == 419); offset += uint32_t_size; + uint8_t readStreamVersion = ReadUint8(packetBuffer, offset); + BOOST_CHECK(readStreamVersion == 4); + offset += uint8_t_size; + uint8_t readPointerBytes = ReadUint8(packetBuffer, offset); + BOOST_CHECK(readPointerBytes == uint64_t_size); + offset += uint8_t_size; + uint8_t readThreadIdBytes = ReadUint8(packetBuffer, offset); + BOOST_CHECK(readThreadIdBytes == threadId_size); + + offset += uint8_t_size; uint32_t DeclCount = ReadUint32(packetBuffer, offset); BOOST_CHECK(DeclCount == 5); offset += uint32_t_size; SwTraceMessage swTraceMessage = ReadSwTraceMessage(packetBuffer->GetReadableData(), offset); - BOOST_CHECK(swTraceMessage.id == 0); - BOOST_CHECK(swTraceMessage.name == "declareLabel"); - BOOST_CHECK(swTraceMessage.uiName == "declare label"); - BOOST_CHECK(swTraceMessage.argTypes.size() == 2); - BOOST_CHECK(swTraceMessage.argTypes[0] == 'p'); - BOOST_CHECK(swTraceMessage.argTypes[1] == 's'); - BOOST_CHECK(swTraceMessage.argNames.size() == 2); - BOOST_CHECK(swTraceMessage.argNames[0] == "guid"); - BOOST_CHECK(swTraceMessage.argNames[1] == "value"); + BOOST_CHECK(swTraceMessage.m_Id == 0); + BOOST_CHECK(swTraceMessage.m_Name == "declareLabel"); + BOOST_CHECK(swTraceMessage.m_UiName == "declare label"); + BOOST_CHECK(swTraceMessage.m_ArgTypes.size() == 2); + BOOST_CHECK(swTraceMessage.m_ArgTypes[0] == 'p'); + BOOST_CHECK(swTraceMessage.m_ArgTypes[1] == 's'); + BOOST_CHECK(swTraceMessage.m_ArgNames.size() == 2); + BOOST_CHECK(swTraceMessage.m_ArgNames[0] == "guid"); + BOOST_CHECK(swTraceMessage.m_ArgNames[1] == "value"); swTraceMessage = ReadSwTraceMessage(packetBuffer->GetReadableData(), offset); - BOOST_CHECK(swTraceMessage.id == 1); - BOOST_CHECK(swTraceMessage.name == "declareEntity"); - BOOST_CHECK(swTraceMessage.uiName == "declare entity"); - BOOST_CHECK(swTraceMessage.argTypes.size() == 1); - BOOST_CHECK(swTraceMessage.argTypes[0] == 'p'); - BOOST_CHECK(swTraceMessage.argNames.size() == 1); - BOOST_CHECK(swTraceMessage.argNames[0] == "guid"); + BOOST_CHECK(swTraceMessage.m_Id == 1); + BOOST_CHECK(swTraceMessage.m_Name == "declareEntity"); + BOOST_CHECK(swTraceMessage.m_UiName == "declare entity"); + BOOST_CHECK(swTraceMessage.m_ArgTypes.size() == 1); + BOOST_CHECK(swTraceMessage.m_ArgTypes[0] == 'p'); + BOOST_CHECK(swTraceMessage.m_ArgNames.size() == 1); + BOOST_CHECK(swTraceMessage.m_ArgNames[0] == "guid"); swTraceMessage = ReadSwTraceMessage(packetBuffer->GetReadableData(), offset); - BOOST_CHECK(swTraceMessage.id == 2); - BOOST_CHECK(swTraceMessage.name == "declareEventClass"); - BOOST_CHECK(swTraceMessage.uiName == "declare event class"); - BOOST_CHECK(swTraceMessage.argTypes.size() == 1); - BOOST_CHECK(swTraceMessage.argTypes[0] == 'p'); - BOOST_CHECK(swTraceMessage.argNames.size() == 1); - BOOST_CHECK(swTraceMessage.argNames[0] == "guid"); + BOOST_CHECK(swTraceMessage.m_Id == 2); + BOOST_CHECK(swTraceMessage.m_Name == "declareEventClass"); + BOOST_CHECK(swTraceMessage.m_UiName == "declare event class"); + BOOST_CHECK(swTraceMessage.m_ArgTypes.size() == 1); + BOOST_CHECK(swTraceMessage.m_ArgTypes[0] == 'p'); + BOOST_CHECK(swTraceMessage.m_ArgNames.size() == 1); + BOOST_CHECK(swTraceMessage.m_ArgNames[0] == "guid"); swTraceMessage = ReadSwTraceMessage(packetBuffer->GetReadableData(), offset); - BOOST_CHECK(swTraceMessage.id == 3); - BOOST_CHECK(swTraceMessage.name == "declareRelationship"); - BOOST_CHECK(swTraceMessage.uiName == "declare relationship"); - BOOST_CHECK(swTraceMessage.argTypes.size() == 4); - BOOST_CHECK(swTraceMessage.argTypes[0] == 'I'); - BOOST_CHECK(swTraceMessage.argTypes[1] == 'p'); - BOOST_CHECK(swTraceMessage.argTypes[2] == 'p'); - BOOST_CHECK(swTraceMessage.argTypes[3] == 'p'); - BOOST_CHECK(swTraceMessage.argNames.size() == 4); - BOOST_CHECK(swTraceMessage.argNames[0] == "relationshipType"); - BOOST_CHECK(swTraceMessage.argNames[1] == "relationshipGuid"); - BOOST_CHECK(swTraceMessage.argNames[2] == "headGuid"); - BOOST_CHECK(swTraceMessage.argNames[3] == "tailGuid"); + BOOST_CHECK(swTraceMessage.m_Id == 3); + BOOST_CHECK(swTraceMessage.m_Name == "declareRelationship"); + BOOST_CHECK(swTraceMessage.m_UiName == "declare relationship"); + BOOST_CHECK(swTraceMessage.m_ArgTypes.size() == 4); + BOOST_CHECK(swTraceMessage.m_ArgTypes[0] == 'I'); + BOOST_CHECK(swTraceMessage.m_ArgTypes[1] == 'p'); + BOOST_CHECK(swTraceMessage.m_ArgTypes[2] == 'p'); + BOOST_CHECK(swTraceMessage.m_ArgTypes[3] == 'p'); + BOOST_CHECK(swTraceMessage.m_ArgNames.size() == 4); + BOOST_CHECK(swTraceMessage.m_ArgNames[0] == "relationshipType"); + BOOST_CHECK(swTraceMessage.m_ArgNames[1] == "relationshipGuid"); + BOOST_CHECK(swTraceMessage.m_ArgNames[2] == "headGuid"); + BOOST_CHECK(swTraceMessage.m_ArgNames[3] == "tailGuid"); swTraceMessage = ReadSwTraceMessage(packetBuffer->GetReadableData(), offset); - BOOST_CHECK(swTraceMessage.id == 4); - BOOST_CHECK(swTraceMessage.name == "declareEvent"); - BOOST_CHECK(swTraceMessage.uiName == "declare event"); - BOOST_CHECK(swTraceMessage.argTypes.size() == 3); - BOOST_CHECK(swTraceMessage.argTypes[0] == '@'); - BOOST_CHECK(swTraceMessage.argTypes[1] == 't'); - BOOST_CHECK(swTraceMessage.argTypes[2] == 'p'); - BOOST_CHECK(swTraceMessage.argNames.size() == 3); - BOOST_CHECK(swTraceMessage.argNames[0] == "timestamp"); - BOOST_CHECK(swTraceMessage.argNames[1] == "threadId"); - BOOST_CHECK(swTraceMessage.argNames[2] == "eventGuid"); + BOOST_CHECK(swTraceMessage.m_Id == 4); + BOOST_CHECK(swTraceMessage.m_Name == "declareEvent"); + BOOST_CHECK(swTraceMessage.m_UiName == "declare event"); + BOOST_CHECK(swTraceMessage.m_ArgTypes.size() == 3); + BOOST_CHECK(swTraceMessage.m_ArgTypes[0] == '@'); + BOOST_CHECK(swTraceMessage.m_ArgTypes[1] == 't'); + BOOST_CHECK(swTraceMessage.m_ArgTypes[2] == 'p'); + BOOST_CHECK(swTraceMessage.m_ArgNames.size() == 3); + BOOST_CHECK(swTraceMessage.m_ArgNames[0] == "timestamp"); + BOOST_CHECK(swTraceMessage.m_ArgNames[1] == "threadId"); + BOOST_CHECK(swTraceMessage.m_ArgNames[2] == "eventGuid"); } BOOST_AUTO_TEST_CASE(SendTimelineEntityPlusEventClassBinaryPacketTest) diff --git a/src/profiling/test/TimelinePacketTests.cpp b/src/profiling/test/TimelinePacketTests.cpp index 68cd948bdd..824f055a41 100644 --- a/src/profiling/test/TimelinePacketTests.cpp +++ b/src/profiling/test/TimelinePacketTests.cpp @@ -520,9 +520,12 @@ BOOST_AUTO_TEST_CASE(TimelineMessageDirectoryPacketTest3) numberOfBytesWritten); BOOST_CHECK(result == TimelinePacketStatus::Ok); - BOOST_CHECK(numberOfBytesWritten == 424); + BOOST_CHECK(numberOfBytesWritten == 427); + unsigned int uint8_t_size = sizeof(uint8_t); unsigned int uint32_t_size = sizeof(uint32_t); + unsigned int uint64_t_size = sizeof(uint64_t); + unsigned int threadId_size = sizeof(std::thread::id); // Check the packet header unsigned int offset = 0; @@ -541,10 +544,21 @@ BOOST_AUTO_TEST_CASE(TimelineMessageDirectoryPacketTest3) uint32_t sequenceNumbered = (packetHeaderWord1 >> 24) & 0x00000001; uint32_t dataLength = (packetHeaderWord1 >> 0) & 0x00FFFFFF; BOOST_CHECK(sequenceNumbered == 0); - BOOST_CHECK(dataLength == 416); + BOOST_CHECK(dataLength == 419); - // Check the number of declarations + // Check the stream header offset += uint32_t_size; + uint8_t readStreamVersion = ReadUint8(buffer.data(), offset); + BOOST_CHECK(readStreamVersion == 4); + offset += uint8_t_size; + uint8_t readPointerBytes = ReadUint8(buffer.data(), offset); + BOOST_CHECK(readPointerBytes == uint64_t_size); + offset += uint8_t_size; + uint8_t readThreadIdBytes = ReadUint8(buffer.data(), offset); + BOOST_CHECK(readThreadIdBytes == threadId_size); + + // Check the number of declarations + offset += uint8_t_size; uint32_t declCount = ReadUint32(buffer.data(), offset); BOOST_CHECK(declCount == 5); @@ -564,7 +578,7 @@ BOOST_AUTO_TEST_CASE(TimelineMessageDirectoryPacketTest3) std::string label = "declareLabel"; offset += uint32_t_size; BOOST_CHECK(std::memcmp(buffer.data() + offset, // Offset to the label in the buffer - label.data(), // The original label + label.data(), // The original label swTraceDeclNameLength - 1) == 0); // The length of the label // Check the ui_name diff --git a/tests/profiling/timelineDecoder/TimelineDirectoryCaptureCommandHandler.cpp b/tests/profiling/timelineDecoder/TimelineDirectoryCaptureCommandHandler.cpp index cb860a950b..f28c7b50bf 100644 --- a/tests/profiling/timelineDecoder/TimelineDirectoryCaptureCommandHandler.cpp +++ b/tests/profiling/timelineDecoder/TimelineDirectoryCaptureCommandHandler.cpp @@ -5,9 +5,13 @@ #include "TimelineDirectoryCaptureCommandHandler.hpp" +#include + #include #include +using namespace armnn::profiling; + namespace armnn { @@ -25,10 +29,17 @@ void TimelineDirectoryCaptureCommandHandler::ParseData(const armnn::profiling::P const unsigned char* data = packet.GetData(); + m_SwTraceHeader.m_StreamVersion = ReadUint8(data, offset); + offset += uint8_t_size; + m_SwTraceHeader.m_PointerBytes = ReadUint8(data, offset); + offset += uint8_t_size; + m_SwTraceHeader.m_ThreadIdBytes = ReadUint8(data, offset); + offset += uint8_t_size; + uint32_t numberOfDeclarations = profiling::ReadUint32(data, offset); offset += uint32_t_size; - for (uint32_t declaration = 0; declaration < numberOfDeclarations; ++declaration) + for (uint32_t declaration = 0; declaration < numberOfDeclarations; ++declaration) { m_SwTraceMessages.push_back(profiling::ReadSwTraceMessage(data, offset)); } @@ -54,21 +65,21 @@ void TimelineDirectoryCaptureCommandHandler::Print() std::cout << "\n"; std::cout << std::string(header.size(), '=') << "\n"; - std::cout<< header; + std::cout << header; - for (auto swTraceMessage : m_SwTraceMessages) + for (const auto& swTraceMessage : m_SwTraceMessages) { std::string body; - body.append(profiling::CentreAlignFormatting(std::to_string(swTraceMessage.id), 12)); + body.append(profiling::CentreAlignFormatting(std::to_string(swTraceMessage.m_Id), 12)); body.append(" | "); - body.append(profiling::CentreAlignFormatting(swTraceMessage.name, 20)); + body.append(profiling::CentreAlignFormatting(swTraceMessage.m_Name, 20)); body.append(" | "); - body.append(profiling::CentreAlignFormatting(swTraceMessage.uiName, 20)); + body.append(profiling::CentreAlignFormatting(swTraceMessage.m_UiName, 20)); body.append(" | "); std::string argTypes; - for(auto argType: swTraceMessage.argTypes) + for (auto argType: swTraceMessage.m_ArgTypes) { argTypes += argType; argTypes += " "; @@ -77,7 +88,7 @@ void TimelineDirectoryCaptureCommandHandler::Print() body.append(" | "); std::string argNames; - for(auto argName: swTraceMessage.argNames) + for (auto argName: swTraceMessage.m_ArgNames) { argNames += argName + " "; } @@ -87,7 +98,7 @@ void TimelineDirectoryCaptureCommandHandler::Print() std::cout << std::string(body.size(), '-') << "\n"; - std::cout<< body; + std::cout << body; } } @@ -95,7 +106,7 @@ void TimelineDirectoryCaptureCommandHandler::operator()(const profiling::Packet& { ParseData(packet); - if(!m_QuietOperation) + if (!m_QuietOperation) { Print(); } @@ -103,4 +114,4 @@ void TimelineDirectoryCaptureCommandHandler::operator()(const profiling::Packet& } //namespace gatordmock -} //namespace armnn \ No newline at end of file +} //namespace armnn diff --git a/tests/profiling/timelineDecoder/TimelineDirectoryCaptureCommandHandler.hpp b/tests/profiling/timelineDecoder/TimelineDirectoryCaptureCommandHandler.hpp index 3a575d7fef..36a82b5510 100644 --- a/tests/profiling/timelineDecoder/TimelineDirectoryCaptureCommandHandler.hpp +++ b/tests/profiling/timelineDecoder/TimelineDirectoryCaptureCommandHandler.hpp @@ -20,6 +20,7 @@ namespace gatordmock class TimelineDirectoryCaptureCommandHandler : public profiling::CommandHandlerFunctor { // Utils + uint32_t uint8_t_size = sizeof(uint8_t); uint32_t uint32_t_size = sizeof(uint32_t); public: @@ -27,12 +28,13 @@ public: uint32_t packetId, uint32_t version, bool quietOperation = false) - : CommandHandlerFunctor(familyId, packetId, version) - , m_QuietOperation(quietOperation) + : CommandHandlerFunctor(familyId, packetId, version) + , m_QuietOperation(quietOperation) {} void operator()(const armnn::profiling::Packet& packet) override; + profiling::SwTraceHeader m_SwTraceHeader; std::vector m_SwTraceMessages; private: @@ -44,4 +46,4 @@ private: } //namespace gatordmock -} //namespace armnn \ No newline at end of file +} //namespace armnn diff --git a/tests/profiling/timelineDecoder/tests/TimelineTests.cpp b/tests/profiling/timelineDecoder/tests/TimelineTests.cpp index a9c352b5fa..8106e6a996 100644 --- a/tests/profiling/timelineDecoder/tests/TimelineTests.cpp +++ b/tests/profiling/timelineDecoder/tests/TimelineTests.cpp @@ -35,18 +35,22 @@ void SendTimelinePacketToCommandHandler(const unsigned char* packetBuffer, uint32_t PacketDataLength = header[1] & 0x00FFFFFF; - std::unique_ptr uniquePacketData = std::make_unique(PacketDataLength); - + auto uniquePacketData = std::make_unique(PacketDataLength); std::memcpy(uniquePacketData.get(), packetBuffer + offset, PacketDataLength); - armnn::profiling::Packet packet = armnn::profiling::Packet(header[0], PacketDataLength, uniquePacketData); + armnn::profiling::Packet packet(header[0], PacketDataLength, uniquePacketData); + + BOOST_CHECK(std::memcmp(packetBuffer + offset, packet.GetData(), packet.GetLength()) == 0); CommandHandler(packet); } -BOOST_AUTO_TEST_CASE(TimelineDirecotryTest) +BOOST_AUTO_TEST_CASE(TimelineDirectoryTest) { + uint32_t uint8_t_size = sizeof(uint8_t); uint32_t uint32_t_size = sizeof(uint32_t); + uint32_t uint64_t_size = sizeof(uint64_t); + uint32_t threadId_size = sizeof(std::thread::id); profiling::BufferManager bufferManager(5); profiling::TimelinePacketWriterFactory timelinePacketWriterFactory(bufferManager); @@ -68,6 +72,16 @@ BOOST_AUTO_TEST_CASE(TimelineDirecotryTest) std::unique_ptr packetBuffer = bufferManager.GetReadableBuffer(); + uint8_t readStreamVersion = ReadUint8(packetBuffer, offset); + BOOST_CHECK(readStreamVersion == 4); + offset += uint8_t_size; + uint8_t readPointerBytes = ReadUint8(packetBuffer, offset); + BOOST_CHECK(readPointerBytes == uint64_t_size); + offset += uint8_t_size; + uint8_t readThreadIdBytes = ReadUint8(packetBuffer, offset); + BOOST_CHECK(readThreadIdBytes == threadId_size); + offset += uint8_t_size; + uint32_t declarationSize = profiling::ReadUint32(packetBuffer, offset); offset += uint32_t_size; for(uint32_t i = 0; i < declarationSize; ++i) @@ -82,20 +96,20 @@ BOOST_AUTO_TEST_CASE(TimelineDirecotryTest) profiling::SwTraceMessage& bufferMessage = swTraceBufferMessages[index]; profiling::SwTraceMessage& handlerMessage = timelineDirectoryCaptureCommandHandler.m_SwTraceMessages[index]; - BOOST_CHECK(bufferMessage.name == handlerMessage.name); - BOOST_CHECK(bufferMessage.uiName == handlerMessage.uiName); - BOOST_CHECK(bufferMessage.id == handlerMessage.id); + BOOST_CHECK(bufferMessage.m_Name == handlerMessage.m_Name); + BOOST_CHECK(bufferMessage.m_UiName == handlerMessage.m_UiName); + BOOST_CHECK(bufferMessage.m_Id == handlerMessage.m_Id); - BOOST_CHECK(bufferMessage.argTypes.size() == handlerMessage.argTypes.size()); - for(uint32_t i = 0; i < bufferMessage.argTypes.size(); ++i) + BOOST_CHECK(bufferMessage.m_ArgTypes.size() == handlerMessage.m_ArgTypes.size()); + for(uint32_t i = 0; i < bufferMessage.m_ArgTypes.size(); ++i) { - BOOST_CHECK(bufferMessage.argTypes[i] == handlerMessage.argTypes[i]); + BOOST_CHECK(bufferMessage.m_ArgTypes[i] == handlerMessage.m_ArgTypes[i]); } - BOOST_CHECK(bufferMessage.argNames.size() == handlerMessage.argNames.size()); - for(uint32_t i = 0; i < bufferMessage.argNames.size(); ++i) + BOOST_CHECK(bufferMessage.m_ArgNames.size() == handlerMessage.m_ArgNames.size()); + for(uint32_t i = 0; i < bufferMessage.m_ArgNames.size(); ++i) { - BOOST_CHECK(bufferMessage.argNames[i] == handlerMessage.argNames[i]); + BOOST_CHECK(bufferMessage.m_ArgNames[i] == handlerMessage.m_ArgNames[i]); } } } -- cgit v1.2.1