aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFinn Williams <Finn.Williams@arm.com>2020-05-01 13:25:55 +0100
committerfinn.williams <finn.williams@arm.com>2020-05-01 13:30:58 +0000
commitd44815fc0c8426364f3199bdf38da3fe2c5157dc (patch)
treed2a77f546269890b3ce4af60abfed6c662fae26e
parentb56cede253b705367e1ad35735568eb9a30a8470 (diff)
downloadarmnn-d44815fc0c8426364f3199bdf38da3fe2c5157dc.tar.gz
Update the CounterDirectory Packet offsets to be relative to the start of the table containing that offset
* IVGCVSW-4763 Update the event pointer table offsets * IVGCVSW-4764 Update the event record block offsets * IVGCVSW-4765 Update the device name offset * IVGCVSW-4766 Update the counter set name offset * IVGCVSW-4767 Update device pointer table offsets * IVGCVSW-4768 Update the counter set pointer table offsets * IVGCVSW-4769 Update the category pointer table offsets Signed-off-by: Finn Williams <Finn.Williams@arm.com> Change-Id: I6e815ae5b16478fc5ec760caf704451fe5f84a29
-rw-r--r--src/profiling/DirectoryCaptureCommandHandler.cpp38
-rw-r--r--src/profiling/SendCounterPacket.cpp146
-rw-r--r--src/profiling/test/ProfilingTests.cpp6
-rw-r--r--src/profiling/test/SendCounterPacketTests.cpp285
4 files changed, 253 insertions, 222 deletions
diff --git a/src/profiling/DirectoryCaptureCommandHandler.cpp b/src/profiling/DirectoryCaptureCommandHandler.cpp
index 93cdde736e..23221fb74e 100644
--- a/src/profiling/DirectoryCaptureCommandHandler.cpp
+++ b/src/profiling/DirectoryCaptureCommandHandler.cpp
@@ -45,6 +45,7 @@ void DirectoryCaptureCommandHandler::ParseData(const armnn::profiling::Packet& p
// Body header word 1:
// 0:31 [32] device_records_pointer_table_offset: offset to the device_records_pointer_table
// The offset is always zero here, as the device record pointer table field is always the first item in the pool
+ const uint32_t deviceRecordsPointerTableOffset = profiling::ReadUint32(data, offset);
offset += uint32_t_size;
// Body header word 2:
@@ -56,7 +57,7 @@ void DirectoryCaptureCommandHandler::ParseData(const armnn::profiling::Packet& p
// Body header word 3:
// 0:31 [32] counter_set_pointer_table_offset: offset to the counter_set_pointer_table
- // counterPointerTableSetOffset = profiling::ReadUint32(data, offset);
+ const uint32_t counterPointerTableSetOffset = profiling::ReadUint32(data, offset);
offset += uint32_t_size;
// Body header word 4:
@@ -68,31 +69,35 @@ void DirectoryCaptureCommandHandler::ParseData(const armnn::profiling::Packet& p
// Body header word 5:
// 0:31 [32] categories_pointer_table_offset: offset to the categories_pointer_table
- // categoriesPointerTableOffset = profiling::ReadUint32(data, offset);
+ const uint32_t categoriesPointerTableOffset = profiling::ReadUint32(data, offset);
offset += uint32_t_size;
std::vector<uint32_t> deviceRecordOffsets(deviceRecordCount);
std::vector<uint32_t> counterSetOffsets(counterSetRecordCount);
std::vector<uint32_t> categoryOffsets(categoryRecordCount);
+ offset = deviceRecordsPointerTableOffset;
for (uint32_t i = 0; i < deviceRecordCount; ++i)
{
deviceRecordOffsets[i] = profiling::ReadUint32(data, offset);
offset += uint32_t_size;
}
+ offset = counterPointerTableSetOffset;
for (uint32_t i = 0; i < counterSetRecordCount; ++i)
{
counterSetOffsets[i] = profiling::ReadUint32(data, offset);
offset += uint32_t_size;
}
+ offset = categoriesPointerTableOffset;
for (uint32_t i = 0; i < categoryRecordCount; ++i)
{
categoryOffsets[i] = profiling::ReadUint32(data, offset);
offset += uint32_t_size;
}
+ offset = deviceRecordsPointerTableOffset;
for (uint32_t deviceIndex = 0; deviceIndex < deviceRecordCount; ++deviceIndex)
{
uint32_t deviceRecordOffset = offset + deviceRecordOffsets[deviceIndex];
@@ -108,15 +113,14 @@ void DirectoryCaptureCommandHandler::ParseData(const armnn::profiling::Packet& p
// Offset from the beginning of the device record pool to the name field.
uint32_t nameOffset = profiling::ReadUint32(data, deviceRecordOffset);
- deviceRecordOffset += uint32_t_size;
- deviceRecordOffset += uint32_t_size;
- deviceRecordOffset += nameOffset;
+ deviceRecordOffset = deviceRecordsPointerTableOffset + nameOffset;
const std::string& deviceName = GetStringNameFromBuffer(data, deviceRecordOffset);
const Device* registeredDevice = m_CounterDirectory.RegisterDevice(deviceName, deviceCores);
m_UidTranslation[registeredDevice->m_Uid] = deviceUid;
}
+ offset = counterPointerTableSetOffset;
for (uint32_t counterSetIndex = 0; counterSetIndex < counterSetRecordCount; ++counterSetIndex)
{
uint32_t counterSetOffset = offset + counterSetOffsets[counterSetIndex];
@@ -140,7 +144,7 @@ void DirectoryCaptureCommandHandler::ParseData(const armnn::profiling::Packet& p
m_CounterDirectory.RegisterCounterSet(GetStringNameFromBuffer(data, counterSetOffset), counterSetCount);
m_UidTranslation[counterSet->m_Uid] = counterSetUid;
}
- ReadCategoryRecords(data, offset, categoryOffsets);
+ ReadCategoryRecords(data, categoriesPointerTableOffset, categoryOffsets);
}
void DirectoryCaptureCommandHandler::ReadCategoryRecords(const unsigned char* const data,
@@ -172,7 +176,7 @@ void DirectoryCaptureCommandHandler::ReadCategoryRecords(const unsigned char* co
std::vector<uint32_t> eventRecordsOffsets(eventCount);
- eventPointerTableOffset += categoryRecordOffset;
+ eventPointerTableOffset += offset + categoryOffsets[categoryIndex];
for (uint32_t eventIndex = 0; eventIndex < eventCount; ++eventIndex)
{
@@ -181,11 +185,10 @@ void DirectoryCaptureCommandHandler::ReadCategoryRecords(const unsigned char* co
}
const std::vector<CounterDirectoryEventRecord>& eventRecords =
- ReadEventRecords(data, categoryRecordOffset, eventRecordsOffsets);
- categoryRecordOffset += uint32_t_size;
+ ReadEventRecords(data, eventPointerTableOffset, eventRecordsOffsets);
const Category* category = m_CounterDirectory.RegisterCategory(
- GetStringNameFromBuffer(data, categoryRecordOffset + nameOffset));
+ GetStringNameFromBuffer(data, offset + categoryOffsets[categoryIndex] + nameOffset + uint32_t_size));
for (auto& counter : eventRecords)
{
const Counter* registeredCounter = m_CounterDirectory.RegisterCounter(armnn::profiling::BACKEND_ID,
@@ -260,6 +263,7 @@ std::vector<CounterDirectoryEventRecord> DirectoryCaptureCommandHandler::ReadEve
// 0:31 [32] name_eventRecordOffset: eventRecordOffset from the
// beginning of the event record pool to the name field
// The eventRecordOffset is always zero here, as the name field is always the first item in the pool
+ uint32_t nameOffset = profiling::ReadUint32(data, eventRecordOffset);
eventRecordOffset += uint32_t_size;
// Event record word 6:
@@ -274,15 +278,19 @@ std::vector<CounterDirectoryEventRecord> DirectoryCaptureCommandHandler::ReadEve
// beginning of the event record pool to the units field.
// An eventRecordOffset value of zero indicates this field is not provided
uint32_t unitsOffset = profiling::ReadUint32(data, eventRecordOffset);
- eventRecordOffset += uint32_t_size;
- eventRecordOffset += uint32_t_size;
- eventRecords[i].m_CounterName = GetStringNameFromBuffer(data, eventRecordOffset);
+ eventRecords[i].m_CounterName = GetStringNameFromBuffer(data, offset +
+ eventRecordsOffsets[i] +
+ nameOffset +
+ uint32_t_size);
- eventRecords[i].m_CounterDescription = GetStringNameFromBuffer(data, eventRecordOffset + descriptionOffset);
+ eventRecords[i].m_CounterDescription = GetStringNameFromBuffer(data, offset +
+ eventRecordsOffsets[i] +
+ descriptionOffset +
+ uint32_t_size);
eventRecords[i].m_CounterUnits = unitsOffset == 0 ? Optional<std::string>() :
- GetStringNameFromBuffer(data, eventRecordOffset + unitsOffset);
+ GetStringNameFromBuffer(data, eventRecordsOffsets[i] + offset + unitsOffset + uint32_t_size);
}
return eventRecords;
diff --git a/src/profiling/SendCounterPacket.cpp b/src/profiling/SendCounterPacket.cpp
index 00fddb6801..f251684f7b 100644
--- a/src/profiling/SendCounterPacket.cpp
+++ b/src/profiling/SendCounterPacket.cpp
@@ -28,21 +28,21 @@ const unsigned int SendCounterPacket::PIPE_MAGIC;
void SendCounterPacket::SendStreamMetaDataPacket()
{
- std::string info(GetSoftwareInfo());
- std::string hardwareVersion(GetHardwareVersion());
- std::string softwareVersion(GetSoftwareVersion());
- std::string processName = GetProcessName().substr(0, 60);
+ const std::string info(GetSoftwareInfo());
+ const std::string hardwareVersion(GetHardwareVersion());
+ const std::string softwareVersion(GetSoftwareVersion());
+ const std::string processName = GetProcessName().substr(0, 60);
- uint32_t infoSize = numeric_cast<uint32_t>(info.size()) + 1;
- uint32_t hardwareVersionSize = numeric_cast<uint32_t>(hardwareVersion.size()) + 1;
- uint32_t softwareVersionSize = numeric_cast<uint32_t>(softwareVersion.size()) + 1;
- uint32_t processNameSize = numeric_cast<uint32_t>(processName.size()) + 1;
+ const uint32_t infoSize = numeric_cast<uint32_t>(info.size()) + 1;
+ const uint32_t hardwareVersionSize = numeric_cast<uint32_t>(hardwareVersion.size()) + 1;
+ const uint32_t softwareVersionSize = numeric_cast<uint32_t>(softwareVersion.size()) + 1;
+ const uint32_t processNameSize = numeric_cast<uint32_t>(processName.size()) + 1;
- uint32_t sizeUint32 = sizeof(uint32_t);
+ const uint32_t sizeUint32 = sizeof(uint32_t);
- uint32_t headerSize = 2 * sizeUint32;
- uint32_t bodySize = 10 * sizeUint32;
- uint32_t packetVersionCountSize = sizeUint32;
+ const uint32_t headerSize = 2 * sizeUint32;
+ const uint32_t bodySize = 10 * sizeUint32;
+ const uint32_t packetVersionCountSize = sizeUint32;
// Supported Packets
// Stream metadata packet (packet family=0; packet id=0)
@@ -51,13 +51,13 @@ void SendCounterPacket::SendStreamMetaDataPacket()
// Request Counter Directory packet (packet family=0, packet id=3)
// Periodic Counter Selection packet (packet family=0, packet id=4)
// Periodic Counter Capture packet (packet family=1, packet class=0, type=0)
- uint32_t packetVersionEntries = 6;
+ const uint32_t packetVersionEntries = 6;
- uint32_t payloadSize = numeric_cast<uint32_t>(infoSize + hardwareVersionSize + softwareVersionSize +
+ const uint32_t payloadSize = numeric_cast<uint32_t>(infoSize + hardwareVersionSize + softwareVersionSize +
processNameSize + packetVersionCountSize +
(packetVersionEntries * 2 * sizeUint32));
- uint32_t totalSize = headerSize + bodySize + payloadSize;
+ const uint32_t totalSize = headerSize + bodySize + payloadSize;
uint32_t offset = 0;
uint32_t reserved = 0;
@@ -196,18 +196,7 @@ bool SendCounterPacket::CreateCategoryRecord(const CategoryPtr& category,
}
// Utils
- size_t uint32_t_size = sizeof(uint32_t);
-
- // Category record word 1:
- // 16:31 [16] event_count: number of events belonging to this category
- // 0:15 [16] reserved: all zeros
- uint32_t categoryRecordWord1 = static_cast<uint32_t>(categoryCounters.size()) << 16;
-
- // Category record word 2:
- // 0:31 [32] event_pointer_table_offset: offset from the beginning of the category data pool to
- // the event_pointer_table
- uint32_t categoryRecordWord2 = 0; // The offset is always zero here, as the event pointer table field is always
- // the first item in the pool
+ const size_t uint32_t_size = sizeof(uint32_t);
// Convert the device name into a SWTrace namestring
std::vector<uint32_t> categoryNameBuffer;
@@ -218,8 +207,18 @@ bool SendCounterPacket::CreateCategoryRecord(const CategoryPtr& category,
return false;
}
+ // Category record word 1:
+ // 16:31 [16] event_count: number of events belonging to this category
+ // 0:15 [16] reserved: all zeros
+ const uint32_t categoryRecordWord1 = static_cast<uint32_t>(categoryCounters.size()) << 16;
+
+ // Category record word 2:
+ // 0:31 [32] event_pointer_table_offset: offset from the beginning of the category data pool to
+ // the event_pointer_table
+ const uint32_t categoryRecordWord2 = static_cast<uint32_t>(3u * uint32_t_size);
+
// Process the event records
- size_t counterCount = categoryCounters.size();
+ const size_t counterCount = categoryCounters.size();
std::vector<EventRecord> eventRecords(counterCount);
std::vector<uint32_t> eventRecordOffsets(counterCount, 0);
size_t eventRecordsSize = 0;
@@ -249,14 +248,14 @@ bool SendCounterPacket::CreateCategoryRecord(const CategoryPtr& category,
// Category record word 3:
// 0:31 [32] name_offset (offset from the beginning of the category data pool to the name field)
- uint32_t categoryRecordWord3 = numeric_cast<uint32_t>(eventRecordOffsets.size() * uint32_t_size);
+ const uint32_t categoryRecordWord3 = numeric_cast<uint32_t>((3u + eventRecordOffsets.size()) * uint32_t_size);
// Calculate the size in words of the category record
- size_t categoryRecordSize = 3u + // The size of the fixed part (device + counter_set + event_count + reserved +
- // event_pointer_table_offset + name_offset)
- eventRecordOffsets.size() + // The size of the variable part (the event pointer table +
- categoryNameBuffer.size() + // and the category name including the null-terminator +
- eventRecordsSize; // the event records)
+ const size_t categoryRecordSize = 3u +// The size of the fixed part (device + counter_set + event_count +
+ // reserved + event_pointer_table_offset + name_offset)
+ eventRecordOffsets.size() + // The size of the variable part (
+ categoryNameBuffer.size() + // the event pointer table + the category name
+ eventRecordsSize; // including the null-terminator + the event records)
// Allocate the necessary space for the category record
categoryRecord.resize(categoryRecordSize);
@@ -296,13 +295,13 @@ bool SendCounterPacket::CreateDeviceRecord(const DevicePtr& device,
// Device record word 0:
// 16:31 [16] uid: the unique identifier for the device
// 0:15 [16] cores: the number of individual streams of counters for one or more cores of some device
- uint32_t deviceRecordWord0 = (static_cast<uint32_t>(deviceUid) << 16) |
+ const uint32_t deviceRecordWord0 = (static_cast<uint32_t>(deviceUid) << 16) |
(static_cast<uint32_t>(deviceCores));
// Device record word 1:
// 0:31 [32] name_offset: offset from the beginning of the device record pool to the name field
- uint32_t deviceRecordWord1 = 0; // The offset is always zero here, as the name field is always
- // the first (and only) item in the pool
+ const uint32_t deviceRecordWord1 = 2u; // The offset is always two here, as the name field is always
+ // the first (and only) item in the pool and there are two device words
// Convert the device name into a SWTrace string
std::vector<uint32_t> deviceNameBuffer;
@@ -315,7 +314,7 @@ bool SendCounterPacket::CreateDeviceRecord(const DevicePtr& device,
}
// Calculate the size in words of the device record
- size_t deviceRecordSize = 2u + // The size of the fixed part (uid + cores + name_offset)
+ const size_t deviceRecordSize = 2u + // The size of the fixed part (uid + cores + name_offset)
deviceNameBuffer.size(); // The size of the variable part (the device name including
// the null-terminator)
@@ -346,13 +345,13 @@ bool SendCounterPacket::CreateCounterSetRecord(const CounterSetPtr& counterSet,
// Counter set record word 0:
// 16:31 [16] uid: the unique identifier for the counter_set
// 0:15 [16] count: the number of counters which can be active in this set at any one time
- uint32_t counterSetRecordWord0 = (static_cast<uint32_t>(counterSetUid) << 16) |
- (static_cast<uint32_t>(counterSetCount));
+ const uint32_t counterSetRecordWord0 = (static_cast<uint32_t>(counterSetUid) << 16) |
+ (static_cast<uint32_t>(counterSetCount));
// Counter set record word 1:
// 0:31 [32] name_offset: offset from the beginning of the counter set pool to the name field
- uint32_t counterSetRecordWord1 = 0; // The offset is always zero here, as the name field is always
- // the first (and only) item in the pool
+ const uint32_t counterSetRecordWord1 = 2u; // The offset is always two here, as the name field is always
+ // the first (and only) item in the pool after the two counter set words
// Convert the device name into a SWTrace namestring
std::vector<uint32_t> counterSetNameBuffer;
@@ -366,9 +365,9 @@ bool SendCounterPacket::CreateCounterSetRecord(const CounterSetPtr& counterSet,
}
// Calculate the size in words of the counter set record
- size_t counterSetRecordSize = 2u + // The size of the fixed part (uid + cores + name_offset)
- counterSetNameBuffer.size(); // The size of the variable part (the counter set name
- // including the null-terminator)
+ const size_t counterSetRecordSize = 2u + // The size of the fixed part (uid + cores + name_offset)
+ counterSetNameBuffer.size(); // The size of the variable part (the counter set
+ // name including the null-terminator)
// Allocate the space for the counter set record
counterSetRecord.resize(counterSetRecordSize);
@@ -406,7 +405,13 @@ bool SendCounterPacket::CreateEventRecord(const CounterPtr& counter,
ARMNN_ASSERT(counterMultiplier);
// Utils
- size_t uint32_t_size = sizeof(uint32_t);
+ const size_t uint32_t_size = sizeof(uint32_t);
+ // eventRecordBlockSize is the size of the fixed part
+ // (counter_uid + max_counter_uid + device +
+ // counter_set + class + interpolation +
+ // multiplier + name_offset + description_offset +
+ // units_offset)
+ const size_t eventRecordBlockSize = 8u;
// Event record word 0:
// 16:31 [16] max_counter_uid: if the device this event is associated with has more than one core and there
@@ -415,22 +420,22 @@ bool SendCounterPacket::CreateEventRecord(const CounterPtr& counter,
// If there is only a single core then this value will be the same as
// the counter_uid value
// 0:15 [16] count_uid: unique ID for the counter. Must be unique across all counters in all categories
- uint32_t eventRecordWord0 = (static_cast<uint32_t>(maxCounterUid) << 16) |
- (static_cast<uint32_t>(counterUid));
+ const uint32_t eventRecordWord0 = (static_cast<uint32_t>(maxCounterUid) << 16) |
+ (static_cast<uint32_t>(counterUid));
// Event record word 1:
// 16:31 [16] device: UID of the device this event is associated with. Set to zero if the event is NOT
// associated with a device
// 0:15 [16] counter_set: UID of the counter_set this event is associated with. Set to zero if the event
// is NOT associated with a counter_set
- uint32_t eventRecordWord1 = (static_cast<uint32_t>(deviceUid) << 16) |
- (static_cast<uint32_t>(counterSetUid));
+ const uint32_t eventRecordWord1 = (static_cast<uint32_t>(deviceUid) << 16) |
+ (static_cast<uint32_t>(counterSetUid));
// Event record word 2:
// 16:31 [16] class: type describing how to treat each data point in a stream of data points
// 0:15 [16] interpolation: type describing how to interpolate each data point in a stream of data points
- uint32_t eventRecordWord2 = (static_cast<uint32_t>(counterClass) << 16) |
- (static_cast<uint32_t>(counterInterpolation));
+ const uint32_t eventRecordWord2 = (static_cast<uint32_t>(counterClass) << 16) |
+ (static_cast<uint32_t>(counterInterpolation));
// Event record word 3-4:
// 0:63 [64] multiplier: internal data stream is represented as integer values, this allows scaling of
@@ -438,13 +443,12 @@ bool SendCounterPacket::CreateEventRecord(const CounterPtr& counter,
uint32_t multiplier[2] = { 0u, 0u };
ARMNN_ASSERT(sizeof(counterMultiplier) == sizeof(multiplier));
std::memcpy(multiplier, &counterMultiplier, sizeof(multiplier));
- uint32_t eventRecordWord3 = multiplier[0];
- uint32_t eventRecordWord4 = multiplier[1];
+ const uint32_t eventRecordWord3 = multiplier[0];
+ const uint32_t eventRecordWord4 = multiplier[1];
// Event record word 5:
// 0:31 [32] name_offset: offset from the beginning of the event record pool to the name field
- uint32_t eventRecordWord5 = 0; // The offset is always zero here, as the name field is always
- // the first item in the pool
+ const uint32_t eventRecordWord5 = static_cast<uint32_t>(eventRecordBlockSize * uint32_t_size);
// Convert the counter name into a SWTrace string
std::vector<uint32_t> counterNameBuffer;
@@ -460,7 +464,8 @@ bool SendCounterPacket::CreateEventRecord(const CounterPtr& counter,
// Event record word 6:
// 0:31 [32] description_offset: offset from the beginning of the event record pool to the description field
// The size of the name buffer in bytes
- uint32_t eventRecordWord6 = numeric_cast<uint32_t>(counterNameBuffer.size() * uint32_t_size);
+ uint32_t eventRecordWord6 =
+ static_cast<uint32_t>((counterNameBuffer.size() + eventRecordBlockSize) * uint32_t_size);
// Convert the counter description into a SWTrace string
std::vector<uint32_t> counterDescriptionBuffer;
@@ -478,9 +483,10 @@ bool SendCounterPacket::CreateEventRecord(const CounterPtr& counter,
// An offset value of zero indicates this field is not provided
bool includeUnits = !counterUnits.empty();
// The size of the description buffer in bytes
- uint32_t eventRecordWord7 = includeUnits ?
+ const uint32_t eventRecordWord7 = includeUnits ?
eventRecordWord6 +
- numeric_cast<uint32_t>(counterDescriptionBuffer.size() * uint32_t_size) :
+ numeric_cast<uint32_t>(counterDescriptionBuffer.size()
+ * uint32_t_size) :
0;
// Convert the counter units into a SWTrace namestring (optional)
@@ -499,13 +505,10 @@ bool SendCounterPacket::CreateEventRecord(const CounterPtr& counter,
}
// Calculate the size in words of the event record
- size_t eventRecordSize = 8u + // The size of the fixed part (counter_uid + max_counter_uid + device +
- // counter_set + class + interpolation +
- // multiplier + name_offset + description_offset +
- // units_offset)
- counterNameBuffer.size() + // The size of the variable part (the counter name,
- counterDescriptionBuffer.size() + // description and units including the null-terminator)
- counterUnitsBuffer.size();
+ const size_t eventRecordSize = eventRecordBlockSize +
+ counterNameBuffer.size() + // The size of the variable part (the counter name,
+ counterDescriptionBuffer.size() + // description and units
+ counterUnitsBuffer.size(); // including the null-terminator)
// Allocate the space for the event record
eventRecord.resize(eventRecordSize);
@@ -563,6 +566,10 @@ void SendCounterPacket::SendCounterDirectoryPacket(const ICounterDirectory& coun
size_t deviceRecordsSize = 0;
size_t deviceIndex = 0;
size_t deviceRecordOffsetIndex = 0;
+
+ pointerTableOffset = numeric_cast<uint32_t>(deviceCount * uint32_t_size +
+ counterSetCount * uint32_t_size +
+ categoryCount * uint32_t_size);
for (auto it = devices.begin(); it != devices.end(); it++)
{
const DevicePtr& device = it->second;
@@ -596,6 +603,8 @@ void SendCounterPacket::SendCounterDirectoryPacket(const ICounterDirectory& coun
size_t counterSetRecordsSize = 0;
size_t counterSetIndex = 0;
size_t counterSetRecordOffsetIndex = 0;
+
+ pointerTableOffset -= numeric_cast<uint32_t>(deviceCount * uint32_t_size);
for (auto it = counterSets.begin(); it != counterSets.end(); it++)
{
const CounterSetPtr& counterSet = it->second;
@@ -629,6 +638,8 @@ void SendCounterPacket::SendCounterDirectoryPacket(const ICounterDirectory& coun
size_t categoryRecordsSize = 0;
size_t categoryIndex = 0;
size_t categoryRecordOffsetIndex = 0;
+
+ pointerTableOffset -= numeric_cast<uint32_t>(counterSetCount * uint32_t_size);
for (auto it = categories.begin(); it != categories.end(); it++)
{
const CategoryPtr& category = *it;
@@ -651,8 +662,6 @@ void SendCounterPacket::SendCounterDirectoryPacket(const ICounterDirectory& coun
categoryRecordOffsetIndex++;
}
-
-
// Calculate the length in words of the counter directory packet's data (excludes the packet header size)
const size_t counterDirectoryPacketDataLength =
bodyHeaderSize + // The size of the body header
@@ -667,7 +676,6 @@ void SendCounterPacket::SendCounterDirectoryPacket(const ICounterDirectory& coun
const size_t counterDirectoryPacketSize = packetHeaderSize + // The size of the packet header
counterDirectoryPacketDataLength; // The data length
-
// Allocate the necessary space for the counter directory packet
std::vector<uint32_t> counterDirectoryPacket(counterDirectoryPacketSize, 0);
diff --git a/src/profiling/test/ProfilingTests.cpp b/src/profiling/test/ProfilingTests.cpp
index bd6ae08e30..dd7d5b8476 100644
--- a/src/profiling/test/ProfilingTests.cpp
+++ b/src/profiling/test/ProfilingTests.cpp
@@ -2439,13 +2439,13 @@ BOOST_AUTO_TEST_CASE(RequestCounterDirectoryCommandHandlerTest2)
BOOST_TEST(bodyHeader1Word5 == 8 + bodyHeaderSizeBytes); // categories_pointer_table_offset
const uint32_t deviceRecordOffset = ReadUint32(readBuffer1, 32);
- BOOST_TEST(deviceRecordOffset == 0);
+ BOOST_TEST(deviceRecordOffset == 12);
const uint32_t counterSetRecordOffset = ReadUint32(readBuffer1, 36);
- BOOST_TEST(counterSetRecordOffset == 20);
+ BOOST_TEST(counterSetRecordOffset == 28);
const uint32_t categoryRecordOffset = ReadUint32(readBuffer1, 40);
- BOOST_TEST(categoryRecordOffset == 44);
+ BOOST_TEST(categoryRecordOffset == 48);
auto readBuffer2 = mockBuffer2.GetReadableBuffer();
diff --git a/src/profiling/test/SendCounterPacketTests.cpp b/src/profiling/test/SendCounterPacketTests.cpp
index 5bfcd2c14d..dd271c9594 100644
--- a/src/profiling/test/SendCounterPacketTests.cpp
+++ b/src/profiling/test/SendCounterPacketTests.cpp
@@ -427,7 +427,7 @@ BOOST_AUTO_TEST_CASE(CreateDeviceRecordTest)
};
BOOST_CHECK(deviceRecordWord0[0] == deviceUid); // uid
BOOST_CHECK(deviceRecordWord0[1] == deviceCores); // cores
- BOOST_CHECK(deviceRecord[1] == 0); // name_offset
+ BOOST_CHECK(deviceRecord[1] == 2); // name_offset
BOOST_CHECK(deviceRecord[2] == deviceName.size() + 1); // The length of the SWTrace string (name)
BOOST_CHECK(std::memcmp(deviceRecord.data() + 3, deviceName.data(), deviceName.size()) == 0); // name
}
@@ -480,7 +480,7 @@ BOOST_AUTO_TEST_CASE(CreateCounterSetRecordTest)
};
BOOST_CHECK(counterSetRecordWord0[0] == counterSetUid); // uid
BOOST_CHECK(counterSetRecordWord0[1] == counterSetCount); // cores
- BOOST_CHECK(counterSetRecord[1] == 0); // name_offset
+ BOOST_CHECK(counterSetRecord[1] == 2); // name_offset
BOOST_CHECK(counterSetRecord[2] == counterSetName.size() + 1); // The length of the SWTrace string (name)
BOOST_CHECK(std::memcmp(counterSetRecord.data() + 3, counterSetName.data(), counterSetName.size()) == 0); // name
}
@@ -564,33 +564,39 @@ BOOST_AUTO_TEST_CASE(CreateEventRecordTest)
eventRecord[3],
eventRecord[4]
};
+
BOOST_CHECK(eventRecordWord0[0] == maxCounterUid); // max_counter_uid
BOOST_CHECK(eventRecordWord0[1] == counterUid); // counter_uid
BOOST_CHECK(eventRecordWord1[0] == deviceUid); // device
+
BOOST_CHECK(eventRecordWord1[1] == counterSetUid); // counter_set
BOOST_CHECK(eventRecordWord2[0] == counterClass); // class
BOOST_CHECK(eventRecordWord2[1] == counterInterpolation); // interpolation
BOOST_CHECK(std::memcmp(eventRecordWord34, &counterMultiplier, sizeof(counterMultiplier)) == 0); // multiplier
ARMNN_NO_CONVERSION_WARN_BEGIN
- uint32_t counterNameOffset = 0; // The name is the first item in pool
+ uint32_t eventRecordBlockSize = 8u * sizeof(uint32_t);
+ uint32_t counterNameOffset = eventRecordBlockSize; // The name is the first item in pool
uint32_t counterDescriptionOffset = counterNameOffset + // Counter name offset
4u + // Counter name length (uint32_t)
counterName.size() + // 18u
1u + // Null-terminator
1u; // Rounding to the next word
+
size_t counterUnitsOffset = counterDescriptionOffset + // Counter description offset
4u + // Counter description length (uint32_t)
counterDescription.size() + // 21u
1u + // Null-terminator
- 2u; // Rounding to the next word
+ 2u; // Rounding to the next word
+
ARMNN_NO_CONVERSION_WARN_END
BOOST_CHECK(eventRecord[5] == counterNameOffset); // name_offset
BOOST_CHECK(eventRecord[6] == counterDescriptionOffset); // description_offset
BOOST_CHECK(eventRecord[7] == counterUnitsOffset); // units_offset
- auto eventRecordPool = reinterpret_cast<unsigned char*>(eventRecord.data() + 8u); // The start of the pool
+ // Offsets are relative to the start of the eventRecord
+ auto eventRecordPool = reinterpret_cast<unsigned char*>(eventRecord.data());
size_t uint32_t_size = sizeof(uint32_t);
// The length of the SWTrace string (name)
@@ -693,7 +699,8 @@ BOOST_AUTO_TEST_CASE(CreateEventRecordNoUnitsTest)
BOOST_CHECK(std::memcmp(eventRecordWord34, &counterMultiplier, sizeof(counterMultiplier)) == 0); // multiplier
ARMNN_NO_CONVERSION_WARN_BEGIN
- uint32_t counterNameOffset = 0; // The name is the first item in pool
+ uint32_t eventRecordBlockSize = 8u * sizeof(uint32_t);
+ uint32_t counterNameOffset = eventRecordBlockSize; // The name is the first item in pool
uint32_t counterDescriptionOffset = counterNameOffset + // Counter name offset
4u + // Counter name length (uint32_t)
counterName.size() + // 18u
@@ -705,7 +712,8 @@ BOOST_AUTO_TEST_CASE(CreateEventRecordNoUnitsTest)
BOOST_CHECK(eventRecord[6] == counterDescriptionOffset); // description_offset
BOOST_CHECK(eventRecord[7] == 0); // units_offset
- auto eventRecordPool = reinterpret_cast<unsigned char*>(eventRecord.data() + 8u); // The start of the pool
+ // Offsets are relative to the start of the eventRecord
+ auto eventRecordPool = reinterpret_cast<unsigned char*>(eventRecord.data());
size_t uint32_t_size = sizeof(uint32_t);
// The length of the SWTrace string (name)
@@ -926,15 +934,16 @@ BOOST_AUTO_TEST_CASE(CreateCategoryRecordTest)
size_t uint32_t_size = sizeof(uint32_t);
ARMNN_NO_CONVERSION_WARN_BEGIN
- uint32_t eventPointerTableOffset = 0; // The event pointer table is the first item in pool
+ uint32_t categoryRecordBlockSize = 3u * uint32_t_size;
+ uint32_t eventPointerTableOffset = categoryRecordBlockSize; // The event pointer table is the first item in pool
uint32_t categoryNameOffset = eventPointerTableOffset + // Event pointer table offset
categoryEventCount * uint32_t_size; // The size of the event pointer table
ARMNN_NO_CONVERSION_WARN_END
BOOST_CHECK(categoryRecord[1] == eventPointerTableOffset); // event_pointer_table_offset
BOOST_CHECK(categoryRecord[2] == categoryNameOffset); // name_offset
-
- auto categoryRecordPool = reinterpret_cast<unsigned char*>(categoryRecord.data() + 3u); // The start of the pool
+ // Offsets are relative to the start of the category record
+ auto categoryRecordPool = reinterpret_cast<unsigned char*>(categoryRecord.data());
// The event pointer table
uint32_t eventRecord0Offset = categoryRecordPool[eventPointerTableOffset + 0 * uint32_t_size];
@@ -960,60 +969,71 @@ BOOST_AUTO_TEST_CASE(CreateCategoryRecordTest)
// Counter1 UID and max counter UID
uint16_t eventRecord0Word0[2] = { 0u, 0u };
- std::memcpy(eventRecord0Word0, categoryRecordPool + eventRecord0Offset, sizeof(eventRecord0Word0));
+ std::memcpy(eventRecord0Word0, categoryRecordPool + categoryRecordBlockSize + eventRecord0Offset,
+ sizeof(eventRecord0Word0));
BOOST_CHECK(eventRecord0Word0[0] == counter1->m_Uid);
BOOST_CHECK(eventRecord0Word0[1] == counter1->m_MaxCounterUid);
// Counter1 name
uint32_t counter1NameOffset = 0;
- std::memcpy(&counter1NameOffset, categoryRecordPool + eventRecord0Offset + 5u * uint32_t_size, uint32_t_size);
+ std::memcpy(&counter1NameOffset, categoryRecordPool + eventRecord0Offset + 5u * uint32_t_size, uint32_t_size);
BOOST_CHECK(counter1NameOffset == 0);
// The length of the SWTrace string (name)
- BOOST_CHECK(categoryRecordPool[eventRecord0Offset + // Offset to the event record
- 8u * uint32_t_size + // Offset to the event record pool
- counter1NameOffset // Offset to the name of the counter
+ BOOST_CHECK(categoryRecordPool[eventRecord0Offset + // Offset to the event record
+ categoryRecordBlockSize + // Offset to the end of the category record block
+ 8u * uint32_t_size + // Offset to the event record pool
+ counter1NameOffset // Offset to the name of the counter
] == counter1->m_Name.size() + 1); // The length of the name including the
// null-terminator
// The counter1 name
- BOOST_CHECK(std::memcmp(categoryRecordPool + // The beginning of the category pool
- eventRecord0Offset + // Offset to the event record
- 8u * uint32_t_size + // Offset to the event record pool
- counter1NameOffset + // Offset to the name of the counter
- uint32_t_size, // The length of the name
+ BOOST_CHECK(std::memcmp(categoryRecordPool + // The beginning of the category pool
+ categoryRecordBlockSize + // Offset to the end of the category record block
+ eventRecord0Offset + // Offset to the event record
+ 8u * uint32_t_size + // Offset to the event record pool
+ counter1NameOffset + // Offset to the name of the counter
+ uint32_t_size, // The length of the name
counter1->m_Name.data(),
counter1->m_Name.size()) == 0); // name
// The null-terminator at the end of the counter1 name
- BOOST_CHECK(categoryRecordPool[eventRecord0Offset + // Offset to the event record
- 8u * uint32_t_size + // Offset to the event record pool
- counter1NameOffset + // Offset to the name of the counter
- uint32_t_size + // The length of the name
- counter1->m_Name.size() // The name of the counter
+ BOOST_CHECK(categoryRecordPool[eventRecord0Offset + // Offset to the event record
+ categoryRecordBlockSize + // Offset to the end of the category record block
+ 8u * uint32_t_size + // Offset to the event record pool
+ counter1NameOffset + // Offset to the name of the counter
+ uint32_t_size + // The length of the name
+ counter1->m_Name.size() // The name of the counter
] == '\0');
// Counter2 name
uint32_t counter2NameOffset = 0;
- std::memcpy(&counter2NameOffset, categoryRecordPool + eventRecord1Offset + 5u * uint32_t_size, uint32_t_size);
- BOOST_CHECK(counter2NameOffset == 0);
+ std::memcpy(&counter2NameOffset, categoryRecordPool +
+ categoryRecordBlockSize +
+ eventRecord1Offset +
+ 5u * uint32_t_size,
+ uint32_t_size);
+ BOOST_CHECK(counter2NameOffset == 8u * uint32_t_size );
// The length of the SWTrace string (name)
+
BOOST_CHECK(categoryRecordPool[eventRecord1Offset + // Offset to the event record
- 8u * uint32_t_size + // Offset to the event record pool
+ categoryRecordBlockSize +
counter2NameOffset // Offset to the name of the counter
] == counter2->m_Name.size() + 1); // The length of the name including the
// null-terminator
// The counter2 name
- BOOST_CHECK(std::memcmp(categoryRecordPool + // The beginning of the category pool
- eventRecord1Offset + // Offset to the event record
- 8u * uint32_t_size + // Offset to the event record pool
- counter2NameOffset + // Offset to the name of the counter
- uint32_t_size, // The length of the name
+ BOOST_CHECK(std::memcmp(categoryRecordPool + // The beginning of the category pool
+ categoryRecordBlockSize + // Offset to the end of the category record block
+ eventRecord1Offset + // Offset to the event record
+ counter2NameOffset + // Offset to the name of the counter
+ uint32_t_size, // The length of the name
counter2->m_Name.data(),
counter2->m_Name.size()) == 0); // name
+
+
// The null-terminator at the end of the counter2 name
- BOOST_CHECK(categoryRecordPool[eventRecord1Offset + // Offset to the event record
- 8u * uint32_t_size + // Offset to the event record pool
- counter2NameOffset + // Offset to the name of the counter
- uint32_t_size + // The length of the name
- counter2->m_Name.size() // The name of the counter
+ BOOST_CHECK(categoryRecordPool[eventRecord1Offset + // Offset to the event record
+ categoryRecordBlockSize + // Offset to the end of the category record block
+ counter2NameOffset + // Offset to the name of the counter
+ uint32_t_size + // The length of the name
+ counter2->m_Name.size() // The name of the counter
] == '\0');
// Counter3 name
@@ -1022,12 +1042,14 @@ BOOST_AUTO_TEST_CASE(CreateCategoryRecordTest)
BOOST_CHECK(counter3NameOffset == 0);
// The length of the SWTrace string (name)
BOOST_CHECK(categoryRecordPool[eventRecord2Offset + // Offset to the event record
+ categoryRecordBlockSize +
8u * uint32_t_size + // Offset to the event record pool
counter3NameOffset // Offset to the name of the counter
] == counter3->m_Name.size() + 1); // The length of the name including the
// null-terminator
// The counter3 name
BOOST_CHECK(std::memcmp(categoryRecordPool + // The beginning of the category pool
+ categoryRecordBlockSize +
eventRecord2Offset + // Offset to the event record
8u * uint32_t_size + // Offset to the event record pool
counter3NameOffset + // Offset to the name of the counter
@@ -1036,6 +1058,7 @@ BOOST_AUTO_TEST_CASE(CreateCategoryRecordTest)
counter3->m_Name.size()) == 0); // name
// The null-terminator at the end of the counter3 name
BOOST_CHECK(categoryRecordPool[eventRecord2Offset + // Offset to the event record
+ categoryRecordBlockSize +
8u * uint32_t_size + // Offset to the event record pool
counter3NameOffset + // Offset to the name of the counter
uint32_t_size + // The length of the name
@@ -1255,26 +1278,22 @@ BOOST_AUTO_TEST_CASE(SendCounterDirectoryPacketTest2)
// Check the device records pointer table
const uint32_t deviceRecordOffset0 = ReadUint32(readBuffer, 32);
const uint32_t deviceRecordOffset1 = ReadUint32(readBuffer, 36);
- BOOST_TEST(deviceRecordOffset0 == 0); // Device record offset for "device1"
- BOOST_TEST(deviceRecordOffset1 == 20); // Device record offset for "device2"
+ BOOST_TEST(deviceRecordOffset0 == 20); // Device record offset for "device1"
+ BOOST_TEST(deviceRecordOffset1 == 40); // Device record offset for "device2"
// Check the counter set pointer table
const uint32_t counterSetRecordOffset0 = ReadUint32(readBuffer, 40);
- BOOST_TEST(counterSetRecordOffset0 == 40); // Counter set record offset for "counterset1"
+ BOOST_TEST(counterSetRecordOffset0 == 52); // Counter set record offset for "counterset1"
// Check the category pointer table
const uint32_t categoryRecordOffset0 = ReadUint32(readBuffer, 44);
const uint32_t categoryRecordOffset1 = ReadUint32(readBuffer, 48);
- BOOST_TEST(categoryRecordOffset0 == 64); // Category record offset for "category1"
- BOOST_TEST(categoryRecordOffset1 == 168); // Category record offset for "category2"
+ BOOST_TEST(categoryRecordOffset0 == 72); // Category record offset for "category1"
+ BOOST_TEST(categoryRecordOffset1 == 176); // Category record offset for "category2"
// Get the device record pool offset
const uint32_t uint32_t_size = sizeof(uint32_t);
- const uint32_t packetBodyPoolOffset = 2u * uint32_t_size + // packet_header
- bodyHeaderWord1 + // body_header
- deviceRecordCount * uint32_t_size + // Size of device_records_pointer_table
- counterSetRecordCount * uint32_t_size // Size of counter_set_pointer_table
- + categoryRecordCount * uint32_t_size; // Size of categories_pointer_table
+ const uint32_t packetHeaderSize = 2u * uint32_t_size;
// Device record structure/collection used for testing
struct DeviceRecord
@@ -1286,30 +1305,41 @@ BOOST_AUTO_TEST_CASE(SendCounterDirectoryPacketTest2)
std::string name;
};
std::vector<DeviceRecord> deviceRecords;
- const uint32_t deviceRecordsPointerTableOffset = 2u * uint32_t_size + // packet_header
+ const uint32_t deviceRecordsPointerTableOffset = packetHeaderSize +
bodyHeaderWord1; // device_records_pointer_table_offset
const unsigned char* readData = readBuffer->GetReadableData();
- for (uint32_t i = 0; i < deviceRecordCount; i++)
+ uint32_t offset = 0;
+ std::vector<uint32_t> data(800);
+
+ for (uint32_t i = 0; i < 800; i+=uint32_t_size)
{
- // Get the device record offset
- const uint32_t deviceRecordOffset = ReadUint32(readBuffer, deviceRecordsPointerTableOffset + i * uint32_t_size);
+ data[i] = ReadUint32(readBuffer, offset);
+ offset += uint32_t_size;
+ }
+ std::vector<uint32_t> deviceRecordOffsets(deviceRecordCount);
+ offset = deviceRecordsPointerTableOffset;
+ for (uint32_t i = 0; i < deviceRecordCount; ++i)
+ {
+ // deviceRecordOffset is relative to the start of the deviceRecordsPointerTable
+ deviceRecordOffsets[i] = ReadUint32(readBuffer, offset) + deviceRecordsPointerTableOffset;
+ offset += uint32_t_size;
+ }
+
+ for (uint32_t i = 0; i < deviceRecordCount; i++)
+ {
// Collect the data for the device record
- const uint32_t deviceRecordWord0 = ReadUint32(readBuffer,
- packetBodyPoolOffset + deviceRecordOffset + 0 * uint32_t_size);
- const uint32_t deviceRecordWord1 = ReadUint32(readBuffer,
- packetBodyPoolOffset + deviceRecordOffset + 1 * uint32_t_size);
+ const uint32_t deviceRecordWord0 = ReadUint32(readBuffer, deviceRecordOffsets[i] + 0 * uint32_t_size);
+ const uint32_t deviceRecordWord1 = ReadUint32(readBuffer, deviceRecordOffsets[i] + 1 * uint32_t_size);
DeviceRecord deviceRecord;
deviceRecord.uid = static_cast<uint16_t>(deviceRecordWord0 >> 16); // uid
deviceRecord.cores = static_cast<uint16_t>(deviceRecordWord0); // cores
deviceRecord.name_offset = deviceRecordWord1; // name_offset
- uint32_t deviceRecordPoolOffset = packetBodyPoolOffset + // Packet body offset
- deviceRecordOffset + // Device record offset
- 2 * uint32_t_size + // Device record header
- deviceRecord.name_offset; // Device name offset
+ uint32_t deviceRecordPoolOffset = deviceRecordOffsets[i] + // Packet body offset
+ deviceRecord.name_offset * uint32_t_size; // Device name offset
uint32_t deviceRecordNameLength = ReadUint32(readBuffer, deviceRecordPoolOffset);
deviceRecord.name_length = deviceRecordNameLength; // name_length
unsigned char deviceRecordNameNullTerminator = // name null-terminator
@@ -1334,6 +1364,7 @@ BOOST_AUTO_TEST_CASE(SendCounterDirectoryPacketTest2)
BOOST_CHECK(device->m_Name == deviceRecord.name);
}
+
// Counter set record structure/collection used for testing
struct CounterSetRecord
{
@@ -1346,28 +1377,29 @@ BOOST_AUTO_TEST_CASE(SendCounterDirectoryPacketTest2)
std::vector<CounterSetRecord> counterSetRecords;
const uint32_t counterSetRecordsPointerTableOffset = 2u * uint32_t_size + // packet_header
bodyHeaderWord3; // counter_set_pointer_table_offset
- for (uint32_t i = 0; i < counterSetRecordCount; i++)
+
+ offset = counterSetRecordsPointerTableOffset;
+ std::vector<uint32_t> counterSetRecordOffsets(counterSetRecordCount);
+
+ for (uint32_t i = 0; i < counterSetRecordCount; ++i)
{
- // Get the counter set record offset
- const uint32_t counterSetRecordOffset = ReadUint32(readBuffer,
- counterSetRecordsPointerTableOffset + i * uint32_t_size);
+ // counterSetRecordOffset is relative to the start of the dcounterSetRecordsPointerTable
+ counterSetRecordOffsets[i] = ReadUint32(readBuffer, offset) + counterSetRecordsPointerTableOffset;
+ offset += uint32_t_size;
+ }
+ for (uint32_t i = 0; i < counterSetRecordCount; i++)
+ {
// Collect the data for the counter set record
- const uint32_t counterSetRecordWord0 = ReadUint32(readBuffer,
- packetBodyPoolOffset + counterSetRecordOffset +
- 0 * uint32_t_size);
- const uint32_t counterSetRecordWord1 = ReadUint32(readBuffer,
- packetBodyPoolOffset + counterSetRecordOffset +
- 1 * uint32_t_size);
+ const uint32_t counterSetRecordWord0 = ReadUint32(readBuffer, counterSetRecordOffsets[i] + 0 * uint32_t_size);
+ const uint32_t counterSetRecordWord1 = ReadUint32(readBuffer, counterSetRecordOffsets[i] + 1 * uint32_t_size);
CounterSetRecord counterSetRecord;
counterSetRecord.uid = static_cast<uint16_t>(counterSetRecordWord0 >> 16); // uid
counterSetRecord.count = static_cast<uint16_t>(counterSetRecordWord0); // count
counterSetRecord.name_offset = counterSetRecordWord1; // name_offset
- uint32_t counterSetRecordPoolOffset = packetBodyPoolOffset + // Packet body offset
- counterSetRecordOffset + // Counter set record offset
- 2 * uint32_t_size + // Counter set record header
- counterSetRecord.name_offset; // Counter set name offset
+ uint32_t counterSetRecordPoolOffset = counterSetRecordOffsets[i] + // Packet body offset
+ counterSetRecord.name_offset * uint32_t_size; // Counter set name offset
uint32_t counterSetRecordNameLength = ReadUint32(readBuffer, counterSetRecordPoolOffset);
counterSetRecord.name_length = counterSetRecordNameLength; // name_length
unsigned char counterSetRecordNameNullTerminator = // name null-terminator
@@ -1426,37 +1458,33 @@ BOOST_AUTO_TEST_CASE(SendCounterDirectoryPacketTest2)
std::vector<CategoryRecord> categoryRecords;
const uint32_t categoryRecordsPointerTableOffset = 2u * uint32_t_size + // packet_header
bodyHeaderWord5; // categories_pointer_table_offset
- for (uint32_t i = 0; i < categoryRecordCount; i++)
+
+ offset = categoryRecordsPointerTableOffset;
+ std::vector<uint32_t> categoryRecordOffsets(categoryRecordCount);
+ for (uint32_t i = 0; i < categoryRecordCount; ++i)
{
- // Get the category record offset
- const uint32_t categoryRecordOffset = ReadUint32(readBuffer, categoryRecordsPointerTableOffset +
- i * uint32_t_size);
+ // categoryRecordOffset is relative to the start of the categoryRecordsPointerTable
+ categoryRecordOffsets[i] = ReadUint32(readBuffer, offset) + categoryRecordsPointerTableOffset;
+ offset += uint32_t_size;
+ }
+ for (uint32_t i = 0; i < categoryRecordCount; i++)
+ {
// Collect the data for the category record
- const uint32_t categoryRecordWord1 = ReadUint32(readBuffer,
- packetBodyPoolOffset + categoryRecordOffset +
- 0 * uint32_t_size);
- const uint32_t categoryRecordWord2 = ReadUint32(readBuffer,
- packetBodyPoolOffset + categoryRecordOffset +
- 1 * uint32_t_size);
- const uint32_t categoryRecordWord3 = ReadUint32(readBuffer,
- packetBodyPoolOffset + categoryRecordOffset +
- 2 * uint32_t_size);
+ const uint32_t categoryRecordWord1 = ReadUint32(readBuffer, categoryRecordOffsets[i] + 0 * uint32_t_size);
+ const uint32_t categoryRecordWord2 = ReadUint32(readBuffer, categoryRecordOffsets[i] + 1 * uint32_t_size);
+ const uint32_t categoryRecordWord3 = ReadUint32(readBuffer, categoryRecordOffsets[i] + 2 * uint32_t_size);
CategoryRecord categoryRecord;
categoryRecord.event_count = static_cast<uint16_t>(categoryRecordWord1 >> 16); // event_count
categoryRecord.event_pointer_table_offset = categoryRecordWord2; // event_pointer_table_offset
categoryRecord.name_offset = categoryRecordWord3; // name_offset
- uint32_t categoryRecordPoolOffset = packetBodyPoolOffset + // Packet body offset
- categoryRecordOffset + // Category record offset
- 3 * uint32_t_size; // Category record header
-
uint32_t categoryRecordNameLength = ReadUint32(readBuffer,
- categoryRecordPoolOffset + categoryRecord.name_offset);
+ categoryRecordOffsets[i] + categoryRecord.name_offset);
categoryRecord.name_length = categoryRecordNameLength; // name_length
unsigned char categoryRecordNameNullTerminator =
ReadUint8(readBuffer,
- categoryRecordPoolOffset +
+ categoryRecordOffsets[i] +
categoryRecord.name_offset +
uint32_t_size +
categoryRecordNameLength - 1); // name null-terminator
@@ -1464,43 +1492,35 @@ BOOST_AUTO_TEST_CASE(SendCounterDirectoryPacketTest2)
std::vector<unsigned char> categoryRecordNameBuffer(categoryRecord.name_length - 1);
std::memcpy(categoryRecordNameBuffer.data(),
readData +
- categoryRecordPoolOffset +
+ categoryRecordOffsets[i] +
categoryRecord.name_offset +
uint32_t_size,
categoryRecordNameBuffer.size());
categoryRecord.name.assign(categoryRecordNameBuffer.begin(), categoryRecordNameBuffer.end()); // name
categoryRecord.event_pointer_table.resize(categoryRecord.event_count);
- for (uint32_t eventIndex = 0; eventIndex < categoryRecord.event_count; eventIndex++)
+ offset = categoryRecordOffsets[i] + categoryRecord.event_pointer_table_offset;
+ for (uint32_t eventOffsetIndex = 0; eventOffsetIndex < categoryRecord.event_count; ++eventOffsetIndex)
{
- uint32_t eventRecordOffset = ReadUint32(readBuffer,
- categoryRecordPoolOffset +
- categoryRecord.event_pointer_table_offset +
- eventIndex * uint32_t_size);
- categoryRecord.event_pointer_table[eventIndex] = eventRecordOffset;
+ // eventRecordOffset is relative to the start of the event pointer table
+ categoryRecord.event_pointer_table[eventOffsetIndex] = ReadUint32(readBuffer, offset) +
+ categoryRecordOffsets[i] +
+ categoryRecord.event_pointer_table_offset;
+ offset += uint32_t_size;
+ }
+ for (uint32_t eventIndex = 0; eventIndex < categoryRecord.event_count; eventIndex++)
+ {
+ const uint32_t eventOffset = categoryRecord.event_pointer_table[eventIndex];
// Collect the data for the event record
- const uint32_t eventRecordWord0 = ReadUint32(readBuffer,
- categoryRecordPoolOffset + eventRecordOffset +
- 0 * uint32_t_size);
- const uint32_t eventRecordWord1 = ReadUint32(readBuffer,
- categoryRecordPoolOffset + eventRecordOffset +
- 1 * uint32_t_size);
- const uint32_t eventRecordWord2 = ReadUint32(readBuffer,
- categoryRecordPoolOffset + eventRecordOffset +
- 2 * uint32_t_size);
- const uint64_t eventRecordWord34 = ReadUint64(readBuffer,
- categoryRecordPoolOffset + eventRecordOffset +
- 3 * uint32_t_size);
- const uint32_t eventRecordWord5 = ReadUint32(readBuffer,
- categoryRecordPoolOffset + eventRecordOffset +
- 5 * uint32_t_size);
- const uint32_t eventRecordWord6 = ReadUint32(readBuffer,
- categoryRecordPoolOffset + eventRecordOffset +
- 6 * uint32_t_size);
- const uint32_t eventRecordWord7 = ReadUint32(readBuffer,
- categoryRecordPoolOffset + eventRecordOffset +
- 7 * uint32_t_size);
+ const uint32_t eventRecordWord0 = ReadUint32(readBuffer, eventOffset + 0 * uint32_t_size);
+ const uint32_t eventRecordWord1 = ReadUint32(readBuffer, eventOffset + 1 * uint32_t_size);
+ const uint32_t eventRecordWord2 = ReadUint32(readBuffer, eventOffset + 2 * uint32_t_size);
+ const uint64_t eventRecordWord34 = ReadUint64(readBuffer, eventOffset + 3 * uint32_t_size);
+ const uint32_t eventRecordWord5 = ReadUint32(readBuffer, eventOffset + 5 * uint32_t_size);
+ const uint32_t eventRecordWord6 = ReadUint32(readBuffer, eventOffset + 6 * uint32_t_size);
+ const uint32_t eventRecordWord7 = ReadUint32(readBuffer, eventOffset + 7 * uint32_t_size);
+
EventRecord eventRecord;
eventRecord.counter_uid = static_cast<uint16_t>(eventRecordWord0); // counter_uid
eventRecord.max_counter_uid = static_cast<uint16_t>(eventRecordWord0 >> 16); // max_counter_uid
@@ -1513,16 +1533,11 @@ BOOST_AUTO_TEST_CASE(SendCounterDirectoryPacketTest2)
eventRecord.description_offset = static_cast<uint32_t>(eventRecordWord6); // description_offset
eventRecord.units_offset = static_cast<uint32_t>(eventRecordWord7); // units_offset
- uint32_t eventRecordPoolOffset = categoryRecordPoolOffset + // Category record pool offset
- eventRecordOffset + // Event record offset
- 8 * uint32_t_size; // Event record header
-
- uint32_t eventRecordNameLength = ReadUint32(readBuffer,
- eventRecordPoolOffset + eventRecord.name_offset);
+ uint32_t eventRecordNameLength = ReadUint32(readBuffer, eventOffset + eventRecord.name_offset);
eventRecord.name_length = eventRecordNameLength; // name_length
unsigned char eventRecordNameNullTerminator =
ReadUint8(readBuffer,
- eventRecordPoolOffset +
+ eventOffset +
eventRecord.name_offset +
uint32_t_size +
eventRecordNameLength - 1); // name null-terminator
@@ -1530,18 +1545,18 @@ BOOST_AUTO_TEST_CASE(SendCounterDirectoryPacketTest2)
std::vector<unsigned char> eventRecordNameBuffer(eventRecord.name_length - 1);
std::memcpy(eventRecordNameBuffer.data(),
readData +
- eventRecordPoolOffset +
+ eventOffset +
eventRecord.name_offset +
uint32_t_size,
eventRecordNameBuffer.size());
eventRecord.name.assign(eventRecordNameBuffer.begin(), eventRecordNameBuffer.end()); // name
uint32_t eventRecordDescriptionLength = ReadUint32(readBuffer,
- eventRecordPoolOffset + eventRecord.description_offset);
+ eventOffset + eventRecord.description_offset);
eventRecord.description_length = eventRecordDescriptionLength; // description_length
unsigned char eventRecordDescriptionNullTerminator =
ReadUint8(readBuffer,
- eventRecordPoolOffset +
+ eventOffset +
eventRecord.description_offset +
uint32_t_size +
eventRecordDescriptionLength - 1); // description null-terminator
@@ -1549,7 +1564,7 @@ BOOST_AUTO_TEST_CASE(SendCounterDirectoryPacketTest2)
std::vector<unsigned char> eventRecordDescriptionBuffer(eventRecord.description_length - 1);
std::memcpy(eventRecordDescriptionBuffer.data(),
readData +
- eventRecordPoolOffset +
+ eventOffset +
eventRecord.description_offset +
uint32_t_size,
eventRecordDescriptionBuffer.size());
@@ -1559,11 +1574,11 @@ BOOST_AUTO_TEST_CASE(SendCounterDirectoryPacketTest2)
if (eventRecord.units_offset > 0)
{
uint32_t eventRecordUnitsLength = ReadUint32(readBuffer,
- eventRecordPoolOffset + eventRecord.units_offset);
+ eventOffset + eventRecord.units_offset);
eventRecord.units_length = eventRecordUnitsLength; // units_length
unsigned char eventRecordUnitsNullTerminator =
ReadUint8(readBuffer,
- eventRecordPoolOffset +
+ eventOffset +
eventRecord.units_offset +
uint32_t_size +
eventRecordUnitsLength - 1); // units null-terminator
@@ -1571,7 +1586,7 @@ BOOST_AUTO_TEST_CASE(SendCounterDirectoryPacketTest2)
std::vector<unsigned char> eventRecordUnitsBuffer(eventRecord.units_length - 1);
std::memcpy(eventRecordUnitsBuffer.data(),
readData +
- eventRecordPoolOffset +
+ eventOffset +
eventRecord.units_offset +
uint32_t_size,
eventRecordUnitsBuffer.size());