StatechartPerformanceTest.cpp
Go to the documentation of this file.
1/*
2* This file is part of ArmarX.
3*
4* Copyright (C) 2011-2016, High Performance Humanoid Technologies (H2T), Karlsruhe Institute of Technology (KIT), all rights reserved.
5*
6* ArmarX is free software; you can redistribute it and/or modify
7* it under the terms of the GNU General Public License version 2 as
8* published by the Free Software Foundation.
9*
10* ArmarX is distributed in the hope that it will be useful, but
11* WITHOUT ANY WARRANTY; without even the implied warranty of
12* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13* GNU General Public License for more details.
14*
15* You should have received a copy of the GNU General Public License
16* along with this program. If not, see <http://www.gnu.org/licenses/>.
17*
18* @package ArmarX::StatechartPerfomanceTest
19* @author ( at kit dot edu)
20* @date
21* @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22* GNU General Public License
23*/
24
26
28
29namespace armarx
30{
31
32
33#ifdef REMOTE
34 void
35 StatechartPerfomanceTest::onInitRemoteStateOfferer()
36 {
37 addState<Statechart_StatechartPerfomanceTest>("PerfTest");
38 }
39#else
40 void
42 {
43 std::cout << "onInitComponent" << std::endl;
44 StringVariantContainerBaseMap input;
45
46 input["Timeout"] = new SingleVariant(4);
47 input["name"] = new SingleVariant(std::string("myname"));
48 input["file"] = new SingleVariant(std::string("file://////"));
52 map->addVariant("left", 0.3f);
53 list->addElement(map);
54 input["sampleList"] = list;
56 }
57
58 void
60 {
61 ARMARX_INFO << "Starting StatechartPerfomanceTest";
62 }
63
64 void
66 {
67 ARMARX_VERBOSE << "thread count: "
68 << ThreadList::getApplicationThreadList()->getRunningTaskNames().size();
69 }
70#endif
71
72
73 void
83
84 void
86 {
87
88 PMPtr mapping = createMapping()
89 ->mapFromParent("Timeout", "Timeout")
90 ->mapFromParent("name", "name")
91 ->mapFromParent("file", "file")
92 ->mapFromParent("sampleList");
93 //add substates
94
95
96 StatePtr stateRun = addState<StateRun>("Running");
97
98 StatePtr stateRun2 = addState<StateRun>("Running2");
99 setInitState(stateRun, mapping);
100 StatePtr stateSuccess = addState<SuccessState>(
101 "Success"); // preimplemented state derived from FinalState, that triggers a transition on the upper state
102 StatePtr stateFailure = addState<FailureState>(
103 "Failure"); // preimplemented state derived from FinalState, that triggers a transition on the upper state
104
105
106 // add transitions
107 // addTransition<EvNext>(getInitState(), stateRun, mapping);
108 addTransition<EvNext>(stateRun, stateRun2, mapping);
109 addTransition<EvTimeout>(stateRun, stateRun2, mapping);
110 addTransitionFromAllStates<Failure>(stateFailure, mapping);
111 addTransition<EvNext>(stateRun2, stateRun, mapping);
112 addTransition<EvTimeout>(stateRun2, stateRun, mapping);
113 addTransition<Success>(stateRun, stateSuccess);
114 addTransition<Success>(stateRun2, stateSuccess);
115 // ...add more transitions
116 }
117
118 void
120 {
121 addToInput("Timeout", VariantType::Int, false);
122 addToInput("name", VariantType::String, false);
123 addToInput("file", VariantType::String, false);
125 counter = 0;
126 }
127
128 void
130 {
131
132 // lastCall = IceUtil::Time::now();
133 // if(counter <= 2)
134 // setTimeoutEvent(100, createEvent<EvTimeout>());
135 if (counter == 0)
136 {
137 lastCall = IceUtil::Time::now();
138 }
139
140 counter++;
141
142 //sleep(1);
143 if (counter > 1000)
144 {
145 IceUtil::Time dura = IceUtil::Time::now() - lastCall;
146 ARMARX_ERROR << "c: " << counter << " Dura total: " << dura.toMilliSeconds()
147 << " avg Duration in ms: " << dura.toMilliSecondsDouble() / counter / 2
148 << flush;
149 ARMARX_ERROR << "Timeout: " << getInput<int>("Timeout") << flush;
150 ARMARX_ERROR << "List Entry: "
151 << getInput<SingleTypeVariantList>("sampleList")
152 ->getElement<StringValueMap>(0)
153 ->getVariant("left")
154 ->getFloat()
155 << flush;
156 counter = 0;
157 lastCall = IceUtil::Time::now();
159 }
160 else
161 {
162 // ARMARX_VERBOSE << "counter :" << counter << std::endl;
163 // setTimeoutEvent(100, createEvent<EvNext>());
165 // ARMARX_VERBOSE << "counter after:" << counter << std::endl;
166 }
167
168 // usleep(100000);
169 }
170
171 void
173 {
174 ARMARX_VERBOSE << "exiting StateRun" << std::endl;
175 }
176
177
178} // namespace armarx
void setLocalMinimumLoggingLevel(MessageTypeT level)
With setLocalMinimumLoggingLevel the minimum verbosity-level of log-messages can be set.
Definition Logging.cpp:66
The SingleTypeVariantList class is a subclass of VariantContainer and is comparable to a std::vector<...
The SingleVariant class is required to store single Variant instances in VariantContainer subclasses.
static IceInternal::Handle< Statechart_StatechartPerfomanceTest > createInstance(std::string stateName="")
void sendEvent(const EventPtr event, StateBasePtr eventProcessor=nullptr)
Function to send an event to a specific state from an onEnter()-function. Must not be called anywhere...
Definition StateUtil.cpp:40
StateBasePtr addState(StateBasePtr pNewState)
Definition State.cpp:140
bool addToInput(const std::string &key, const ContainerType &type, bool optional, VariantContainerBasePtr defaultValue=VariantContainerBasePtr())
Adds a key,type-pair to the input parameters.
Definition State.cpp:309
std::enable_if_t< std::is_base_of_v< VariantDataClass, T >, IceInternal::Handle< T > > getInput(const std::string &key) const
getInput can be used to access a specific input parameter.
Definition State.h:620
StateBasePtr setInitState(StateBasePtr initState, ParameterMappingPtr initialStateMapping=ParameterMappingPtr())
Sets the initial substate of this state.
Definition State.cpp:354
TransitionIceBase & addTransition(EventPtr event, StateIceBasePtr sourceState, StateIceBasePtr destinationState, ParameterMappingIceBasePtr mappingToNextStatesInput=nullptr, ParameterMappingIceBasePtr mappingToParentStatesLocal=nullptr, ParameterMappingIceBasePtr mappingToParentStatesOutput=nullptr)
Definition State.cpp:250
TransitionIceBase & addTransitionFromAllStates(StateIceBasePtr destinationState, ParameterMappingIceBasePtr mappingToNextStatesInput=nullptr, ParameterMappingIceBasePtr mappingToParentStatesLocal=nullptr, ParameterMappingIceBasePtr mappingToParentStatesOutput=nullptr)
Function to add a new transition from all substates to destinationState.
Definition State.h:577
bool setToplevelState(const armarx::StatePtr &newToplevelState, StringVariantContainerBaseMap startParameters=StringVariantContainerBaseMap())
setToplevelState initializes newToplevelState with the current StatechartContext and the current Stat...
void onInitStatechart() override
onInitStatechart this method is called when the statechart is started.
void onExitStatechart() override
onExitStatechart can be implemented by subclasses
void onConnectStatechart() override
onConnectStatechart is called before armarx::StatechartContext::startStatechart() and after armarx::S...
The StringValueMap class is a subclass of VariantContainer and is comparable to a std::map<std::strin...
static ThreadListPtr getApplicationThreadList()
getApplicationThreadList retrieves the ThreadList, that contains all TimerTasks and PeriodicTasks in ...
#define ARMARX_INFO
The normal logging level.
Definition Logging.h:181
#define ARMARX_ERROR
The logging level for unexpected behaviour, that must be fixed.
Definition Logging.h:196
#define ARMARX_VERBOSE
The logging level for verbose information.
Definition Logging.h:187
const VariantTypeId String
Definition Variant.h:921
const VariantTypeId Int
Definition Variant.h:917
const VariantContainerType Map
const VariantTypeId Float
Definition Variant.h:919
const VariantContainerType List
This file offers overloads of toIce() and fromIce() functions for STL container types.
IceInternal::Handle< SingleTypeVariantList > SingleTypeVariantListPtr
IceInternal::Handle< State > StatePtr
Definition State.h:44
ParameterMappingPtr PMPtr
IceInternal::Handle< StringValueMap > StringValueMapPtr
const LogSender::manipulator flush
Definition LogSender.h:251
ParameterMappingPtr createMapping()
Returns a new and empty instance of ParameterMapping.
void defineParameters() override
Virtual function, in which input/local/output parameters can be specified.
void onEnter() override
Virtual function, in which the behaviour of state is defined, when it is entered. Can be overridden,...
void onExit() override
Virtual function, in which the behaviour of state is defined, when it is exited. Can be overridden,...
void defineParameters() override
Virtual function, in which input/local/output parameters can be specified.
void defineSubstates() override
Virtual function, in which substates, transition and mappings can be added.