blob: 7f949d361aa1ff9702f584c52513659d54216ff2 [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"
8
9#include <armnn/Exceptions.hpp>
Jan Eilers156113c2020-09-09 19:11:16 +010010#include <fmt/format.h>
Keith Davis33ed2212020-03-30 10:43:41 +010011
Cathal Corbett5aa9fd72022-02-25 15:33:28 +000012namespace arm
Keith Davis33ed2212020-03-30 10:43:41 +010013{
14
Cathal Corbett5aa9fd72022-02-25 15:33:28 +000015namespace pipe
Keith Davis33ed2212020-03-30 10:43:41 +010016{
17
Jim Flynnbbfe6032020-07-20 16:57:44 +010018void ActivateTimelineReportingCommandHandler::operator()(const arm::pipe::Packet& packet)
Keith Davis33ed2212020-03-30 10:43:41 +010019{
20 ProfilingState currentState = m_StateMachine.GetCurrentState();
21
22 if (!m_ReportStructure.has_value())
23 {
24 throw armnn::Exception(std::string("Profiling Service constructor must be initialised with an "
25 "IReportStructure argument in order to run timeline reporting"));
26 }
27
28 switch ( currentState )
29 {
30 case ProfilingState::Uninitialised:
31 case ProfilingState::NotConnected:
32 case ProfilingState::WaitingForAck:
Cathal Corbett5aa9fd72022-02-25 15:33:28 +000033 throw armnn::RuntimeException(fmt::format(
Jan Eilers156113c2020-09-09 19:11:16 +010034 "Activate Timeline Reporting Command Handler invoked while in a wrong state: {}",
35 GetProfilingStateName(currentState)));
Keith Davis33ed2212020-03-30 10:43:41 +010036 case ProfilingState::Active:
37 if ( !( packet.GetPacketFamily() == 0u && packet.GetPacketId() == 6u ))
38 {
39 throw armnn::Exception(std::string("Expected Packet family = 0, id = 6 but received family =")
40 + std::to_string(packet.GetPacketFamily())
41 + " id = " + std::to_string(packet.GetPacketId()));
42 }
43
Finn Williams895e1182020-08-07 11:43:24 +010044 if(!m_TimelineReporting)
45 {
46 m_SendTimelinePacket.SendTimelineMessageDirectoryPackage();
Keith Davis33ed2212020-03-30 10:43:41 +010047
Finn Williams895e1182020-08-07 11:43:24 +010048 TimelineUtilityMethods::SendWellKnownLabelsAndEventClasses(m_SendTimelinePacket);
Keith Davis33ed2212020-03-30 10:43:41 +010049
Finn Williams895e1182020-08-07 11:43:24 +010050 m_TimelineReporting = true;
Keith Davis33ed2212020-03-30 10:43:41 +010051
Finn Williams895e1182020-08-07 11:43:24 +010052 m_ReportStructure.value().ReportStructure();
Keith Davis33ed2212020-03-30 10:43:41 +010053
Finn Williams895e1182020-08-07 11:43:24 +010054 m_BackendNotifier.NotifyBackendsForTimelineReporting();
55 }
Keith Davis33ed2212020-03-30 10:43:41 +010056
57 break;
58 default:
Cathal Corbett5aa9fd72022-02-25 15:33:28 +000059 throw armnn::RuntimeException(fmt::format("Unknown profiling service state: {}",
Jan Eilers156113c2020-09-09 19:11:16 +010060 static_cast<int>(currentState)));
Keith Davis33ed2212020-03-30 10:43:41 +010061 }
62}
63
Cathal Corbett5aa9fd72022-02-25 15:33:28 +000064} // namespace pipe
Keith Davis33ed2212020-03-30 10:43:41 +010065
Cathal Corbett5aa9fd72022-02-25 15:33:28 +000066} // namespace arm