 |
Belle II Software
release-05-01-25
|
16 #include <unordered_map>
43 template<
class AClass>
44 void log(
const std::string& key,
const AClass& value);
50 template<
size_t MAX_SIZE = 100>
51 void average(
const std::string& key,
double value);
53 template<
size_t AVERAGE_SIZE = 2000>
54 void timeit(
const std::string& key);
56 void logTime(
const std::string& key);
60 std::map<std::string, std::variant<long, double, std::string>>
m_monitoring;
62 std::unordered_map<std::string, std::tuple<std::vector<double>,
size_t>>
m_averages;
64 std::unordered_map<std::string, std::tuple<unsigned long, std::chrono::system_clock::time_point>>
m_timeCounters;
73 std::string
operator()(
const std::string& value);
97 template<
class AClass>
103 template<
size_t MAX_SIZE>
108 if (averages.size() == MAX_SIZE) {
109 averages[index] = value;
110 index = (index + 1) % MAX_SIZE;
112 averages.push_back(value);
115 log(key, std::accumulate(averages.begin(), averages.end(), 0.0) / averages.size());
118 template<
size_t AVERAGE_SIZE>
122 if (calls % AVERAGE_SIZE == 0) {
123 auto current = std::chrono::high_resolution_clock::now();
124 double elapsed = std::chrono::duration_cast<std::chrono::duration<double>>(
125 current - timestamp).count();
127 log(key, AVERAGE_SIZE / elapsed);
132 auto displayTime = std::chrono::system_clock::to_time_t(current);
133 log(key +
"_last_measurement", std::ctime(&displayTime));
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 reache...
std::string operator()(long value)
just stringify longs
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 ...
Visitor Helper for decrementing a numerical value.
void logTime(const std::string &key)
Store the current time as a string under the given key.
void operator()(long &value)
-1 for longs
void decrement(const std::string &key)
Decrement the value with the given key (only numerical values). If not present, set to -1.
std::unordered_map< std::string, std::tuple< std::vector< double >, size_t > > m_averages
Internal storage of the previous values when calculating averages.
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,...
void increment(const std::string &key)
Increment the value with the given key (only numerical values). If not present, set to 1.
Abstract base class for different kinds of events.
void operator()(long &value)
+1 for longs
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_...
Visitor Helper for incrementing a numerical value.
virtual std::string getMonitoringJSON() const
Convert the stored monitoring values to a JSON string ready for sending out via a message.
std::map< std::string, std::variant< long, double, std::string > > m_monitoring
Internal storage of all stored values.