32 if (not M.has_ended())
39 using clock = std::chrono::high_resolution_clock;
72 "if the measurement hasn't started it must not have ended");
91 void dump(std::ostream &out)
const;
112 [&](
auto &elem) { return elem.name == name; });
123 std::size_t
start(std::string name) {
125 [&](
auto &elem) { return elem.name == name; });
132 it->begin = clock::now();
146 M_insist(not M.has_ended(),
"cannot stop that measurement because it has already been stopped");
157 out <<
"Timer measurements:\n";
158 for (
auto &M : timer)
159 out <<
" " << M <<
'\n';
164 void dump(std::ostream &out)
const;
177#define M_TIME_EXPR(EXPR, DESCR, TIMER) \
178 [&]() { auto TP = (TIMER).create_timing((DESCR)); return (EXPR); }();
179#define M_TIME_BLOCK(DESCR, TIMER, BLOCK) {\
180 auto TP = (TIMER).create_timing((DESCR)); \
183#define M_TIME_THIS(DESCR, TIMER) \
184 auto M_PASTE(__timer_, __COUNTER__) = (TIMER).create_timing((DESCR));
duration duration() const
Returns the duration of a finished Measurement.
bool has_ended() const
Returns true iff this Measurement has ended.
bool is_finished() const
Returns true iff this Measurement has completed.
void stop()
Stop this Measurement by setting the end time point to NOW.
void start()
Start this Measurement by setting the start time point to NOW.
bool is_unused() const
Returns true iff the Measurement is unused, i.e.
bool is_active() const
Returns true iff this Measurement is currently in process.
void clear()
Clear this Measurement, rendering it unused.
std::string name
the name of this Measurement
friend std::ostream & operator<<(std::ostream &out, const Measurement &M)
Measurement(std::string name, time_point begin=time_point(), time_point end=time_point())
bool has_started() const
Returns true iff this Measurement has begun.
time_point end
the begin and end time points of this Measurement
A proxy class to record a Measurement with a Timer.
std::size_t id_
the ID of the Measurement
Timer & timer_
the Timer instance
TimingProcess(Timer &timer, std::size_t index)
Collect timings of events.
void clear()
Erase all Measurements from this Timer.
M_LCOV_EXCL_STOP duration total() const
Computes the total duration of all Measurements.
const std::vector< Measurement > & measurements() const
std::chrono::high_resolution_clock clock
const Measurement & get(const std::string &name) const
const Measurement & get(std::size_t i) const
TimingProcess create_timing(std::string name)
Creates a new TimingProcess with the given name.
clock::time_point time_point
M_LCOV_EXCL_START friend std::ostream & operator<<(std::ostream &out, const Timer &timer)
Print all finished and in-process timings of timer to out.
std::vector< Measurement > measurements_
std::size_t start(std::string name)
Start a new Measurement with the name name.
void stop(std::size_t id)
Stops the Measurement with the given ID.
Signals that an argument to a function of method was invalid.
Signals that an index-based or key-based access was out of range.