Nikhil Raj | 3ecc510 | 2019-09-03 15:55:33 +0100 | [diff] [blame] | 1 | // |
| 2 | // Copyright © 2017 Arm Ltd. All rights reserved. |
| 3 | // SPDX-License-Identifier: MIT |
| 4 | // |
| 5 | #pragma once |
| 6 | |
| 7 | #include <atomic> |
| 8 | |
| 9 | namespace armnn |
| 10 | { |
| 11 | |
| 12 | namespace profiling |
| 13 | { |
| 14 | |
| 15 | enum class ProfilingState |
| 16 | { |
| 17 | Uninitialised, |
| 18 | NotConnected, |
| 19 | WaitingForAck, |
| 20 | Active |
| 21 | }; |
| 22 | |
| 23 | class ProfilingStateMachine |
| 24 | { |
| 25 | public: |
| 26 | ProfilingStateMachine(): m_State(ProfilingState::Uninitialised) {}; |
| 27 | ProfilingStateMachine(ProfilingState state): m_State(state) {}; |
| 28 | |
| 29 | ProfilingState GetCurrentState() const; |
| 30 | void TransitionToState(ProfilingState newState); |
| 31 | |
| 32 | bool IsOneOfStates(ProfilingState state1) |
| 33 | { |
| 34 | return false; |
| 35 | } |
| 36 | |
| 37 | template<typename T, typename... Args > |
| 38 | bool IsOneOfStates(T state1, T state2, Args... args) |
| 39 | { |
| 40 | if (state1 == state2) |
| 41 | { |
| 42 | return true; |
| 43 | } |
| 44 | else |
| 45 | { |
| 46 | return IsOneOfStates(state1, args...); |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | private: |
| 51 | std::atomic<ProfilingState> m_State; |
| 52 | }; |
| 53 | |
| 54 | constexpr char const* GetProfilingStateName(ProfilingState state) |
| 55 | { |
| 56 | switch(state) |
| 57 | { |
| 58 | case ProfilingState::Uninitialised: return "Uninitialised"; |
| 59 | case ProfilingState::NotConnected: return "NotConnected"; |
| 60 | case ProfilingState::WaitingForAck: return "WaitingForAck"; |
| 61 | case ProfilingState::Active: return "Active"; |
| 62 | default: return "Unknown"; |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | } //namespace profiling |
| 67 | |
| 68 | } //namespace armnn |
| 69 | |