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
27namespace armarx
28{
31 {
32 //defineRequiredProperty<std::string>("PropertyName", "Description");
33 //defineOptionalProperty<std::string>("PropertyName", "DefaultValue", "Description");
34
36 "DebugObserverName", "DebugObserver", "Name of the topic the DebugObserver listens on");
37
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 ");
51 "RemoteTopicSleepDelayMS",
52 -1,
53 "Delay between topic sleep calls: < 0 disable; = 0 no delay; > 0 enable with delay ");
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
163
164 void
168
175} // namespace armarx
176
177void
178armarx::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
190void
191armarx::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
202void
203armarx::PingLoadTest::ping(Ice::Long senderTime, const Ice::Current&)
204{
205 ARMARX_IMPORTANT << getName() + ": ping. Time diff: "
206 << (TimeUtil::GetTime().toMicroSeconds() - senderTime) << "us";
207}
208
209Ice::Long
211{
212 return TimeUtil::GetTime().toMicroSeconds();
213}
#define VAROUT(x)
ComponentPropertyDefinitions(std::string prefix, bool hasObjectNameParameter=true)
Definition Component.cpp:46
TopicProxyType getTopicFromProperty(const std::string &propertyName)
Get a topic proxy whose name is specified by the given property.
Definition Component.h:221
bool usingProxyFromProperty(const std::string &propertyName, const std::string &endpoints="")
Use a proxy whose name is specified by the given property.
void offeringTopicFromProperty(const std::string &propertyName)
Offer a topic whose name is specified by the given property.
void usingTopicFromProperty(const std::string &propertyName, bool orderedPublishing=false)
Use a topic whose name is specified by the given property.
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
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
Definition Component.cpp:90
Property< PropertyType > getProperty(const std::string &name)
std::string getName() const
Retrieve name of object.
PingLoadTestPropertyDefinitions(std::string prefix)
void remoteTopicSleep(const std::string &targetNameFilter, Ice::Long sleepMS, const Ice::Current &) override
virtual void onInitComponent() override
void pingTopic(int seqNr, Ice::Long senderTime, const Ice::Current &) override
virtual void onDisconnectComponent() override
Ice::Long getRemoteTime(const Ice::Current &) override
virtual armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
virtual void onConnectComponent() override
void ping(Ice::Long senderTime, const Ice::Current &) override
virtual void onExitComponent() override
virtual std::string getDefaultName() const override
std::string prefix
Prefix of the properties such as namespace, domain, component name, etc.
PropertyDefinition< PropertyType > & defineOptionalProperty(const std::string &name, PropertyType defaultValue, const std::string &description="", PropertyDefinitionBase::PropertyConstness constness=PropertyDefinitionBase::eConstant)
static IceUtil::Time GetTime(TimeMode timeMode=TimeMode::VirtualTime)
Get the current time.
Definition TimeUtil.cpp:42
static void SleepMS(float milliseconds)
Definition TimeUtil.h:203
#define ARMARX_IMPORTANT
The logging level for always important information, but expected behaviour (in contrast to ARMARX_WAR...
Definition Logging.h:190
This file offers overloads of toIce() and fromIce() functions for STL container types.
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.