1 // 2 // Copyright © 2020 Arm Ltd and Contributors. All rights reserved. 3 // SPDX-License-Identifier: MIT 4 // 5 6 #include "ActivateTimelineReportingCommandHandler.hpp" 7 8 #include <client/include/TimelineUtilityMethods.hpp> 9 10 #include <common/include/ProfilingException.hpp> 11 12 #include <fmt/format.h> 13 14 namespace arm 15 { 16 17 namespace pipe 18 { 19 operator ()(const arm::pipe::Packet & packet)20void ActivateTimelineReportingCommandHandler::operator()(const arm::pipe::Packet& packet) 21 { 22 ProfilingState currentState = m_StateMachine.GetCurrentState(); 23 24 if (!m_ReportStructure.has_value()) 25 { 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")); 29 } 30 31 switch ( currentState ) 32 { 33 case ProfilingState::Uninitialised: 34 case ProfilingState::NotConnected: 35 case ProfilingState::WaitingForAck: 36 throw arm::pipe::ProfilingException(fmt::format( 37 "Activate Timeline Reporting Command Handler invoked while in a wrong state: {}", 38 GetProfilingStateName(currentState))); 39 case ProfilingState::Active: 40 if ( !( packet.GetPacketFamily() == 0u && packet.GetPacketId() == 6u )) 41 { 42 throw arm::pipe::ProfilingException(std::string( 43 "Expected Packet family = 0, id = 6 but received family =") 44 + std::to_string(packet.GetPacketFamily()) 45 + " id = " + std::to_string(packet.GetPacketId())); 46 } 47 48 if (!m_TimelineReporting) 49 { 50 m_SendTimelinePacket.SendTimelineMessageDirectoryPackage(); 51 52 TimelineUtilityMethods::SendWellKnownLabelsAndEventClasses(m_SendTimelinePacket); 53 54 m_TimelineReporting = true; 55 56 if (m_ReportStructure.has_value()) 57 { 58 m_ReportStructure.value().ReportStructure(m_ProfilingService); 59 } 60 61 m_BackendNotifier.NotifyBackendsForTimelineReporting(); 62 } 63 64 break; 65 default: 66 throw arm::pipe::ProfilingException(fmt::format("Unknown profiling service state: {}", 67 static_cast<int>(currentState))); 68 } 69 } 70 71 } // namespace pipe 72 73 } // namespace arm 74