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