24 #elif defined(__APPLE__)
25 # include <mach/mach_time.h>
27 # include <sys/time.h>
30 #define OIIO_TIMER_LINUX_USE_clock_gettime 1
71 const char*
name = NULL)
73 , m_printdtr(printdtr == PrintDtr || printdtr == PrintCtrDtr)
78 if (startnow == StartNow) {
80 if (printdtr == PrintCtrDtr) {
124 m_elapsed_ticks += tickdiff(m_starttime, n);
127 return seconds(m_elapsed_ticks);
145 m_elapsed_ticks +=
r;
154 double lap() {
return seconds(lap_ticks()); }
158 ticks_t ticks()
const {
return ticks_since_start() + m_elapsed_ticks; }
169 return m_ticking ? tickdiff(m_starttime, now()) :
ticks_t(0);
200 ticks_t m_elapsed_ticks;
205 ticks_t now(
void) const
210 # if defined(__APPLE__)
211 return mach_absolute_time();
212 # elif OIIO_TIMER_LINUX_USE_clock_gettime
214 clock_gettime(CLOCK_MONOTONIC, &
t);
215 return int64_t(
t.tv_sec) * int64_t(1000000000) +
t.tv_nsec;
218 gettimeofday(&
t, NULL);
219 return int64_t(
t.tv_sec) * int64_t(1000000) +
t.tv_usec;
226 ticks_t tickdiff(ticks_t
then, ticks_t now)
const
228 return (now > then) ? now - then : then - now;
232 double diff(ticks_t then, ticks_t now)
const
234 return seconds(tickdiff(then, now));
237 static double seconds_per_tick;
238 static ticks_t ticks_per_second;
239 friend class TimerSetupOnce;
void start()
Start (or restart) ticking, if we are not currently.
String-related utilities, all in namespace Strutil.
**If you just want to fire and then
bool ticking() const
Is the timer currently ticking?
void add_ticks(ticks_t delta)
double time_since_start(void) const
GLuint const GLchar * name
Timer(bool startnow=true)
double operator()(void) const
Timer(StartNowVal startnow, PrintDtrVal printdtr=DontPrintDtr, const char *name=NULL)
#define OIIO_NAMESPACE_END
void add_seconds(double t)
FMT_INLINE void print(format_string< T...> fmt, T &&...args)
ticks_t ticks_since_start(void) const
static double seconds(ticks_t ticks)
Convert number of ticks to seconds.
#define OIIO_NAMESPACE_BEGIN