Sadik Armagan | b5f01b2 | 2019-09-18 17:29:00 +0100 | [diff] [blame] | 1 | // |
Jim Flynn | 6398a98 | 2020-05-27 17:05:21 +0100 | [diff] [blame] | 2 | // Copyright © 2019 Arm Ltd and Contributors. All rights reserved. |
Sadik Armagan | b5f01b2 | 2019-09-18 17:29:00 +0100 | [diff] [blame] | 3 | // SPDX-License-Identifier: MIT |
| 4 | // |
| 5 | |
| 6 | #include "ConnectionAcknowledgedCommandHandler.hpp" |
Jim Flynn | 2776183 | 2022-03-20 21:52:17 +0000 | [diff] [blame] | 7 | |
| 8 | #include <client/include/TimelineUtilityMethods.hpp> |
Sadik Armagan | b5f01b2 | 2019-09-18 17:29:00 +0100 | [diff] [blame] | 9 | |
Jim Flynn | f9db3ef | 2022-03-08 21:23:44 +0000 | [diff] [blame] | 10 | #include <common/include/ProfilingException.hpp> |
Sadik Armagan | b5f01b2 | 2019-09-18 17:29:00 +0100 | [diff] [blame] | 11 | |
Jan Eilers | 156113c | 2020-09-09 19:11:16 +0100 | [diff] [blame] | 12 | #include <fmt/format.h> |
Matteo Martincigh | d0613b5 | 2019-10-09 16:47:04 +0100 | [diff] [blame] | 13 | |
Cathal Corbett | 5aa9fd7 | 2022-02-25 15:33:28 +0000 | [diff] [blame] | 14 | namespace arm |
Sadik Armagan | b5f01b2 | 2019-09-18 17:29:00 +0100 | [diff] [blame] | 15 | { |
| 16 | |
Cathal Corbett | 5aa9fd7 | 2022-02-25 15:33:28 +0000 | [diff] [blame] | 17 | namespace pipe |
Sadik Armagan | b5f01b2 | 2019-09-18 17:29:00 +0100 | [diff] [blame] | 18 | { |
| 19 | |
Jim Flynn | bbfe603 | 2020-07-20 16:57:44 +0100 | [diff] [blame] | 20 | void ConnectionAcknowledgedCommandHandler::operator()(const arm::pipe::Packet& packet) |
Sadik Armagan | b5f01b2 | 2019-09-18 17:29:00 +0100 | [diff] [blame] | 21 | { |
Matteo Martincigh | d0613b5 | 2019-10-09 16:47:04 +0100 | [diff] [blame] | 22 | ProfilingState currentState = m_StateMachine.GetCurrentState(); |
| 23 | switch (currentState) |
Sadik Armagan | b5f01b2 | 2019-09-18 17:29:00 +0100 | [diff] [blame] | 24 | { |
Matteo Martincigh | d0613b5 | 2019-10-09 16:47:04 +0100 | [diff] [blame] | 25 | case ProfilingState::Uninitialised: |
| 26 | case ProfilingState::NotConnected: |
Jim Flynn | f9db3ef | 2022-03-08 21:23:44 +0000 | [diff] [blame] | 27 | throw arm::pipe::ProfilingException(fmt::format("Connection Acknowledged Command Handler invoked while in an " |
| 28 | "wrong state: {}", |
| 29 | GetProfilingStateName(currentState))); |
Matteo Martincigh | d0613b5 | 2019-10-09 16:47:04 +0100 | [diff] [blame] | 30 | case ProfilingState::WaitingForAck: |
| 31 | // Process the packet |
| 32 | if (!(packet.GetPacketFamily() == 0u && packet.GetPacketId() == 1u)) |
| 33 | { |
Jim Flynn | f9db3ef | 2022-03-08 21:23:44 +0000 | [diff] [blame] | 34 | throw arm::pipe::InvalidArgumentException(fmt::format("Expected Packet family = 0, id = 1 but " |
| 35 | "received family = {}, id = {}", |
| 36 | packet.GetPacketFamily(), |
| 37 | packet.GetPacketId())); |
Matteo Martincigh | d0613b5 | 2019-10-09 16:47:04 +0100 | [diff] [blame] | 38 | } |
Matteo Martincigh | c2728f9 | 2019-10-07 12:35:21 +0100 | [diff] [blame] | 39 | |
Matteo Martincigh | d0613b5 | 2019-10-09 16:47:04 +0100 | [diff] [blame] | 40 | // Once a Connection Acknowledged packet has been received, move to the Active state immediately |
| 41 | m_StateMachine.TransitionToState(ProfilingState::Active); |
Colm Donelan | 2ba48d2 | 2019-11-29 09:10:59 +0000 | [diff] [blame] | 42 | // Send the counter directory packet. |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 43 | m_SendCounterPacket.SendCounterDirectoryPacket(m_CounterDirectory); |
Finn Williams | d7fcafa | 2020-04-23 17:55:18 +0100 | [diff] [blame] | 44 | |
| 45 | if (m_TimelineEnabled) |
| 46 | { |
| 47 | m_SendTimelinePacket.SendTimelineMessageDirectoryPackage(); |
| 48 | TimelineUtilityMethods::SendWellKnownLabelsAndEventClasses(m_SendTimelinePacket); |
| 49 | } |
Finn Williams | cf2ad55 | 2020-03-20 15:10:59 +0000 | [diff] [blame] | 50 | |
Jim Flynn | 6398a98 | 2020-05-27 17:05:21 +0100 | [diff] [blame] | 51 | if (m_BackendProfilingContext.has_value()) |
Finn Williams | fe5a24b | 2020-04-09 16:05:28 +0100 | [diff] [blame] | 52 | { |
| 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 Flynn | f9db3ef | 2022-03-08 21:23:44 +0000 | [diff] [blame] | 58 | throw arm::pipe::BackendProfilingException( |
Cathal Corbett | 6f07372 | 2022-03-04 12:11:09 +0000 | [diff] [blame] | 59 | "Unable to enable profiling on Backend Id: " + backendContext.first); |
Finn Williams | fe5a24b | 2020-04-09 16:05:28 +0100 | [diff] [blame] | 60 | } |
| 61 | } |
| 62 | } |
| 63 | |
Jim Flynn | 6398a98 | 2020-05-27 17:05:21 +0100 | [diff] [blame] | 64 | // 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 Martincigh | d0613b5 | 2019-10-09 16:47:04 +0100 | [diff] [blame] | 67 | break; |
| 68 | case ProfilingState::Active: |
| 69 | return; // NOP |
| 70 | default: |
Jim Flynn | f9db3ef | 2022-03-08 21:23:44 +0000 | [diff] [blame] | 71 | throw arm::pipe::ProfilingException(fmt::format("Unknown profiling service state: {}", |
| 72 | static_cast<int>(currentState))); |
Matteo Martincigh | d0613b5 | 2019-10-09 16:47:04 +0100 | [diff] [blame] | 73 | } |
Sadik Armagan | b5f01b2 | 2019-09-18 17:29:00 +0100 | [diff] [blame] | 74 | } |
| 75 | |
Cathal Corbett | 5aa9fd7 | 2022-02-25 15:33:28 +0000 | [diff] [blame] | 76 | } // namespace pipe |
Sadik Armagan | b5f01b2 | 2019-09-18 17:29:00 +0100 | [diff] [blame] | 77 | |
Cathal Corbett | 5aa9fd7 | 2022-02-25 15:33:28 +0000 | [diff] [blame] | 78 | } // namespace arm |