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 
29 namespace armarx
30 {
31 
32 
33 #ifdef REMOTE
34  void StatechartPerfomanceTest::onInitRemoteStateOfferer()
35  {
36  addState<Statechart_StatechartPerfomanceTest>("PerfTest");
37  }
38 #else
40  {
41  std::cout << "onInitComponent" << std::endl;
42  StringVariantContainerBaseMap input;
43 
44  input["Timeout"] = new SingleVariant(4);
45  input["name"] = new SingleVariant(std::string("myname"));
46  input["file"] = new SingleVariant(std::string("file://////"));
49  map->addVariant("left", 0.3f);
50  list->addElement(map);
51  input["sampleList"] = list;
53  }
54 
56  {
57  ARMARX_INFO << "Starting StatechartPerfomanceTest";
58 
59  }
60 
62  {
63  ARMARX_VERBOSE << "thread count: " << ThreadList::getApplicationThreadList()->getRunningTaskNames().size();
64  }
65 #endif
66 
67 
68 
70  {
71  setLocalMinimumLoggingLevel(MessageTypeT::WARN);
72 
73  addToInput("Timeout", VariantType::Int, false);
74  addToInput("name", VariantType::String, false);
75  addToInput("file", VariantType::String, false);
76  addToInput("sampleList", VariantType::List(VariantType::Map(VariantType::Float)), false);
77  }
78 
80  {
81 
82  PMPtr mapping = createMapping()
83  ->mapFromParent("Timeout", "Timeout")
84  ->mapFromParent("name", "name")
85  ->mapFromParent("file", "file")
86  ->mapFromParent("sampleList");
87  //add substates
88 
89 
90  StatePtr stateRun = addState<StateRun>("Running");
91 
92  StatePtr stateRun2 = addState<StateRun>("Running2");
93  setInitState(stateRun, mapping);
94  StatePtr stateSuccess = addState<SuccessState>("Success"); // preimplemented state derived from FinalState, that triggers a transition on the upper state
95  StatePtr stateFailure = addState<FailureState>("Failure"); // preimplemented state derived from FinalState, that triggers a transition on the upper state
96 
97 
98 
99  // add transitions
100  // addTransition<EvNext>(getInitState(), stateRun, mapping);
101  addTransition<EvNext>(stateRun, stateRun2, mapping);
102  addTransition<EvTimeout>(stateRun, stateRun2, mapping);
103  addTransitionFromAllStates<Failure>(stateFailure, mapping);
104  addTransition<EvNext>(stateRun2, stateRun, mapping);
105  addTransition<EvTimeout>(stateRun2, stateRun, mapping);
106  addTransition<Success>(stateRun, stateSuccess);
107  addTransition<Success>(stateRun2, stateSuccess);
108  // ...add more transitions
109  }
110 
111 
112 
114  {
115  addToInput("Timeout", VariantType::Int, false);
116  addToInput("name", VariantType::String, false);
117  addToInput("file", VariantType::String, false);
118  addToInput("sampleList", VariantType::List(VariantType::Map(VariantType::Float)), false);
119  counter = 0;
120  }
121 
123  {
124 
125  // lastCall = IceUtil::Time::now();
126  // if(counter <= 2)
127  // setTimeoutEvent(100, createEvent<EvTimeout>());
128  if (counter == 0)
129  {
130  lastCall = IceUtil::Time::now();
131  }
132 
133  counter++;
134 
135  //sleep(1);
136  if (counter > 1000)
137  {
138  IceUtil::Time dura = IceUtil::Time::now() - lastCall;
139  ARMARX_ERROR << "c: " << counter << " Dura total: " << dura.toMilliSeconds() << " avg Duration in ms: " << dura.toMilliSecondsDouble() / counter / 2 << flush;
140  ARMARX_ERROR << "Timeout: " << getInput<int>("Timeout") << flush;
141  ARMARX_ERROR << "List Entry: " << getInput<SingleTypeVariantList>("sampleList")->getElement<StringValueMap>(0)->getVariant("left")->getFloat() << flush;
142  counter = 0;
143  lastCall = IceUtil::Time::now();
144  sendEvent<Failure>();
145  }
146  else
147  {
148  // ARMARX_VERBOSE << "counter :" << counter << std::endl;
149  // setTimeoutEvent(100, createEvent<EvNext>());
150  sendEvent<EvNext>();
151  // ARMARX_VERBOSE << "counter after:" << counter << std::endl;
152  }
153 
154  // usleep(100000);
155 
156  }
157 
158 
159 
161  {
162  ARMARX_VERBOSE << "exiting StateRun" << std::endl;
163  }
164 
165 
166 
167 }
ARMARX_VERBOSE
#define ARMARX_VERBOSE
Definition: Logging.h:180
armarx::VariantType::Float
const VariantTypeId Float
Definition: Variant.h:918
armarx::VariantType::List
const VariantContainerType List
Definition: SingleTypeVariantList.h:191
armarx::MessageTypeT::WARN
@ WARN
armarx::StateRun::onEnter
void onEnter() override
Definition: StatechartPerformanceTest.cpp:122
list
list(APPEND SOURCES ${QT_RESOURCES}) set(COMPONENT_LIBS ArmarXGui ArmarXCoreObservers ArmarXCoreEigen3Variants PlotterController $
Definition: CMakeLists.txt:49
armarx::VariantType::Map
const VariantContainerType Map
Definition: StringValueMap.h:247
armarx::StateRun::defineParameters
void defineParameters() override
Definition: StatechartPerformanceTest.cpp:113
armarx::ThreadList::getApplicationThreadList
static ThreadListPtr getApplicationThreadList()
getApplicationThreadList retrieves the ThreadList, that contains all TimerTasks and PeriodicTasks in ...
Definition: ThreadList.cpp:189
armarx::createMapping
ParameterMappingPtr createMapping()
Returns a new and empty instance of ParameterMapping.
Definition: ParameterMapping.cpp:235
armarx::VariantType::StringValueMap
const VariantTypeId StringValueMap
Definition: StringValueMap.h:249
IceInternal::Handle< SingleTypeVariantList >
armarx::StatechartContext::setToplevelState
bool setToplevelState(const armarx::StatePtr &newToplevelState, StringVariantContainerBaseMap startParameters=StringVariantContainerBaseMap())
setToplevelState initializes newToplevelState with the current StatechartContext and the current Stat...
Definition: StatechartContext.cpp:180
armarx::StateRun::lastCall
IceUtil::Time lastCall
Definition: StatechartPerformanceTest.h:83
armarx::SingleVariant
The SingleVariant class is required to store single Variant instances in VariantContainer subclasses.
Definition: VariantContainer.h:109
armarx::flush
const LogSender::manipulator flush
Definition: LogSender.h:251
armarx::aron::input
ReaderT::InputType & input
Definition: rw.h:19
ThreadList.h
armarx::StatechartPerformanceTest::onInitStatechart
void onInitStatechart() override
onInitStatechart this method is called when the statechart is started.
Definition: StatechartPerformanceTest.cpp:39
ARMARX_ERROR
#define ARMARX_ERROR
Definition: Logging.h:189
armarx::Statechart_StatechartPerfomanceTest::defineParameters
void defineParameters() override
Definition: StatechartPerformanceTest.cpp:69
armarx::armem::Time
armarx::core::time::DateTime Time
Definition: forward_declarations.h:13
ARMARX_INFO
#define ARMARX_INFO
Definition: Logging.h:174
armarx::StatechartPerformanceTest::onConnectStatechart
void onConnectStatechart() override
onConnectStatechart is called before armarx::StatechartContext::startStatechart() and after armarx::S...
Definition: StatechartPerformanceTest.cpp:55
armarx::StateRun::counter
int counter
Definition: StatechartPerformanceTest.h:84
armarx::VariantType::Int
const VariantTypeId Int
Definition: Variant.h:916
armarx::StatechartPerformanceTest::onExitStatechart
void onExitStatechart() override
onExitStatechart can be implemented by subclasses
Definition: StatechartPerformanceTest.cpp:61
StatechartPerformanceTest.h
armarx::StateRun::onExit
void onExit() override
Definition: StatechartPerformanceTest.cpp:160
armarx::StateTemplate< Statechart_StatechartPerfomanceTest >::createInstance
static IceInternal::Handle< StateType > createInstance(std::string stateName="")
Creates a new state instance of the type of the template parameter.
Definition: StateTemplate.h:95
armarx::Statechart_StatechartPerfomanceTest::defineSubstates
void defineSubstates() override
Definition: StatechartPerformanceTest.cpp:79
armarx::VariantType::String
const VariantTypeId String
Definition: Variant.h:920
armarx::StringValueMap
The StringValueMap class is a subclass of VariantContainer and is comparable to a std::map<std::strin...
Definition: StringValueMap.h:49
armarx::VariantType::SingleTypeVariantList
const VariantTypeId SingleTypeVariantList
Definition: SingleTypeVariantList.h:193
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28