Belle II Software  release-08-01-10
ZMQLogger Class Reference

Base class for the ZMQ connection to help monitor and log certain values. More...

#include <ZMQLogger.h>

Inheritance diagram for ZMQLogger:
Collaboration diagram for ZMQLogger:

Classes

struct  Decrementor
 Visitor Helper for decrementing a numerical value. More...
 
struct  Incrementor
 Visitor Helper for incrementing a numerical value. More...
 
struct  toJSON
 Visitor Helper for converting a variant value into a JSON string. More...
 

Public Member Functions

virtual std::string getMonitoringJSON () const
 Convert the stored monitoring values to a JSON string ready for sending out via a message.
 
template<class AClass >
void log (const std::string &key, const AClass &value)
 Store a value under a certain key. Different types of values can be stored, namely long, double or string. Mixtures are not allowed for a given key.
 
void increment (const std::string &key)
 Increment the value with the given key (only numerical values). If not present, set to 1.
 
void decrement (const std::string &key)
 Decrement the value with the given key (only numerical values). If not present, set to -1.
 
template<size_t MAX_SIZE = 100>
void average (const std::string &key, double value)
 Instead of storeing the double value directly under the given key, store the average of the last MAX_SIZE values.
 
template<size_t AVERAGE_SIZE = 2000>
void timeit (const std::string &key)
 Measure the rate of calls with the same key every AVERAGE_SIZE calls (and also display the last time AVERAGE_SIZE was reached under <key>_last_measurement)
 
void logTime (const std::string &key)
 Store the current time as a string under the given key.
 

Private Attributes

std::map< std::string, std::variant< long, double, std::string > > m_monitoring
 Internal storage of all stored values.
 
std::unordered_map< std::string, std::tuple< std::vector< double >, size_t > > m_averages
 Internal storage of the previous values when calculating averages.
 
std::unordered_map< std::string, std::tuple< unsigned long, std::chrono::system_clock::time_point > > m_timeCounters
 Internal storage how often the timeit function for a given key was called and when it has last reached MAX_SIZE.
 

Detailed Description

Base class for the ZMQ connection to help monitor and log certain values.

Which and when to monitor/log must be defined by the derived classes, this base class only gives helpers to store/add/average/measure time and most importantly convert all stored monitoring values to a JSON string on request (useful e.g. for monitoring purposes).

Please note, that in all cases you need to call the corresponding monitor function by yourself. There is no "registering" of monitor values, values will only be stored on actively calling a monitor function (e.g. log).

Definition at line 35 of file ZMQLogger.h.


The documentation for this class was generated from the following files: