26 #include "misc/_config.h"
32 #if SPOT_HAVE_SYS_TIMES_H
33 # include <sys/times.h>
48 typedef std::chrono::high_resolution_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();
96 wall_start_ = std::chrono::high_resolution_clock::now();
97 #ifdef SPOT_HAVE_TIMES
100 start_.utime = tmp.tms_utime + tmp.tms_cutime;
101 start_.stime = tmp.tms_stime + tmp.tms_cstime;
103 start_.utime = clock();
111 auto end = std::chrono::high_resolution_clock::now();
112 wall_cumul_ = std::chrono::duration_cast
113 <std::chrono::milliseconds>(end - wall_start_).count();
114 #ifdef SPOT_HAVE_TIMES
117 total_.utime += tmp.tms_utime + tmp.tms_cutime - start_.utime;
118 total_.stime += tmp.tms_stime + tmp.tms_cstime - start_.stime;
120 total_.utime += clock() - start_.utime;
158 std::chrono::milliseconds::rep
168 std::chrono::high_resolution_clock::time_point wall_start_;
169 std::chrono::milliseconds::rep wall_cumul_;
188 item_type& it = tm[name];
199 tm[name].first.stop();
212 tm_type::iterator i = tm.find(name);
213 assert(i != tm.end());
214 assert(0 < i->second.second);
215 if (0 == --i->second.second)
221 timer(
const std::string& name)
const
223 tm_type::const_iterator i = tm.find(name);
224 assert(i != tm.end());
225 return i->second.first;
232 return tm[name].first;
247 SPOT_API std::ostream&
248 print(std::ostream& os)
const;
258 typedef std::pair<spot::timer, int> item_type;
259 typedef std::map<std::string, item_type> tm_type;
clock_t stime() const
Return the system time of all accumulated interval.
Definition: timer.hh:141
spot::timer & timer(const std::string &name)
Return the timer name.
Definition: timer.hh:230
std::chrono::milliseconds::rep walltime() const
Return cumulative wall time.
Definition: timer.hh:159
void start()
Marks the start if the measurement.
Definition: timer.hh:52
A map of timer, where each timer has a name.
Definition: timer.hh:176
void start(const std::string &name)
Start a timer with name name.
Definition: timer.hh:186
void stop(const std::string &name)
Stop timer name.
Definition: timer.hh:197
clock_t utime() const
Return the user time of all accumulated interval.
Definition: timer.hh:131
bool is_running() const
Whether the timer is running.
Definition: timer.hh:149
const spot::timer & timer(const std::string &name) const
Return the timer name.
Definition: timer.hh:221
void cancel(const std::string &name)
Cancel timer name.
Definition: timer.hh:210
double stop()
Returns the elapsed duration in seconds.
Definition: timer.hh:61
void start()
Start a time interval.
Definition: timer.hh:92
bool empty() const
Whether there is no timer in the map.
Definition: timer.hh:241
void stop()
Stop a time interval and update the sum of all intervals.
Definition: timer.hh:109
A simple stopwatch.
Definition: timer.hh:45
std::ostream & print(std::ostream &os) const
Format information about all timers in a table.
void reset_all()
Remove information about all timers.
Definition: timer.hh:252
A timekeeper that accumulate interval of time.
Definition: timer.hh:82
A structure to record elapsed time in clock ticks.
Definition: timer.hh:71