25 #include <spot/misc/common.hh>
26 #include <spot/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();
94 SPOT_ASSERT(!running);
96 #ifdef SPOT_HAVE_TIMES
99 start_.utime = tmp.tms_utime + tmp.tms_cutime;
100 start_.stime = tmp.tms_stime + tmp.tms_cstime;
102 start_.utime = clock();
110 #ifdef SPOT_HAVE_TIMES
113 total_.utime += tmp.tms_utime + tmp.tms_cutime - start_.utime;
114 total_.stime += tmp.tms_stime + tmp.tms_cstime - start_.stime;
116 total_.utime += clock() - start_.utime;
118 SPOT_ASSERT(running);
172 item_type& it = tm[name];
183 tm[name].first.stop();
196 tm_type::iterator i = tm.find(name);
197 if (SPOT_UNLIKELY(i == tm.end()))
198 throw std::invalid_argument(
"timer_map::cancel(): unknown name");
199 SPOT_ASSERT(0 < i->second.second);
200 if (0 == --i->second.second)
206 timer(
const std::string& name)
const
208 tm_type::const_iterator i = tm.find(name);
209 if (SPOT_UNLIKELY(i == tm.end()))
210 throw std::invalid_argument(
"timer_map::timer(): unknown name");
211 return i->second.first;
218 return tm[name].first;
233 SPOT_API std::ostream&
234 print(std::ostream& os)
const;
244 typedef std::pair<spot::timer, int> item_type;
245 typedef std::map<std::string, item_type> tm_type;
clock_t stime() const
Return the system time of all accumulated interval.
Definition: timer.hh:137
spot::timer & timer(const std::string &name)
Return the timer name.
Definition: timer.hh:216
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:160
void start(const std::string &name)
Start a timer with name name.
Definition: timer.hh:170
void stop(const std::string &name)
Stop timer name.
Definition: timer.hh:181
clock_t utime() const
Return the user time of all accumulated interval.
Definition: timer.hh:127
bool is_running() const
Whether the timer is running.
Definition: timer.hh:145
const spot::timer & timer(const std::string &name) const
Return the timer name.
Definition: timer.hh:206
void cancel(const std::string &name)
Cancel timer name.
Definition: timer.hh:194
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:227
void stop()
Stop a time interval and update the sum of all intervals.
Definition: timer.hh:108
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:238
A timekeeper that accumulate interval of time.
Definition: timer.hh:82
A structure to record elapsed time in clock ticks.
Definition: timer.hh:71