//
-// Copyright © 2017 Arm Ltd. All rights reserved.
+// Copyright © 2017 Arm Ltd and Contributors. All rights reserved.
// SPDX-License-Identifier: MIT
//
#include "SendCounterPacket.hpp"
-#include "EncodeVersion.hpp"
+#include <common/include/EncodeVersion.hpp>
#include <armnn/Exceptions.hpp>
#include <armnn/Conversion.hpp>
#include <Processes.hpp>
#include <armnn/utility/Assert.hpp>
+#include <armnn/utility/NumericCast.hpp>
#include <common/include/Constants.hpp>
+#include <common/include/SwTrace.hpp>
#include <boost/format.hpp>
-#include <boost/numeric/conversion/cast.hpp>
#include <cstring>
namespace profiling
{
-using boost::numeric_cast;
-
void SendCounterPacket::SendStreamMetaDataPacket()
{
const std::string info(GetSoftwareInfo());
const std::string softwareVersion(GetSoftwareVersion());
const std::string processName = GetProcessName().substr(0, 60);
- 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;
+ const uint32_t infoSize = armnn::numeric_cast<uint32_t>(info.size()) + 1;
+ const uint32_t hardwareVersionSize = armnn::numeric_cast<uint32_t>(hardwareVersion.size()) + 1;
+ const uint32_t softwareVersionSize = armnn::numeric_cast<uint32_t>(softwareVersion.size()) + 1;
+ const uint32_t processNameSize = armnn::numeric_cast<uint32_t>(processName.size()) + 1;
const uint32_t sizeUint32 = sizeof(uint32_t);
const uint32_t packetVersionCountSize = sizeUint32;
// Supported Packets
- // Stream metadata packet (packet family=0; packet id=0)
- // Connection Acknowledged packet (packet family=0, packet id=1)
- // Counter Directory packet (packet family=0; packet id=2)
- // 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)
- const uint32_t packetVersionEntries = 6;
-
- const uint32_t payloadSize = numeric_cast<uint32_t>(infoSize + hardwareVersionSize + softwareVersionSize +
- processNameSize + packetVersionCountSize +
- (packetVersionEntries * 2 * sizeUint32));
+ // Packet Encoding version 1.0.0
+ // Control packet family
+ // Stream metadata packet (packet family=0; packet id=0)
+ // Connection Acknowledged packet ( packet family=0, packet id=1) Version 1.0.0
+ // Counter Directory packet (packet family=0; packet id=2) Version 1.0.0
+ // Request Counter Directory packet ( packet family=0, packet id=3) Version 1.0.0
+ // Periodic Counter Selection packet ( packet family=0, packet id=4) Version 1.0.0
+ // Per Job Counter Selection packet ( packet family=0, packet id=5) Version 1.0.0
+ // Activate Timeline Reporting (packet family = 0, packet id = 6) Version 1.0.0
+ // Deactivate Timeline Reporting (packet family = 0, packet id = 7) Version 1.0.0
+ // Counter Packet Family
+ // Periodic Counter Capture (packet_family = 3, packet_class = 0, packet_type = 0) Version 1.0.0
+ // Per-Job Counter Capture (packet_family = 3, packet_class = 1, packet_type = 0,1) Version 1.0.0
+ // Timeline Packet Family
+ // Timeline Message Directory (packet_family = 1, packet_class = 0, packet_type = 0) Version 1.0.0
+ // Timeline Message (packet_family = 1, packet_class = 0, packet_type = 1) Version 1.0.0
+ std::vector<std::pair<uint32_t, uint32_t>> packetVersions;
+ packetVersions.push_back(std::make_pair(ConstructHeader(0, 0), arm::pipe::EncodeVersion(1, 0, 0)));
+ packetVersions.push_back(std::make_pair(ConstructHeader(0, 1), arm::pipe::EncodeVersion(1, 0, 0)));
+ packetVersions.push_back(std::make_pair(ConstructHeader(0, 2), arm::pipe::EncodeVersion(1, 0, 0)));
+ packetVersions.push_back(std::make_pair(ConstructHeader(0, 3), arm::pipe::EncodeVersion(1, 0, 0)));
+ packetVersions.push_back(std::make_pair(ConstructHeader(0, 4), arm::pipe::EncodeVersion(1, 0, 0)));
+ packetVersions.push_back(std::make_pair(ConstructHeader(0, 5), arm::pipe::EncodeVersion(1, 0, 0)));
+ packetVersions.push_back(std::make_pair(ConstructHeader(0, 6), arm::pipe::EncodeVersion(1, 0, 0)));
+ packetVersions.push_back(std::make_pair(ConstructHeader(0, 7), arm::pipe::EncodeVersion(1, 0, 0)));
+ packetVersions.push_back(std::make_pair(ConstructHeader(3, 0, 0), arm::pipe::EncodeVersion(1, 0, 0)));
+ packetVersions.push_back(std::make_pair(ConstructHeader(3, 1, 0), arm::pipe::EncodeVersion(1, 0, 0)));
+ packetVersions.push_back(std::make_pair(ConstructHeader(3, 1, 1), arm::pipe::EncodeVersion(1, 0, 0)));
+ packetVersions.push_back(std::make_pair(ConstructHeader(1, 0, 0), arm::pipe::EncodeVersion(1, 0, 0)));
+ packetVersions.push_back(std::make_pair(ConstructHeader(1, 0, 1), arm::pipe::EncodeVersion(1, 0, 0)));
+ uint32_t numberOfVersions = armnn::numeric_cast<uint32_t>(packetVersions.size());
+ uint32_t packetVersionSize = armnn::numeric_cast<uint32_t>(numberOfVersions * 2 * sizeUint32);
+
+ const uint32_t payloadSize = armnn::numeric_cast<uint32_t>(infoSize + hardwareVersionSize +
+ softwareVersionSize + processNameSize +
+ packetVersionCountSize + packetVersionSize);
const uint32_t totalSize = headerSize + bodySize + payloadSize;
uint32_t offset = 0;
// Packet body
offset += sizeUint32;
- WriteUint32(writeBuffer, offset, armnnProfiling::PIPE_MAGIC); // pipe_magic
+ WriteUint32(writeBuffer, offset, arm::pipe::PIPE_MAGIC); // pipe_magic
offset += sizeUint32;
- WriteUint32(writeBuffer, offset, EncodeVersion(1, 0, 0)); // stream_metadata_version
+ WriteUint32(writeBuffer, offset, arm::pipe::EncodeVersion(1, 0, 0)); // stream_metadata_version
offset += sizeUint32;
WriteUint32(writeBuffer, offset, MAX_METADATA_PACKET_LENGTH); // max_data_length
offset += sizeUint32;
int pid = armnnUtils::Processes::GetCurrentId();
- WriteUint32(writeBuffer, offset, numeric_cast<uint32_t>(pid)); // pid
+ WriteUint32(writeBuffer, offset, armnn::numeric_cast<uint32_t>(pid)); // pid
offset += sizeUint32;
uint32_t poolOffset = bodySize;
WriteUint32(writeBuffer, offset, poolOffset); // offset_info
memcpy(&writeBuffer->GetWritableData()[offset], processName.c_str(), processNameSize);
offset += processNameSize;
- if (packetVersionEntries)
+ if (!packetVersions.empty())
{
// Packet Version Count
- WriteUint32(writeBuffer, offset, packetVersionEntries << 16);
+ WriteUint32(writeBuffer, offset, numberOfVersions << 16);
+ offset += sizeUint32;
// Packet Version Entries
- uint32_t packetFamily = 0;
- uint32_t packetId = 0;
-
- offset += sizeUint32;
- for (uint32_t i = 0; i < packetVersionEntries - 1; ++i)
+ for (std::pair<uint32_t, uint32_t>& packetVersion : packetVersions)
{
- WriteUint32(writeBuffer, offset, ((packetFamily & 0x3F) << 26) | ((packetId++ & 0x3FF) << 16));
+ WriteUint32(writeBuffer, offset, packetVersion.first);
offset += sizeUint32;
- WriteUint32(writeBuffer, offset, EncodeVersion(1, 0, 0));
+ WriteUint32(writeBuffer, offset, packetVersion.second);
offset += sizeUint32;
}
-
- packetFamily = 1;
- packetId = 0;
-
- WriteUint32(writeBuffer, offset, ((packetFamily & 0x3F) << 26) | ((packetId & 0x3FF) << 16));
- offset += sizeUint32;
- WriteUint32(writeBuffer, offset, EncodeVersion(1, 0, 0));
}
}
catch(...)
CategoryRecord& categoryRecord,
std::string& errorMessage)
{
- using namespace boost::numeric;
-
ARMNN_ASSERT(category);
const std::string& categoryName = category->m_Name;
// Convert the device name into a SWTrace namestring
std::vector<uint32_t> categoryNameBuffer;
- if (!StringToSwTraceString<SwTraceNameCharPolicy>(categoryName, categoryNameBuffer))
+ if (!arm::pipe::StringToSwTraceString<arm::pipe::SwTraceNameCharPolicy>(categoryName, categoryNameBuffer))
{
errorMessage = boost::str(boost::format("Cannot convert the name of category (%1%) to an SWTrace namestring")
% categoryName);
std::vector<EventRecord> eventRecords(counterCount);
std::vector<uint32_t> eventRecordOffsets(counterCount, 0);
size_t eventRecordsSize = 0;
- uint32_t eventRecordsOffset =
- numeric_cast<uint32_t>((eventRecords.size() + categoryNameBuffer.size()) * uint32_t_size);
+ uint32_t eventRecordsOffset = armnn::numeric_cast<uint32_t>(
+ (eventRecords.size() + categoryNameBuffer.size()) * uint32_t_size);
for (size_t counterIndex = 0, eventRecordIndex = 0, eventRecordOffsetIndex = 0;
counterIndex < counterCount;
counterIndex++, eventRecordIndex++, eventRecordOffsetIndex++)
// Add the event record offset to the event pointer table offset field
eventRecordOffsets[eventRecordOffsetIndex] = eventRecordsOffset;
- eventRecordsOffset += numeric_cast<uint32_t>(eventRecord.size() * uint32_t_size);
+ eventRecordsOffset += armnn::numeric_cast<uint32_t>(eventRecord.size() * uint32_t_size);
}
// Category record word 3:
// 0:31 [32] name_offset (offset from the beginning of the category data pool to the name field)
- const uint32_t categoryRecordWord3 = numeric_cast<uint32_t>((3u + eventRecordOffsets.size()) * uint32_t_size);
+ const uint32_t categoryRecordWord3 = armnn::numeric_cast<uint32_t>(
+ (3u + eventRecordOffsets.size()) * uint32_t_size);
// Calculate the size in words of the category record
const size_t categoryRecordSize = 3u +// The size of the fixed part (device + counter_set + event_count +
// Convert the device name into a SWTrace string
std::vector<uint32_t> deviceNameBuffer;
- if (!StringToSwTraceString<SwTraceCharPolicy>(deviceName, deviceNameBuffer))
+ if (!arm::pipe::StringToSwTraceString<arm::pipe::SwTraceCharPolicy>(deviceName, deviceNameBuffer))
{
errorMessage = boost::str(boost::format("Cannot convert the name of device %1% (%2%) to an SWTrace string")
% deviceUid
// Convert the device name into a SWTrace namestring
std::vector<uint32_t> counterSetNameBuffer;
- if (!StringToSwTraceString<SwTraceNameCharPolicy>(counterSet->m_Name, counterSetNameBuffer))
+ if (!arm::pipe::StringToSwTraceString<arm::pipe::SwTraceNameCharPolicy>(counterSet->m_Name, counterSetNameBuffer))
{
errorMessage = boost::str(boost::format("Cannot convert the name of counter set %1% (%2%) to "
"an SWTrace namestring")
EventRecord& eventRecord,
std::string& errorMessage)
{
- using namespace boost::numeric;
-
ARMNN_ASSERT(counter);
uint16_t counterUid = counter->m_Uid;
// Convert the counter name into a SWTrace string
std::vector<uint32_t> counterNameBuffer;
- if (!StringToSwTraceString<SwTraceCharPolicy>(counterName, counterNameBuffer))
+ if (!arm::pipe::StringToSwTraceString<arm::pipe::SwTraceCharPolicy>(counterName, counterNameBuffer))
{
errorMessage = boost::str(boost::format("Cannot convert the name of counter %1% (name: %2%) "
"to an SWTrace string")
// Convert the counter description into a SWTrace string
std::vector<uint32_t> counterDescriptionBuffer;
- if (!StringToSwTraceString<SwTraceCharPolicy>(counterDescription, counterDescriptionBuffer))
+ if (!arm::pipe::StringToSwTraceString<arm::pipe::SwTraceCharPolicy>(counterDescription, counterDescriptionBuffer))
{
errorMessage = boost::str(boost::format("Cannot convert the description of counter %1% (description: %2%) "
"to an SWTrace string")
// The size of the description buffer in bytes
const uint32_t eventRecordWord7 = includeUnits ?
eventRecordWord6 +
- numeric_cast<uint32_t>(counterDescriptionBuffer.size()
+ armnn::numeric_cast<uint32_t>(counterDescriptionBuffer.size()
* uint32_t_size) :
0;
if (includeUnits)
{
// Convert the counter units into a SWTrace namestring
- if (!StringToSwTraceString<SwTraceNameCharPolicy>(counterUnits, counterUnitsBuffer))
+ if (!arm::pipe::StringToSwTraceString<arm::pipe::SwTraceNameCharPolicy>(counterUnits, counterUnitsBuffer))
{
errorMessage = boost::str(boost::format("Cannot convert the units of counter %1% (units: %2%) "
"to an SWTrace string")
void SendCounterPacket::SendCounterDirectoryPacket(const ICounterDirectory& counterDirectory)
{
- using namespace boost::numeric;
-
// Get the amount of data that needs to be put into the packet
const uint16_t categoryCount = counterDirectory.GetCategoryCount();
const uint16_t deviceCount = counterDirectory.GetDeviceCount();
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);
+ pointerTableOffset = armnn::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;
// Add the device record offset to the device records pointer table offset field
deviceRecordOffsets[deviceRecordOffsetIndex] = pointerTableOffset;
- pointerTableOffset += numeric_cast<uint32_t>(deviceRecord.size() * uint32_t_size);
+ pointerTableOffset += armnn::numeric_cast<uint32_t>(deviceRecord.size() * uint32_t_size);
deviceIndex++;
deviceRecordOffsetIndex++;
size_t counterSetIndex = 0;
size_t counterSetRecordOffsetIndex = 0;
- pointerTableOffset -= numeric_cast<uint32_t>(deviceCount * uint32_t_size);
+ pointerTableOffset -= armnn::numeric_cast<uint32_t>(deviceCount * uint32_t_size);
for (auto it = counterSets.begin(); it != counterSets.end(); it++)
{
const CounterSetPtr& counterSet = it->second;
// Add the counter set record offset to the counter set records pointer table offset field
counterSetRecordOffsets[counterSetRecordOffsetIndex] = pointerTableOffset;
- pointerTableOffset += numeric_cast<uint32_t>(counterSetRecord.size() * uint32_t_size);
+ pointerTableOffset += armnn::numeric_cast<uint32_t>(counterSetRecord.size() * uint32_t_size);
counterSetIndex++;
counterSetRecordOffsetIndex++;
size_t categoryIndex = 0;
size_t categoryRecordOffsetIndex = 0;
- pointerTableOffset -= numeric_cast<uint32_t>(counterSetCount * uint32_t_size);
+ pointerTableOffset -= armnn::numeric_cast<uint32_t>(counterSetCount * uint32_t_size);
for (auto it = categories.begin(); it != categories.end(); it++)
{
const CategoryPtr& category = *it;
// Add the category record offset to the category records pointer table offset field
categoryRecordOffsets[categoryRecordOffsetIndex] = pointerTableOffset;
- pointerTableOffset += numeric_cast<uint32_t>(categoryRecord.size() * uint32_t_size);
+ pointerTableOffset += armnn::numeric_cast<uint32_t>(categoryRecord.size() * uint32_t_size);
categoryIndex++;
categoryRecordOffsetIndex++;
// Packet header word 1:
// 0:31 [32] data_length: length of data, in bytes
- uint32_t packetHeaderWord1 = numeric_cast<uint32_t>(counterDirectoryPacketDataLength * uint32_t_size);
+ uint32_t packetHeaderWord1 = armnn::numeric_cast<uint32_t>(
+ counterDirectoryPacketDataLength * uint32_t_size);
// Create the packet header
uint32_t packetHeader[2]
// Body header word 3:
// 0:31 [32] counter_set_pointer_table_offset: offset to the counter_set_pointer_table
- const uint32_t bodyHeaderWord3 =
- numeric_cast<uint32_t>(deviceRecordOffsets.size() * uint32_t_size // The size of the
- + bodyHeaderSizeBytes); // device records pointer table
+ const uint32_t bodyHeaderWord3 = armnn::numeric_cast<uint32_t>(deviceRecordOffsets.size() *
+ uint32_t_size + // The size of the
+ bodyHeaderSizeBytes); // device records pointer table
// Body header word 4:
// 16:31 [16] categories_count: number of entries in the categories_pointer_table
// Body header word 3:
// 0:31 [32] categories_pointer_table_offset: offset to the categories_pointer_table
const uint32_t bodyHeaderWord5 =
- numeric_cast<uint32_t>(
+ armnn::numeric_cast<uint32_t>(
deviceRecordOffsets.size() * uint32_t_size + // The size of the device records
counterSetRecordOffsets.size() * uint32_t_size // pointer table, plus the size of
+ bodyHeaderSizeBytes); // the counter set pointer table
ARMNN_NO_CONVERSION_WARN_END
// Calculate the total size in bytes of the counter directory packet
- uint32_t totalSize = numeric_cast<uint32_t>(counterDirectoryPacketSize * uint32_t_size);
+ uint32_t totalSize = armnn::numeric_cast<uint32_t>(counterDirectoryPacketSize * uint32_t_size);
// Reserve space in the buffer for the packet
uint32_t reserved = 0;
for (uint32_t counterDirectoryPacketWord : counterDirectoryPacket)
{
WriteUint32(writeBuffer, offset, counterDirectoryPacketWord);
- offset += numeric_cast<uint32_t>(uint32_t_size);
+ offset += armnn::numeric_cast<uint32_t>(uint32_t_size);
}
m_BufferManager.Commit(writeBuffer, totalSize);
uint32_t packetClass = 0;
uint32_t packetType = 0;
uint32_t headerSize = 2 * uint32_t_size;
- uint32_t bodySize = uint64_t_size + numeric_cast<uint32_t>(values.size()) * (uint16_t_size + uint32_t_size);
+ uint32_t bodySize = uint64_t_size + armnn::numeric_cast<uint32_t>(values.size()) * (uint16_t_size + uint32_t_size);
uint32_t totalSize = headerSize + bodySize;
uint32_t offset = 0;
uint32_t reserved = 0;
uint32_t packetFamily = 0;
uint32_t packetId = 4;
uint32_t headerSize = 2 * uint32_t_size;
- uint32_t bodySize = uint32_t_size + numeric_cast<uint32_t>(selectedCounterIds.size()) * uint16_t_size;
+ uint32_t bodySize = uint32_t_size + armnn::numeric_cast<uint32_t>(selectedCounterIds.size()) * uint16_t_size;
uint32_t totalSize = headerSize + bodySize;
uint32_t offset = 0;
uint32_t reserved = 0;