12 #if QT_VERSION >= 0x040800 13 #define USE_ELAPSED_TIMER 1 18 #include <qelapsedtimer.h> 28 d_data =
new PrivateData();
38 return d_data->timer.isValid();
48 const qint64 nsecs =
d_data->timer.restart();
54 const qint64 nsecs =
d_data->timer.nsecsElapsed();
58 #else // !USE_ELAPSED_TIMER 60 #include <qdatetime.h> 62 #if !defined(Q_OS_WIN) 68 #include <mach/mach_time.h> 69 #define QWT_HIGH_RESOLUTION_CLOCK 70 #elif defined(_POSIX_TIMERS) 72 #define QWT_HIGH_RESOLUTION_CLOCK 73 #elif defined(Q_OS_WIN) 74 #define QWT_HIGH_RESOLUTION_CLOCK 75 #include <qt_windows.h> 78 #if defined(QWT_HIGH_RESOLUTION_CLOCK) 80 class QwtHighResolutionClock
83 QwtHighResolutionClock();
91 static double precision();
96 static double msecsTo( uint64_t, uint64_t );
99 #elif defined(_POSIX_TIMERS) 101 static double msecsTo(
const struct timespec &,
102 const struct timespec & );
104 static bool isMonotonic();
106 struct timespec d_timeStamp;
109 #elif defined(Q_OS_WIN) 111 LARGE_INTEGER d_startTicks;
112 LARGE_INTEGER d_ticksPerSecond;
116 #if defined(Q_OS_MAC) 117 QwtHighResolutionClock::QwtHighResolutionClock():
122 double QwtHighResolutionClock::precision()
127 void QwtHighResolutionClock::start()
129 d_timeStamp = mach_absolute_time();
132 double QwtHighResolutionClock::restart()
134 const uint64_t
timeStamp = mach_absolute_time();
135 const double elapsed = msecsTo( d_timeStamp, timeStamp );
136 d_timeStamp = timeStamp;
141 double QwtHighResolutionClock::elapsed()
const 143 return msecsTo( d_timeStamp, mach_absolute_time() );
146 bool QwtHighResolutionClock::isNull()
const 148 return d_timeStamp == 0;
151 double QwtHighResolutionClock::msecsTo(
152 uint64_t from, uint64_t to )
156 static double conversion = 0.0;
157 if ( conversion == 0.0 )
159 mach_timebase_info_data_t info;
160 kern_return_t err = mach_timebase_info( &info );
164 conversion = 1e-6 * ( double ) info.numer / (
double ) info.denom;
167 return conversion * ( double ) difference;
170 #elif defined(_POSIX_TIMERS) 172 QwtHighResolutionClock::QwtHighResolutionClock()
174 d_clockId = isMonotonic() ? CLOCK_MONOTONIC : CLOCK_REALTIME;
175 d_timeStamp.tv_sec = d_timeStamp.tv_nsec = 0;
178 double QwtHighResolutionClock::precision()
180 struct timespec resolution;
182 int clockId = isMonotonic() ? CLOCK_MONOTONIC : CLOCK_REALTIME;
183 ::clock_getres( clockId, &resolution );
185 return resolution.tv_nsec / 1e3;
188 inline bool QwtHighResolutionClock::isNull()
const 190 return d_timeStamp.tv_sec <= 0 && d_timeStamp.tv_nsec <= 0;
193 inline void QwtHighResolutionClock::start()
195 ::clock_gettime( d_clockId, &d_timeStamp );
198 double QwtHighResolutionClock::restart()
201 ::clock_gettime( d_clockId, &timeStamp );
203 const double elapsed = msecsTo( d_timeStamp, timeStamp );
209 inline double QwtHighResolutionClock::elapsed()
const 212 ::clock_gettime( d_clockId, &timeStamp );
214 return msecsTo( d_timeStamp, timeStamp );
217 inline double QwtHighResolutionClock::msecsTo(
218 const struct timespec &t1,
const struct timespec &t2 )
220 return ( t2.tv_sec - t1.tv_sec ) * 1e3
221 + ( t2.tv_nsec - t1.tv_nsec ) * 1e-6;
224 bool QwtHighResolutionClock::isMonotonic()
228 #if (_POSIX_MONOTONIC_CLOCK-0 > 0) 231 static int returnValue = 0;
233 if ( returnValue == 0 )
235 #if (_POSIX_MONOTONIC_CLOCK-0 < 0) || !defined(_SC_MONOTONIC_CLOCK) 237 #elif (_POSIX_MONOTONIC_CLOCK == 0) 239 const long x = sysconf( _SC_MONOTONIC_CLOCK );
240 returnValue = ( x >= 200112L ) ? 1 : -1;
244 return returnValue != -1;
248 #elif defined(Q_OS_WIN) 250 QwtHighResolutionClock::QwtHighResolutionClock()
252 d_startTicks.QuadPart = 0;
253 QueryPerformanceFrequency( &d_ticksPerSecond );
256 double QwtHighResolutionClock::precision()
259 if ( QueryPerformanceFrequency( &ticks ) && ticks.QuadPart > 0 )
260 return 1e3 / ticks.QuadPart;
265 inline bool QwtHighResolutionClock::isNull()
const 267 return d_startTicks.QuadPart <= 0;
270 inline void QwtHighResolutionClock::start()
272 QueryPerformanceCounter( &d_startTicks );
275 inline double QwtHighResolutionClock::restart()
278 QueryPerformanceCounter( &ticks );
280 const double dt = ticks.QuadPart - d_startTicks.QuadPart;
281 d_startTicks = ticks;
283 return dt / d_ticksPerSecond.QuadPart * 1e3;
286 inline double QwtHighResolutionClock::elapsed()
const 289 QueryPerformanceCounter( &ticks );
291 const double dt = ticks.QuadPart - d_startTicks.QuadPart;
292 return dt / d_ticksPerSecond.QuadPart * 1e3;
297 #endif // QWT_HIGH_RESOLUTION_CLOCK 302 #if defined(QWT_HIGH_RESOLUTION_CLOCK) 303 QwtHighResolutionClock *clock;
313 #if defined(QWT_HIGH_RESOLUTION_CLOCK) 315 if ( QwtHighResolutionClock::precision() > 0.0 )
316 d_data->clock =
new QwtHighResolutionClock;
323 #if defined(QWT_HIGH_RESOLUTION_CLOCK) 334 #if defined(QWT_HIGH_RESOLUTION_CLOCK) 336 return d_data->clock->isNull();
339 return d_data->time.isNull();
347 #if defined(QWT_HIGH_RESOLUTION_CLOCK) 364 #if defined(QWT_HIGH_RESOLUTION_CLOCK) 366 return d_data->clock->restart();
369 return d_data->time.restart();
378 double elapsed = 0.0;
380 #if defined(QWT_HIGH_RESOLUTION_CLOCK) 383 if ( !
d_data->clock->isNull() )
384 elapsed =
d_data->clock->elapsed();
390 if ( !
d_data->time.isNull() )
391 elapsed =
d_data->time.elapsed();
ros::Time * timeStamp(M &m)
virtual ~QwtSystemClock()
Destructor.
CONSTEXPR_F diff_t difference(year_tag, fields f1, fields f2) noexcept
QwtSystemClock()
Constructs a null clock object.
TFSIMD_FORCE_INLINE const tfScalar & x() const