Narumol Prangnawarat | 4803369 | 2019-09-20 12:04:55 +0100 | [diff] [blame] | 1 | // |
| 2 | // Copyright © 2019 Arm Ltd. All rights reserved. |
| 3 | // SPDX-License-Identifier: MIT |
| 4 | // |
| 5 | |
| 6 | #include "RequestCounterDirectoryCommandHandler.hpp" |
| 7 | |
Jan Eilers | 156113c | 2020-09-09 19:11:16 +0100 | [diff] [blame] | 8 | #include <fmt/format.h> |
Matteo Martincigh | d0613b5 | 2019-10-09 16:47:04 +0100 | [diff] [blame] | 9 | |
Narumol Prangnawarat | 4803369 | 2019-09-20 12:04:55 +0100 | [diff] [blame] | 10 | namespace armnn |
| 11 | { |
| 12 | |
| 13 | namespace profiling |
| 14 | { |
| 15 | |
Jim Flynn | bbfe603 | 2020-07-20 16:57:44 +0100 | [diff] [blame] | 16 | void RequestCounterDirectoryCommandHandler::operator()(const arm::pipe::Packet& packet) |
Narumol Prangnawarat | 4803369 | 2019-09-20 12:04:55 +0100 | [diff] [blame] | 17 | { |
Matteo Martincigh | 8efc500 | 2019-10-10 14:30:29 +0100 | [diff] [blame] | 18 | ProfilingState currentState = m_StateMachine.GetCurrentState(); |
| 19 | switch (currentState) |
| 20 | { |
| 21 | case ProfilingState::Uninitialised: |
| 22 | case ProfilingState::NotConnected: |
| 23 | case ProfilingState::WaitingForAck: |
Jan Eilers | 156113c | 2020-09-09 19:11:16 +0100 | [diff] [blame] | 24 | throw RuntimeException(fmt::format("Request Counter Directory Comand Handler invoked while in an " |
| 25 | "wrong state: {}", |
| 26 | GetProfilingStateName(currentState))); |
Matteo Martincigh | 8efc500 | 2019-10-10 14:30:29 +0100 | [diff] [blame] | 27 | case ProfilingState::Active: |
| 28 | // Process the packet |
| 29 | if (!(packet.GetPacketFamily() == 0u && packet.GetPacketId() == 3u)) |
| 30 | { |
Jan Eilers | 156113c | 2020-09-09 19:11:16 +0100 | [diff] [blame] | 31 | throw armnn::InvalidArgumentException(fmt::format("Expected Packet family = 0, id = 3 but " |
| 32 | "received family = {}, id = {}", |
| 33 | packet.GetPacketFamily(), |
| 34 | packet.GetPacketId())); |
Matteo Martincigh | 8efc500 | 2019-10-10 14:30:29 +0100 | [diff] [blame] | 35 | } |
Narumol Prangnawarat | 4803369 | 2019-09-20 12:04:55 +0100 | [diff] [blame] | 36 | |
Matteo Martincigh | 9723d02 | 2019-11-13 10:56:41 +0000 | [diff] [blame] | 37 | // Send all the packet required for the handshake with the external profiling service |
Matteo Martincigh | 8efc500 | 2019-10-10 14:30:29 +0100 | [diff] [blame] | 38 | m_SendCounterPacket.SendCounterDirectoryPacket(m_CounterDirectory); |
Matteo Martincigh | 9723d02 | 2019-11-13 10:56:41 +0000 | [diff] [blame] | 39 | m_SendTimelinePacket.SendTimelineMessageDirectoryPackage(); |
Matteo Martincigh | 8efc500 | 2019-10-10 14:30:29 +0100 | [diff] [blame] | 40 | |
Matteo Martincigh | 8efc500 | 2019-10-10 14:30:29 +0100 | [diff] [blame] | 41 | break; |
| 42 | default: |
Jan Eilers | 156113c | 2020-09-09 19:11:16 +0100 | [diff] [blame] | 43 | throw RuntimeException(fmt::format("Unknown profiling service state: {}", |
| 44 | static_cast<int>(currentState))); |
Matteo Martincigh | 8efc500 | 2019-10-10 14:30:29 +0100 | [diff] [blame] | 45 | } |
Narumol Prangnawarat | 4803369 | 2019-09-20 12:04:55 +0100 | [diff] [blame] | 46 | } |
| 47 | |
| 48 | } // namespace profiling |
| 49 | |
Matteo Martincigh | d0613b5 | 2019-10-09 16:47:04 +0100 | [diff] [blame] | 50 | } // namespace armnn |