blob: 2d2d2bd80d59812ecd8c9a827f8652658fad7b29 [file] [log] [blame]
Matteo Martincigh994b5342019-10-11 17:19:56 +01001//
Jim Flynnbbfe6032020-07-20 16:57:44 +01002// Copyright © 2019 Arm Ltd and Contributors. All rights reserved.
Matteo Martincigh994b5342019-10-11 17:19:56 +01003// SPDX-License-Identifier: MIT
4//
5
6#include "PerJobCounterSelectionCommandHandler.hpp"
Jim Flynnf9db3ef2022-03-08 21:23:44 +00007
8#include <common/include/CommonProfilingUtils.hpp>
Matteo Martincigh994b5342019-10-11 17:19:56 +01009
Jan Eilers156113c2020-09-09 19:11:16 +010010#include <fmt/format.h>
Matteo Martincigh994b5342019-10-11 17:19:56 +010011
Cathal Corbett5aa9fd72022-02-25 15:33:28 +000012namespace arm
Matteo Martincigh994b5342019-10-11 17:19:56 +010013{
14
Cathal Corbett5aa9fd72022-02-25 15:33:28 +000015namespace pipe
Matteo Martincigh994b5342019-10-11 17:19:56 +010016{
17
Jim Flynnbbfe6032020-07-20 16:57:44 +010018void PerJobCounterSelectionCommandHandler::operator()(const arm::pipe::Packet& packet)
Matteo Martincigh994b5342019-10-11 17:19:56 +010019{
20 ProfilingState currentState = m_StateMachine.GetCurrentState();
21 switch (currentState)
22 {
23 case ProfilingState::Uninitialised:
24 case ProfilingState::NotConnected:
25 case ProfilingState::WaitingForAck:
Jim Flynnf9db3ef2022-03-08 21:23:44 +000026 throw arm::pipe::ProfilingException(fmt::format(
Jan Eilers156113c2020-09-09 19:11:16 +010027 "Per-Job Counter Selection Command Handler invoked while in an incorrect state: {}",
28 GetProfilingStateName(currentState)));
Matteo Martincigh994b5342019-10-11 17:19:56 +010029 case ProfilingState::Active:
30 // Process the packet
31 if (!(packet.GetPacketFamily() == 0u && packet.GetPacketId() == 5u))
32 {
Jim Flynnf9db3ef2022-03-08 21:23:44 +000033 throw arm::pipe::InvalidArgumentException(fmt::format("Expected Packet family = 0, id = 5 but "
34 "received family = {}, id = {}",
35 packet.GetPacketFamily(),
36 packet.GetPacketId()));
Matteo Martincigh994b5342019-10-11 17:19:56 +010037 }
38
39 // Silently drop the packet
40
41 break;
42 default:
Jim Flynnf9db3ef2022-03-08 21:23:44 +000043 throw arm::pipe::ProfilingException(fmt::format("Unknown profiling service state: {}",
44 static_cast<int>(currentState)));
Matteo Martincigh994b5342019-10-11 17:19:56 +010045 }
46}
47
Cathal Corbett5aa9fd72022-02-25 15:33:28 +000048} // namespace pipe
Matteo Martincigh994b5342019-10-11 17:19:56 +010049
Cathal Corbett5aa9fd72022-02-25 15:33:28 +000050} // namespace arm