TopicTimingClient.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 RobotAPI::ArmarXObjects::TopicTimingClient
17 * @author Fabian Paus ( fabian dot paus 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 "TopicTimingClient.h"
24
26
27namespace armarx
28{
31 {
32 defineOptionalProperty<std::string>("TimingTestTopicName", "TimingTestTopic", "-");
34 "SimulateWorkForMS", 20, "Sleeps until it returns from the topic call");
35
37 "DebugObserverName", "DebugObserver", "Name of the topic the DebugObserver listens on");
38 }
39
40 std::string
42 {
43 return "TopicTimingClient";
44 }
45
46 void
48 {
49 usingTopicFromProperty("TimingTestTopicName");
50
51 offeringTopicFromProperty("DebugObserverName");
52 }
53
54 void
56 {
57 // Get topics and proxies here. Pass the *InterfacePrx type as template argument.
58 debugObserver = getTopicFromProperty<DebugObserverInterfacePrx>("DebugObserverName");
59 // debugDrawer.getTopic(*this); // Calls this->getTopic().
60
61 // getProxyFromProperty<MyProxyInterfacePrx>("MyProxyName");
62
63 lastSmallTime = IceUtil::Time::now();
64
65 updateTimes = boost::circular_buffer<IceUtil::Time>(11);
66
67 simulateWorkForMS = getProperty<int>("SimulateWorkForMS").getValue();
68 }
69
70 void
74
75 void
79
86} // namespace armarx
87
88void
89armarx::TopicTimingClient::reportSmall(const topic_timing::SmallData& data, const Ice::Current&)
90{
91 IceUtil::Time time_now = IceUtil::Time::now();
92
93 IceUtil::Time time_sent = IceUtil::Time::microSeconds(data.sentTimestamp);
94
95 IceUtil::Time dur_transfer = time_now - time_sent;
96
97 IceUtil::Time dur_cycle;
98 {
99 std::unique_lock<std::mutex> lock(mutex);
100 dur_cycle = time_now - lastSmallTime;
101 lastSmallTime = time_now;
102 updateTimes.push_back(time_now);
103
104 usleep(simulateWorkForMS * 1000);
105 }
106
107 // Calculate updates per second
108 float updatesPerSecond = 0.0f;
109 IceUtil::Time duration = IceUtil::Time::microSeconds(0);
110 if (updateTimes.size() > 1)
111 {
112 duration = updateTimes.back() - updateTimes.front();
113 updatesPerSecond = (updateTimes.size() - 1) / duration.toSecondsDouble();
114 }
115
116 StringVariantBaseMap channel;
117 channel["DurationTransfer"] = new Variant(dur_transfer.toMilliSecondsDouble());
118 channel["DurationCycle"] = new Variant(dur_cycle.toMilliSecondsDouble());
119 channel["Duration10"] = new Variant(duration.toMilliSecondsDouble());
120 channel["UpdatesPerSecond"] = new Variant(updatesPerSecond);
121 debugObserver->setDebugChannel("TopicTimingClientSmall-" + getName(), channel);
122}
123
124void
125armarx::TopicTimingClient::reportBig(const topic_timing::BigData& data, const Ice::Current&)
126{
127 IceUtil::Time sentTime = IceUtil::Time::microSeconds(data.sentTimestamp);
128 (void)sentTime;
129}
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
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.
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.
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)
virtual void onInitComponent() override
void reportBig(const topic_timing::BigData &data, const Ice::Current &) override
virtual void onDisconnectComponent() override
virtual armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
void reportSmall(const topic_timing::SmallData &data, const Ice::Current &) override
virtual void onConnectComponent() override
virtual void onExitComponent() override
virtual std::string getDefaultName() const override
The Variant class is described here: Variants.
Definition Variant.h:224
This file offers overloads of toIce() and fromIce() functions for STL container types.
std::map< std::string, VariantBasePtr > StringVariantBaseMap
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.