resurrecting-open-source-projects / scrot

SCReenshOT - command line screen capture utility
Other
511 stars 51 forks source link

improve timing in `scrot --delay` #261

Closed guijan closed 1 year ago

guijan commented 1 year ago

This will conflict with #257, has only been minimally tested, and there are other places in the code where it's useful but hasn't been put to use yet, so it remains a draft.

Old nanosleep() code (master) on OpenBSD: openbsd-scrot-nanosleep New clock_nanosleep() code (this PR), falling back to a local clock_nanosleep() implementation on systems lacking this POSIX function like OpenBSD and OS X, running on OpenBSD: openbsd-scrot-clock_nanosleep The timing error is consistently smaller across several runs. If you subtract the user and system runtime and the 60 second sleep from the real runtime, you get the timing error. It has been reduced by an order of magnitude here.

guijan commented 1 year ago

Turns out the other nanosleep() calls shouldn't even be there (#274), so this PR is ready for review now that it's rebased and tested on OpenBSD.

guijan commented 1 year ago

Now the PR is significantly different, I've done very basic testing on OpenBSD, but it still needs more testing.

guijan commented 1 year ago

Yeah, in an algorithmic sense, both paths are the same: they both make the error relative to the sleep constant. It just annoys me when we don't use the good features of each platform. #ifdef removed.