delpi  0.0.1
DElta-complete LP solver
Loading...
Searching...
No Matches
Stats.h
1
8#pragma once
9
10#include <atomic>
11#include <iosfwd>
12#include <string>
13
14#include "delpi/util/Timer.h"
15
16namespace delpi {
17
22class Stats {
23 private:
25
26 protected:
27 bool enabled_;
28 std::string class_name_;
29 std::string operations_name_;
30
31 public:
38 explicit Stats(bool enabled, std::string class_name, std::string name_time = "Time spent in Operations");
39 Stats(const Stats &other) = default;
40 Stats &operator=(const Stats &other) = default;
41 virtual ~Stats() = default;
42
43 Stats &operator+=(const Stats &other);
44 Stats operator+(const Stats &other) const;
45
47 [[nodiscard]] bool enabled() const { return enabled_; }
49 [[nodiscard]] Timer &m_timer() { return timer_; }
51 [[nodiscard]] const Timer &timer() const { return timer_; }
53 [[nodiscard]] const std::string &class_name() const { return class_name_; }
59 [[nodiscard]] virtual std::string ToSegmentString() const;
64 [[nodiscard]] virtual std::string ToString() const;
65};
66
71class IterationStats : public Stats {
72 private:
73 std::atomic<unsigned int> iterations_;
74 std::string iterations_name_;
75
76 public:
84 explicit IterationStats(bool enabled, std::string class_name, std::string name_time = "Time spent in Operations",
85 std::string iterations_name = "Total # of Iterations");
86 IterationStats(const IterationStats &other);
87 IterationStats &operator=(const IterationStats &other);
88
89 IterationStats &operator+=(const IterationStats &other);
90 IterationStats operator+(const IterationStats &other) const;
91
92 [[nodiscard]] std::string ToSegmentString() const override;
93
94 [[nodiscard]] std::string ToString() const override;
95
100 void Increase();
101
103 [[nodiscard]] unsigned int iterations() const { return iterations_.load(); }
108 void SetIterations(const unsigned int iterations) { iterations_ = iterations; }
109
110 void operator++();
111 void operator++(int);
112};
113
114std::ostream &operator<<(std::ostream &os, const Stats &stats);
115std::ostream &operator<<(std::ostream &os, const IterationStats &stats);
116
117} // namespace delpi
118
119#ifdef DELPI_INCLUDE_FMT
120
121#include "delpi/util/logging.h"
122
123OSTREAM_FORMATTER(delpi::Stats);
124OSTREAM_FORMATTER(delpi::IterationStats);
125
126#endif
Dataclass collecting statistics about some operation or process.
Definition Stats.h:71
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.
Definition Stats.cpp:49
std::string ToString() const override
Convert the current state of the object to a formatted string.
Definition Stats.cpp:47
std::atomic< unsigned int > iterations_
Atomic counter for the total number of iterations.
Definition Stats.h:73
std::string iterations_name_
Name to give to the iteration operation.
Definition Stats.h:74
void Increase()
Increase the iteration counter by one.
Definition Stats.cpp:40
std::string ToSegmentString() const override
Convert the current state of the object to a formatted string, only including the specific part the S...
Definition Stats.cpp:44
void SetIterations(const unsigned int iterations)
Set the total number of iterations.
Definition Stats.h:108
Dataclass collecting statistics about some operation or process.
Definition Stats.h:22
virtual std::string ToString() const
Convert the current state of the object to a formatted string.
Definition Stats.cpp:26
std::string class_name_
Name of the class running the operation the Stats object is collecting statistics for.
Definition Stats.h:28
Stats(bool enabled, std::string class_name, std::string name_time="Time spent in Operations")
Construct a Stats object.
Definition Stats.cpp:20
virtual std::string ToSegmentString() const
Convert the current state of the object to a formatted string, only including the specific part the S...
Definition Stats.cpp:23
Timer timer_
Timer object to measure the cumulative time spent in the operation.
Definition Stats.h:24
bool enabled_
Flag to enable/disable the collection of statistics.
Definition Stats.h:27
std::string operations_name_
Name of the operation the Stats object is collecting statistics for.
Definition Stats.h:29
Timer class using the a steady clock.
Definition Timer.h:95
Global namespace for the delpi library.