25 #include <spot/misc/common.hh>
26 #include <spot/misc/_config.h>
32 #if __has_include(<sys/times.h>)
33 # include <sys/times.h>
48 typedef std::chrono::steady_clock clock;
49 clock::time_point start_;
54 start_ = clock::now();
63 auto t = clock::now();
64 typedef std::chrono::duration<double> seconds;
65 return std::chrono::duration_cast<seconds>(t - start_).count();
73 : utime(0), stime(0), cutime(0), cstime(0)
97 SPOT_ASSERT(!running);
99 wall_start_ = std::chrono::steady_clock::now();
100 #ifdef SPOT_HAVE_TIMES
103 start_.utime = tmp.tms_utime;
104 start_.cutime = tmp.tms_cutime;
105 start_.stime = tmp.tms_stime;
106 start_.cstime = tmp.tms_cstime;
108 start_.utime = clock();
116 auto end = std::chrono::steady_clock::now();
117 wall_cumul_ += std::chrono::duration_cast
118 <std::chrono::milliseconds>(end - wall_start_).count();
119 #ifdef SPOT_HAVE_TIMES
122 total_.utime += tmp.tms_utime - start_.utime;
123 total_.cutime += tmp.tms_cutime - start_.cutime;
124 total_.stime += tmp.tms_stime - start_.stime;
125 total_.cstime += tmp.tms_cstime - start_.cstime;
127 total_.utime += clock() - start_.utime;
129 SPOT_ASSERT(running);
151 return total_.cutime;
172 return total_.cstime;
175 clock_t get_uscp(
bool user,
bool system,
bool children,
bool parent)
const
182 if (user && children)
185 if (system && parent)
188 if (system && children)
206 std::chrono::milliseconds::rep
216 std::chrono::steady_clock::time_point wall_start_;
217 std::chrono::milliseconds::rep wall_cumul_ = 0;
240 item_type& it = tm[name];
251 tm[name].first.stop();
264 tm_type::iterator i = tm.find(name);
265 if (SPOT_UNLIKELY(i == tm.end()))
266 throw std::invalid_argument(
"timer_map::cancel(): unknown name");
267 SPOT_ASSERT(0 < i->second.second);
268 if (0 == --i->second.second)
274 timer(
const std::string& name)
const
276 tm_type::const_iterator i = tm.find(name);
277 if (SPOT_UNLIKELY(i == tm.end()))
278 throw std::invalid_argument(
"timer_map::timer(): unknown name");
279 return i->second.first;
294 SPOT_API std::ostream&
305 typedef std::pair<spot::timer, int> item_type;
306 typedef std::map<std::string, item_type> tm_type;
323 walltime_lap_ = walltimer.
stop();
327 double walltime()
const
329 return walltime_lap_;
332 clock_t cputime(
bool user,
bool system,
bool children,
bool parent)
const
334 return cputimer.get_uscp(user, system, children, parent);
340 double walltime_lap_ = 0;
A map of timer, where each timer has a name.
Definition: timer.hh:229
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:288
void stop(const std::string &name)
Stop timer name.
Definition: timer.hh:249
void start(const std::string &name)
Start a timer with name name.
Definition: timer.hh:238
void cancel(const std::string &name)
Cancel timer name.
Definition: timer.hh:262
void reset_all()
Remove information about all timers.
Definition: timer.hh:299
const spot::timer & timer(const std::string &name) const
Return the timer name.
Definition: timer.hh:274
clock_t stime() const
Return the system time of the current process (whithout children) of all accumulated interval.
Definition: timer.hh:160
std::chrono::milliseconds::rep walltime() const
Return cumulative wall time.
Definition: timer.hh:207
clock_t cutime() const
Return the user time of children of all accumulated interval.
Definition: timer.hh:149
void stop()
Stop a time interval and update the sum of all intervals.
Definition: timer.hh:114
bool is_running() const
Whether the timer is running.
Definition: timer.hh:196
clock_t cstime() const
Return the system time of children of all accumulated interval.
Definition: timer.hh:170
void start()
Start a time interval.
Definition: timer.hh:95
clock_t utime() const
Return the user time of the current process (without children) of all accumulated interval.
Definition: timer.hh:139
Definition: automata.hh:27
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:312
A simple stopwatch.
Definition: timer.hh:46
void start()
Marks the start if the measurement.
Definition: timer.hh:52
double stop()
Returns the elapsed duration in seconds.
Definition: timer.hh:61
A structure to record elapsed time in clock ticks.
Definition: timer.hh:71