blob: 995562fb3f13c823312db0e58258c61c4d333d80 [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);
Matteo Martincighcdfb9412019-11-08 11:23:06 +000043 m_SendTimelinePacket.SendTimelineMessageDirectoryPackage();
Finn Williamscf2ad552020-03-20 15:10:59 +000044 TimelineUtilityMethods::SendWellKnownLabelsAndEventClasses(m_SendTimelinePacket);
45
Finn Williamsfe5a24b2020-04-09 16:05:28 +010046 if(m_BackendProfilingContext.has_value())
47 {
48 for (auto backendContext : m_BackendProfilingContext.value())
49 {
50 // Enable profiling on the backend and assert that it returns true
51 if(!backendContext.second->EnableProfiling(true))
52 {
53 throw BackendProfilingException(
54 "Unable to enable profiling on Backend Id: " + backendContext.first.Get());
55 }
56 }
57 }
58
Matteo Martincighd0613b52019-10-09 16:47:04 +010059 break;
60 case ProfilingState::Active:
61 return; // NOP
62 default:
63 throw RuntimeException(boost::str(boost::format("Unknown profiling service state: %1%")
64 % static_cast<int>(currentState)));
65 }
Sadik Armaganb5f01b22019-09-18 17:29:00 +010066}
67
68} // namespace profiling
69
70} // namespace armnn
71