Sadik Armagan | b5f01b2 | 2019-09-18 17:29:00 +0100 | [diff] [blame] | 1 | // |
Jim Flynn | 6398a98 | 2020-05-27 17:05:21 +0100 | [diff] [blame] | 2 | // Copyright © 2019 Arm Ltd and Contributors. All rights reserved. |
Sadik Armagan | b5f01b2 | 2019-09-18 17:29:00 +0100 | [diff] [blame] | 3 | // SPDX-License-Identifier: MIT |
| 4 | // |
| 5 | |
| 6 | #include "ConnectionAcknowledgedCommandHandler.hpp" |
Finn Williams | cf2ad55 | 2020-03-20 15:10:59 +0000 | [diff] [blame] | 7 | #include "TimelineUtilityMethods.hpp" |
Sadik Armagan | b5f01b2 | 2019-09-18 17:29:00 +0100 | [diff] [blame] | 8 | |
| 9 | #include <armnn/Exceptions.hpp> |
| 10 | |
Matteo Martincigh | d0613b5 | 2019-10-09 16:47:04 +0100 | [diff] [blame] | 11 | #include <boost/format.hpp> |
| 12 | |
Sadik Armagan | b5f01b2 | 2019-09-18 17:29:00 +0100 | [diff] [blame] | 13 | namespace armnn |
| 14 | { |
| 15 | |
| 16 | namespace profiling |
| 17 | { |
| 18 | |
Jim Flynn | bbfe603 | 2020-07-20 16:57:44 +0100 | [diff] [blame] | 19 | void ConnectionAcknowledgedCommandHandler::operator()(const arm::pipe::Packet& packet) |
Sadik Armagan | b5f01b2 | 2019-09-18 17:29:00 +0100 | [diff] [blame] | 20 | { |
Matteo Martincigh | d0613b5 | 2019-10-09 16:47:04 +0100 | [diff] [blame] | 21 | ProfilingState currentState = m_StateMachine.GetCurrentState(); |
| 22 | switch (currentState) |
Sadik Armagan | b5f01b2 | 2019-09-18 17:29:00 +0100 | [diff] [blame] | 23 | { |
Matteo Martincigh | d0613b5 | 2019-10-09 16:47:04 +0100 | [diff] [blame] | 24 | case ProfilingState::Uninitialised: |
| 25 | case ProfilingState::NotConnected: |
Matteo Martincigh | e848538 | 2019-10-10 14:08:21 +0100 | [diff] [blame] | 26 | throw RuntimeException(boost::str(boost::format("Connection Acknowledged Command Handler invoked while in an " |
Matteo Martincigh | d0613b5 | 2019-10-09 16:47:04 +0100 | [diff] [blame] | 27 | "wrong state: %1%") |
| 28 | % GetProfilingStateName(currentState))); |
| 29 | case ProfilingState::WaitingForAck: |
| 30 | // Process the packet |
| 31 | if (!(packet.GetPacketFamily() == 0u && packet.GetPacketId() == 1u)) |
| 32 | { |
| 33 | throw armnn::InvalidArgumentException(boost::str(boost::format("Expected Packet family = 0, id = 1 but " |
| 34 | "received family = %1%, id = %2%") |
| 35 | % packet.GetPacketFamily() |
| 36 | % packet.GetPacketId())); |
| 37 | } |
Matteo Martincigh | c2728f9 | 2019-10-07 12:35:21 +0100 | [diff] [blame] | 38 | |
Matteo Martincigh | d0613b5 | 2019-10-09 16:47:04 +0100 | [diff] [blame] | 39 | // Once a Connection Acknowledged packet has been received, move to the Active state immediately |
| 40 | m_StateMachine.TransitionToState(ProfilingState::Active); |
Colm Donelan | 2ba48d2 | 2019-11-29 09:10:59 +0000 | [diff] [blame] | 41 | // Send the counter directory packet. |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 42 | m_SendCounterPacket.SendCounterDirectoryPacket(m_CounterDirectory); |
Finn Williams | d7fcafa | 2020-04-23 17:55:18 +0100 | [diff] [blame] | 43 | |
| 44 | if (m_TimelineEnabled) |
| 45 | { |
| 46 | m_SendTimelinePacket.SendTimelineMessageDirectoryPackage(); |
| 47 | TimelineUtilityMethods::SendWellKnownLabelsAndEventClasses(m_SendTimelinePacket); |
| 48 | } |
Finn Williams | cf2ad55 | 2020-03-20 15:10:59 +0000 | [diff] [blame] | 49 | |
Jim Flynn | 6398a98 | 2020-05-27 17:05:21 +0100 | [diff] [blame] | 50 | if (m_BackendProfilingContext.has_value()) |
Finn Williams | fe5a24b | 2020-04-09 16:05:28 +0100 | [diff] [blame] | 51 | { |
| 52 | for (auto backendContext : m_BackendProfilingContext.value()) |
| 53 | { |
| 54 | // Enable profiling on the backend and assert that it returns true |
| 55 | if(!backendContext.second->EnableProfiling(true)) |
| 56 | { |
| 57 | throw BackendProfilingException( |
| 58 | "Unable to enable profiling on Backend Id: " + backendContext.first.Get()); |
| 59 | } |
| 60 | } |
| 61 | } |
| 62 | |
Jim Flynn | 6398a98 | 2020-05-27 17:05:21 +0100 | [diff] [blame] | 63 | // At this point signal any external processes waiting on the profiling system |
| 64 | // to come up that profiling is fully active |
| 65 | m_ProfilingServiceStatus.NotifyProfilingServiceActive(); |
Matteo Martincigh | d0613b5 | 2019-10-09 16:47:04 +0100 | [diff] [blame] | 66 | break; |
| 67 | case ProfilingState::Active: |
| 68 | return; // NOP |
| 69 | default: |
| 70 | throw RuntimeException(boost::str(boost::format("Unknown profiling service state: %1%") |
| 71 | % static_cast<int>(currentState))); |
| 72 | } |
Sadik Armagan | b5f01b2 | 2019-09-18 17:29:00 +0100 | [diff] [blame] | 73 | } |
| 74 | |
| 75 | } // namespace profiling |
| 76 | |
| 77 | } // namespace armnn |
| 78 | |