PingLoadTest.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of ArmarX.
3  *
4  * ArmarX is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation.
7  *
8  * ArmarX is distributed in the hope that it will be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  *
16  * @package ArmarXCore::ArmarXObjects::PingLoadTest
17  * @author Simon Ottenhaus ( simon dot ottenhaus at kit dot edu )
18  * @date 2019
19  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20  * GNU General Public License
21  */
22 
23 #include "PingLoadTest.h"
24 
26 
27 
28 namespace armarx
29 {
32  {
33  //defineRequiredProperty<std::string>("PropertyName", "Description");
34  //defineOptionalProperty<std::string>("PropertyName", "DefaultValue", "Description");
35 
36  defineOptionalProperty<std::string>("DebugObserverName", "DebugObserver", "Name of the topic the DebugObserver listens on");
37 
38  defineOptionalProperty<std::string>("RemotePingComponentName", "", "Name of the remote ping component");
39  defineOptionalProperty<std::string>("PingTopicName", "PingTopic", "Name of the ping topic");
40 
41  defineOptionalProperty<int>("PingProxyDelayMS", -1, "Delay between proxy ping messages: < 0 disable ping; = 0 no delay; > 0 enable with delay ");
42  defineOptionalProperty<int>("PingTopicDelayMS", -1, "Delay between topic ping messages: < 0 disable ping; = 0 no delay; > 0 enable with delay ");
43  defineOptionalProperty<int>("RemoteTopicSleepDelayMS", -1, "Delay between topic sleep calls: < 0 disable; = 0 no delay; > 0 enable with delay ");
44  defineOptionalProperty<int>("SleepDuringTopicPing", -1, "Sleep during topic ping: < 0 disable; = 0 no delay; > 0 enable with delay ");
45  }
46 
47 
48  std::string PingLoadTest::getDefaultName() const
49  {
50  return "PingLoadTest";
51  }
52 
53 
55  {
56  // Register offered topices and used proxies here.
57  offeringTopicFromProperty("DebugObserverName");
58  // debugDrawer.offeringTopic(*this); // Calls this->offeringTopic().
59  if (getProperty<std::string>("RemotePingComponentName").getValue() != "")
60  {
61  usingProxyFromProperty("RemotePingComponentName");
62  }
63  // Using a proxy will cause the component to wait until the proxy is available.
64  // usingProxyFromProperty("MyProxyName");
65 
66  offeringTopicFromProperty("PingTopicName");
67  usingTopicFromProperty("PingTopicName");
68 
69  getProperty(PingProxyDelayMS, "PingProxyDelayMS");
70  getProperty(PingTopicDelayMS, "PingTopicDelayMS");
71  getProperty(RemoteTopicSleepDelayMS, "RemoteTopicSleepDelayMS");
72  getProperty(SleepDuringTopicPing, "SleepDuringTopicPing");
73 
74  ARMARX_IMPORTANT << VAROUT(PingProxyDelayMS);
75  ARMARX_IMPORTANT << VAROUT(PingTopicDelayMS);
76  ARMARX_IMPORTANT << VAROUT(RemoteTopicSleepDelayMS);
77 
78 
79  }
80 
81 
82 
83 
85  {
86  // Get topics and proxies here. Pass the *InterfacePrx type as template argument.
87  debugObserver = getTopicFromProperty<DebugObserverInterfacePrx>("DebugObserverName");
88  // debugDrawer.getTopic(*this); // Calls this->getTopic().
89 
90  if (getProperty<std::string>("RemotePingComponentName").getValue() != "")
91  {
92  getProxyFromProperty(remotePingPrx, "RemotePingComponentName");
93  }
94  getTopicFromProperty(pingTopicPrx, "PingTopicName");
95 
96  // getProxyFromProperty<MyProxyInterfacePrx>("MyProxyName");
97 
98  if (PingProxyDelayMS >= 0)
99  {
100  taskProxyPing = new RunningTask<PingLoadTest>(this, &PingLoadTest::taskProxyPingRun, "taskProxyPing");
101  taskProxyPing->start();
102  }
103  if (PingTopicDelayMS >= 0)
104  {
105  taskTopicPing = new RunningTask<PingLoadTest>(this, &PingLoadTest::taskTopicPingRun, "taskTopicPing");
106  taskTopicPing->start();
107  }
108  if (RemoteTopicSleepDelayMS >= 0)
109  {
110  taskTopicSleep = new RunningTask<PingLoadTest>(this, &PingLoadTest::taskTopicSleepPingRun, "taskTopicSleep");
111  taskTopicSleep->start();
112  }
113  }
114 
115  void PingLoadTest::taskProxyPingRun()
116  {
117  while (taskProxyPing->isRunning())
118  {
119  remotePingPrx->ping(TimeUtil::GetTime().toMicroSeconds());
120  TimeUtil::SleepMS(PingProxyDelayMS);
121  }
122  }
123  void PingLoadTest::taskTopicPingRun()
124  {
125  topicPingSeqNr = 0;
126  while (taskTopicPing->isRunning())
127  {
128  pingTopicPrx->pingTopic(topicPingSeqNr, TimeUtil::GetTime().toMicroSeconds());
129  topicPingSeqNr++;
130  TimeUtil::SleepMS(PingTopicDelayMS);
131  }
132  }
133  void PingLoadTest::taskTopicSleepPingRun()
134  {
135  while (taskTopicSleep->isRunning())
136  {
137  pingTopicPrx->remoteTopicSleep("__any__", 1000);
138  TimeUtil::SleepMS(RemoteTopicSleepDelayMS);
139  }
140  }
141 
142 
144  {
145 
146  }
147 
148 
150  {
151 
152  }
153 
154 
155 
156 
158  {
161  }
162 }
163 
164 
165 void armarx::PingLoadTest::pingTopic(int seqNr, Ice::Long senderTime, const Ice::Current&)
166 {
167  ARMARX_IMPORTANT << "seqNr: " << seqNr << " " << getName() + ": pingTopic. Time diff: " << (TimeUtil::GetTime().toMicroSeconds() - senderTime) << "us";
168  if (SleepDuringTopicPing > 0)
169  {
170  ARMARX_IMPORTANT << "seqNr: " << seqNr << " sleeping for " << SleepDuringTopicPing << "ms";
171  TimeUtil::SleepMS(SleepDuringTopicPing);
172  ARMARX_IMPORTANT << "seqNr: " << seqNr << " finshed sleep";
173  }
174 }
175 
176 void armarx::PingLoadTest::remoteTopicSleep(const std::string& targetNameFilter, Ice::Long sleepMS, const Ice::Current&)
177 {
178  if (targetNameFilter == getName() || targetNameFilter == "" || targetNameFilter == "__any__")
179  {
180  ARMARX_IMPORTANT << "remoteTopicSleep: sleeping for " << sleepMS << "ms";
181  TimeUtil::SleepMS(sleepMS);
182  }
183 }
184 
185 void armarx::PingLoadTest::ping(Ice::Long senderTime, const Ice::Current&)
186 {
187  ARMARX_IMPORTANT << getName() + ": ping. Time diff: " << (TimeUtil::GetTime().toMicroSeconds() - senderTime) << "us";
188 }
189 
191 {
192  return TimeUtil::GetTime().toMicroSeconds();
193 }
armarx::PingLoadTest::ping
void ping(Ice::Long senderTime, const Ice::Current &) override
Definition: PingLoadTest.cpp:185
ARMARX_IMPORTANT
#define ARMARX_IMPORTANT
Definition: Logging.h:183
armarx::PingLoadTest::onInitComponent
virtual void onInitComponent() override
Definition: PingLoadTest.cpp:54
armarx::PingLoadTest::pingTopic
void pingTopic(int seqNr, Ice::Long senderTime, const Ice::Current &) override
Definition: PingLoadTest.cpp:165
armarx::Component::offeringTopicFromProperty
void offeringTopicFromProperty(const std::string &propertyName)
Offer a topic whose name is specified by the given property.
Definition: Component.cpp:154
armarx::PingLoadTest::createPropertyDefinitions
virtual armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
Definition: PingLoadTest.cpp:157
armarx::Component::usingProxyFromProperty
bool usingProxyFromProperty(const std::string &propertyName, const std::string &endpoints="")
Use a proxy whose name is specified by the given property.
Definition: Component.cpp:167
armarx::PingLoadTest::onConnectComponent
virtual void onConnectComponent() override
Definition: PingLoadTest.cpp:84
armarx::RunningTask
Definition: ArmarXMultipleObjectsScheduler.h:35
armarx::Component::getTopicFromProperty
TopicProxyType getTopicFromProperty(const std::string &propertyName)
Get a topic proxy whose name is specified by the given property.
Definition: Component.h:218
armarx::Component::getProxyFromProperty
ProxyType getProxyFromProperty(const std::string &propertyName, bool addToDependencies=false, const std::string &endpoints="", bool throwOnProxyError=true)
Get a proxy whose name is specified by the given property.
Definition: Component.h:236
armarx::Component::usingTopicFromProperty
void usingTopicFromProperty(const std::string &propertyName, bool orderedPublishing=false)
Use a topic whose name is specified by the given property.
Definition: Component.cpp:160
armarx::VariantType::Long
const VariantTypeId Long
Definition: Variant.h:917
armarx::PingLoadTest::remoteTopicSleep
void remoteTopicSleep(const std::string &targetNameFilter, Ice::Long sleepMS, const Ice::Current &) override
Definition: PingLoadTest.cpp:176
armarx::TimeUtil::GetTime
static IceUtil::Time GetTime(TimeMode timeMode=TimeMode::VirtualTime)
Get the current time.
Definition: TimeUtil.cpp:42
armarx::PingLoadTestPropertyDefinitions
Definition: PingLoadTest.h:40
armarx::Component::getConfigIdentifier
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
Definition: Component.cpp:74
armarx::TimeUtil::SleepMS
static void SleepMS(float milliseconds)
Definition: TimeUtil.h:195
armarx::ComponentPropertyDefinitions
Default component property definition container.
Definition: Component.h:70
TimeUtil.h
armarx::PropertyUser::getProperty
Property< PropertyType > getProperty(const std::string &name)
Property creation and retrieval.
Definition: PropertyUser.h:179
VAROUT
#define VAROUT(x)
Definition: StringHelpers.h:182
IceUtil::Handle< class PropertyDefinitionContainer >
armarx::PingLoadTest::getDefaultName
virtual std::string getDefaultName() const override
Definition: PingLoadTest.cpp:48
armarx::PingLoadTest::getRemoteTime
Ice::Long getRemoteTime(const Ice::Current &) override
Definition: PingLoadTest.cpp:190
PingLoadTest.h
armarx::ManagedIceObject::getName
std::string getName() const
Retrieve name of object.
Definition: ManagedIceObject.cpp:107
armarx::PingLoadTestPropertyDefinitions::PingLoadTestPropertyDefinitions
PingLoadTestPropertyDefinitions(std::string prefix)
Definition: PingLoadTest.cpp:30
armarx::PingLoadTest::onExitComponent
virtual void onExitComponent() override
Definition: PingLoadTest.cpp:149
armarx::PropertyDefinitionsPtr
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
Definition: forward_declarations.h:34
armarx::PingLoadTest::onDisconnectComponent
virtual void onDisconnectComponent() override
Definition: PingLoadTest.cpp:143
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28