ArmNN
 20.05
TestTimelinePacketHandler.cpp
Go to the documentation of this file.
1 //
2 // Copyright © 2020 Arm Ltd. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5 
8 
10 
11 #include <chrono>
12 #include <iostream>
13 #include <sstream>
14 
15 namespace armnn
16 {
17 
18 namespace profiling
19 {
20 
22 {
23  std::vector<uint32_t> headers;
24  headers.push_back(m_DirectoryHeader); // message directory
25  headers.push_back(m_MessageHeader); // message
26  return headers;
27 }
28 
29 void TestTimelinePacketHandler::HandlePacket(const Packet& packet)
30 {
31  if (packet.GetHeader() == m_DirectoryHeader)
32  {
33  ProcessDirectoryPacket(packet);
34  }
35  else if (packet.GetHeader() == m_MessageHeader)
36  {
37  ProcessMessagePacket(packet);
38  }
39  else
40  {
41  std::stringstream ss;
42  ss << "Received a packet with unknown header [" << packet.GetHeader() << "]";
43  throw armnn::Exception(ss.str());
44  }
45 }
46 
48 {
49  m_Connection->Close();
50 }
51 
53 {
54  std::unique_lock<std::mutex> lck(m_InferenceCompletedMutex);
55 
56  auto start = std::chrono::high_resolution_clock::now();
57  // Here we we will go back to sleep after a spurious wake up if
58  // m_InferenceCompleted is not yet true.
59  if (!m_InferenceCompletedConditionVariable.wait_for(lck,
60  std::chrono::milliseconds(timeout),
61  [&]{return m_InferenceCompleted == true;}))
62  {
63  auto finish = std::chrono::high_resolution_clock::now();
64  std::chrono::duration<double, std::milli> elapsed = finish - start;
65  std::stringstream ss;
66  ss << "Timed out waiting on inference completion for " << elapsed.count() << " ms";
67  throw armnn::TimeoutException(ss.str());
68  }
69  return;
70 }
71 
73 {
74  { // only lock when we are updating the inference completed variable
75  std::unique_lock<std::mutex> lck(m_InferenceCompletedMutex);
76  m_InferenceCompleted = true;
77  }
78  m_InferenceCompletedConditionVariable.notify_one();
79 }
80 
81 void TestTimelinePacketHandler::ProcessDirectoryPacket(const Packet& packet)
82 {
83  m_DirectoryDecoder(packet);
84 }
85 
86 void TestTimelinePacketHandler::ProcessMessagePacket(const Packet& packet)
87 {
88  m_Decoder(packet);
89 }
90 
91 // TimelineMessageDecoder functions
93 {
94  m_TimelineModel.AddEntity(entity.m_Guid);
96 }
97 
99  const ITimelineDecoder::EventClass& eventClass)
100 {
101  // for the moment terminate the run here so we can get this code
102  // onto master prior to a major re-organisation
103  if (m_PacketHandler != nullptr)
104  {
105  m_PacketHandler->SetInferenceComplete();
106  }
107  IgnoreUnused(eventClass);
109 }
110 
112 {
113  IgnoreUnused(event);
115 }
116 
118 {
119  m_TimelineModel.AddLabel(label);
121 }
122 
124  const ITimelineDecoder::Relationship& relationship)
125 {
126  m_TimelineModel.AddRelationship(relationship);
128 }
129 
130 } // namespace profiling
131 
132 } // namespace armnn
virtual TimelineStatus CreateRelationship(const Relationship &) override
virtual TimelineStatus CreateEvent(const Event &) override
virtual TimelineStatus CreateLabel(const Label &) override
virtual void HandlePacket(const Packet &packet) override
process the packet
Copyright (c) 2020 ARM Limited.
void IgnoreUnused(Ts &&...)
virtual std::vector< uint32_t > GetHeadersAccepted() override
void AddRelationship(const ITimelineDecoder::Relationship &relationship)
Base class for all ArmNN exceptions so that users can filter to just those.
Definition: Exceptions.hpp:46
virtual TimelineStatus CreateEventClass(const EventClass &) override
virtual TimelineStatus CreateEntity(const Entity &) override
void AddLabel(const ITimelineDecoder::Label &label)