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