Go to the documentation of this file.
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);
223 void update(
const pal_statistics_msgs::StatisticsNames &names,
224 const pal_statistics_msgs::StatisticsValues &values);
227 pal_statistics_msgs::Statistics
msg_;
RegistrationsRAII internal_stats_raii_
bool enable(const IdType &id)
void startPublishThreadImpl()
void publish()
publish Reads the values of all registered variables and publishes them to the topic associated to th...
bool disable(const IdType &id)
bool publishAsync()
publishAsync Capture data and flag it to be published by the publisher thread. Real-Time safe.
void doPublish(bool publish_names_msg=true)
doPublish publishes the subscribed topics, requires mutex
StatisticsRegistry(const std::string &topic)
bool setEnabledmpl(const IdType &id, bool enabled)
FRIEND_TEST(PalStatisticsTest, stressAsync)
void startPublishThread()
startPublishThread creates and starts the publisherThread. The user still has to call publishAsync ea...
The StatisticsRegistry class reads the value of registered variables and publishes them on the specif...
unsigned int publish_async_failures_
void unregisterVariable(const std::string &name, RegistrationsRAII *bookkeeping=NULL)
Simple wrapper around boost lockfree queue to keep track of the reserved memory Boost's implementatio...
pal_statistics_msgs::Statistics msg_
This message is generated using an updated StatiticsNames and StatisticsValues.
ros::Publisher pub_values_
double last_async_pub_duration_
void publish(const boost::shared_ptr< M > &message) const
The RegistrationList class.
GeneratedStatistics generated_statistics_
void publishCustomStatistic(const std::string &name, T value)
publishCustomStatistic publishes a one-time statistic
pal_statistics_msgs::Statistics createMsg()
createMsg creates a Statistics message from the registered variables, useful for debugging
std::atomic< bool > is_data_ready_
pal_statistics_msgs::StatisticsNames names_msg_
unsigned int last_names_version_
virtual ~StatisticsRegistry()
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
void publisherThreadCycle()
void update(const pal_statistics_msgs::StatisticsNames &names, const pal_statistics_msgs::StatisticsValues &values)
pal_statistics_msgs::StatisticsValues values_msg_
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...
void publishCustomStatistics(const pal_statistics_msgs::Statistics &msg)
publishCustomStatistic publishes a one-time statistics msg
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
ros::Publisher pub_names_
unsigned int publish_async_attempts_
LockFreeQueue< EnabledId > enabled_ids_
disabled_ids_ this is used to keep track of enabled/disabled variables in a lock free way
std::atomic< bool > interrupt_thread_
boost::shared_ptr< boost::thread > publisher_thread_
IdType registerInternal(const std::string &name, VariableHolder &&variable, RegistrationsRAII *bookkeeping, bool enabled)
void updateMsgUnsafe()
updateMsgUnsafe Updates the internal message variable without acquiring the mutex Should only be used...
The RegistrationsRAII class holds handles to registered variables and when it is destroyed,...
RegistrationList registration_list_