14#define DLINEAR_STATS_FMT "{:<35} @ {:<26} = {:>15} sec"
15#define DLINEAR_ITERATION_STATS_FMT "{:<35} @ {:<26} = {:>15}"
19Stats::Stats(
const bool enabled, std::string class_name, std::string operations_name)
20 : timer_{}, enabled_{enabled}, class_name_{
std::move(class_name)}, operations_name_{
std::move(operations_name)} {}
33Stats Stats::operator+(
const Stats &other)
const {
49 std::string iterations_name)
50 :
Stats(enabled,
std::move(class_name),
std::move(operations_name)),
52 iterations_name_{
std::move(iterations_name)} {}
54 :
Stats(other), iterations_{other.iterations_.load()}, iterations_name_{other.iterations_name_} {}
56void IterationStats::operator++() {
Increase(); }
57void IterationStats::operator++(
int) {
Increase(); }
58IterationStats &IterationStats::operator=(
const IterationStats &other) {
60 Stats::operator=(other);
66IterationStats &IterationStats::operator+=(
const IterationStats &other) {
67 Stats::operator+=(other);
69 std::atomic_fetch_add_explicit(&
iterations_, other.iterations_.load(), std::memory_order_relaxed);
72IterationStats IterationStats::operator+(
const IterationStats &other)
const {
78std::ostream &operator<<(std::ostream &os,
const Stats &stats) {
return os << stats.ToString(); }
79std::ostream &operator<<(std::ostream &os,
const IterationStats &stats) {
return os << stats.ToString(); }
Dataclass collecting statistics about some operation or process.
std::string ToSegmentString() const override
Convert the current state of the object to a formatted string, only including the specific part the S...
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::atomic< unsigned int > iterations_
Atomic counter for the total number of iterations.
std::string ToString() const override
Convert the current state of the object to a formatted string.
std::string iterations_name_
Name to give to the iteration operation.
void Increase()
Increase the iteration counter by one.
Dataclass collecting statistics about some operation or process.
std::string class_name_
Name of the class running the operation the Stats object is collecting statistics for.
Timer timer_
Timer object to measure the cumulative time spent in the operation.
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...
bool enabled_
Flag to enable/disable the collection of statistics.
virtual std::string ToString() const
Convert the current state of the object to a formatted string.
std::string operations_name_
Name of the operation the Stats object is collecting statistics for.
std::chrono::duration< double >::rep seconds() const
Get read-only access to the number elapsed seconds of the timer.
Global namespace for the dlinear library.