aboutsummaryrefslogtreecommitdiff
path: root/src/profiling/SendCounterPacket.cpp
diff options
context:
space:
mode:
authorFerran Balaguer <ferran.balaguer@arm.com>2019-09-04 16:47:34 +0100
committerFerran Balaguer Arm <ferran.balaguer@arm.com>2019-09-09 10:28:39 +0000
commit47d0fe98ca6ab3ba1d21b0971d3009a287974442 (patch)
tree04f22e9db6f98d21b3c172a3473e9c9f230b657b /src/profiling/SendCounterPacket.cpp
parent9e0deb76fc25be6a0e898f53a115af3aeed9e5b8 (diff)
downloadarmnn-47d0fe98ca6ab3ba1d21b0971d3009a287974442.tar.gz
IVGCVSW-3690 Implement SendCounterPacket.SendStreamMetaDataPacket() function
Signed-off-by: Ferran Balaguer <ferran.balaguer@arm.com> Change-Id: I9e034b0caaff5371fadfdba20fdbe3171d4cd2e6
Diffstat (limited to 'src/profiling/SendCounterPacket.cpp')
-rw-r--r--src/profiling/SendCounterPacket.cpp143
1 files changed, 142 insertions, 1 deletions
diff --git a/src/profiling/SendCounterPacket.cpp b/src/profiling/SendCounterPacket.cpp
index 645b79196e..61d32da0bc 100644
--- a/src/profiling/SendCounterPacket.cpp
+++ b/src/profiling/SendCounterPacket.cpp
@@ -11,8 +11,11 @@
#include <boost/format.hpp>
#include <boost/numeric/conversion/cast.hpp>
+#include <boost/core/ignore_unused.hpp>
+#include <iostream>
#include <unistd.h>
+#include <string.h>
namespace armnn
{
@@ -22,9 +25,147 @@ namespace profiling
using boost::numeric_cast;
+const unsigned int SendCounterPacket::PIPE_MAGIC;
+const unsigned int SendCounterPacket::MAX_METADATA_PACKET_LENGTH;
+
void SendCounterPacket::SendStreamMetaDataPacket()
{
- throw armnn::UnimplementedException();
+ std::string info(GetSoftwareInfo());
+ std::string hardwareVersion(GetHardwareVersion());
+ std::string softwareVersion(GetSoftwareVersion());
+ std::string processName = GetProcessName().substr(0, 60);
+
+ uint32_t infoSize = numeric_cast<uint32_t>(info.size()) > 0 ? numeric_cast<uint32_t>(info.size()) + 1 : 0;
+ uint32_t hardwareVersionSize = numeric_cast<uint32_t>(hardwareVersion.size()) > 0 ?
+ numeric_cast<uint32_t>(hardwareVersion.size()) + 1 : 0;
+ uint32_t softwareVersionSize = numeric_cast<uint32_t>(softwareVersion.size()) > 0 ?
+ numeric_cast<uint32_t>(softwareVersion.size()) + 1 : 0;
+ uint32_t processNameSize = numeric_cast<uint32_t>(processName.size()) > 0 ?
+ numeric_cast<uint32_t>(processName.size()) + 1 : 0;
+
+ uint32_t sizeUint32 = numeric_cast<uint32_t>(sizeof(uint32_t));
+
+ uint32_t headerSize = 2 * sizeUint32;
+ uint32_t bodySize = 10 * sizeUint32;
+ 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)
+ uint32_t packetVersionEntries = 5;
+
+ uint32_t payloadSize = numeric_cast<uint32_t>(infoSize + hardwareVersionSize + softwareVersionSize +
+ processNameSize + packetVersionCountSize +
+ (packetVersionEntries * 2 * sizeUint32));
+
+ uint32_t totalSize = headerSize + bodySize + payloadSize;
+ uint32_t offset = 0;
+ uint32_t reserved = 0;
+
+ unsigned char *writeBuffer = m_Buffer.Reserve(totalSize, reserved);
+
+ if (reserved < totalSize)
+ {
+ // Cancel the operation.
+ m_Buffer.Commit(0);
+ throw RuntimeException(boost::str(boost::format("No space left in buffer. Unable to reserve (%1%) bytes.")
+ % totalSize));
+ }
+
+ if (writeBuffer == nullptr)
+ {
+ // Cancel the operation.
+ m_Buffer.Commit(0);
+ throw RuntimeException("Error reserving buffer memory.");
+ }
+
+ try
+ {
+ // Create header
+
+ WriteUint32(writeBuffer, offset, 0);
+ offset += sizeUint32;
+ WriteUint32(writeBuffer, offset, totalSize - headerSize);
+
+ // Packet body
+
+ offset += sizeUint32;
+ WriteUint32(writeBuffer, offset, PIPE_MAGIC); // pipe_magic
+ offset += sizeUint32;
+ WriteUint32(writeBuffer, offset, EncodeVersion(1, 0, 0)); // stream_metadata_version
+ offset += sizeUint32;
+ WriteUint32(writeBuffer, offset, MAX_METADATA_PACKET_LENGTH); // max_data_length
+ offset += sizeUint32;
+ WriteUint32(writeBuffer, offset, numeric_cast<uint32_t>(getpid())); // pid
+ offset += sizeUint32;
+ uint32_t poolOffset = bodySize;
+ WriteUint32(writeBuffer, offset, infoSize ? poolOffset : 0); // offset_info
+ offset += sizeUint32;
+ poolOffset += infoSize;
+ WriteUint32(writeBuffer, offset, hardwareVersionSize ? poolOffset : 0); // offset_hw_version
+ offset += sizeUint32;
+ poolOffset += hardwareVersionSize;
+ WriteUint32(writeBuffer, offset, softwareVersionSize ? poolOffset : 0); // offset_sw_version
+ offset += sizeUint32;
+ poolOffset += softwareVersionSize;
+ WriteUint32(writeBuffer, offset, processNameSize ? poolOffset : 0); // offset_process_name
+ offset += sizeUint32;
+ poolOffset += processNameSize;
+ WriteUint32(writeBuffer, offset, packetVersionEntries ? poolOffset : 0); // offset_packet_version_table
+ offset += sizeUint32;
+ WriteUint32(writeBuffer, offset, 0); // reserved
+ offset += sizeUint32;
+
+ // Pool
+
+ if (infoSize) {
+ memcpy(&writeBuffer[offset], info.c_str(), infoSize);
+ offset += infoSize;
+ }
+
+ if (hardwareVersionSize) {
+ memcpy(&writeBuffer[offset], hardwareVersion.c_str(), hardwareVersionSize);
+ offset += hardwareVersionSize;
+ }
+
+ if (softwareVersionSize) {
+ memcpy(&writeBuffer[offset], softwareVersion.c_str(), softwareVersionSize);
+ offset += softwareVersionSize;
+ }
+
+ if (processNameSize) {
+ memcpy(&writeBuffer[offset], processName.c_str(), processNameSize);
+ offset += processNameSize;
+ }
+
+ if (packetVersionEntries) {
+ // Packet Version Count
+ WriteUint32(writeBuffer, offset, packetVersionEntries << 16);
+
+ // Packet Version Entries
+ uint32_t packetFamily = 0;
+ uint32_t packetId = 0;
+
+ offset += sizeUint32;
+ for (uint32_t i = 0; i < packetVersionEntries; ++i) {
+ WriteUint32(writeBuffer, offset, ((packetFamily & 0x3F) << 26) | ((packetId++ & 0x3FF) << 16));
+ offset += sizeUint32;
+ WriteUint32(writeBuffer, offset, EncodeVersion(1, 0, 0));
+ offset += sizeUint32;
+ }
+ }
+ }
+ catch(...)
+ {
+ // Cancel the operation.
+ m_Buffer.Commit(0);
+ throw RuntimeException("Error processing packet.");
+ }
+
+ m_Buffer.Commit(totalSize);
}
void SendCounterPacket::SendCounterDirectoryPacket(const Category& category, const std::vector<Counter>& counters)