aboutsummaryrefslogtreecommitdiff
path: root/src/profiling/SendTimelinePacket.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/profiling/SendTimelinePacket.cpp')
-rw-r--r--src/profiling/SendTimelinePacket.cpp128
1 files changed, 47 insertions, 81 deletions
diff --git a/src/profiling/SendTimelinePacket.cpp b/src/profiling/SendTimelinePacket.cpp
index 707bfba5c4..d769b64a05 100644
--- a/src/profiling/SendTimelinePacket.cpp
+++ b/src/profiling/SendTimelinePacket.cpp
@@ -13,99 +13,68 @@ namespace profiling
void SendTimelinePacket::Commit()
{
- if (m_WriteBuffer != nullptr)
+ if (m_WriteBuffer == nullptr)
{
- // Commit the message
- m_BufferManager.Commit(m_WriteBuffer, m_Offset);
- m_WriteBuffer.reset(nullptr);
- m_Offset = 0;
- m_BufferSize = 0;
+ // Can't commit from a null buffer
+ return;
}
+
+ // Commit the message
+ m_BufferManager.Commit(m_WriteBuffer, m_Offset);
+ m_WriteBuffer.reset(nullptr);
+ m_Offset = 0;
+ m_BufferSize = 0;
}
void SendTimelinePacket::ReserveBuffer()
{
- if (m_WriteBuffer == nullptr)
+ if (m_WriteBuffer != nullptr)
{
- uint32_t reserved = 0;
+ // Buffer already reserved
+ return;
+ }
- // Reserve the buffer
- m_WriteBuffer = m_BufferManager.Reserve(MAX_METADATA_PACKET_LENGTH, reserved);
+ uint32_t reserved = 0;
- // Check if there is enough space in the buffer
- if (m_WriteBuffer == nullptr || reserved < m_Offset)
- {
- throw BufferExhaustion("No space left on buffer", CHECK_LOCATION());
- }
- m_BufferSize = reserved;
+ // Reserve the buffer
+ m_WriteBuffer = m_BufferManager.Reserve(MAX_METADATA_PACKET_LENGTH, reserved);
+
+ // Check if there is enough space in the buffer
+ if (m_WriteBuffer == nullptr || reserved < m_Offset)
+ {
+ throw BufferExhaustion("No space left on buffer", CHECK_LOCATION());
}
-}
-#define FORWARD_WRITE_BINARY_FUNC(func, ...) \
-try \
-{ \
- ReserveBuffer(); \
- unsigned int numberOfBytes = 0; \
- while (1) \
- { \
- TimelinePacketStatus result = func(__VA_ARGS__, numberOfBytes); \
- if (result == armnn::profiling::TimelinePacketStatus::BufferExhaustion) \
- { \
- Commit(); \
- ReserveBuffer(); \
- } \
- else if (result == armnn::profiling::TimelinePacketStatus::Error) \
- { \
- throw RuntimeException("Error processing while sending TimelineBinaryPacket.", CHECK_LOCATION()); \
- } \
- else \
- { \
- break; \
- } \
- } \
- m_Offset += numberOfBytes; \
- m_BufferSize -= numberOfBytes; \
-} \
-catch(...) \
-{ \
- throw RuntimeException("Error processing while sending TimelineBinaryPacket.", CHECK_LOCATION()); \
+ m_BufferSize = reserved;
}
void SendTimelinePacket::SendTimelineEntityBinaryPacket(uint64_t profilingGuid)
{
- FORWARD_WRITE_BINARY_FUNC(WriteTimelineEntityBinaryPacket,
- profilingGuid,
- &m_WriteBuffer->GetWritableData()[m_Offset],
- m_BufferSize);
+ ForwardWriteBinaryFunction(WriteTimelineEntityBinaryPacket,
+ profilingGuid);
}
void SendTimelinePacket::SendTimelineEventBinaryPacket(uint64_t timestamp,
std::thread::id threadId,
uint64_t profilingGuid)
{
- FORWARD_WRITE_BINARY_FUNC(WriteTimelineEventBinaryPacket,
- timestamp,
- threadId,
- profilingGuid,
- &m_WriteBuffer->GetWritableData()[m_Offset],
- m_BufferSize);
+ ForwardWriteBinaryFunction(WriteTimelineEventBinaryPacket,
+ timestamp,
+ threadId,
+ profilingGuid);
}
void SendTimelinePacket::SendTimelineEventClassBinaryPacket(uint64_t profilingGuid)
{
- FORWARD_WRITE_BINARY_FUNC(WriteTimelineEventClassBinaryPacket,
- profilingGuid,
- &m_WriteBuffer->GetWritableData()[m_Offset],
- m_BufferSize);
+ ForwardWriteBinaryFunction(WriteTimelineEventClassBinaryPacket,
+ profilingGuid);
}
void SendTimelinePacket::SendTimelineLabelBinaryPacket(uint64_t profilingGuid, const std::string& label)
{
- FORWARD_WRITE_BINARY_FUNC(WriteTimelineLabelBinaryPacket,
- profilingGuid,
- label,
- &m_WriteBuffer->GetWritableData()[m_Offset],
- m_BufferSize);
+ ForwardWriteBinaryFunction(WriteTimelineLabelBinaryPacket,
+ profilingGuid,
+ label);
}
void SendTimelinePacket::SendTimelineRelationshipBinaryPacket(ProfilingRelationshipType relationshipType,
@@ -113,41 +82,38 @@ void SendTimelinePacket::SendTimelineRelationshipBinaryPacket(ProfilingRelations
uint64_t headGuid,
uint64_t tailGuid)
{
- FORWARD_WRITE_BINARY_FUNC(WriteTimelineRelationshipBinaryPacket,
- relationshipType,
- relationshipGuid,
- headGuid,
- tailGuid,
- &m_WriteBuffer->GetWritableData()[m_Offset],
- m_BufferSize);
+ ForwardWriteBinaryFunction(WriteTimelineRelationshipBinaryPacket,
+ relationshipType,
+ relationshipGuid,
+ headGuid,
+ tailGuid);
}
void SendTimelinePacket::SendTimelineMessageDirectoryPackage()
{
try
{
- // Reserve buffer if hasn't already reserved
+ // Reserve buffer if it hasn't already been reserved
ReserveBuffer();
- unsigned int numberOfBytes = 0;
// Write to buffer
+ unsigned int numberOfBytesWritten = 0;
TimelinePacketStatus result = WriteTimelineMessageDirectoryPackage(&m_WriteBuffer->GetWritableData()[m_Offset],
m_BufferSize,
- numberOfBytes);
-
+ numberOfBytesWritten);
if (result != armnn::profiling::TimelinePacketStatus::Ok)
{
- throw RuntimeException("Error processing TimelineMessageDirectoryPackage.", CHECK_LOCATION());
+ throw RuntimeException("Error processing TimelineMessageDirectoryPackage", CHECK_LOCATION());
}
// Commit the message
- m_Offset += numberOfBytes;
- m_BufferSize -= numberOfBytes;
- m_BufferManager.Commit(m_WriteBuffer, m_Offset);
+ m_Offset += numberOfBytesWritten;
+ m_BufferSize -= numberOfBytesWritten;
+ Commit();
}
- catch(...)
+ catch (...)
{
- throw RuntimeException("Error processing TimelineMessageDirectoryPackage.", CHECK_LOCATION());
+ throw RuntimeException("Error processing TimelineMessageDirectoryPackage", CHECK_LOCATION());
}
}