aboutsummaryrefslogtreecommitdiff
path: root/src/profiling/ProfilingStateMachine.cpp
diff options
context:
space:
mode:
authorMatteo Martincigh <matteo.martincigh@arm.com>2019-10-02 12:50:57 +0100
committerMatteo Martincigh <matteo.martincigh@arm.com>2019-10-07 10:34:54 +0100
commita84edee4702c112a6e004b1987acc11144e2d6dd (patch)
tree738ce957b2fa26423df188b0d370664d15c86665 /src/profiling/ProfilingStateMachine.cpp
parentd66d68b13fb309e8d4eac9435a58b89dd6a55158 (diff)
downloadarmnn-a84edee4702c112a6e004b1987acc11144e2d6dd.tar.gz
IVGCVSW-3937 Initial ServiceProfiling refactoring
* Made the ServiceProfiling class a singleton * Registered basic category and counters * Code refactoring * Updated unit tests accordingly Signed-off-by: Matteo Martincigh <matteo.martincigh@arm.com> Change-Id: I648a6202eead2a3016aac14d905511bd945a90cb
Diffstat (limited to 'src/profiling/ProfilingStateMachine.cpp')
-rw-r--r--src/profiling/ProfilingStateMachine.cpp136
1 files changed, 69 insertions, 67 deletions
diff --git a/src/profiling/ProfilingStateMachine.cpp b/src/profiling/ProfilingStateMachine.cpp
index 682e1b8894..5af5bfbed0 100644
--- a/src/profiling/ProfilingStateMachine.cpp
+++ b/src/profiling/ProfilingStateMachine.cpp
@@ -7,87 +7,89 @@
#include <armnn/Exceptions.hpp>
+#include <sstream>
+
namespace armnn
{
namespace profiling
{
+namespace
+{
+
+void ThrowStateTransitionException(ProfilingState expectedState, ProfilingState newState)
+{
+ std::stringstream ss;
+ ss << "Cannot transition from state [" << GetProfilingStateName(expectedState) << "] "
+ << "to state [" << GetProfilingStateName(newState) << "]";
+ throw armnn::RuntimeException(ss.str());
+}
+
+} // Anonymous namespace
+
ProfilingState ProfilingStateMachine::GetCurrentState() const
{
- return m_State;
+ return m_State.load();
}
void ProfilingStateMachine::TransitionToState(ProfilingState newState)
{
- switch (newState)
- {
- case ProfilingState::Uninitialised:
- {
- ProfilingState expectedState = m_State.load(std::memory_order::memory_order_relaxed);
- do {
- if (!IsOneOfStates(expectedState, ProfilingState::Uninitialised))
- {
- throw armnn::Exception(std::string("Cannot transition from state [")
- + GetProfilingStateName(expectedState)
- +"] to [" + GetProfilingStateName(newState) + "]");
- }
- } while (!m_State.compare_exchange_strong(expectedState, newState,
- std::memory_order::memory_order_relaxed));
-
- break;
- }
- case ProfilingState::NotConnected:
- {
- ProfilingState expectedState = m_State.load(std::memory_order::memory_order_relaxed);
- do {
- if (!IsOneOfStates(expectedState, ProfilingState::Uninitialised, ProfilingState::NotConnected,
- ProfilingState::Active))
- {
- throw armnn::Exception(std::string("Cannot transition from state [")
- + GetProfilingStateName(expectedState)
- +"] to [" + GetProfilingStateName(newState) + "]");
- }
- } while (!m_State.compare_exchange_strong(expectedState, newState,
- std::memory_order::memory_order_relaxed));
-
- break;
- }
- case ProfilingState::WaitingForAck:
- {
- ProfilingState expectedState = m_State.load(std::memory_order::memory_order_relaxed);
- do {
- if (!IsOneOfStates(expectedState, ProfilingState::NotConnected, ProfilingState::WaitingForAck))
- {
- throw armnn::Exception(std::string("Cannot transition from state [")
- + GetProfilingStateName(expectedState)
- +"] to [" + GetProfilingStateName(newState) + "]");
- }
- } while (!m_State.compare_exchange_strong(expectedState, newState,
- std::memory_order::memory_order_relaxed));
+ ProfilingState expectedState = m_State.load(std::memory_order::memory_order_relaxed);
- break;
- }
- case ProfilingState::Active:
- {
- ProfilingState expectedState = m_State.load(std::memory_order::memory_order_relaxed);
- do {
- if (!IsOneOfStates(expectedState, ProfilingState::WaitingForAck, ProfilingState::Active))
- {
- throw armnn::Exception(std::string("Cannot transition from state [")
- + GetProfilingStateName(expectedState)
- +"] to [" + GetProfilingStateName(newState) + "]");
- }
- } while (!m_State.compare_exchange_strong(expectedState, newState,
- std::memory_order::memory_order_relaxed));
+ switch (newState)
+ {
+ case ProfilingState::Uninitialised:
+ do
+ {
+ if (!IsOneOfStates(expectedState, ProfilingState::Uninitialised))
+ {
+ ThrowStateTransitionException(expectedState, newState);
+ }
+ }
+ while (!m_State.compare_exchange_strong(expectedState, newState, std::memory_order::memory_order_relaxed));
+ break;
+ case ProfilingState::NotConnected:
+ do
+ {
+ if (!IsOneOfStates(expectedState, ProfilingState::Uninitialised, ProfilingState::NotConnected,
+ ProfilingState::Active))
+ {
+ ThrowStateTransitionException(expectedState, newState);
+ }
+ }
+ while (!m_State.compare_exchange_strong(expectedState, newState, std::memory_order::memory_order_relaxed));
+ break;
+ case ProfilingState::WaitingForAck:
+ do
+ {
+ if (!IsOneOfStates(expectedState, ProfilingState::NotConnected, ProfilingState::WaitingForAck))
+ {
+ ThrowStateTransitionException(expectedState, newState);
+ }
+ }
+ while (!m_State.compare_exchange_strong(expectedState, newState, std::memory_order::memory_order_relaxed));
+ break;
+ case ProfilingState::Active:
+ do
+ {
+ if (!IsOneOfStates(expectedState, ProfilingState::WaitingForAck, ProfilingState::Active))
+ {
+ ThrowStateTransitionException(expectedState, newState);
+ }
+ }
+ while (!m_State.compare_exchange_strong(expectedState, newState, std::memory_order::memory_order_relaxed));
+ break;
+ default:
+ break;
+ }
+}
- break;
- }
- default:
- break;
- }
+void ProfilingStateMachine::Reset()
+{
+ m_State.store(ProfilingState::Uninitialised);
}
-} //namespace profiling
+} // namespace profiling
-} //namespace armnn \ No newline at end of file
+} // namespace armnn