6#include "delpi/util/Stats.h"
15#define DELPI_STATS_FMT "{:<35} @ {:<26} = {:>15} sec"
16#define DELPI_ITERATION_STATS_FMT "{:<35} @ {:<26} = {:>15}"
20Stats::Stats(
const bool enabled, std::string class_name, std::string operations_name)
34Stats Stats::operator+(
const Stats &other)
const {
50 std::string iterations_name)
51 :
Stats(enabled, std::move(class_name), std::move(operations_name)),
55 :
Stats(other), iterations_{other.iterations_.load()}, iterations_name_{other.iterations_name_} {}
57void IterationStats::operator++() {
Increase(); }
58void IterationStats::operator++(
int) {
Increase(); }
61 Stats::operator=(other);
68 Stats::operator+=(other);
70 std::atomic_fetch_add_explicit(&
iterations_, other.iterations_.load(), std::memory_order_relaxed);
79std::ostream &operator<<(std::ostream &os,
const Stats &stats) {
return os << stats.ToString(); }
80std::ostream &operator<<(std::ostream &os,
const IterationStats &stats) {
return os << stats.ToString(); }
Dataclass collecting statistics about some operation or process.
IterationStats(bool enabled, std::string class_name, std::string name_time="Time spent in Operations", std::string iterations_name="Total # of Iterations")
Construct an IterationStats object.
std::string ToString() const override
Convert the current state of the object to a formatted string.
std::atomic< unsigned int > iterations_
Atomic counter for the total number of iterations.
std::string iterations_name_
Name to give to the iteration operation.
void Increase()
Increase the iteration counter by one.
std::string ToSegmentString() const override
Convert the current state of the object to a formatted string, only including the specific part the S...
Dataclass collecting statistics about some operation or process.
virtual std::string ToString() const
Convert the current state of the object to a formatted string.
std::string class_name_
Name of the class running the operation the Stats object is collecting statistics for.
Stats(bool enabled, std::string class_name, std::string name_time="Time spent in Operations")
Construct a Stats object.
virtual std::string ToSegmentString() const
Convert the current state of the object to a formatted string, only including the specific part the S...
Timer timer_
Timer object to measure the cumulative time spent in the operation.
bool enabled_
Flag to enable/disable the collection of statistics.
std::string operations_name_
Name of the operation the Stats object is collecting statistics for.
Global namespace for the delpi library.