23 #ifndef SPOT_MISC_TIMER_HH
24 # define SPOT_MISC_TIMER_HH
27 # include "misc/_config.h"
32 # if SPOT_HAVE_SYS_TIMES_H
33 # include <sys/times.h>
71 wall_start_ = std::chrono::high_resolution_clock::now();
72 #ifdef SPOT_HAVE_TIMES
75 start_.utime = tmp.tms_utime;
76 start_.stime = tmp.tms_stime;
78 start_.utime = clock();
86 auto end = std::chrono::high_resolution_clock::now();
87 wall_cumul_ = std::chrono::duration_cast
88 <std::chrono::milliseconds>(end - wall_start_).count();
89 #ifdef SPOT_HAVE_TIMES
92 total_.utime += tmp.tms_utime - start_.utime;
93 total_.stime += tmp.tms_stime - start_.stime;
95 total_.utime += clock() - start_.utime;
134 std::chrono::milliseconds::rep
144 std::chrono::high_resolution_clock::time_point wall_start_;
145 std::chrono::milliseconds::rep wall_cumul_;
164 item_type& it = tm[name];
175 tm[name].first.stop();
188 tm_type::iterator i = tm.find(name);
189 assert(i != tm.end());
190 assert(0 < i->second.second);
191 if (0 == --i->second.second)
197 timer(
const std::string& name)
const
199 tm_type::const_iterator i = tm.find(name);
200 assert(i != tm.end());
201 return i->second.first;
208 return tm[name].first;
223 SPOT_API std::ostream&
224 print(std::ostream& os)
const;
234 typedef std::pair<spot::timer, int> item_type;
235 typedef std::map<std::string, item_type> tm_type;
242 #endif // SPOT_MISC_TIMER_HH
clock_t stime() const
Return the system time of all accumulated interval.
Definition: timer.hh:116
spot::timer & timer(const std::string &name)
Return the timer name.
Definition: timer.hh:206
std::chrono::milliseconds::rep walltime() const
Return cumulative wall time.
Definition: timer.hh:135
A map of timer, where each timer has a name.
Definition: timer.hh:152
void start(const std::string &name)
Start a timer with name name.
Definition: timer.hh:162
SPOT_API std::ostream & print(std::ostream &os) const
Format information about all timers in a table.
void stop(const std::string &name)
Stop timer name.
Definition: timer.hh:173
clock_t utime() const
Return the user time of all accumulated interval.
Definition: timer.hh:106
bool is_running() const
Whether the timer is running.
Definition: timer.hh:124
const spot::timer & timer(const std::string &name) const
Return the timer name.
Definition: timer.hh:197
void cancel(const std::string &name)
Cancel timer name.
Definition: timer.hh:186
void start()
Start a time interval.
Definition: timer.hh:67
bool empty() const
Whether there is no timer in the map.
Definition: timer.hh:217
void stop()
Stop a time interval and update the sum of all intervals.
Definition: timer.hh:84
void reset_all()
Remove information about all timers.
Definition: timer.hh:228
A timekeeper that accumulate interval of time.
Definition: timer.hh:57
A structure to record elapsed time in clock ticks.
Definition: timer.hh:46