diff options
author | Bradley T. Hughes <bradley.hughes@nokia.com> | 2010-09-30 15:29:40 (GMT) |
---|---|---|
committer | Bradley T. Hughes <bradley.hughes@nokia.com> | 2010-12-20 14:23:14 (GMT) |
commit | e679392978c21266ec0bf6f960ab8c5f0621e18b (patch) | |
tree | 292f2e214acb4cb9b8f3e89a102d65cb7d9260a9 /src/corelib/tools/qelapsedtimer_unix.cpp | |
parent | daba2c507ad42c66dafa6a29cffa94e9641e0c58 (diff) | |
download | Qt-e679392978c21266ec0bf6f960ab8c5f0621e18b.zip Qt-e679392978c21266ec0bf6f960ab8c5f0621e18b.tar.gz Qt-e679392978c21266ec0bf6f960ab8c5f0621e18b.tar.bz2 |
Add QElapsedTimer::nsecsElapsed() const
Allow sub-millisecond resolution on systems where it is possible. On UNIX,
with monotonic clock support we get full nanosecond resolution, microsecond
otherwise. On Windows we convert the performance counters to nanoseconds if
availble, otherwise we only have millisecond resolution. On Mac, the mach time
is converted to nanoseconds. On Symbian, we have microsecond resolution.
Reviewed-by: joao
Diffstat (limited to 'src/corelib/tools/qelapsedtimer_unix.cpp')
-rw-r--r-- | src/corelib/tools/qelapsedtimer_unix.cpp | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/src/corelib/tools/qelapsedtimer_unix.cpp b/src/corelib/tools/qelapsedtimer_unix.cpp index 633fa00..7407e1b 100644 --- a/src/corelib/tools/qelapsedtimer_unix.cpp +++ b/src/corelib/tools/qelapsedtimer_unix.cpp @@ -167,6 +167,17 @@ qint64 QElapsedTimer::restart() return elapsedAndRestart(t1, t2, &t1, &t2); } +qint64 QElapsedTimer::nsecsElapsed() const +{ + qint64 sec, frac; + do_gettime(&sec, &frac); + sec = sec - t1; + frac = frac - t2; + if (!monotonicClockAvailable) + frac *= 1000; + return sec * Q_INT64_C(1000000000) + frac; +} + qint64 QElapsedTimer::elapsed() const { qint64 sec, frac; |