blob: aca750d5e877777e1b85d07312bc0eba65499db1 [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"
7#include "TimelineUtilityMethods.hpp"
Cathal Corbett19793552022-03-04 10:36:34 +00008#include <ArmNNProfilingServiceInitialiser.hpp>
9#include <armnn/profiling/ArmNNProfiling.hpp>
Keith Davis33ed2212020-03-30 10:43:41 +010010
Jim Flynnf9db3ef2022-03-08 21:23:44 +000011#include <common/include/ProfilingException.hpp>
12
Jan Eilers156113c2020-09-09 19:11:16 +010013#include <fmt/format.h>
Keith Davis33ed2212020-03-30 10:43:41 +010014
Cathal Corbett5aa9fd72022-02-25 15:33:28 +000015namespace arm
Keith Davis33ed2212020-03-30 10:43:41 +010016{
17
Cathal Corbett5aa9fd72022-02-25 15:33:28 +000018namespace pipe
Keith Davis33ed2212020-03-30 10:43:41 +010019{
20
Jim Flynnbbfe6032020-07-20 16:57:44 +010021void ActivateTimelineReportingCommandHandler::operator()(const arm::pipe::Packet& packet)
Keith Davis33ed2212020-03-30 10:43:41 +010022{
23 ProfilingState currentState = m_StateMachine.GetCurrentState();
24
25 if (!m_ReportStructure.has_value())
26 {
Jim Flynnf9db3ef2022-03-08 21:23:44 +000027 throw arm::pipe::ProfilingException(std::string(
28 "Profiling Service constructor must be initialised with an "
29 "IReportStructure argument in order to run timeline reporting"));
Keith Davis33ed2212020-03-30 10:43:41 +010030 }
31
32 switch ( currentState )
33 {
34 case ProfilingState::Uninitialised:
35 case ProfilingState::NotConnected:
36 case ProfilingState::WaitingForAck:
Jim Flynnf9db3ef2022-03-08 21:23:44 +000037 throw arm::pipe::ProfilingException(fmt::format(
Jan Eilers156113c2020-09-09 19:11:16 +010038 "Activate Timeline Reporting Command Handler invoked while in a wrong state: {}",
39 GetProfilingStateName(currentState)));
Keith Davis33ed2212020-03-30 10:43:41 +010040 case ProfilingState::Active:
41 if ( !( packet.GetPacketFamily() == 0u && packet.GetPacketId() == 6u ))
42 {
Jim Flynnf9db3ef2022-03-08 21:23:44 +000043 throw arm::pipe::ProfilingException(std::string(
44 "Expected Packet family = 0, id = 6 but received family =")
Keith Davis33ed2212020-03-30 10:43:41 +010045 + std::to_string(packet.GetPacketFamily())
46 + " id = " + std::to_string(packet.GetPacketId()));
47 }
48
Jim Flynn4a962112022-03-13 20:18:58 +000049 if (!m_TimelineReporting)
Finn Williams895e1182020-08-07 11:43:24 +010050 {
51 m_SendTimelinePacket.SendTimelineMessageDirectoryPackage();
Keith Davis33ed2212020-03-30 10:43:41 +010052
Finn Williams895e1182020-08-07 11:43:24 +010053 TimelineUtilityMethods::SendWellKnownLabelsAndEventClasses(m_SendTimelinePacket);
Keith Davis33ed2212020-03-30 10:43:41 +010054
Finn Williams895e1182020-08-07 11:43:24 +010055 m_TimelineReporting = true;
Keith Davis33ed2212020-03-30 10:43:41 +010056
Cathal Corbett19793552022-03-04 10:36:34 +000057 armnn::ArmNNProfilingServiceInitialiser initialiser;
58 std::unique_ptr<IProfilingService> profilingService = IProfilingService::CreateProfilingService(
59 arm::pipe::MAX_ARMNN_COUNTER, initialiser);
60 m_ReportStructure.value().ReportStructure(*profilingService);
Keith Davis33ed2212020-03-30 10:43:41 +010061
Finn Williams895e1182020-08-07 11:43:24 +010062 m_BackendNotifier.NotifyBackendsForTimelineReporting();
63 }
Keith Davis33ed2212020-03-30 10:43:41 +010064
65 break;
66 default:
Jim Flynnf9db3ef2022-03-08 21:23:44 +000067 throw arm::pipe::ProfilingException(fmt::format("Unknown profiling service state: {}",
68 static_cast<int>(currentState)));
Keith Davis33ed2212020-03-30 10:43:41 +010069 }
70}
71
Cathal Corbett5aa9fd72022-02-25 15:33:28 +000072} // namespace pipe
Keith Davis33ed2212020-03-30 10:43:41 +010073
Jim Flynnf9db3ef2022-03-08 21:23:44 +000074} // namespace arm