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" |
| 8 | |
| 9 | #include <armnn/Exceptions.hpp> |
Jan Eilers | 156113c | 2020-09-09 19:11:16 +0100 | [diff] [blame] | 10 | #include <fmt/format.h> |
Keith Davis | 33ed221 | 2020-03-30 10:43:41 +0100 | [diff] [blame] | 11 | |
| 12 | namespace armnn |
| 13 | { |
| 14 | |
| 15 | namespace profiling |
| 16 | { |
| 17 | |
Jim Flynn | bbfe603 | 2020-07-20 16:57:44 +0100 | [diff] [blame] | 18 | void ActivateTimelineReportingCommandHandler::operator()(const arm::pipe::Packet& packet) |
Keith Davis | 33ed221 | 2020-03-30 10:43:41 +0100 | [diff] [blame] | 19 | { |
| 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: |
Jan Eilers | 156113c | 2020-09-09 19:11:16 +0100 | [diff] [blame] | 33 | throw RuntimeException(fmt::format( |
| 34 | "Activate Timeline Reporting Command Handler invoked while in a wrong state: {}", |
| 35 | GetProfilingStateName(currentState))); |
Keith Davis | 33ed221 | 2020-03-30 10:43:41 +0100 | [diff] [blame] | 36 | 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 Williams | 895e118 | 2020-08-07 11:43:24 +0100 | [diff] [blame] | 44 | if(!m_TimelineReporting) |
| 45 | { |
| 46 | m_SendTimelinePacket.SendTimelineMessageDirectoryPackage(); |
Keith Davis | 33ed221 | 2020-03-30 10:43:41 +0100 | [diff] [blame] | 47 | |
Finn Williams | 895e118 | 2020-08-07 11:43:24 +0100 | [diff] [blame] | 48 | TimelineUtilityMethods::SendWellKnownLabelsAndEventClasses(m_SendTimelinePacket); |
Keith Davis | 33ed221 | 2020-03-30 10:43:41 +0100 | [diff] [blame] | 49 | |
Finn Williams | 895e118 | 2020-08-07 11:43:24 +0100 | [diff] [blame] | 50 | m_TimelineReporting = true; |
Keith Davis | 33ed221 | 2020-03-30 10:43:41 +0100 | [diff] [blame] | 51 | |
Finn Williams | 895e118 | 2020-08-07 11:43:24 +0100 | [diff] [blame] | 52 | m_ReportStructure.value().ReportStructure(); |
Keith Davis | 33ed221 | 2020-03-30 10:43:41 +0100 | [diff] [blame] | 53 | |
Finn Williams | 895e118 | 2020-08-07 11:43:24 +0100 | [diff] [blame] | 54 | m_BackendNotifier.NotifyBackendsForTimelineReporting(); |
| 55 | } |
Keith Davis | 33ed221 | 2020-03-30 10:43:41 +0100 | [diff] [blame] | 56 | |
| 57 | break; |
| 58 | default: |
Jan Eilers | 156113c | 2020-09-09 19:11:16 +0100 | [diff] [blame] | 59 | throw RuntimeException(fmt::format("Unknown profiling service state: {}", |
| 60 | static_cast<int>(currentState))); |
Keith Davis | 33ed221 | 2020-03-30 10:43:41 +0100 | [diff] [blame] | 61 | } |
| 62 | } |
| 63 | |
| 64 | } // namespace profiling |
| 65 | |
| 66 | } // namespace armnn |