blob: 601f8541fff506138d6548facd4f9fa547ac7d42 [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
Jan Eilers156113c2020-09-09 19:11:16 +01008#include <fmt/format.h>
Matteo Martincighd0613b52019-10-09 16:47:04 +01009
Cathal Corbett5aa9fd72022-02-25 15:33:28 +000010namespace arm
Narumol Prangnawarat48033692019-09-20 12:04:55 +010011{
12
Cathal Corbett5aa9fd72022-02-25 15:33:28 +000013namespace pipe
Narumol Prangnawarat48033692019-09-20 12:04:55 +010014{
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:
Cathal Corbett5aa9fd72022-02-25 15:33:28 +000024 throw armnn::RuntimeException(fmt::format("Request Counter Directory Comand Handler invoked while in an "
Jan Eilers156113c2020-09-09 19:11:16 +010025 "wrong state: {}",
26 GetProfilingStateName(currentState)));
Matteo Martincigh8efc5002019-10-10 14:30:29 +010027 case ProfilingState::Active:
28 // Process the packet
29 if (!(packet.GetPacketFamily() == 0u && packet.GetPacketId() == 3u))
30 {
Jan Eilers156113c2020-09-09 19:11:16 +010031 throw armnn::InvalidArgumentException(fmt::format("Expected Packet family = 0, id = 3 but "
32 "received family = {}, id = {}",
33 packet.GetPacketFamily(),
34 packet.GetPacketId()));
Matteo Martincigh8efc5002019-10-10 14:30:29 +010035 }
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:
Cathal Corbett5aa9fd72022-02-25 15:33:28 +000043 throw armnn::RuntimeException(fmt::format("Unknown profiling service state: {}",
Jan Eilers156113c2020-09-09 19:11:16 +010044 static_cast<int>(currentState)));
Matteo Martincigh8efc5002019-10-10 14:30:29 +010045 }
Narumol Prangnawarat48033692019-09-20 12:04:55 +010046}
47
Cathal Corbett5aa9fd72022-02-25 15:33:28 +000048} // namespace pipe
Narumol Prangnawarat48033692019-09-20 12:04:55 +010049
Cathal Corbett5aa9fd72022-02-25 15:33:28 +000050} // namespace arm