blob: 8f78ae63f08e7f78eb6a74b0707e61ab0d11a0ee [file] [log] [blame]
Narumol Prangnawarat48033692019-09-20 12:04:55 +01001//
2// Copyright © 2019 Arm Ltd. All rights reserved.
3// SPDX-License-Identifier: MIT
4//
5
6#include "RequestCounterDirectoryCommandHandler.hpp"
7
Matteo Martincigh8efc5002019-10-10 14:30:29 +01008#include <boost/format.hpp>
Matteo Martincighd0613b52019-10-09 16:47:04 +01009
Narumol Prangnawarat48033692019-09-20 12:04:55 +010010namespace armnn
11{
12
13namespace profiling
14{
15
Jim Flynnbbfe6032020-07-20 16:57:44 +010016void RequestCounterDirectoryCommandHandler::operator()(const arm::pipe::Packet& packet)
Narumol Prangnawarat48033692019-09-20 12:04:55 +010017{
Matteo Martincigh8efc5002019-10-10 14:30:29 +010018 ProfilingState currentState = m_StateMachine.GetCurrentState();
19 switch (currentState)
20 {
21 case ProfilingState::Uninitialised:
22 case ProfilingState::NotConnected:
23 case ProfilingState::WaitingForAck:
Matteo Martincighe8485382019-10-10 14:08:21 +010024 throw RuntimeException(boost::str(boost::format("Request Counter Directory Comand Handler invoked while in an "
Matteo Martincigh8efc5002019-10-10 14:30:29 +010025 "wrong state: %1%")
26 % GetProfilingStateName(currentState)));
27 case ProfilingState::Active:
28 // Process the packet
29 if (!(packet.GetPacketFamily() == 0u && packet.GetPacketId() == 3u))
30 {
31 throw armnn::InvalidArgumentException(boost::str(boost::format("Expected Packet family = 0, id = 3 but "
32 "received family = %1%, id = %2%")
33 % packet.GetPacketFamily()
34 % packet.GetPacketId()));
35 }
Narumol Prangnawarat48033692019-09-20 12:04:55 +010036
Matteo Martincigh9723d022019-11-13 10:56:41 +000037 // Send all the packet required for the handshake with the external profiling service
Matteo Martincigh8efc5002019-10-10 14:30:29 +010038 m_SendCounterPacket.SendCounterDirectoryPacket(m_CounterDirectory);
Matteo Martincigh9723d022019-11-13 10:56:41 +000039 m_SendTimelinePacket.SendTimelineMessageDirectoryPackage();
Matteo Martincigh8efc5002019-10-10 14:30:29 +010040
Matteo Martincigh8efc5002019-10-10 14:30:29 +010041 break;
42 default:
43 throw RuntimeException(boost::str(boost::format("Unknown profiling service state: %1%")
44 % static_cast<int>(currentState)));
45 }
Narumol Prangnawarat48033692019-09-20 12:04:55 +010046}
47
48} // namespace profiling
49
Matteo Martincighd0613b52019-10-09 16:47:04 +010050} // namespace armnn