26 #ifndef _PAL_STATISTICS_H_ 27 #define _PAL_STATISTICS_H_ 30 #include <boost/thread/lock_guard.hpp> 31 #include <boost/thread/mutex.hpp> 32 #include <boost/thread/condition_variable.hpp> 33 #include <boost/thread/thread.hpp> 34 #include <pal_statistics_msgs/Statistics.h> 36 #include <gtest/gtest_prod.h> 109 pal_statistics_msgs::Statistics
createMsg();
114 template <
typename T>
117 pal_statistics_msgs::Statistics msg;
118 pal_statistics_msgs::Statistic stat;
120 stat.value =
static_cast<double>(value);
121 msg.statistics.push_back(stat);
162 bool updateMsg(pal_statistics_msgs::StatisticsNames &names,
163 pal_statistics_msgs::StatisticsValues &values,
bool smart_fill =
false);
181 void doPublish(
bool publish_names_msg =
true);
220 : last_names_version_(-1)
222 void update(
const pal_statistics_msgs::StatisticsNames &names,
223 const pal_statistics_msgs::StatisticsValues &values);
226 pal_statistics_msgs::Statistics
msg_;
bool publishAsync()
publishAsync Capture data and flag it to be published by the publisher thread. Real-Time safe...
IdType registerInternal(const std::string &name, VariableHolder &&variable, RegistrationsRAII *bookkeeping, bool enabled)
The RegistrationList class.
StatisticsRegistry(const std::string &topic)
FRIEND_TEST(PalStatisticsTest, stressAsync)
pal_statistics_msgs::StatisticsValues values_msg_
ros::Publisher pub_values_
The StatisticsRegistry class reads the value of registered variables and publishes them on the specif...
unsigned int last_names_version_
void doPublish(bool publish_names_msg=true)
doPublish publishes the subscribed topics, requires mutex
bool updateMsg(pal_statistics_msgs::StatisticsNames &names, pal_statistics_msgs::StatisticsValues &values, bool smart_fill=false)
updateMsg update names and values, optionally using smartfill to minimize copying ...
GeneratedStatistics generated_statistics_
RegistrationList registration_list_
void publishCustomStatistic(const std::string &name, T value)
publishCustomStatistic publishes a one-time statistic
bool enable(const IdType &id)
RegistrationsRAII internal_stats_raii_
void startPublishThread()
startPublishThread creates and starts the publisherThread. The user still has to call publishAsync ea...
void publish()
publish Reads the values of all registered variables and publishes them to the topic associated to th...
unsigned int publish_async_attempts_
void update(const std::string &key, const XmlRpc::XmlRpcValue &v)
void publish(const boost::shared_ptr< M > &message) const
bool setEnabledmpl(const IdType &id, bool enabled)
boost::shared_ptr< boost::thread > publisher_thread_
void updateMsgUnsafe()
updateMsgUnsafe Updates the internal message variable without acquiring the mutex Should only be used...
pal_statistics_msgs::Statistics msg_
This message is generated using an updated StatiticsNames and StatisticsValues.
ros::Publisher pub_names_
double last_async_pub_duration_
pal_statistics_msgs::StatisticsNames names_msg_
LockFreeQueue< EnabledId > enabled_ids_
disabled_ids_ this is used to keep track of enabled/disabled variables in a lock free way ...
IdType registerVariable(const std::string &name, const double *variable, RegistrationsRAII *bookkeeping=NULL, bool enabled=true)
registerVariable Specialization for double*, the most common case, to avoid going through a boost fun...
virtual ~StatisticsRegistry()
void publisherThreadCycle()
The RegistrationsRAII class holds handles to registered variables and when it is destroyed, unregisters them automatically.
unsigned int publish_async_failures_
void publishCustomStatistics(const pal_statistics_msgs::Statistics &msg)
publishCustomStatistic publishes a one-time statistics msg
bool disable(const IdType &id)
Simple wrapper around boost lockfree queue to keep track of the reserved memory Boost's implementatio...
void startPublishThreadImpl()
pal_statistics_msgs::Statistics createMsg()
createMsg creates a Statistics message from the registered variables, useful for debugging ...
void unregisterVariable(const std::string &name, RegistrationsRAII *bookkeeping=NULL)
void handlePendingDisables(const boost::unique_lock< boost::mutex > &data_lock)
handlePendingDisables Empties by handling the queue of disabled/enabled ids.
IdType registerFunction(const std::string &name, const boost::function< double()> &funct, RegistrationsRAII *bookkeeping=NULL, bool enabled=true)
registerFunction Adds a function that returns double with the specified name
std::atomic< bool > is_data_ready_