blob: 9f20b9cb8070e832e9f0d312f57971e4ecd9d241 [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"
Jim Flynn27761832022-03-20 21:52:17 +00007
8#include <client/include/TimelineUtilityMethods.hpp>
Sadik Armaganb5f01b22019-09-18 17:29:00 +01009
Jim Flynnf9db3ef2022-03-08 21:23:44 +000010#include <common/include/ProfilingException.hpp>
Sadik Armaganb5f01b22019-09-18 17:29:00 +010011
Jan Eilers156113c2020-09-09 19:11:16 +010012#include <fmt/format.h>
Matteo Martincighd0613b52019-10-09 16:47:04 +010013
Cathal Corbett5aa9fd72022-02-25 15:33:28 +000014namespace arm
Sadik Armaganb5f01b22019-09-18 17:29:00 +010015{
16
Cathal Corbett5aa9fd72022-02-25 15:33:28 +000017namespace pipe
Sadik Armaganb5f01b22019-09-18 17:29:00 +010018{
19
Jim Flynnbbfe6032020-07-20 16:57:44 +010020void ConnectionAcknowledgedCommandHandler::operator()(const arm::pipe::Packet& packet)
Sadik Armaganb5f01b22019-09-18 17:29:00 +010021{
Matteo Martincighd0613b52019-10-09 16:47:04 +010022 ProfilingState currentState = m_StateMachine.GetCurrentState();
23 switch (currentState)
Sadik Armaganb5f01b22019-09-18 17:29:00 +010024 {
Matteo Martincighd0613b52019-10-09 16:47:04 +010025 case ProfilingState::Uninitialised:
26 case ProfilingState::NotConnected:
Jim Flynnf9db3ef2022-03-08 21:23:44 +000027 throw arm::pipe::ProfilingException(fmt::format("Connection Acknowledged Command Handler invoked while in an "
28 "wrong state: {}",
29 GetProfilingStateName(currentState)));
Matteo Martincighd0613b52019-10-09 16:47:04 +010030 case ProfilingState::WaitingForAck:
31 // Process the packet
32 if (!(packet.GetPacketFamily() == 0u && packet.GetPacketId() == 1u))
33 {
Jim Flynnf9db3ef2022-03-08 21:23:44 +000034 throw arm::pipe::InvalidArgumentException(fmt::format("Expected Packet family = 0, id = 1 but "
35 "received family = {}, id = {}",
36 packet.GetPacketFamily(),
37 packet.GetPacketId()));
Matteo Martincighd0613b52019-10-09 16:47:04 +010038 }
Matteo Martincighc2728f92019-10-07 12:35:21 +010039
Matteo Martincighd0613b52019-10-09 16:47:04 +010040 // Once a Connection Acknowledged packet has been received, move to the Active state immediately
41 m_StateMachine.TransitionToState(ProfilingState::Active);
Colm Donelan2ba48d22019-11-29 09:10:59 +000042 // Send the counter directory packet.
Keith Davis3201eea2019-10-24 17:30:41 +010043 m_SendCounterPacket.SendCounterDirectoryPacket(m_CounterDirectory);
Finn Williamsd7fcafa2020-04-23 17:55:18 +010044
45 if (m_TimelineEnabled)
46 {
47 m_SendTimelinePacket.SendTimelineMessageDirectoryPackage();
48 TimelineUtilityMethods::SendWellKnownLabelsAndEventClasses(m_SendTimelinePacket);
49 }
Finn Williamscf2ad552020-03-20 15:10:59 +000050
Jim Flynn6398a982020-05-27 17:05:21 +010051 if (m_BackendProfilingContext.has_value())
Finn Williamsfe5a24b2020-04-09 16:05:28 +010052 {
53 for (auto backendContext : m_BackendProfilingContext.value())
54 {
55 // Enable profiling on the backend and assert that it returns true
56 if(!backendContext.second->EnableProfiling(true))
57 {
Jim Flynnf9db3ef2022-03-08 21:23:44 +000058 throw arm::pipe::BackendProfilingException(
Cathal Corbett6f073722022-03-04 12:11:09 +000059 "Unable to enable profiling on Backend Id: " + backendContext.first);
Finn Williamsfe5a24b2020-04-09 16:05:28 +010060 }
61 }
62 }
63
Jim Flynn6398a982020-05-27 17:05:21 +010064 // At this point signal any external processes waiting on the profiling system
65 // to come up that profiling is fully active
66 m_ProfilingServiceStatus.NotifyProfilingServiceActive();
Matteo Martincighd0613b52019-10-09 16:47:04 +010067 break;
68 case ProfilingState::Active:
69 return; // NOP
70 default:
Jim Flynnf9db3ef2022-03-08 21:23:44 +000071 throw arm::pipe::ProfilingException(fmt::format("Unknown profiling service state: {}",
72 static_cast<int>(currentState)));
Matteo Martincighd0613b52019-10-09 16:47:04 +010073 }
Sadik Armaganb5f01b22019-09-18 17:29:00 +010074}
75
Cathal Corbett5aa9fd72022-02-25 15:33:28 +000076} // namespace pipe
Sadik Armaganb5f01b22019-09-18 17:29:00 +010077
Cathal Corbett5aa9fd72022-02-25 15:33:28 +000078} // namespace arm