dlinear  0.0.1
Delta-complete SMT solver for linear programming
Loading...
Searching...
No Matches
Stats.h
1
8#pragma once
9
10#include <atomic>
11#include <iosfwd>
12#include <string>
13
14#include "dlinear/util/Timer.h"
15
16namespace dlinear {
17
23class Stats {
24 private:
26
27 protected:
28 bool enabled_;
29 std::string class_name_;
30 std::string operations_name_;
31
32 public:
39 explicit Stats(bool enabled, std::string class_name, std::string name_time = "Time spent in Operations");
40 Stats(const Stats &other) = default;
41 Stats &operator=(const Stats &other) = default;
42 virtual ~Stats() = default;
43
44 Stats &operator+=(const Stats &other);
45 Stats operator+(const Stats &other) const;
46
48 [[nodiscard]] bool enabled() const { return enabled_; }
50 [[nodiscard]] Timer &m_timer() { return timer_; }
52 [[nodiscard]] const Timer &timer() const { return timer_; }
58 [[nodiscard]] virtual std::string ToSegmentString() const;
63 [[nodiscard]] virtual std::string ToString() const;
64};
65
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(); }
104
105 void operator++();
106 void operator++(int);
107};
108
109std::ostream &operator<<(std::ostream &os, const Stats &stats);
110std::ostream &operator<<(std::ostream &os, const IterationStats &stats);
111
112} // namespace dlinear
Dataclass collecting statistics about some operation or process.
Definition Stats.h:71
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:43
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:48
std::atomic< unsigned int > iterations_
Atomic counter for the total number of iterations.
Definition Stats.h:73
unsigned int iterations() const
Get read-only access to the iterations of the stats.
Definition Stats.h:103
std::string ToString() const override
Convert the current state of the object to a formatted string.
Definition Stats.cpp:46
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:39
Dataclass collecting statistics about some operation or process.
Definition Stats.h:23
std::string class_name_
Name of the class running the operation the Stats object is collecting statistics for.
Definition Stats.h:29
Timer timer_
Timer object to measure the cumulative time spent in the operation.
Definition Stats.h:25
Stats(bool enabled, std::string class_name, std::string name_time="Time spent in Operations")
Construct a Stats object.
Definition Stats.cpp:19
Timer & m_timer()
Get read-write access to the timer of the stats.
Definition Stats.h:50
const Timer & timer() const
Get read-only access to the timer of the stats.
Definition Stats.h:52
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:22
bool enabled_
Flag to enable/disable the collection of statistics.
Definition Stats.h:28
bool enabled() const
Check whether the stats is enabled.
Definition Stats.h:48
virtual std::string ToString() const
Convert the current state of the object to a formatted string.
Definition Stats.cpp:25
std::string operations_name_
Name of the operation the Stats object is collecting statistics for.
Definition Stats.h:30
Timer class using the a steady clock.
Definition Timer.h:95
Global namespace for the dlinear library.