blob: 9589dd808bea9e03cc158e604c7b907ed2ae35f1 [file] [log] [blame]
Keith Davis33ed2212020-03-30 10:43:41 +01001//
Jim Flynnbbfe6032020-07-20 16:57:44 +01002// Copyright © 2020 Arm Ltd and Contributors. All rights reserved.
Keith Davis33ed2212020-03-30 10:43:41 +01003// SPDX-License-Identifier: MIT
4//
5
6#include "ActivateTimelineReportingCommandHandler.hpp"
Jim Flynn27761832022-03-20 21:52:17 +00007
8#include <client/include/TimelineUtilityMethods.hpp>
9
Jim Flynnf9db3ef2022-03-08 21:23:44 +000010#include <common/include/ProfilingException.hpp>
11
Jan Eilers156113c2020-09-09 19:11:16 +010012#include <fmt/format.h>
Keith Davis33ed2212020-03-30 10:43:41 +010013
Cathal Corbett5aa9fd72022-02-25 15:33:28 +000014namespace arm
Keith Davis33ed2212020-03-30 10:43:41 +010015{
16
Cathal Corbett5aa9fd72022-02-25 15:33:28 +000017namespace pipe
Keith Davis33ed2212020-03-30 10:43:41 +010018{
19
Jim Flynnbbfe6032020-07-20 16:57:44 +010020void ActivateTimelineReportingCommandHandler::operator()(const arm::pipe::Packet& packet)
Keith Davis33ed2212020-03-30 10:43:41 +010021{
22 ProfilingState currentState = m_StateMachine.GetCurrentState();
23
24 if (!m_ReportStructure.has_value())
25 {
Jim Flynnf9db3ef2022-03-08 21:23:44 +000026 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 Davis33ed2212020-03-30 10:43:41 +010029 }
30
31 switch ( currentState )
32 {
33 case ProfilingState::Uninitialised:
34 case ProfilingState::NotConnected:
35 case ProfilingState::WaitingForAck:
Jim Flynnf9db3ef2022-03-08 21:23:44 +000036 throw arm::pipe::ProfilingException(fmt::format(
Jan Eilers156113c2020-09-09 19:11:16 +010037 "Activate Timeline Reporting Command Handler invoked while in a wrong state: {}",
38 GetProfilingStateName(currentState)));
Keith Davis33ed2212020-03-30 10:43:41 +010039 case ProfilingState::Active:
40 if ( !( packet.GetPacketFamily() == 0u && packet.GetPacketId() == 6u ))
41 {
Jim Flynnf9db3ef2022-03-08 21:23:44 +000042 throw arm::pipe::ProfilingException(std::string(
43 "Expected Packet family = 0, id = 6 but received family =")
Keith Davis33ed2212020-03-30 10:43:41 +010044 + std::to_string(packet.GetPacketFamily())
45 + " id = " + std::to_string(packet.GetPacketId()));
46 }
47
Jim Flynn4a962112022-03-13 20:18:58 +000048 if (!m_TimelineReporting)
Finn Williams895e1182020-08-07 11:43:24 +010049 {
50 m_SendTimelinePacket.SendTimelineMessageDirectoryPackage();
Keith Davis33ed2212020-03-30 10:43:41 +010051
Finn Williams895e1182020-08-07 11:43:24 +010052 TimelineUtilityMethods::SendWellKnownLabelsAndEventClasses(m_SendTimelinePacket);
Keith Davis33ed2212020-03-30 10:43:41 +010053
Finn Williams895e1182020-08-07 11:43:24 +010054 m_TimelineReporting = true;
Keith Davis33ed2212020-03-30 10:43:41 +010055
Jim Flynn9c85b412022-03-16 00:27:43 +000056 if (m_ReportStructure.has_value())
57 {
58 m_ReportStructure.value().ReportStructure(m_ProfilingService);
59 }
Keith Davis33ed2212020-03-30 10:43:41 +010060
Finn Williams895e1182020-08-07 11:43:24 +010061 m_BackendNotifier.NotifyBackendsForTimelineReporting();
62 }
Keith Davis33ed2212020-03-30 10:43:41 +010063
64 break;
65 default:
Jim Flynnf9db3ef2022-03-08 21:23:44 +000066 throw arm::pipe::ProfilingException(fmt::format("Unknown profiling service state: {}",
67 static_cast<int>(currentState)));
Keith Davis33ed2212020-03-30 10:43:41 +010068 }
69}
70
Cathal Corbett5aa9fd72022-02-25 15:33:28 +000071} // namespace pipe
Keith Davis33ed2212020-03-30 10:43:41 +010072
Jim Flynnf9db3ef2022-03-08 21:23:44 +000073} // namespace arm