Sorry, I'm seeing new things here.
I see under Linux that clock_gettime(), has options for CLOCK_MONOTONIC,
and also CLOCK_MONOTONIC_RAW. CLOCK_MONOTONIC "is affected by the
incremental adjustments performed by adjtime and NTP." So it seems that
would be best? Which does QElapsedTimer use?
Thanks again!
Josh
Thiago,
Thanks, this is really helpful. This particular code is only used by me (I've
added a module to my program to allow screencasting of my program with alpha
channel so that it can be overlaid over video of me. Hence the need for the
clock to be roughly synched to the camera clock so the video and screencast
are in synch). So I am just trying to optimize the situation to get the best
clock for me. So when I was reading about ntp, it sounded like it would
gently adjust the time (speed up / slow down internal clock to synch with
time), and thereby correct for drift over time. But it sounds like switching
to QElapsedTimer is better.
Do you know offhand about how accurate typical PC system clocks are? I'm
wondering about how much drift there would be after an hour of recording
screencasts.
Josh
On Friday, 28 July 2017 16:15:27 PDT Joshua Grauman wrote:
> I have a related but different question.
>
> I am reading the time with QDateTime::currentMSecsSinceEpoch(). How
> susceptible is this time to clock drift/jitter/etc. on Linux (Kubuntu
> 16.04.2)?
It's susceptible to complete jumps. You're using the realtime clock.
> I know ntpd is constantly updating the time, and there is some
> error involved in this.
How do you know that all your users are using ntpd? How do you know that
they
are in a network that allows NTP packets (it's UDP)?
And how sure are you that the system won't run ntpdate on a whim once you
connect to a network? (it shouldn't, but a lot of poorly-configured
systems
exist)
> If I am reading the time from
> QDateTime::currentMSecsSinceEpoch() and using it to set a QTimer every
> 40ms, how does ntpd constantly correcting the time going to affect this,
> if at all?
QTimer has nothing to do with the current wall-clock time. The Qt event
loop
uses the monotonic clock exclusively.
> FYI: My timer slot basically looks like this:
>
> void myClass::animationTimerSlot(void)
> {
> if(firstTime)
> startTime=QDateTime::currentMSecsSinceEpoch();
>
> dowork();
>
> frameCnt++;
> int t = startTime + ((double)frameCnt*40.0) -
> QDateTime::currentMSecsSinceEpoch(); if(t<0)
> t=0;
> animTimer->start(t);
> }
Your code is susceptible to time jumps. If the clock went backwards for a
second (for example), your t would be about 1000 and your animation would
stop
for a second.
Use the monotonic clock instead.
--
Thiago Macieira - thiago.macieira (AT) intel.com
Software Architect - Intel Open Source Technology Center
_______________________________________________
Interest mailing list
Interest@qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest
_______________________________________________
Interest mailing list
Interest@qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest
_______________________________________________
Interest mailing list
Interest@qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest