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);
buffer[offset + 1] = static_cast<unsigned char>((value >> 8) & 0xFF);
}
+void WriteUint8(unsigned char* buffer, unsigned int offset, uint8_t value)
+{
+ BOOST_ASSERT(buffer);
+
+ buffer[offset] = static_cast<unsigned char>(value);
+}
+
void ReadBytes(const IPacketBufferPtr& packetBuffer, unsigned int offset, unsigned int valueSize, uint8_t outValue[])
{
BOOST_ASSERT(packetBuffer);
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<uint32_t, uint32_t> 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.
// 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
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;
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;
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());
std::string argName;
while (std::getline(stringStream, argName, ','))
{
- swTraceMessage.argNames.push_back(argName);
+ swTraceMessage.m_ArgNames.push_back(argName);
}
offset += CalculateSizeOfPaddedSwString(swTraceString);
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<uint32_t, uint32_t> 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
}
// 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 |
// | 3 | declareRelationship | declare relationship | Ippp | relationshipType,relationshipGuid, |
// | | | | | headGuid,tailGuid |
// | 4 | declareEvent | declare event | @tp | timestamp,threadId,eventGuid |
-
std::vector<std::vector<std::string>> 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<std::vector<std::vector<uint32_t>>> swTraceTimelineDirectoryMessages;
-
- for (const auto& timelineDirectoryMessage : timelineDirectoryMessages)
+ // Build the message declarations
+ std::vector<uint32_t> swTraceBuffer;
+ for (const auto& directoryComponent : timelineDirectoryMessages)
{
- messagesDataLength += uint32_t_size; // decl_id
-
- std::vector<std::vector<uint32_t>> swTraceStringsVector;
- for (const auto& label : timelineDirectoryMessage)
+ // decl_id
+ uint32_t declId = 0;
+ try
+ {
+ declId = boost::numeric_cast<uint32_t>(std::stoul(directoryComponent[0]));
+ }
+ catch (const std::exception&)
{
- std::vector<uint32_t> swTraceString;
- bool result = StringToSwTraceString<SwTraceCharPolicy>(label, swTraceString);
- if (!result)
- {
- return TimelinePacketStatus::Error;
- }
-
- messagesDataLength += boost::numeric_cast<unsigned int>(swTraceString.size()) * uint32_t_size;
- swTraceStringsVector.push_back(swTraceString);
+ return TimelinePacketStatus::Error;
+ }
+ swTraceBuffer.push_back(declId);
+
+ bool result = true;
+ result &= ConvertDirectoryComponent<SwTraceNameCharPolicy>(directoryComponent[1], swTraceBuffer); // decl_name
+ result &= ConvertDirectoryComponent<SwTraceCharPolicy> (directoryComponent[2], swTraceBuffer); // ui_name
+ result &= ConvertDirectoryComponent<SwTraceTypeCharPolicy>(directoryComponent[3], swTraceBuffer); // arg_types
+ result &= ConvertDirectoryComponent<SwTraceCharPolicy> (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<unsigned int>(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)
}
// Create packet header
- uint32_t dataLength = boost::numeric_cast<uint32_t>(messagesDataLength);
- std::pair<uint32_t, uint32_t> packetHeader = CreateTimelinePacketHeader(1, 0, 0, 0, 0, dataLength);
+ auto packetHeader = CreateTimelinePacketHeader(1, 0, 0, 0, 0, boost::numeric_cast<uint32_t>(dataLength));
// Initialize the offset for writing in the buffer
unsigned int offset = 0;
WriteUint32(buffer, offset, packetHeader.second);
offset += uint32_t_size;
- WriteUint32(buffer, offset, static_cast<uint32_t >(swTraceTimelineDirectoryMessages.size()));
+ // Write the stream header
+ uint8_t streamVersion = 4;
+ uint8_t pointerBytes = boost::numeric_cast<uint8_t>(uint64_t_size); // All GUIDs are uint64_t
+ uint8_t threadIdBytes = boost::numeric_cast<uint8_t>(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<uint32_t>(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<uint32_t> swTraceString : swTraceTimelineDirectoryMessages[i])
- {
- for (uint32_t swTraceDeclStringWord : swTraceString)
- {
- WriteUint32(buffer, offset, swTraceDeclStringWord);
- offset += uint32_t_size;
- }
- }
}
// Update the number of bytes written
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<char> argTypes;
- std::vector<std::string> argNames;
+ uint32_t m_Id;
+ std::string m_Name;
+ std::string m_UiName;
+ std::vector<char> m_ArgTypes;
+ std::vector<std::string> m_ArgNames;
};
struct SwTraceCharPolicy
}
};
+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 <typename SwTracePolicy>
bool IsValidSwTraceString(const std::string& s)
{
return true;
}
+template <typename SwTracePolicy,
+ typename SwTraceBuffer = std::vector<uint32_t>>
+bool ConvertDirectoryComponent(const std::string& directoryComponent, SwTraceBuffer& swTraceBuffer)
+{
+ // Convert the directory component using the given policy
+ SwTraceBuffer tempSwTraceBuffer;
+ bool result = StringToSwTraceString<SwTracePolicy>(directoryComponent, tempSwTraceBuffer);
+ if (!result)
+ {
+ return false;
+ }
+
+ swTraceBuffer.insert(swTraceBuffer.end(), tempSwTraceBuffer.begin(), tempSwTraceBuffer.end());
+
+ return true;
+}
+
uint16_t GetNextUid(bool peekOnly = false);
std::vector<uint16_t> GetNextCounterUids(uint16_t cores);
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);
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);
// 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);
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)
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;
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);
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
#include "TimelineDirectoryCaptureCommandHandler.hpp"
+#include <ProfilingUtils.hpp>
+
#include <iostream>
#include <string>
+using namespace armnn::profiling;
+
namespace armnn
{
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));
}
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 += " ";
body.append(" | ");
std::string argNames;
- for(auto argName: swTraceMessage.argNames)
+ for (auto argName: swTraceMessage.m_ArgNames)
{
argNames += argName + " ";
}
std::cout << std::string(body.size(), '-') << "\n";
- std::cout<< body;
+ std::cout << body;
}
}
{
ParseData(packet);
- if(!m_QuietOperation)
+ if (!m_QuietOperation)
{
Print();
}
} //namespace gatordmock
-} //namespace armnn
\ No newline at end of file
+} //namespace armnn
class TimelineDirectoryCaptureCommandHandler : public profiling::CommandHandlerFunctor
{
// Utils
+ uint32_t uint8_t_size = sizeof(uint8_t);
uint32_t uint32_t_size = sizeof(uint32_t);
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<profiling::SwTraceMessage> m_SwTraceMessages;
private:
} //namespace gatordmock
-} //namespace armnn
\ No newline at end of file
+} //namespace armnn
uint32_t PacketDataLength = header[1] & 0x00FFFFFF;
- std::unique_ptr<unsigned char[]> uniquePacketData = std::make_unique<unsigned char[]>(PacketDataLength);
-
+ auto uniquePacketData = std::make_unique<unsigned char[]>(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);
std::unique_ptr<profiling::IPacketBuffer> 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)
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]);
}
}
}