ArmNN
 21.02
ConnectionAcknowledgedCommandHandler.cpp
Go to the documentation of this file.
1 //
2 // Copyright © 2019 Arm Ltd and Contributors. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5 
8 
9 #include <armnn/Exceptions.hpp>
10 
11 #include <fmt/format.h>
12 
13 namespace armnn
14 {
15 
16 namespace profiling
17 {
18 
19 void ConnectionAcknowledgedCommandHandler::operator()(const arm::pipe::Packet& packet)
20 {
21  ProfilingState currentState = m_StateMachine.GetCurrentState();
22  switch (currentState)
23  {
26  throw RuntimeException(fmt::format("Connection Acknowledged Command Handler invoked while in an "
27  "wrong state: {}",
28  GetProfilingStateName(currentState)));
30  // Process the packet
31  if (!(packet.GetPacketFamily() == 0u && packet.GetPacketId() == 1u))
32  {
33  throw armnn::InvalidArgumentException(fmt::format("Expected Packet family = 0, id = 1 but "
34  "received family = {}, id = {}",
35  packet.GetPacketFamily(),
36  packet.GetPacketId()));
37  }
38 
39  // Once a Connection Acknowledged packet has been received, move to the Active state immediately
41  // Send the counter directory packet.
42  m_SendCounterPacket.SendCounterDirectoryPacket(m_CounterDirectory);
43 
44  if (m_TimelineEnabled)
45  {
46  m_SendTimelinePacket.SendTimelineMessageDirectoryPackage();
48  }
49 
50  if (m_BackendProfilingContext.has_value())
51  {
52  for (auto backendContext : m_BackendProfilingContext.value())
53  {
54  // Enable profiling on the backend and assert that it returns true
55  if(!backendContext.second->EnableProfiling(true))
56  {
58  "Unable to enable profiling on Backend Id: " + backendContext.first.Get());
59  }
60  }
61  }
62 
63  // At this point signal any external processes waiting on the profiling system
64  // to come up that profiling is fully active
65  m_ProfilingServiceStatus.NotifyProfilingServiceActive();
66  break;
68  return; // NOP
69  default:
70  throw RuntimeException(fmt::format("Unknown profiling service state: {}",
71  static_cast<int>(currentState)));
72  }
73 }
74 
75 } // namespace profiling
76 
77 } // namespace armnn
78 
Copyright (c) 2021 ARM Limited and Contributors.
bool has_value() const noexcept
Definition: Optional.hpp:53
void TransitionToState(ProfilingState newState)
static void SendWellKnownLabelsAndEventClasses(ISendTimelinePacket &timelinePacket)
virtual void SendCounterDirectoryPacket(const ICounterDirectory &counterDirectory)=0
Create and write a CounterDirectoryPacket from the parameters to the buffer.
virtual void SendTimelineMessageDirectoryPackage()=0
Create and write a TimelineMessageDirectoryPackage in the buffer.
constexpr char const * GetProfilingStateName(ProfilingState state)