The StatisticsRegistry class reads the value of registered variables and publishes them on the specified topic. More...
#include <pal_statistics.h>
Classes | |
struct | EnabledId |
struct | GeneratedStatistics |
Public Member Functions | |
pal_statistics_msgs::Statistics | createMsg () |
createMsg creates a Statistics message from the registered variables, useful for debugging More... | |
bool | disable (const IdType &id) |
bool | enable (const IdType &id) |
void | publish () |
publish Reads the values of all registered variables and publishes them to the topic associated to this object. More... | |
bool | publishAsync () |
publishAsync Capture data and flag it to be published by the publisher thread. Real-Time safe. More... | |
template<typename T > | |
void | publishCustomStatistic (const std::string &name, T value) |
publishCustomStatistic publishes a one-time statistic More... | |
void | publishCustomStatistics (const pal_statistics_msgs::Statistics &msg) |
publishCustomStatistic publishes a one-time statistics msg More... | |
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 More... | |
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 function call to read the variable More... | |
void | startPublishThread () |
startPublishThread creates and starts the publisherThread. The user still has to call publishAsync each time a message must be publisher. More... | |
StatisticsRegistry (const std::string &topic) | |
void | unregisterVariable (const std::string &name, RegistrationsRAII *bookkeeping=NULL) |
void | unregisterVariable (IdType id, RegistrationsRAII *bookkeeping=NULL) |
virtual | ~StatisticsRegistry () |
Private Member Functions | |
void | doPublish (bool publish_names_msg=true) |
doPublish publishes the subscribed topics, requires mutex More... | |
FRIEND_TEST (PalStatisticsTest, stressAsync) | |
void | handlePendingDisables (const boost::unique_lock< boost::mutex > &data_lock) |
handlePendingDisables Empties by handling the queue of disabled/enabled ids. More... | |
void | publisherThreadCycle () |
IdType | registerInternal (const std::string &name, VariableHolder &&variable, RegistrationsRAII *bookkeeping, bool enabled) |
bool | setEnabledmpl (const IdType &id, bool enabled) |
void | startPublishThreadImpl () |
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 More... | |
void | updateMsgUnsafe () |
updateMsgUnsafe Updates the internal message variable without acquiring the mutex Should only be used if the mutex has already been acquired by the thread calling this More... | |
Private Attributes | |
boost::mutex | data_mutex_ |
LockFreeQueue< EnabledId > | enabled_ids_ |
disabled_ids_ this is used to keep track of enabled/disabled variables in a lock free way More... | |
GeneratedStatistics | generated_statistics_ |
RegistrationsRAII | internal_stats_raii_ |
std::atomic< bool > | interrupt_thread_ |
std::atomic< bool > | is_data_ready_ |
double | last_async_pub_duration_ |
pal_statistics_msgs::StatisticsNames | names_msg_ |
ros::NodeHandle | nh_ |
ros::Publisher | pub_ |
boost::mutex | pub_mutex_ |
ros::Publisher | pub_names_ |
ros::Publisher | pub_values_ |
unsigned int | publish_async_attempts_ |
unsigned int | publish_async_failures_ |
boost::shared_ptr< boost::thread > | publisher_thread_ |
RegistrationList | registration_list_ |
pal_statistics_msgs::StatisticsValues | values_msg_ |
The StatisticsRegistry class reads the value of registered variables and publishes them on the specified topic.
If you are using repeated names, it's better to use the Id of the registered variables or the RegistratonRAII for unregister/disable
Definition at line 53 of file pal_statistics.h.
pal_statistics::StatisticsRegistry::StatisticsRegistry | ( | const std::string & | topic | ) |
Definition at line 14 of file pal_statistics.cpp.
|
virtual |
Definition at line 31 of file pal_statistics.cpp.
pal_statistics_msgs::Statistics pal_statistics::StatisticsRegistry::createMsg | ( | ) |
createMsg creates a Statistics message from the registered variables, useful for debugging
Definition at line 183 of file pal_statistics.cpp.
bool pal_statistics::StatisticsRegistry::disable | ( | const IdType & | id | ) |
Definition at line 202 of file pal_statistics.cpp.
|
private |
doPublish publishes the subscribed topics, requires mutex
Definition at line 163 of file pal_statistics.cpp.
bool pal_statistics::StatisticsRegistry::enable | ( | const IdType & | id | ) |
These functions disable/enable the publication of one or more variables
They are RT safe and thread safe. They guarantee that on the next publish (or publishAsync) call, the specified variables will or will not be read and published.
If you need a deterministic way of preventing a variable from being published, you need to unregister it, but it is not RT safe.
Definition at line 197 of file pal_statistics.cpp.
|
private |
|
private |
handlePendingDisables Empties by handling the queue of disabled/enabled ids.
Definition at line 149 of file pal_statistics.cpp.
void pal_statistics::StatisticsRegistry::publish | ( | ) |
publish Reads the values of all registered variables and publishes them to the topic associated to this object.
Definition at line 74 of file pal_statistics.cpp.
bool pal_statistics::StatisticsRegistry::publishAsync | ( | ) |
publishAsync Capture data and flag it to be published by the publisher thread. Real-Time safe.
Definition at line 86 of file pal_statistics.cpp.
|
inline |
publishCustomStatistic publishes a one-time statistic
Definition at line 115 of file pal_statistics.h.
|
inline |
publishCustomStatistic publishes a one-time statistics msg
Definition at line 129 of file pal_statistics.h.
|
private |
Definition at line 220 of file pal_statistics.cpp.
IdType pal_statistics::StatisticsRegistry::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
bookkeeping | same as in registerVariable |
Definition at line 44 of file pal_statistics.cpp.
|
private |
Definition at line 125 of file pal_statistics.cpp.
|
inline |
registerVariable Specialization for double*, the most common case, to avoid going through a boost function call to read the variable
Definition at line 64 of file pal_statistics.h.
|
private |
Definition at line 140 of file pal_statistics.cpp.
void pal_statistics::StatisticsRegistry::startPublishThread | ( | ) |
startPublishThread creates and starts the publisherThread. The user still has to call publishAsync each time a message must be publisher.
Definition at line 115 of file pal_statistics.cpp.
|
private |
Definition at line 120 of file pal_statistics.cpp.
void pal_statistics::StatisticsRegistry::unregisterVariable | ( | const std::string & | name, |
RegistrationsRAII * | bookkeeping = NULL |
||
) |
Definition at line 62 of file pal_statistics.cpp.
void pal_statistics::StatisticsRegistry::unregisterVariable | ( | IdType | id, |
RegistrationsRAII * | bookkeeping = NULL |
||
) |
Definition at line 51 of file pal_statistics.cpp.
|
private |
updateMsg update names and values, optionally using smartfill to minimize copying
Definition at line 207 of file pal_statistics.cpp.
|
private |
updateMsgUnsafe Updates the internal message variable without acquiring the mutex Should only be used if the mutex has already been acquired by the thread calling this
|
private |
Definition at line 185 of file pal_statistics.h.
|
private |
disabled_ids_ this is used to keep track of enabled/disabled variables in a lock free way
enable/disable need to write, but they cannot be locked, and cannot be skipped if they fail to acquire a mutex. Therefore they write to a lockfree structure. This structure is processed in the next publish or publishAsync that has the write lock and can modify shared structures.
Definition at line 205 of file pal_statistics.h.
|
private |
Definition at line 233 of file pal_statistics.h.
|
private |
Definition at line 238 of file pal_statistics.h.
|
private |
Definition at line 215 of file pal_statistics.h.
|
private |
Definition at line 214 of file pal_statistics.h.
|
private |
Definition at line 237 of file pal_statistics.h.
|
private |
Definition at line 231 of file pal_statistics.h.
|
private |
Definition at line 183 of file pal_statistics.h.
|
private |
Definition at line 210 of file pal_statistics.h.
|
private |
Definition at line 209 of file pal_statistics.h.
|
private |
Definition at line 211 of file pal_statistics.h.
|
private |
Definition at line 212 of file pal_statistics.h.
|
private |
Definition at line 235 of file pal_statistics.h.
|
private |
Definition at line 236 of file pal_statistics.h.
|
private |
Definition at line 216 of file pal_statistics.h.
|
private |
Definition at line 186 of file pal_statistics.h.
|
private |
Definition at line 232 of file pal_statistics.h.