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" |
| 7 | #include "TimelineUtilityMethods.hpp" |
Cathal Corbett | 1979355 | 2022-03-04 10:36:34 +0000 | [diff] [blame] | 8 | #include <ArmNNProfilingServiceInitialiser.hpp> |
| 9 | #include <armnn/profiling/ArmNNProfiling.hpp> |
Keith Davis | 33ed221 | 2020-03-30 10:43:41 +0100 | [diff] [blame] | 10 | |
Jim Flynn | f9db3ef | 2022-03-08 21:23:44 +0000 | [diff] [blame] | 11 | #include <common/include/ProfilingException.hpp> |
| 12 | |
Jan Eilers | 156113c | 2020-09-09 19:11:16 +0100 | [diff] [blame] | 13 | #include <fmt/format.h> |
Keith Davis | 33ed221 | 2020-03-30 10:43:41 +0100 | [diff] [blame] | 14 | |
Cathal Corbett | 5aa9fd7 | 2022-02-25 15:33:28 +0000 | [diff] [blame] | 15 | namespace arm |
Keith Davis | 33ed221 | 2020-03-30 10:43:41 +0100 | [diff] [blame] | 16 | { |
| 17 | |
Cathal Corbett | 5aa9fd7 | 2022-02-25 15:33:28 +0000 | [diff] [blame] | 18 | namespace pipe |
Keith Davis | 33ed221 | 2020-03-30 10:43:41 +0100 | [diff] [blame] | 19 | { |
| 20 | |
Jim Flynn | bbfe603 | 2020-07-20 16:57:44 +0100 | [diff] [blame] | 21 | void ActivateTimelineReportingCommandHandler::operator()(const arm::pipe::Packet& packet) |
Keith Davis | 33ed221 | 2020-03-30 10:43:41 +0100 | [diff] [blame] | 22 | { |
| 23 | ProfilingState currentState = m_StateMachine.GetCurrentState(); |
| 24 | |
| 25 | if (!m_ReportStructure.has_value()) |
| 26 | { |
Jim Flynn | f9db3ef | 2022-03-08 21:23:44 +0000 | [diff] [blame] | 27 | 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 Davis | 33ed221 | 2020-03-30 10:43:41 +0100 | [diff] [blame] | 30 | } |
| 31 | |
| 32 | switch ( currentState ) |
| 33 | { |
| 34 | case ProfilingState::Uninitialised: |
| 35 | case ProfilingState::NotConnected: |
| 36 | case ProfilingState::WaitingForAck: |
Jim Flynn | f9db3ef | 2022-03-08 21:23:44 +0000 | [diff] [blame] | 37 | throw arm::pipe::ProfilingException(fmt::format( |
Jan Eilers | 156113c | 2020-09-09 19:11:16 +0100 | [diff] [blame] | 38 | "Activate Timeline Reporting Command Handler invoked while in a wrong state: {}", |
| 39 | GetProfilingStateName(currentState))); |
Keith Davis | 33ed221 | 2020-03-30 10:43:41 +0100 | [diff] [blame] | 40 | case ProfilingState::Active: |
| 41 | if ( !( packet.GetPacketFamily() == 0u && packet.GetPacketId() == 6u )) |
| 42 | { |
Jim Flynn | f9db3ef | 2022-03-08 21:23:44 +0000 | [diff] [blame] | 43 | throw arm::pipe::ProfilingException(std::string( |
| 44 | "Expected Packet family = 0, id = 6 but received family =") |
Keith Davis | 33ed221 | 2020-03-30 10:43:41 +0100 | [diff] [blame] | 45 | + std::to_string(packet.GetPacketFamily()) |
| 46 | + " id = " + std::to_string(packet.GetPacketId())); |
| 47 | } |
| 48 | |
Jim Flynn | 4a96211 | 2022-03-13 20:18:58 +0000 | [diff] [blame] | 49 | if (!m_TimelineReporting) |
Finn Williams | 895e118 | 2020-08-07 11:43:24 +0100 | [diff] [blame] | 50 | { |
| 51 | m_SendTimelinePacket.SendTimelineMessageDirectoryPackage(); |
Keith Davis | 33ed221 | 2020-03-30 10:43:41 +0100 | [diff] [blame] | 52 | |
Finn Williams | 895e118 | 2020-08-07 11:43:24 +0100 | [diff] [blame] | 53 | TimelineUtilityMethods::SendWellKnownLabelsAndEventClasses(m_SendTimelinePacket); |
Keith Davis | 33ed221 | 2020-03-30 10:43:41 +0100 | [diff] [blame] | 54 | |
Finn Williams | 895e118 | 2020-08-07 11:43:24 +0100 | [diff] [blame] | 55 | m_TimelineReporting = true; |
Keith Davis | 33ed221 | 2020-03-30 10:43:41 +0100 | [diff] [blame] | 56 | |
Cathal Corbett | 1979355 | 2022-03-04 10:36:34 +0000 | [diff] [blame] | 57 | 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 Davis | 33ed221 | 2020-03-30 10:43:41 +0100 | [diff] [blame] | 61 | |
Finn Williams | 895e118 | 2020-08-07 11:43:24 +0100 | [diff] [blame] | 62 | m_BackendNotifier.NotifyBackendsForTimelineReporting(); |
| 63 | } |
Keith Davis | 33ed221 | 2020-03-30 10:43:41 +0100 | [diff] [blame] | 64 | |
| 65 | break; |
| 66 | default: |
Jim Flynn | f9db3ef | 2022-03-08 21:23:44 +0000 | [diff] [blame] | 67 | throw arm::pipe::ProfilingException(fmt::format("Unknown profiling service state: {}", |
| 68 | static_cast<int>(currentState))); |
Keith Davis | 33ed221 | 2020-03-30 10:43:41 +0100 | [diff] [blame] | 69 | } |
| 70 | } |
| 71 | |
Cathal Corbett | 5aa9fd7 | 2022-02-25 15:33:28 +0000 | [diff] [blame] | 72 | } // namespace pipe |
Keith Davis | 33ed221 | 2020-03-30 10:43:41 +0100 | [diff] [blame] | 73 | |
Jim Flynn | f9db3ef | 2022-03-08 21:23:44 +0000 | [diff] [blame] | 74 | } // namespace arm |