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 namespace armarx
28 {
31  {
32  //defineRequiredProperty<std::string>("PropertyName", "Description");
33  //defineOptionalProperty<std::string>("PropertyName", "DefaultValue", "Description");
34 
35  defineOptionalProperty<std::string>(
36  "DebugObserverName", "DebugObserver", "Name of the topic the DebugObserver listens on");
37 
38  defineOptionalProperty<std::string>(
39  "RemotePingComponentName", "", "Name of the remote ping component");
40  defineOptionalProperty<std::string>("PingTopicName", "PingTopic", "Name of the ping topic");
41 
42  defineOptionalProperty<int>("PingProxyDelayMS",
43  -1,
44  "Delay between proxy ping messages: < 0 disable ping; = 0 no "
45  "delay; > 0 enable with delay ");
46  defineOptionalProperty<int>("PingTopicDelayMS",
47  -1,
48  "Delay between topic ping messages: < 0 disable ping; = 0 no "
49  "delay; > 0 enable with delay ");
50  defineOptionalProperty<int>(
51  "RemoteTopicSleepDelayMS",
52  -1,
53  "Delay between topic sleep calls: < 0 disable; = 0 no delay; > 0 enable with delay ");
54  defineOptionalProperty<int>(
55  "SleepDuringTopicPing",
56  -1,
57  "Sleep during topic ping: < 0 disable; = 0 no delay; > 0 enable with delay ");
58  }
59 
60  std::string
62  {
63  return "PingLoadTest";
64  }
65 
66  void
68  {
69  // Register offered topices and used proxies here.
70  offeringTopicFromProperty("DebugObserverName");
71  // debugDrawer.offeringTopic(*this); // Calls this->offeringTopic().
72  if (getProperty<std::string>("RemotePingComponentName").getValue() != "")
73  {
74  usingProxyFromProperty("RemotePingComponentName");
75  }
76  // Using a proxy will cause the component to wait until the proxy is available.
77  // usingProxyFromProperty("MyProxyName");
78 
79  offeringTopicFromProperty("PingTopicName");
80  usingTopicFromProperty("PingTopicName");
81 
82  getProperty(PingProxyDelayMS, "PingProxyDelayMS");
83  getProperty(PingTopicDelayMS, "PingTopicDelayMS");
84  getProperty(RemoteTopicSleepDelayMS, "RemoteTopicSleepDelayMS");
85  getProperty(SleepDuringTopicPing, "SleepDuringTopicPing");
86 
87  ARMARX_IMPORTANT << VAROUT(PingProxyDelayMS);
88  ARMARX_IMPORTANT << VAROUT(PingTopicDelayMS);
89  ARMARX_IMPORTANT << VAROUT(RemoteTopicSleepDelayMS);
90  }
91 
92  void
94  {
95  // Get topics and proxies here. Pass the *InterfacePrx type as template argument.
96  debugObserver = getTopicFromProperty<DebugObserverInterfacePrx>("DebugObserverName");
97  // debugDrawer.getTopic(*this); // Calls this->getTopic().
98 
99  if (getProperty<std::string>("RemotePingComponentName").getValue() != "")
100  {
101  getProxyFromProperty(remotePingPrx, "RemotePingComponentName");
102  }
103  getTopicFromProperty(pingTopicPrx, "PingTopicName");
104 
105  // getProxyFromProperty<MyProxyInterfacePrx>("MyProxyName");
106 
107  if (PingProxyDelayMS >= 0)
108  {
109  taskProxyPing = new RunningTask<PingLoadTest>(
110  this, &PingLoadTest::taskProxyPingRun, "taskProxyPing");
111  taskProxyPing->start();
112  }
113  if (PingTopicDelayMS >= 0)
114  {
115  taskTopicPing = new RunningTask<PingLoadTest>(
116  this, &PingLoadTest::taskTopicPingRun, "taskTopicPing");
117  taskTopicPing->start();
118  }
119  if (RemoteTopicSleepDelayMS >= 0)
120  {
121  taskTopicSleep = new RunningTask<PingLoadTest>(
122  this, &PingLoadTest::taskTopicSleepPingRun, "taskTopicSleep");
123  taskTopicSleep->start();
124  }
125  }
126 
127  void
128  PingLoadTest::taskProxyPingRun()
129  {
130  while (taskProxyPing->isRunning())
131  {
132  remotePingPrx->ping(TimeUtil::GetTime().toMicroSeconds());
133  TimeUtil::SleepMS(PingProxyDelayMS);
134  }
135  }
136 
137  void
138  PingLoadTest::taskTopicPingRun()
139  {
140  topicPingSeqNr = 0;
141  while (taskTopicPing->isRunning())
142  {
143  pingTopicPrx->pingTopic(topicPingSeqNr, TimeUtil::GetTime().toMicroSeconds());
144  topicPingSeqNr++;
145  TimeUtil::SleepMS(PingTopicDelayMS);
146  }
147  }
148 
149  void
150  PingLoadTest::taskTopicSleepPingRun()
151  {
152  while (taskTopicSleep->isRunning())
153  {
154  pingTopicPrx->remoteTopicSleep("__any__", 1000);
155  TimeUtil::SleepMS(RemoteTopicSleepDelayMS);
156  }
157  }
158 
159  void
161  {
162  }
163 
164  void
166  {
167  }
168 
171  {
174  }
175 } // namespace armarx
176 
177 void
178 armarx::PingLoadTest::pingTopic(int seqNr, Ice::Long senderTime, const Ice::Current&)
179 {
180  ARMARX_IMPORTANT << "seqNr: " << seqNr << " " << getName() + ": pingTopic. Time diff: "
181  << (TimeUtil::GetTime().toMicroSeconds() - senderTime) << "us";
182  if (SleepDuringTopicPing > 0)
183  {
184  ARMARX_IMPORTANT << "seqNr: " << seqNr << " sleeping for " << SleepDuringTopicPing << "ms";
185  TimeUtil::SleepMS(SleepDuringTopicPing);
186  ARMARX_IMPORTANT << "seqNr: " << seqNr << " finshed sleep";
187  }
188 }
189 
190 void
191 armarx::PingLoadTest::remoteTopicSleep(const std::string& targetNameFilter,
192  Ice::Long sleepMS,
193  const Ice::Current&)
194 {
195  if (targetNameFilter == getName() || targetNameFilter == "" || targetNameFilter == "__any__")
196  {
197  ARMARX_IMPORTANT << "remoteTopicSleep: sleeping for " << sleepMS << "ms";
198  TimeUtil::SleepMS(sleepMS);
199  }
200 }
201 
202 void
203 armarx::PingLoadTest::ping(Ice::Long senderTime, const Ice::Current&)
204 {
205  ARMARX_IMPORTANT << getName() + ": ping. Time diff: "
206  << (TimeUtil::GetTime().toMicroSeconds() - senderTime) << "us";
207 }
208 
209 Ice::Long
211 {
212  return TimeUtil::GetTime().toMicroSeconds();
213 }
armarx::PingLoadTest::ping
void ping(Ice::Long senderTime, const Ice::Current &) override
Definition: PingLoadTest.cpp:203
ARMARX_IMPORTANT
#define ARMARX_IMPORTANT
Definition: Logging.h:190
armarx::PingLoadTest::onInitComponent
virtual void onInitComponent() override
Definition: PingLoadTest.cpp:67
armarx::PingLoadTest::pingTopic
void pingTopic(int seqNr, Ice::Long senderTime, const Ice::Current &) override
Definition: PingLoadTest.cpp:178
armarx::Component::offeringTopicFromProperty
void offeringTopicFromProperty(const std::string &propertyName)
Offer a topic whose name is specified by the given property.
Definition: Component.cpp:159
armarx::PingLoadTest::createPropertyDefinitions
virtual armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
Definition: PingLoadTest.cpp:170
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:172
armarx::PingLoadTest::onConnectComponent
virtual void onConnectComponent() override
Definition: PingLoadTest.cpp:93
armarx::RunningTask
Definition: ArmarXMultipleObjectsScheduler.h:36
armarx::Component::getTopicFromProperty
TopicProxyType getTopicFromProperty(const std::string &propertyName)
Get a topic proxy whose name is specified by the given property.
Definition: Component.h:221
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:242
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:165
armarx::VariantType::Long
const VariantTypeId Long
Definition: Variant.h:918
armarx::PingLoadTest::remoteTopicSleep
void remoteTopicSleep(const std::string &targetNameFilter, Ice::Long sleepMS, const Ice::Current &) override
Definition: PingLoadTest.cpp:191
armarx::TimeUtil::GetTime
static IceUtil::Time GetTime(TimeMode timeMode=TimeMode::VirtualTime)
Get the current time.
Definition: TimeUtil.cpp:42
armarx::PingLoadTestPropertyDefinitions
Definition: PingLoadTest.h:38
armarx::Component::getConfigIdentifier
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
Definition: Component.cpp:79
armarx::TimeUtil::SleepMS
static void SleepMS(float milliseconds)
Definition: TimeUtil.h:203
armarx::ComponentPropertyDefinitions
Default component property definition container.
Definition: Component.h:69
TimeUtil.h
armarx::PropertyUser::getProperty
Property< PropertyType > getProperty(const std::string &name)
Property creation and retrieval.
Definition: PropertyUser.h:180
VAROUT
#define VAROUT(x)
Definition: StringHelpers.h:198
IceUtil::Handle< class PropertyDefinitionContainer >
armarx::PingLoadTest::getDefaultName
virtual std::string getDefaultName() const override
Definition: PingLoadTest.cpp:61
armarx::PingLoadTest::getRemoteTime
Ice::Long getRemoteTime(const Ice::Current &) override
Definition: PingLoadTest.cpp:210
PingLoadTest.h
armarx::ManagedIceObject::getName
std::string getName() const
Retrieve name of object.
Definition: ManagedIceObject.cpp:108
armarx::PingLoadTestPropertyDefinitions::PingLoadTestPropertyDefinitions
PingLoadTestPropertyDefinitions(std::string prefix)
Definition: PingLoadTest.cpp:29
armarx::PingLoadTest::onExitComponent
virtual void onExitComponent() override
Definition: PingLoadTest.cpp:165
armarx::PropertyDefinitionsPtr
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
Definition: forward_declarations.h:35
armarx::PingLoadTest::onDisconnectComponent
virtual void onDisconnectComponent() override
Definition: PingLoadTest.cpp:160
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:27