25 #include <spot/misc/common.hh> 26 #include <spot/misc/_config.h> 32 #if SPOT_HAVE_SYS_TIMES_H 33 # include <sys/times.h> 47 typedef std::chrono::high_resolution_clock clock;
48 clock::time_point start_;
53 start_ = clock::now();
62 auto t = clock::now();
63 typedef std::chrono::duration<double> seconds;
64 return std::chrono::duration_cast<seconds>(t - start_).count();
72 : utime(0), stime(0), cutime(0), cstime(0)
96 SPOT_ASSERT(!running);
98 wall_start_ = std::chrono::high_resolution_clock::now();
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 auto end = std::chrono::high_resolution_clock::now();
116 wall_cumul_ = std::chrono::duration_cast
117 <std::chrono::milliseconds>(end - wall_start_).count();
118 #ifdef SPOT_HAVE_TIMES 121 total_.utime += tmp.tms_utime - start_.utime;
122 total_.cutime += tmp.tms_cutime - start_.cutime;
123 total_.stime += tmp.tms_stime - start_.stime;
124 total_.cstime += tmp.tms_cstime - start_.cstime;
126 total_.utime += clock() - start_.utime;
128 SPOT_ASSERT(running);
150 return total_.cutime;
171 return total_.cstime;
174 clock_t get_uscp(
bool user,
bool system,
bool children,
bool parent)
const 181 if (user && children)
184 if (system && parent)
187 if (system && children)
205 std::chrono::milliseconds::rep
215 std::chrono::high_resolution_clock::time_point wall_start_;
216 std::chrono::milliseconds::rep wall_cumul_;
239 item_type& it = tm[name];
250 tm[name].first.stop();
263 tm_type::iterator i = tm.find(name);
264 if (SPOT_UNLIKELY(i == tm.end()))
265 throw std::invalid_argument(
"timer_map::cancel(): unknown name");
266 SPOT_ASSERT(0 < i->second.second);
267 if (0 == --i->second.second)
273 timer(
const std::string& name)
const 275 tm_type::const_iterator i = tm.find(name);
276 if (SPOT_UNLIKELY(i == tm.end()))
277 throw std::invalid_argument(
"timer_map::timer(): unknown name");
278 return i->second.first;
293 SPOT_API std::ostream&
294 print(std::ostream& os)
const;
304 typedef std::pair<spot::timer, int> item_type;
305 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:148
clock_t stime() const
Return the system time of the current process (whithout children) of all accumulated interval...
Definition: timer.hh:159
void start()
Marks the start if the measurement.
Definition: timer.hh:51
A map of timer, where each timer has a name.
Definition: timer.hh:227
void start(const std::string &name)
Start a timer with name name.
Definition: timer.hh:237
std::chrono::milliseconds::rep walltime() const
Return cumulative wall time.
Definition: timer.hh:206
void stop(const std::string &name)
Stop timer name.
Definition: timer.hh:248
clock_t utime() const
Return the user time of the current process (without children) of all accumulated interval...
Definition: timer.hh:138
const spot::timer & timer(const std::string &name) const
Return the timer name.
Definition: timer.hh:273
clock_t cstime() const
Return the system time of children of all accumulated interval.
Definition: timer.hh:169
bool empty() const
Whether there is no timer in the map.
Definition: timer.hh:287
void cancel(const std::string &name)
Cancel timer name.
Definition: timer.hh:261
double stop()
Returns the elapsed duration in seconds.
Definition: timer.hh:60
bool is_running() const
Whether the timer is running.
Definition: timer.hh:195
void start()
Start a time interval.
Definition: timer.hh:94
std::ostream & operator<<(std::ostream &os, const formula &f)
Print a formula.
void stop()
Stop a time interval and update the sum of all intervals.
Definition: timer.hh:113
A simple stopwatch.
Definition: timer.hh:44
void reset_all()
Remove information about all timers.
Definition: timer.hh:298
A structure to record elapsed time in clock ticks.
Definition: timer.hh:69