blob: 2dbab3c1d59885d64186d62b99a76641fe55838c [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
16void RequestCounterDirectoryCommandHandler::operator()(const Packet& packet)
17{
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
41 // Notify the Send Thread that new data is available in the Counter Stream Buffer
42 m_SendCounterPacket.SetReadyToRead();
43
44 break;
45 default:
46 throw RuntimeException(boost::str(boost::format("Unknown profiling service state: %1%")
47 % static_cast<int>(currentState)));
48 }
Narumol Prangnawarat48033692019-09-20 12:04:55 +010049}
50
51} // namespace profiling
52
Matteo Martincighd0613b52019-10-09 16:47:04 +010053} // namespace armnn