21#include <spot/misc/common.hh>
22#include <spot/misc/_config.h>
28#if __has_include(<sys/times.h>)
29# include <sys/times.h>
44 typedef std::chrono::steady_clock clock;
45 clock::time_point start_;
50 start_ = clock::now();
59 auto t = clock::now();
60 typedef std::chrono::duration<double> seconds;
61 return std::chrono::duration_cast<seconds>(t - start_).count();
69 : utime(0), stime(0), cutime(0), cstime(0)
93 SPOT_ASSERT(!running);
95 wall_start_ = std::chrono::steady_clock::now();
99 start_.utime = tmp.tms_utime;
100 start_.cutime = tmp.tms_cutime;
101 start_.stime = tmp.tms_stime;
102 start_.cstime = tmp.tms_cstime;
104 start_.utime = clock();
112 auto end = std::chrono::steady_clock::now();
113 wall_cumul_ += std::chrono::duration_cast
114 <std::chrono::milliseconds>(end - wall_start_).count();
115#ifdef SPOT_HAVE_TIMES
118 total_.utime += tmp.tms_utime - start_.utime;
119 total_.cutime += tmp.tms_cutime - start_.cutime;
120 total_.stime += tmp.tms_stime - start_.stime;
121 total_.cstime += tmp.tms_cstime - start_.cstime;
123 total_.utime += clock() - start_.utime;
125 SPOT_ASSERT(running);
147 return total_.cutime;
168 return total_.cstime;
171 clock_t get_uscp(
bool user,
bool system,
bool children,
bool parent)
const
178 if (user && children)
181 if (system && parent)
184 if (system && children)
202 std::chrono::milliseconds::rep
212 std::chrono::steady_clock::time_point wall_start_;
213 std::chrono::milliseconds::rep wall_cumul_ = 0;
236 item_type& it = tm[name];
247 tm[name].first.stop();
260 tm_type::iterator i = tm.find(name);
261 if (SPOT_UNLIKELY(i == tm.end()))
262 throw std::invalid_argument(
"timer_map::cancel(): unknown name");
263 SPOT_ASSERT(0 < i->second.second);
264 if (0 == --i->second.second)
270 timer(
const std::string& name)
const
272 tm_type::const_iterator i = tm.find(name);
273 if (SPOT_UNLIKELY(i == tm.end()))
274 throw std::invalid_argument(
"timer_map::timer(): unknown name");
275 return i->second.first;
290 SPOT_API std::ostream&
301 typedef std::pair<spot::timer, int> item_type;
302 typedef std::map<std::string, item_type> tm_type;
319 walltime_lap_ = walltimer.
stop();
323 double walltime()
const
325 return walltime_lap_;
328 clock_t cputime(
bool user,
bool system,
bool children,
bool parent)
const
330 return cputimer.get_uscp(user, system, children, parent);
336 double walltime_lap_ = 0;
A map of timer, where each timer has a name.
Definition: timer.hh:225
std::ostream & print(std::ostream &os) const
Format information about all timers in a table.
bool empty() const
Whether there is no timer in the map.
Definition: timer.hh:284
void stop(const std::string &name)
Stop timer name.
Definition: timer.hh:245
void start(const std::string &name)
Start a timer with name name.
Definition: timer.hh:234
const spot::timer & timer(const std::string &name) const
Return the timer name.
Definition: timer.hh:270
void cancel(const std::string &name)
Cancel timer name.
Definition: timer.hh:258
void reset_all()
Remove information about all timers.
Definition: timer.hh:295
clock_t stime() const
Return the system time of the current process (without children) of all accumulated interval.
Definition: timer.hh:156
std::chrono::milliseconds::rep walltime() const
Return cumulative wall time.
Definition: timer.hh:203
clock_t cutime() const
Return the user time of children of all accumulated interval.
Definition: timer.hh:145
void stop()
Stop a time interval and update the sum of all intervals.
Definition: timer.hh:110
bool is_running() const
Whether the timer is running.
Definition: timer.hh:192
clock_t cstime() const
Return the system time of children of all accumulated interval.
Definition: timer.hh:166
void start()
Start a time interval.
Definition: timer.hh:91
clock_t utime() const
Return the user time of the current process (without children) of all accumulated interval.
Definition: timer.hh:135
Definition: automata.hh:26
struct spot::process_timer process_timer
Struct used to start and stop both timer and stopwatch clocks.
std::ostream & operator<<(std::ostream &os, const formula &f)
Print a formula.
Struct used to start and stop both timer and stopwatch clocks.
Definition: timer.hh:308
A simple stopwatch.
Definition: timer.hh:42
void start()
Marks the start if the measurement.
Definition: timer.hh:48
double stop()
Returns the elapsed duration in seconds.
Definition: timer.hh:57
A structure to record elapsed time in clock ticks.
Definition: timer.hh:67