1 /********************* */
2 /*! \file stats_timer.h
4 ** Top contributors (to current version):
6 ** This file is part of the CVC4 project.
7 ** Copyright (c) 2009-2021 by the authors listed in the file AUTHORS
8 ** in the top-level source directory and their institutional affiliations.
9 ** All rights reserved. See the file COPYING in the top-level source
10 ** directory for licensing information.\endverbatim
12 ** \brief Timer statistics
14 ** Stat classes that hold timers
17 #include "cvc4_private_library.h"
19 #ifndef CVC4__UTIL__STATS_TIMER_H
20 #define CVC4__UTIL__STATS_TIMER_H
24 #include "cvc4_export.h"
25 #include "util/stats_base.h"
28 namespace timer_stat_detail
{
29 using clock
= std::chrono::steady_clock
;
30 using time_point
= clock::time_point
;
31 struct duration
: public std::chrono::nanoseconds
34 } // namespace timer_stat_detail
37 void CVC4_EXPORT
safe_print(int fd
, const timer_stat_detail::duration
& t
);
42 * A timer statistic. The timer can be started and stopped
43 * arbitrarily, like a stopwatch; the value of the statistic at the
44 * end is the accumulated time over all (start,stop) pairs.
46 class CVC4_EXPORT TimerStat
: public BackedStat
<timer_stat_detail::duration
>
49 typedef cvc5::CodeTimer CodeTimer
;
52 * Construct a timer statistic with the given name. Newly-constructed
53 * timers have a 0.0 value and are not running.
55 TimerStat(const std::string
& name
)
56 : BackedStat
<timer_stat_detail::duration
>(name
,
57 timer_stat_detail::duration()),
63 /** Start the timer. */
67 * Stop the timer and update the statistic value with the
72 /** If the timer is currently running */
75 timer_stat_detail::duration
get() const;
77 void flushInformation(std::ostream
& out
) const override
;
78 void safeFlushInformation(int fd
) const override
;
80 SExpr
getValue() const override
;
83 /** The last start time of this timer */
84 timer_stat_detail::time_point d_start
;
86 /** Whether this timer is currently running */
88 }; /* class TimerStat */
91 * Utility class to make it easier to call stop() at the end of a
92 * code block. When constructed, it starts the timer. When
93 * destructed, it stops the timer.
98 CodeTimer(TimerStat
& timer
, bool allow_reentrant
= false);
105 /** Private copy constructor undefined (no copy permitted). */
106 CodeTimer(const CodeTimer
& timer
) = delete;
107 /** Private assignment operator undefined (no copy permitted). */
108 CodeTimer
& operator=(const CodeTimer
& timer
) = delete;
109 }; /* class CodeTimer */