Keith Davis | 33ed221 | 2020-03-30 10:43:41 +0100 | [diff] [blame] | 1 | // |
Jim Flynn | bbfe603 | 2020-07-20 16:57:44 +0100 | [diff] [blame] | 2 | // Copyright © 2020 Arm Ltd and Contributors. All rights reserved. |
Keith Davis | 33ed221 | 2020-03-30 10:43:41 +0100 | [diff] [blame] | 3 | // SPDX-License-Identifier: MIT |
| 4 | // |
| 5 | |
| 6 | #include "ActivateTimelineReportingCommandHandler.hpp" |
Jim Flynn | 2776183 | 2022-03-20 21:52:17 +0000 | [diff] [blame] | 7 | |
| 8 | #include <client/include/TimelineUtilityMethods.hpp> |
| 9 | |
Jim Flynn | f9db3ef | 2022-03-08 21:23:44 +0000 | [diff] [blame] | 10 | #include <common/include/ProfilingException.hpp> |
| 11 | |
Jan Eilers | 156113c | 2020-09-09 19:11:16 +0100 | [diff] [blame] | 12 | #include <fmt/format.h> |
Keith Davis | 33ed221 | 2020-03-30 10:43:41 +0100 | [diff] [blame] | 13 | |
Cathal Corbett | 5aa9fd7 | 2022-02-25 15:33:28 +0000 | [diff] [blame] | 14 | namespace arm |
Keith Davis | 33ed221 | 2020-03-30 10:43:41 +0100 | [diff] [blame] | 15 | { |
| 16 | |
Cathal Corbett | 5aa9fd7 | 2022-02-25 15:33:28 +0000 | [diff] [blame] | 17 | namespace pipe |
Keith Davis | 33ed221 | 2020-03-30 10:43:41 +0100 | [diff] [blame] | 18 | { |
| 19 | |
Jim Flynn | bbfe603 | 2020-07-20 16:57:44 +0100 | [diff] [blame] | 20 | void ActivateTimelineReportingCommandHandler::operator()(const arm::pipe::Packet& packet) |
Keith Davis | 33ed221 | 2020-03-30 10:43:41 +0100 | [diff] [blame] | 21 | { |
| 22 | ProfilingState currentState = m_StateMachine.GetCurrentState(); |
| 23 | |
| 24 | if (!m_ReportStructure.has_value()) |
| 25 | { |
Jim Flynn | f9db3ef | 2022-03-08 21:23:44 +0000 | [diff] [blame] | 26 | throw arm::pipe::ProfilingException(std::string( |
| 27 | "Profiling Service constructor must be initialised with an " |
| 28 | "IReportStructure argument in order to run timeline reporting")); |
Keith Davis | 33ed221 | 2020-03-30 10:43:41 +0100 | [diff] [blame] | 29 | } |
| 30 | |
| 31 | switch ( currentState ) |
| 32 | { |
| 33 | case ProfilingState::Uninitialised: |
| 34 | case ProfilingState::NotConnected: |
| 35 | case ProfilingState::WaitingForAck: |
Jim Flynn | f9db3ef | 2022-03-08 21:23:44 +0000 | [diff] [blame] | 36 | throw arm::pipe::ProfilingException(fmt::format( |
Jan Eilers | 156113c | 2020-09-09 19:11:16 +0100 | [diff] [blame] | 37 | "Activate Timeline Reporting Command Handler invoked while in a wrong state: {}", |
| 38 | GetProfilingStateName(currentState))); |
Keith Davis | 33ed221 | 2020-03-30 10:43:41 +0100 | [diff] [blame] | 39 | case ProfilingState::Active: |
| 40 | if ( !( packet.GetPacketFamily() == 0u && packet.GetPacketId() == 6u )) |
| 41 | { |
Jim Flynn | f9db3ef | 2022-03-08 21:23:44 +0000 | [diff] [blame] | 42 | throw arm::pipe::ProfilingException(std::string( |
| 43 | "Expected Packet family = 0, id = 6 but received family =") |
Keith Davis | 33ed221 | 2020-03-30 10:43:41 +0100 | [diff] [blame] | 44 | + std::to_string(packet.GetPacketFamily()) |
| 45 | + " id = " + std::to_string(packet.GetPacketId())); |
| 46 | } |
| 47 | |
Jim Flynn | 4a96211 | 2022-03-13 20:18:58 +0000 | [diff] [blame] | 48 | if (!m_TimelineReporting) |
Finn Williams | 895e118 | 2020-08-07 11:43:24 +0100 | [diff] [blame] | 49 | { |
| 50 | m_SendTimelinePacket.SendTimelineMessageDirectoryPackage(); |
Keith Davis | 33ed221 | 2020-03-30 10:43:41 +0100 | [diff] [blame] | 51 | |
Finn Williams | 895e118 | 2020-08-07 11:43:24 +0100 | [diff] [blame] | 52 | TimelineUtilityMethods::SendWellKnownLabelsAndEventClasses(m_SendTimelinePacket); |
Keith Davis | 33ed221 | 2020-03-30 10:43:41 +0100 | [diff] [blame] | 53 | |
Finn Williams | 895e118 | 2020-08-07 11:43:24 +0100 | [diff] [blame] | 54 | m_TimelineReporting = true; |
Keith Davis | 33ed221 | 2020-03-30 10:43:41 +0100 | [diff] [blame] | 55 | |
Jim Flynn | 9c85b41 | 2022-03-16 00:27:43 +0000 | [diff] [blame] | 56 | if (m_ReportStructure.has_value()) |
| 57 | { |
| 58 | m_ReportStructure.value().ReportStructure(m_ProfilingService); |
| 59 | } |
Keith Davis | 33ed221 | 2020-03-30 10:43:41 +0100 | [diff] [blame] | 60 | |
Finn Williams | 895e118 | 2020-08-07 11:43:24 +0100 | [diff] [blame] | 61 | m_BackendNotifier.NotifyBackendsForTimelineReporting(); |
| 62 | } |
Keith Davis | 33ed221 | 2020-03-30 10:43:41 +0100 | [diff] [blame] | 63 | |
| 64 | break; |
| 65 | default: |
Jim Flynn | f9db3ef | 2022-03-08 21:23:44 +0000 | [diff] [blame] | 66 | throw arm::pipe::ProfilingException(fmt::format("Unknown profiling service state: {}", |
| 67 | static_cast<int>(currentState))); |
Keith Davis | 33ed221 | 2020-03-30 10:43:41 +0100 | [diff] [blame] | 68 | } |
| 69 | } |
| 70 | |
Cathal Corbett | 5aa9fd7 | 2022-02-25 15:33:28 +0000 | [diff] [blame] | 71 | } // namespace pipe |
Keith Davis | 33ed221 | 2020-03-30 10:43:41 +0100 | [diff] [blame] | 72 | |
Jim Flynn | f9db3ef | 2022-03-08 21:23:44 +0000 | [diff] [blame] | 73 | } // namespace arm |