namespace profiling
{
+class Category
+{
+public:
+ std::string m_Name;
+};
+
class Device
{
public:
std::string m_Units;
};
-class Category
+class CounterSet
{
public:
+ uint16_t m_Uid;
std::string m_Name;
+ uint16_t m_Count;
};
class CounterDirectory final
virtual void SendStreamMetaDataPacket() = 0;
/// Create and write a CounterDirectoryPacket from the parameters to the buffer.
- virtual void SendCounterDirectoryPacket(const Category& category, const std::vector<Counter>& counters) = 0;
+ virtual void SendCounterDirectoryPacket(const CounterDirectory& counterDirectory) = 0;
/// Create and write a PeriodicCounterCapturePacket from the parameters to the buffer.
virtual void SendPeriodicCounterCapturePacket(uint64_t timestamp, const IndexValuePairsVector& values) = 0;
{
public:
Packet(uint32_t header, uint32_t length, const char* data)
- : m_Header(header), m_Length(length), m_Data(data)
- {
- m_PacketId = ((header >> 16) & 1023);
- m_PacketFamily = (header >> 26);
-
- if (length == 0)
- {
- if (m_Data != nullptr)
- {
- throw armnn::Exception("Data should be null");
- }
- }
- };
+ : m_Header(header),
+ m_Length(length),
+ m_Data(data)
+ {
+ m_PacketId = ((header >> 16) & 1023);
+ m_PacketFamily = (header >> 26);
+
+ if (length == 0 && m_Data != nullptr)
+ {
+ throw armnn::InvalidArgumentException("Data should be null when length is zero");
+ }
+ }
uint32_t GetHeader() const;
uint32_t GetPacketFamily() const;
{
BOOST_ASSERT(buffer);
- buffer[offset] = static_cast<unsigned char>(value & 0xFF);
+ buffer[offset] = static_cast<unsigned char>(value & 0xFF);
buffer[offset + 1] = static_cast<unsigned char>((value >> 8) & 0xFF);
buffer[offset + 2] = static_cast<unsigned char>((value >> 16) & 0xFF);
buffer[offset + 3] = static_cast<unsigned char>((value >> 24) & 0xFF);
void WriteUint16(unsigned char* buffer, unsigned int offset, uint16_t value)
{
- BOOST_ASSERT(buffer != nullptr);
+ BOOST_ASSERT(buffer);
- buffer[offset] = static_cast<unsigned char>(value & 0xFF);
+ buffer[offset] = static_cast<unsigned char>(value & 0xFF);
buffer[offset + 1] = static_cast<unsigned char>((value >> 8) & 0xFF);
}
BOOST_ASSERT(buffer);
uint32_t value = 0;
- value = static_cast<uint32_t>(buffer[offset]);
+ value = static_cast<uint32_t>(buffer[offset]);
value |= static_cast<uint32_t>(buffer[offset + 1]) << 8;
value |= static_cast<uint32_t>(buffer[offset + 2]) << 16;
value |= static_cast<uint32_t>(buffer[offset + 3]) << 24;
BOOST_ASSERT(buffer);
uint32_t value = 0;
- value = static_cast<uint32_t>(buffer[offset]);
+ value = static_cast<uint32_t>(buffer[offset]);
value |= static_cast<uint32_t>(buffer[offset + 1]) << 8;
return static_cast<uint16_t>(value);
}
} // namespace profiling
-} // namespace armnn
\ No newline at end of file
+} // namespace armnn
#include <boost/numeric/conversion/cast.hpp>
#include <boost/core/ignore_unused.hpp>
-#include <iostream>
-#include <unistd.h>
-#include <string.h>
+#include <cstring>
namespace armnn
{
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));
+ CancelOperationAndThrow<BufferExhaustion>(
+ 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.");
+ CancelOperationAndThrow<RuntimeException>("Error reserving buffer memory.");
}
try
// Pool
- if (infoSize) {
+ if (infoSize)
+ {
memcpy(&writeBuffer[offset], info.c_str(), infoSize);
offset += infoSize;
}
- if (hardwareVersionSize) {
+ if (hardwareVersionSize)
+ {
memcpy(&writeBuffer[offset], hardwareVersion.c_str(), hardwareVersionSize);
offset += hardwareVersionSize;
}
- if (softwareVersionSize) {
+ if (softwareVersionSize)
+ {
memcpy(&writeBuffer[offset], softwareVersion.c_str(), softwareVersionSize);
offset += softwareVersionSize;
}
- if (processNameSize) {
+ if (processNameSize)
+ {
memcpy(&writeBuffer[offset], processName.c_str(), processNameSize);
offset += processNameSize;
}
- if (packetVersionEntries) {
+ if (packetVersionEntries)
+ {
// Packet Version Count
WriteUint32(writeBuffer, offset, packetVersionEntries << 16);
}
catch(...)
{
- // Cancel the operation.
- m_Buffer.Commit(0);
- throw RuntimeException("Error processing packet.");
+ CancelOperationAndThrow<RuntimeException>("Error processing packet.");
}
m_Buffer.Commit(totalSize);
}
-void SendCounterPacket::SendCounterDirectoryPacket(const Category& category, const std::vector<Counter>& counters)
+void SendCounterPacket::SendCounterDirectoryPacket(const CounterDirectory& counterDirectory)
{
throw armnn::UnimplementedException();
}
if (reserved < totalSize)
{
- // Cancel the operation.
- m_Buffer.Commit(0);
- throw profiling::BufferExhaustion(
- boost::str(boost::format("No space left in buffer. Unable to reserve (%1%) bytes.") % totalSize));
+ CancelOperationAndThrow<BufferExhaustion>(
+ 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.");
+ CancelOperationAndThrow<RuntimeException>("Error reserving buffer memory.");
}
// Create header.
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.")
+ CancelOperationAndThrow<BufferExhaustion>(
+ 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.");
+ CancelOperationAndThrow<RuntimeException>("Error reserving buffer memory.");
}
// Create header.
} // namespace profiling
-} // namespace armnn
\ No newline at end of file
+} // namespace armnn
public:
using IndexValuePairsVector = std::vector<std::pair<uint16_t, uint32_t>>;
- SendCounterPacket(IBufferWrapper& buffer) : m_Buffer(buffer), m_ReadyToRead(false) {};
+ SendCounterPacket(IBufferWrapper& buffer)
+ : m_Buffer(buffer),
+ m_ReadyToRead(false)
+ {}
void SendStreamMetaDataPacket() override;
- void SendCounterDirectoryPacket(const Category& category, const std::vector<Counter>& counters) override;
+ void SendCounterDirectoryPacket(const CounterDirectory& counterDirectory) override;
void SendPeriodicCounterCapturePacket(uint64_t timestamp, const IndexValuePairsVector& values) override;
static const unsigned int MAX_METADATA_PACKET_LENGTH = 4096;
private:
+ template <typename ExceptionType>
+ void CancelOperationAndThrow(const std::string& errorMessage)
+ {
+ // Cancel the operation
+ m_Buffer.Commit(0);
+
+ // Throw a runtime exception with the given error message
+ throw ExceptionType(errorMessage);
+ }
+
IBufferWrapper& m_Buffer;
bool m_ReadyToRead;
};
memcpy(buffer, message.c_str(), static_cast<unsigned int>(message.size()) + 1);
}
- void SendCounterDirectoryPacket(const Category& category, const std::vector<Counter>& counters) override
+ void SendCounterDirectoryPacket(const CounterDirectory& counterDirectory) override
{
std::string message("SendCounterDirectoryPacket");
unsigned int reserved = 0;
BOOST_TEST(strcmp(buffer, "SendStreamMetaDataPacket") == 0);
- Category category;
- std::vector<Counter> counters;
- sendCounterPacket.SendCounterDirectoryPacket(category, counters);
+ CounterDirectory counterDirectory(1, "counter_directory", 0, 0, 0);
+ sendCounterPacket.SendCounterDirectoryPacket(counterDirectory);
BOOST_TEST(strcmp(buffer, "SendCounterDirectoryPacket") == 0);
uint32_t capturePeriod = 1000;
std::vector<uint16_t> selectedCounterIds;
BOOST_CHECK_THROW(sendPacket1.SendPeriodicCounterSelectionPacket(capturePeriod, selectedCounterIds),
- armnn::RuntimeException);
+ armnn::profiling::BufferExhaustion);
// Packet without any counters
MockBuffer mockBuffer2(512);
// Error no space left in buffer
MockBuffer mockBuffer1(10);
SendCounterPacket sendPacket1(mockBuffer1);
- BOOST_CHECK_THROW(sendPacket1.SendStreamMetaDataPacket(), armnn::RuntimeException);
+ BOOST_CHECK_THROW(sendPacket1.SendStreamMetaDataPacket(), armnn::profiling::BufferExhaustion);
// Full metadata packet