ArmNN
 20.02
SendTimelinePacket.hpp
Go to the documentation of this file.
1 //
2 // Copyright © 2019 Arm Ltd. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5 
6 #pragma once
7 
8 #include "IBufferManager.hpp"
10 #include "ProfilingUtils.hpp"
11 
12 #include <boost/assert.hpp>
13 
14 #include <memory>
15 
16 namespace armnn
17 {
18 
19 namespace profiling
20 {
21 
23 {
24 public:
26  : m_BufferManager(bufferManager)
27  , m_WriteBuffer(nullptr)
28  , m_Offset(8u)
29  , m_RemainingBufferSize(0u)
30  {}
31 
32  /// Commits the current buffer and reset the member variables
33  void Commit() override;
34 
35  /// Create and write a TimelineEntityBinaryPacket from the parameters to the buffer.
36  void SendTimelineEntityBinaryPacket(uint64_t profilingGuid) override;
37 
38  /// Create and write a TimelineEventBinaryPacket from the parameters to the buffer.
39  void SendTimelineEventBinaryPacket(uint64_t timestamp, std::thread::id threadId, uint64_t profilingGuid) override;
40 
41  /// Create and write a TimelineEventClassBinaryPacket from the parameters to the buffer.
42  void SendTimelineEventClassBinaryPacket(uint64_t profilingGuid) override;
43 
44  /// Create and write a TimelineLabelBinaryPacket from the parameters to the buffer.
45  void SendTimelineLabelBinaryPacket(uint64_t profilingGuid, const std::string& label) override;
46 
47  /// Create and write a TimelineMessageDirectoryPackage in the buffer
49 
50  /// Create and write a TimelineRelationshipBinaryPacket from the parameters to the buffer.
52  uint64_t relationshipGuid,
53  uint64_t headGuid,
54  uint64_t tailGuid) override;
55 private:
56  /// Reserves maximum packet size from buffer
57  void ReserveBuffer();
58 
59  template <typename Func, typename ... Params>
60  void ForwardWriteBinaryFunction(Func& func, Params&& ... params);
61 
62  IBufferManager& m_BufferManager;
63  IPacketBufferPtr m_WriteBuffer;
64  unsigned int m_Offset;
65  unsigned int m_RemainingBufferSize;
66 
67  const unsigned int m_uint32_t_size = sizeof(uint32_t);
68 
69  std::pair<uint32_t, uint32_t> m_PacketHeader;
70  uint32_t m_PacketDataLength;
71 
72  bool m_DirectoryPackage = false;
73 };
74 
75 template<typename Func, typename ... Params>
76 void SendTimelinePacket::ForwardWriteBinaryFunction(Func& func, Params&& ... params)
77 {
78  try
79  {
80  ReserveBuffer();
81  BOOST_ASSERT(m_WriteBuffer);
82  unsigned int numberOfBytesWritten = 0;
83  // Header will be prepended to the buffer on Commit()
84  while ( true )
85  {
86  TimelinePacketStatus result = func(std::forward<Params>(params)...,
87  &m_WriteBuffer->GetWritableData()[m_Offset],
88  m_RemainingBufferSize,
89  numberOfBytesWritten);
90  switch ( result )
91  {
93  Commit();
94  ReserveBuffer();
95  continue;
96 
98  throw RuntimeException("Error processing while sending TimelineBinaryPacket",
99  CHECK_LOCATION());
100 
101  default:
102  m_Offset += numberOfBytesWritten;
103  m_RemainingBufferSize -= numberOfBytesWritten;
104  return;
105  }
106  }
107  }
108  catch ( ... )
109  {
110  throw RuntimeException("Error processing while sending TimelineBinaryPacket", CHECK_LOCATION());
111  }
112 }
113 
114 } // namespace profiling
115 
116 } // namespace armnn
void SendTimelineMessageDirectoryPackage() override
Create and write a TimelineMessageDirectoryPackage in the buffer.
void SendTimelineLabelBinaryPacket(uint64_t profilingGuid, const std::string &label) override
Create and write a TimelineLabelBinaryPacket from the parameters to the buffer.
void SendTimelineEntityBinaryPacket(uint64_t profilingGuid) override
Create and write a TimelineEntityBinaryPacket from the parameters to the buffer.
void SendTimelineEventClassBinaryPacket(uint64_t profilingGuid) override
Create and write a TimelineEventClassBinaryPacket from the parameters to the buffer.
Copyright (c) 2020 ARM Limited.
void Commit() override
Commits the current buffer and reset the member variables.
#define CHECK_LOCATION()
Definition: Exceptions.hpp:192
void SendTimelineEventBinaryPacket(uint64_t timestamp, std::thread::id threadId, uint64_t profilingGuid) override
Create and write a TimelineEventBinaryPacket from the parameters to the buffer.
SendTimelinePacket(IBufferManager &bufferManager)
virtual void SendTimelineRelationshipBinaryPacket(ProfilingRelationshipType relationshipType, uint64_t relationshipGuid, uint64_t headGuid, uint64_t tailGuid) override
Create and write a TimelineRelationshipBinaryPacket from the parameters to the buffer.
std::unique_ptr< IPacketBuffer > IPacketBufferPtr