ArmNN  NotReleased
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(0u)
29  , m_BufferSize(0u)
30  {}
31 
33  void Commit() override;
34 
36  void SendTimelineEntityBinaryPacket(uint64_t profilingGuid) override;
37 
39  void SendTimelineEventBinaryPacket(uint64_t timestamp, std::thread::id threadId, uint64_t profilingGuid) override;
40 
42  void SendTimelineEventClassBinaryPacket(uint64_t profilingGuid) override;
43 
45  void SendTimelineLabelBinaryPacket(uint64_t profilingGuid, const std::string& label) override;
46 
49 
52  uint64_t relationshipGuid,
53  uint64_t headGuid,
54  uint64_t tailGuid) override;
55 private:
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_BufferSize;
66 };
67 
68 template <typename Func, typename ... Params>
69 void SendTimelinePacket::ForwardWriteBinaryFunction(Func& func, Params&& ... params)
70 {
71  try
72  {
73  ReserveBuffer();
74  BOOST_ASSERT(m_WriteBuffer);
75  unsigned int numberOfBytesWritten = 0;
76  while (true)
77  {
78  TimelinePacketStatus result = func(std::forward<Params>(params)...,
79  &m_WriteBuffer->GetWritableData()[m_Offset],
80  m_BufferSize,
81  numberOfBytesWritten);
82  switch (result)
83  {
85  Commit();
86  ReserveBuffer();
87  continue;
88 
90  throw RuntimeException("Error processing while sending TimelineBinaryPacket", CHECK_LOCATION());
91 
92  default:
93  m_Offset += numberOfBytesWritten;
94  m_BufferSize -= numberOfBytesWritten;
95  return;
96  }
97  }
98  }
99  catch (...)
100  {
101  throw RuntimeException("Error processing while sending TimelineBinaryPacket", CHECK_LOCATION());
102  }
103 }
104 
105 } // namespace profiling
106 
107 } // namespace armnn
void SendTimelineEntityBinaryPacket(uint64_t profilingGuid) override
Create and write a TimelineEntityBinaryPacket from the parameters to the buffer.
void SendTimelineLabelBinaryPacket(uint64_t profilingGuid, const std::string &label) override
Create and write a TimelineLabelBinaryPacket from the parameters to the buffer.
void SendTimelineEventClassBinaryPacket(uint64_t profilingGuid) override
Create and write a TimelineEventClassBinaryPacket from the parameters to the buffer.
std::unique_ptr< IPacketBuffer > IPacketBufferPtr
#define CHECK_LOCATION()
Definition: Exceptions.hpp:169
void SendTimelineMessageDirectoryPackage() override
Create and write a TimelineMessageDirectoryPackage in the buffer.
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.
SendTimelinePacket(IBufferManager &bufferManager)
void SendTimelineEventBinaryPacket(uint64_t timestamp, std::thread::id threadId, uint64_t profilingGuid) override
Create and write a TimelineEventBinaryPacket from the parameters to the buffer.
void Commit() override
Commits the current buffer and reset the member variables.