m_AvailableList.reserve(numberOfBuffers);
for (unsigned int i = 0; i < numberOfBuffers; ++i)
{
- std::unique_ptr<IPacketBuffer> buffer = std::make_unique<PacketBuffer>(maxPacketSize);
+ IPacketBufferPtr buffer = std::make_unique<PacketBuffer>(maxPacketSize);
m_AvailableList.emplace_back(std::move(buffer));
}
m_ReadableList.reserve(numberOfBuffers);
}
-std::unique_ptr<IPacketBuffer> BufferManager::Reserve(unsigned int requestedSize, unsigned int& reservedSize)
+IPacketBufferPtr BufferManager::Reserve(unsigned int requestedSize, unsigned int& reservedSize)
{
reservedSize = 0;
std::unique_lock<std::mutex> availableListLock(m_AvailableMutex, std::defer_lock);
availableListLock.unlock();
return nullptr;
}
- std::unique_ptr<IPacketBuffer> buffer = std::move(m_AvailableList.back());
+ IPacketBufferPtr buffer = std::move(m_AvailableList.back());
m_AvailableList.pop_back();
availableListLock.unlock();
reservedSize = requestedSize;
return buffer;
}
-void BufferManager::Commit(std::unique_ptr<IPacketBuffer>& packetBuffer, unsigned int size)
+void BufferManager::Commit(IPacketBufferPtr& packetBuffer, unsigned int size)
{
std::unique_lock<std::mutex> readableListLock(m_ReadableMutex, std::defer_lock);
packetBuffer->Commit(size);
m_ReadDataAvailable.notify_one();
}
-void BufferManager::Release(std::unique_ptr<IPacketBuffer>& packetBuffer)
+void BufferManager::Release(IPacketBufferPtr& packetBuffer)
{
std::unique_lock<std::mutex> availableListLock(m_AvailableMutex, std::defer_lock);
packetBuffer->Release();
availableListLock.unlock();
}
-std::unique_ptr<IPacketBuffer> BufferManager::GetReadableBuffer()
+IPacketBufferPtr BufferManager::GetReadableBuffer()
{
std::unique_lock<std::mutex> readableListLock(m_ReadableMutex);
if (!m_ReadableList.empty())
{
- std::unique_ptr<IPacketBuffer> buffer = std::move(m_ReadableList.back());
+ IPacketBufferPtr buffer = std::move(m_ReadableList.back());
m_ReadableList.pop_back();
readableListLock.unlock();
return buffer;
return nullptr;
}
-void BufferManager::MarkRead(std::unique_ptr<IPacketBuffer>& packetBuffer)
+void BufferManager::MarkRead(IPacketBufferPtr& packetBuffer)
{
std::unique_lock<std::mutex> availableListLock(m_AvailableMutex, std::defer_lock);
packetBuffer->MarkRead();
~BufferManager() {}
- std::unique_ptr<IPacketBuffer> Reserve(unsigned int requestedSize, unsigned int& reservedSize) override;
+ IPacketBufferPtr Reserve(unsigned int requestedSize, unsigned int& reservedSize) override;
- void Commit(std::unique_ptr<IPacketBuffer>& packetBuffer, unsigned int size) override;
+ void Commit(IPacketBufferPtr& packetBuffer, unsigned int size) override;
- void Release(std::unique_ptr<IPacketBuffer>& packetBuffer) override;
+ void Release(IPacketBufferPtr& packetBuffer) override;
- std::unique_ptr<IPacketBuffer> GetReadableBuffer() override;
+ IPacketBufferPtr GetReadableBuffer() override;
- void MarkRead(std::unique_ptr<IPacketBuffer>& packetBuffer) override;
+ void MarkRead(IPacketBufferPtr& packetBuffer) override;
private:
// Maximum buffer size
unsigned int m_MaxBufferSize;
// List of available packet buffers
- std::vector<std::unique_ptr<IPacketBuffer>> m_AvailableList;
+ std::vector<IPacketBufferPtr> m_AvailableList;
// List of readable packet buffers
- std::vector<std::unique_ptr<IPacketBuffer>> m_ReadableList;
+ std::vector<IPacketBufferPtr> m_ReadableList;
// Mutex for available packet buffer list
std::mutex m_AvailableMutex;
public:
virtual ~IBufferManager() {}
- virtual std::unique_ptr<IPacketBuffer> Reserve(unsigned int requestedSize, unsigned int& reservedSize) = 0;
+ virtual IPacketBufferPtr Reserve(unsigned int requestedSize, unsigned int& reservedSize) = 0;
- virtual void Commit(std::unique_ptr<IPacketBuffer>& packetBuffer, unsigned int size) = 0;
+ virtual void Commit(IPacketBufferPtr& packetBuffer, unsigned int size) = 0;
- virtual void Release(std::unique_ptr<IPacketBuffer>& packetBuffer) = 0;
+ virtual void Release(IPacketBufferPtr& packetBuffer) = 0;
- virtual std::unique_ptr<IPacketBuffer> GetReadableBuffer() = 0;
+ virtual IPacketBufferPtr GetReadableBuffer() = 0;
- virtual void MarkRead(std::unique_ptr<IPacketBuffer>& packetBuffer) = 0;
+ virtual void MarkRead(IPacketBufferPtr& packetBuffer) = 0;
};
} // namespace profiling
#pragma once
+#include <memory>
+
namespace armnn
{
virtual unsigned char* GetWritableData() = 0;
};
+using IPacketBufferPtr = std::unique_ptr<IPacketBuffer>;
+
} // namespace profiling
-} // namespace armnn
\ No newline at end of file
+} // namespace armnn
return counterUids;
}
-void WriteUint64(const std::unique_ptr<IPacketBuffer>& packetBuffer, unsigned int offset, uint64_t value)
+void WriteUint64(const IPacketBufferPtr& packetBuffer, unsigned int offset, uint64_t value)
{
BOOST_ASSERT(packetBuffer);
WriteUint64(packetBuffer->GetWritableData(), offset, value);
}
-void WriteUint32(const std::unique_ptr<IPacketBuffer>& packetBuffer, unsigned int offset, uint32_t value)
+void WriteUint32(const IPacketBufferPtr& packetBuffer, unsigned int offset, uint32_t value)
{
BOOST_ASSERT(packetBuffer);
WriteUint32(packetBuffer->GetWritableData(), offset, value);
}
-void WriteUint16(const std::unique_ptr<IPacketBuffer>& packetBuffer, unsigned int offset, uint16_t value)
+void WriteUint16(const IPacketBufferPtr& packetBuffer, unsigned int offset, uint16_t value)
{
BOOST_ASSERT(packetBuffer);
buffer[offset + 1] = static_cast<unsigned char>((value >> 8) & 0xFF);
}
-uint64_t ReadUint64(const std::unique_ptr<IPacketBuffer>& packetBuffer, unsigned int offset)
+uint64_t ReadUint64(const IPacketBufferPtr& packetBuffer, unsigned int offset)
{
BOOST_ASSERT(packetBuffer);
return ReadUint64(packetBuffer->GetReadableData(), offset);
}
-uint32_t ReadUint32(const std::unique_ptr<IPacketBuffer>& packetBuffer, unsigned int offset)
+uint32_t ReadUint32(const IPacketBufferPtr& packetBuffer, unsigned int offset)
{
BOOST_ASSERT(packetBuffer);
return ReadUint32(packetBuffer->GetReadableData(), offset);
}
-uint16_t ReadUint16(const std::unique_ptr<IPacketBuffer>& packetBuffer, unsigned int offset)
+uint16_t ReadUint16(const IPacketBufferPtr& packetBuffer, unsigned int offset)
{
BOOST_ASSERT(packetBuffer);
return ReadUint16(packetBuffer->GetReadableData(), offset);
}
-uint8_t ReadUint8(const std::unique_ptr<IPacketBuffer>& packetBuffer, unsigned int offset)
+uint8_t ReadUint8(const IPacketBufferPtr& packetBuffer, unsigned int offset)
{
BOOST_ASSERT(packetBuffer);
}
// Read TimelineMessageDirectoryPacket from given IPacketBuffer and offset
-SwTraceMessage ReadSwTraceMessage(const std::unique_ptr<IPacketBuffer>& packetBuffer, unsigned int& offset)
+SwTraceMessage ReadSwTraceMessage(const IPacketBufferPtr& packetBuffer, unsigned int& offset)
{
BOOST_ASSERT(packetBuffer);
std::vector<uint16_t> GetNextCounterUids(uint16_t cores);
-void WriteUint64(const std::unique_ptr<IPacketBuffer>& packetBuffer, unsigned int offset, uint64_t value);
+void WriteUint64(const IPacketBufferPtr& packetBuffer, unsigned int offset, uint64_t value);
-void WriteUint32(const std::unique_ptr<IPacketBuffer>& packetBuffer, unsigned int offset, uint32_t value);
+void WriteUint32(const IPacketBufferPtr& packetBuffer, unsigned int offset, uint32_t value);
-void WriteUint16(const std::unique_ptr<IPacketBuffer>& packetBuffer, unsigned int offset, uint16_t value);
+void WriteUint16(const IPacketBufferPtr& packetBuffer, unsigned int offset, uint16_t value);
void WriteUint64(unsigned char* buffer, unsigned int offset, uint64_t value);
void WriteUint16(unsigned char* buffer, unsigned int offset, uint16_t value);
-uint64_t ReadUint64(const std::unique_ptr<IPacketBuffer>& packetBuffer, unsigned int offset);
+uint64_t ReadUint64(const IPacketBufferPtr& packetBuffer, unsigned int offset);
-uint32_t ReadUint32(const std::unique_ptr<IPacketBuffer>& packetBuffer, unsigned int offset);
+uint32_t ReadUint32(const IPacketBufferPtr& packetBuffer, unsigned int offset);
-uint16_t ReadUint16(const std::unique_ptr<IPacketBuffer>& packetBuffer, unsigned int offset);
+uint16_t ReadUint16(const IPacketBufferPtr& packetBuffer, unsigned int offset);
-uint8_t ReadUint8(const std::unique_ptr<IPacketBuffer>& packetBuffer, unsigned int offset);
+uint8_t ReadUint8(const IPacketBufferPtr& packetBuffer, unsigned int offset);
uint64_t ReadUint64(unsigned const char* buffer, unsigned int offset);
uint32_t CalculateSizeOfPaddedSwString(const std::string& str);
-SwTraceMessage ReadSwTraceMessage(const std::unique_ptr<IPacketBuffer>& packetBuffer, unsigned int& offset);
+SwTraceMessage ReadSwTraceMessage(const IPacketBufferPtr& packetBuffer, unsigned int& offset);
TimelinePacketStatus WriteTimelineLabelBinaryPacket(uint64_t profilingGuid,
const std::string& label,
uint32_t offset = 0;
uint32_t reserved = 0;
- std::unique_ptr<IPacketBuffer> writeBuffer = m_BufferManager.Reserve(totalSize, reserved);
+ IPacketBufferPtr writeBuffer = m_BufferManager.Reserve(totalSize, reserved);
if (writeBuffer == nullptr || reserved < totalSize)
{
// Reserve space in the buffer for the packet
uint32_t reserved = 0;
- std::unique_ptr<IPacketBuffer> writeBuffer = m_BufferManager.Reserve(totalSize, reserved);
+ IPacketBufferPtr writeBuffer = m_BufferManager.Reserve(totalSize, reserved);
if (writeBuffer == nullptr || reserved < totalSize)
{
uint32_t offset = 0;
uint32_t reserved = 0;
- std::unique_ptr<IPacketBuffer> writeBuffer = m_BufferManager.Reserve(totalSize, reserved);
+ IPacketBufferPtr writeBuffer = m_BufferManager.Reserve(totalSize, reserved);
if (writeBuffer == nullptr || reserved < totalSize)
{
uint32_t offset = 0;
uint32_t reserved = 0;
- std::unique_ptr<IPacketBuffer> writeBuffer = m_BufferManager.Reserve(totalSize, reserved);
+ IPacketBufferPtr writeBuffer = m_BufferManager.Reserve(totalSize, reserved);
if (writeBuffer == nullptr || reserved < totalSize)
{
void SendCounterPacket::FlushBuffer(IProfilingConnection& profilingConnection, bool notifyWatchers)
{
// Get the first available readable buffer
- std::unique_ptr<IPacketBuffer> packetBuffer = m_BufferManager.GetReadableBuffer();
+ IPacketBufferPtr packetBuffer = m_BufferManager.GetReadableBuffer();
// Initialize the flag that indicates whether at least a packet has been sent
bool packetsSent = false;
}
template <typename ExceptionType>
- void CancelOperationAndThrow(std::unique_ptr<IPacketBuffer>& writerBuffer, const std::string& errorMessage)
+ void CancelOperationAndThrow(IPacketBufferPtr& writerBuffer, const std::string& errorMessage)
{
if (std::is_same<ExceptionType, armnn::profiling::BufferExhaustion>::value)
{
void ReserveBuffer();
IBufferManager& m_BufferManager;
- std::unique_ptr<IPacketBuffer> m_WriteBuffer;
+ IPacketBufferPtr m_WriteBuffer;
unsigned int m_Offset;
unsigned int m_BufferSize;
};
BOOST_AUTO_TEST_CASE(PacketBufferTest0)
{
- std::unique_ptr<IPacketBuffer> packetBuffer = std::make_unique<PacketBuffer>(512);
+ IPacketBufferPtr packetBuffer = std::make_unique<PacketBuffer>(512);
BOOST_TEST(packetBuffer->GetSize() == 0);
BOOST_AUTO_TEST_CASE(PacketBufferTest1)
{
- std::unique_ptr<IPacketBuffer> packetBuffer = std::make_unique<PacketBuffer>(512);
+ IPacketBufferPtr packetBuffer = std::make_unique<PacketBuffer>(512);
BOOST_TEST(packetBuffer->GetSize() == 0);
}
BOOST_AUTO_TEST_CASE(PacketBufferReleaseTest) {
- std::unique_ptr<IPacketBuffer> packetBuffer = std::make_unique<PacketBuffer>(512);
+ IPacketBufferPtr packetBuffer = std::make_unique<PacketBuffer>(512);
BOOST_TEST(packetBuffer->GetSize() == 0);
BOOST_AUTO_TEST_CASE(PacketBufferCommitErrorTest)
{
- std::unique_ptr<IPacketBuffer> packetBuffer = std::make_unique<PacketBuffer>(8);
+ IPacketBufferPtr packetBuffer = std::make_unique<PacketBuffer>(8);
// Cannot commit data bigger than the max size of the buffer
BOOST_CHECK_THROW(packetBuffer->Commit(16);, armnn::RuntimeException);
~MockBufferManager() {}
- std::unique_ptr<IPacketBuffer> Reserve(unsigned int requestedSize, unsigned int& reservedSize) override
+ IPacketBufferPtr Reserve(unsigned int requestedSize, unsigned int& reservedSize) override
{
if (requestedSize > m_BufferSize)
{
return std::move(m_Buffer);
}
- void Commit(std::unique_ptr<IPacketBuffer>& packetBuffer, unsigned int size) override
+ void Commit(IPacketBufferPtr& packetBuffer, unsigned int size) override
{
packetBuffer->Commit(size);
m_Buffer = std::move(packetBuffer);
}
- std::unique_ptr<IPacketBuffer> GetReadableBuffer() override
+ IPacketBufferPtr GetReadableBuffer() override
{
return std::move(m_Buffer);
}
- void Release(std::unique_ptr<IPacketBuffer>& packetBuffer) override
+ void Release(IPacketBufferPtr& packetBuffer) override
{
packetBuffer->Release();
m_Buffer = std::move(packetBuffer);
}
- void MarkRead(std::unique_ptr<IPacketBuffer>& packetBuffer) override
+ void MarkRead(IPacketBufferPtr& packetBuffer) override
{
packetBuffer->MarkRead();
m_Buffer = std::move(packetBuffer);
private:
unsigned int m_BufferSize;
- std::unique_ptr<IPacketBuffer> m_Buffer;
+ IPacketBufferPtr m_Buffer;
};
class MockStreamCounterBuffer : public IBufferManager
{
public:
- using IPacketBufferPtr = std::unique_ptr<IPacketBuffer>;
-
MockStreamCounterBuffer(unsigned int maxBufferSize = 4096)
: m_MaxBufferSize(maxBufferSize)
, m_BufferList()
{
std::string message("SendStreamMetaDataPacket");
unsigned int reserved = 0;
- std::unique_ptr<IPacketBuffer> buffer = m_BufferManager.Reserve(1024, reserved);
+ IPacketBufferPtr buffer = m_BufferManager.Reserve(1024, reserved);
memcpy(buffer->GetWritableData(), message.c_str(), static_cast<unsigned int>(message.size()) + 1);
m_BufferManager.Commit(buffer, reserved);
}
{
std::string message("SendCounterDirectoryPacket");
unsigned int reserved = 0;
- std::unique_ptr<IPacketBuffer> buffer = m_BufferManager.Reserve(1024, reserved);
+ IPacketBufferPtr buffer = m_BufferManager.Reserve(1024, reserved);
memcpy(buffer->GetWritableData(), message.c_str(), static_cast<unsigned int>(message.size()) + 1);
m_BufferManager.Commit(buffer, reserved);
}
{
std::string message("SendPeriodicCounterCapturePacket");
unsigned int reserved = 0;
- std::unique_ptr<IPacketBuffer> buffer = m_BufferManager.Reserve(1024, reserved);
+ IPacketBufferPtr buffer = m_BufferManager.Reserve(1024, reserved);
memcpy(buffer->GetWritableData(), message.c_str(), static_cast<unsigned int>(message.size()) + 1);
m_BufferManager.Commit(buffer, reserved);
}
{
std::string message("SendPeriodicCounterSelectionPacket");
unsigned int reserved = 0;
- std::unique_ptr<IPacketBuffer> buffer = m_BufferManager.Reserve(1024, reserved);
+ IPacketBufferPtr buffer = m_BufferManager.Reserve(1024, reserved);
memcpy(buffer->GetWritableData(), message.c_str(), static_cast<unsigned int>(message.size()) + 1);
m_BufferManager.Commit(buffer, reserved);
}