blob: 7fa3785a43016df145a7d74fcca5dd14899d1c03 [file] [log] [blame]
Sadik Armaganb5f01b22019-09-18 17:29:00 +01001//
Jim Flynn6398a982020-05-27 17:05:21 +01002// Copyright © 2019 Arm Ltd and Contributors. All rights reserved.
Sadik Armaganb5f01b22019-09-18 17:29:00 +01003// 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
Jim Flynnbbfe6032020-07-20 16:57:44 +010019void ConnectionAcknowledgedCommandHandler::operator()(const arm::pipe::Packet& packet)
Sadik Armaganb5f01b22019-09-18 17:29:00 +010020{
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
Jim Flynn6398a982020-05-27 17:05:21 +010050 if (m_BackendProfilingContext.has_value())
Finn Williamsfe5a24b2020-04-09 16:05:28 +010051 {
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
Jim Flynn6398a982020-05-27 17:05:21 +010063 // 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();
Matteo Martincighd0613b52019-10-09 16:47:04 +010066 break;
67 case ProfilingState::Active:
68 return; // NOP
69 default:
70 throw RuntimeException(boost::str(boost::format("Unknown profiling service state: %1%")
71 % static_cast<int>(currentState)));
72 }
Sadik Armaganb5f01b22019-09-18 17:29:00 +010073}
74
75} // namespace profiling
76
77} // namespace armnn
78