• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // Copyright © 2019 Arm Ltd and Contributors. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5 
6 #include "ConnectionAcknowledgedCommandHandler.hpp"
7 #include "TimelineUtilityMethods.hpp"
8 
9 #include <armnn/Exceptions.hpp>
10 
11 #include <fmt/format.h>
12 
13 namespace armnn
14 {
15 
16 namespace profiling
17 {
18 
operator ()(const arm::pipe::Packet & packet)19 void ConnectionAcknowledgedCommandHandler::operator()(const arm::pipe::Packet& packet)
20 {
21     ProfilingState currentState = m_StateMachine.GetCurrentState();
22     switch (currentState)
23     {
24     case ProfilingState::Uninitialised:
25     case ProfilingState::NotConnected:
26         throw RuntimeException(fmt::format("Connection Acknowledged Command Handler invoked while in an "
27                                            "wrong state: {}",
28                                            GetProfilingStateName(currentState)));
29     case ProfilingState::WaitingForAck:
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
40         m_StateMachine.TransitionToState(ProfilingState::Active);
41         // Send the counter directory packet.
42         m_SendCounterPacket.SendCounterDirectoryPacket(m_CounterDirectory);
43 
44         if (m_TimelineEnabled)
45         {
46             m_SendTimelinePacket.SendTimelineMessageDirectoryPackage();
47             TimelineUtilityMethods::SendWellKnownLabelsAndEventClasses(m_SendTimelinePacket);
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                 {
57                     throw BackendProfilingException(
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;
67     case ProfilingState::Active:
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 
79