blob: 7690573ccf26537ac5767a41253a3fde3ba63e70 [file] [log] [blame]
Sadik Armaganb5f01b22019-09-18 17:29:00 +01001//
2// Copyright © 2019 Arm Ltd. All rights reserved.
3// SPDX-License-Identifier: MIT
4//
5
6#include "ConnectionAcknowledgedCommandHandler.hpp"
Finn Williamscf2ad552020-03-20 15:10:59 +00007#include "TimelineUtilityMethods.hpp"
Sadik Armaganb5f01b22019-09-18 17:29:00 +01008
9#include <armnn/Exceptions.hpp>
10
Matteo Martincighd0613b52019-10-09 16:47:04 +010011#include <boost/format.hpp>
12
Sadik Armaganb5f01b22019-09-18 17:29:00 +010013namespace armnn
14{
15
16namespace profiling
17{
18
19void ConnectionAcknowledgedCommandHandler::operator()(const Packet& packet)
20{
Matteo Martincighd0613b52019-10-09 16:47:04 +010021 ProfilingState currentState = m_StateMachine.GetCurrentState();
22 switch (currentState)
Sadik Armaganb5f01b22019-09-18 17:29:00 +010023 {
Matteo Martincighd0613b52019-10-09 16:47:04 +010024 case ProfilingState::Uninitialised:
25 case ProfilingState::NotConnected:
Matteo Martincighe8485382019-10-10 14:08:21 +010026 throw RuntimeException(boost::str(boost::format("Connection Acknowledged Command Handler invoked while in an "
Matteo Martincighd0613b52019-10-09 16:47:04 +010027 "wrong state: %1%")
28 % GetProfilingStateName(currentState)));
29 case ProfilingState::WaitingForAck:
30 // Process the packet
31 if (!(packet.GetPacketFamily() == 0u && packet.GetPacketId() == 1u))
32 {
33 throw armnn::InvalidArgumentException(boost::str(boost::format("Expected Packet family = 0, id = 1 but "
34 "received family = %1%, id = %2%")
35 % packet.GetPacketFamily()
36 % packet.GetPacketId()));
37 }
Matteo Martincighc2728f92019-10-07 12:35:21 +010038
Matteo Martincighd0613b52019-10-09 16:47:04 +010039 // Once a Connection Acknowledged packet has been received, move to the Active state immediately
40 m_StateMachine.TransitionToState(ProfilingState::Active);
Colm Donelan2ba48d22019-11-29 09:10:59 +000041 // Send the counter directory packet.
Keith Davis3201eea2019-10-24 17:30:41 +010042 m_SendCounterPacket.SendCounterDirectoryPacket(m_CounterDirectory);
Finn Williamsd7fcafa2020-04-23 17:55:18 +010043
44 if (m_TimelineEnabled)
45 {
46 m_SendTimelinePacket.SendTimelineMessageDirectoryPackage();
47 TimelineUtilityMethods::SendWellKnownLabelsAndEventClasses(m_SendTimelinePacket);
48 }
Finn Williamscf2ad552020-03-20 15:10:59 +000049
Finn Williamsfe5a24b2020-04-09 16:05:28 +010050 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
Matteo Martincighd0613b52019-10-09 16:47:04 +010063 break;
64 case ProfilingState::Active:
65 return; // NOP
66 default:
67 throw RuntimeException(boost::str(boost::format("Unknown profiling service state: %1%")
68 % static_cast<int>(currentState)));
69 }
Sadik Armaganb5f01b22019-09-18 17:29:00 +010070}
71
72} // namespace profiling
73
74} // namespace armnn
75