aboutsummaryrefslogtreecommitdiff
path: root/src/profiling/SendTimelinePacket.cpp
diff options
context:
space:
mode:
authorSadik Armagan <sadik.armagan@arm.com>2019-10-24 10:26:05 +0100
committerJim Flynn Arm <jim.flynn@arm.com>2019-10-24 10:06:40 +0000
commit7bbdf9db051f40377a284a28375816e60349376d (patch)
treedc7d8442cecb2f23ca2f93c8535316ed5207be69 /src/profiling/SendTimelinePacket.cpp
parenta87698211b6aaab38424865d200534d96f55dcf2 (diff)
downloadarmnn-7bbdf9db051f40377a284a28375816e60349376d.tar.gz
IVGCVSW-3950 Create SendTimelinePacket interface and class
* Implemented ISendTimelinePacket interface and its implementation SendTimelinePacket * Implemented TimelinePacketWriterFactory * Implemented unit tests for SendTimelinePacket functions Signed-off-by: Sadik Armagan <sadik.armagan@arm.com> Change-Id: I0a47586437f99510394d4d94589dccfb397d38e5
Diffstat (limited to 'src/profiling/SendTimelinePacket.cpp')
-rw-r--r--src/profiling/SendTimelinePacket.cpp154
1 files changed, 154 insertions, 0 deletions
diff --git a/src/profiling/SendTimelinePacket.cpp b/src/profiling/SendTimelinePacket.cpp
new file mode 100644
index 0000000000..e6e5ee7d5b
--- /dev/null
+++ b/src/profiling/SendTimelinePacket.cpp
@@ -0,0 +1,154 @@
+//
+// Copyright © 2019 Arm Ltd. All rights reserved.
+// SPDX-License-Identifier: MIT
+//
+
+#include "SendTimelinePacket.hpp"
+
+namespace armnn
+{
+
+namespace profiling
+{
+
+void SendTimelinePacket::Commit()
+{
+ if (m_WriteBuffer != nullptr)
+ {
+ // 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)
+ {
+ uint32_t reserved = 0;
+
+ // 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 RuntimeException("No space left on buffer", CHECK_LOCATION());
+ }
+ m_BufferSize = reserved;
+ }
+}
+
+#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()); \
+}
+
+void SendTimelinePacket::SendTimelineEntityBinaryPacket(uint64_t profilingGuid)
+{
+ FORWARD_WRITE_BINARY_FUNC(WriteTimelineEntityBinaryPacket,
+ profilingGuid,
+ &m_WriteBuffer->GetWritableData()[m_Offset],
+ m_BufferSize);
+}
+
+void SendTimelinePacket::SendTimelineEventBinaryPacket(uint64_t timestamp, uint32_t threadId, uint64_t profilingGuid)
+{
+ FORWARD_WRITE_BINARY_FUNC(WriteTimelineEventBinaryPacket,
+ timestamp,
+ threadId,
+ profilingGuid,
+ &m_WriteBuffer->GetWritableData()[m_Offset],
+ m_BufferSize);
+}
+
+void SendTimelinePacket::SendTimelineEventClassBinaryPacket(uint64_t profilingGuid)
+{
+ FORWARD_WRITE_BINARY_FUNC(WriteTimelineEventClassBinaryPacket,
+ profilingGuid,
+ &m_WriteBuffer->GetWritableData()[m_Offset],
+ m_BufferSize);
+}
+
+void SendTimelinePacket::SendTimelineLabelBinaryPacket(uint64_t profilingGuid, const std::string& label)
+{
+ FORWARD_WRITE_BINARY_FUNC(WriteTimelineLabelBinaryPacket,
+ profilingGuid,
+ label,
+ &m_WriteBuffer->GetWritableData()[m_Offset],
+ m_BufferSize);
+}
+
+void SendTimelinePacket::SendTimelineRelationshipBinaryPacket(ProfilingRelationshipType relationshipType,
+ uint64_t relationshipGuid,
+ uint64_t headGuid,
+ uint64_t tailGuid)
+{
+ FORWARD_WRITE_BINARY_FUNC(WriteTimelineRelationshipBinaryPacket,
+ relationshipType,
+ relationshipGuid,
+ headGuid,
+ tailGuid,
+ &m_WriteBuffer->GetWritableData()[m_Offset],
+ m_BufferSize);
+}
+
+void SendTimelinePacket::SendTimelineMessageDirectoryPackage()
+{
+ try
+ {
+ // Reserve buffer if hasn't already reserved
+ ReserveBuffer();
+
+ unsigned int numberOfBytes = 0;
+ // Write to buffer
+ TimelinePacketStatus result = WriteTimelineMessageDirectoryPackage(&m_WriteBuffer->GetWritableData()[m_Offset],
+ m_BufferSize,
+ numberOfBytes);
+
+ if (result != armnn::profiling::TimelinePacketStatus::Ok)
+ {
+ throw RuntimeException("Error processing TimelineMessageDirectoryPackage.", CHECK_LOCATION());
+ }
+
+ // Commit the message
+ m_Offset += numberOfBytes;
+ m_BufferSize -= numberOfBytes;
+ m_BufferManager.Commit(m_WriteBuffer, m_Offset);
+ }
+ catch(...)
+ {
+ throw RuntimeException("Error processing TimelineMessageDirectoryPackage.", CHECK_LOCATION());
+ }
+}
+
+} // namespace profiling
+
+} // namespace armnn