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();
73 : utime(0), stime(0), cutime(0), cstime(0)
97 SPOT_ASSERT(!running);
99 #ifdef SPOT_HAVE_TIMES 102 start_.utime = tmp.tms_utime;
103 start_.cutime = tmp.tms_cutime;
104 start_.stime = tmp.tms_stime;
105 start_.cstime = tmp.tms_cstime;
107 start_.utime = clock();
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)
205 inline std::ostream& operator<<(std::ostream& os,
const timer& dt);
223 item_type& it = tm[name];
234 tm[name].first.stop();
247 tm_type::iterator i = tm.find(name);
248 if (SPOT_UNLIKELY(i == tm.end()))
249 throw std::invalid_argument(
"timer_map::cancel(): unknown name");
250 SPOT_ASSERT(0 < i->second.second);
251 if (0 == --i->second.second)
257 timer(
const std::string& name)
const 259 tm_type::const_iterator i = tm.find(name);
260 if (SPOT_UNLIKELY(i == tm.end()))
261 throw std::invalid_argument(
"timer_map::timer(): unknown name");
262 return i->second.first;
277 SPOT_API std::ostream&
278 print(std::ostream& os)
const;
288 typedef std::pair<spot::timer, int> item_type;
289 typedef std::map<std::string, item_type> tm_type;
clock_t cutime() const
Return the user time of children of all accumulated interval.
Definition: timer.hh:145
clock_t stime() const
Return the system time of the current process (whithout children) of all accumulated interval...
Definition: timer.hh:156
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:211
void start(const std::string &name)
Start a timer with name name.
Definition: timer.hh:221
void stop(const std::string &name)
Stop timer name.
Definition: timer.hh:232
clock_t utime() const
Return the user time of the current process (without children) of all accumulated interval...
Definition: timer.hh:135
const spot::timer & timer(const std::string &name) const
Return the timer name.
Definition: timer.hh:257
clock_t cstime() const
Return the system time of children of all accumulated interval.
Definition: timer.hh:166
bool empty() const
Whether there is no timer in the map.
Definition: timer.hh:271
void cancel(const std::string &name)
Cancel timer name.
Definition: timer.hh:245
double stop()
Returns the elapsed duration in seconds.
Definition: timer.hh:61
bool is_running() const
Whether the timer is running.
Definition: timer.hh:192
void start()
Start a time interval.
Definition: timer.hh:95
void stop()
Stop a time interval and update the sum of all intervals.
Definition: timer.hh:113
A simple stopwatch.
Definition: timer.hh:45
void reset_all()
Remove information about all timers.
Definition: timer.hh:282
A structure to record elapsed time in clock ticks.
Definition: timer.hh:70