scripts: use the monotonic clock to compute time elapsed
PATCH 1/1 scripts: use the monotonic clock to compute time elapsed
From: Joseph Tilahun <[email protected]>
The monotonic clock is preferable over the system clock when computing the time elapsed.
--- scripts/oe-pkgdata-browser | 4 ++-- scripts/runqemu | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-)
scripts/oe-pkgdata-browser +2 -2
@@ -29,10 +29,10 @@ FileColumns = enum.IntEnum("FileColumns", {"Filename": 0, "Size": 1}) import time def timeit(f): def timed(*args, **kw): - ts = time.time() + ts = time.monotonic() print ("func:%r calling" % f.__name__) result = f(*args, **kw) - te = time.time() + te = time.monotonic() print ('func:%r args:[%r, %r] took: %2.4f sec' % \ (f.__name__, args, kw, te-ts)) return result
scripts/runqemu +2 -2
@@ -1252,9 +1252,9 @@ to your build configuration. if self.snapshot and tmpfsdir: newrootfs = os.path.join(tmpfsdir, os.path.basename(self.rootfs)) + "." + str(os.getpid()) logger.info("Copying rootfs to %s" % newrootfs) - copy_start = time.time() + copy_start = time.monotonic() shutil.copyfile(self.rootfs, newrootfs) - logger.info("Copy done in %s seconds" % (time.time() - copy_start)) + logger.info("Copy done in %s seconds" % (time.monotonic() - copy_start)) self.rootfs = newrootfs # Don't need a second copy now! self.snapshot = False
Signature · 10 lines
2.25.1 -- ________ This email and any attachments may contain Astranis confidential and/or proprietary information governed by a non-disclosure agreement, and are intended solely for the individual or entity specified by the message.
Quoted 4 lines · jtilahun via lists.yoctoproject.org
From: Joseph Tilahun <[email protected]>
The monotonic clock is preferable over the system clock when computing the time elapsed.
I agree. Otherwise, if you suspend your laptop, the time information counts the time spent sleeping.
I submitted a patch to BitBake a while ago, but there was the fear that my change would break other parts (though it was working fine in my tests).
However, I believe you should send your patch to [email protected] instead, because that's a change for the openembedded-core repository. The "poky" repository is an aggregation of multiple original repositories. Thanks!
Michael.
Signature · 3 lines
Michael Opdenacker, Bootlin Embedded Linux and Kernel engineering https://bootlin.com
Quoted 11 lines · Michael Opdenacker via lists.yoctoproject.org
Quoted 4 lines · jtilahun via lists.yoctoproject.org
From: Joseph Tilahun <[email protected]>
The monotonic clock is preferable over the system clock when computing the time elapsed.
I agree. Otherwise, if you suspend your laptop, the time information counts the time spent sleeping.
I submitted a patch to BitBake a while ago, but there was the fear that my change would break other parts (though it was working fine in my tests).
The issue was that the python manual page clearly says:
"""
The reference point of the returned value is undefined, so that only the difference between the results of two calls is valid. """
and the timestamps being sent out by parts of bitbake may be used as absolute time values (e.g. displayed to the user), not just for comparison.
Cheers,
Richard
Thank you for the background Michael. I sent this patch to [email protected] per your message.
Richard, I understand the point you cite from the Python manual page. Regarding this patch specifically, only the difference between the results of two calls is used. So the concern you raise is not applicable to this patch specifically. Given that, I'd appreciate it if you could take a look.
Thanks,
Joseph
Quoted 32 lines · Richard Purdie
Quoted 11 lines · Michael Opdenacker via lists.yoctoproject.org
Quoted 4 lines · jtilahun via lists.yoctoproject.org
From: Joseph Tilahun <[email protected]>
The monotonic clock is preferable over the system clock when computing the time elapsed.
I agree. Otherwise, if you suspend your laptop, the time information counts the time spent sleeping.
I submitted a patch to BitBake a while ago, but there was the fear that my change would break other parts (though it was working fine in mytests).
The issue was that the python manual page clearly says:
"""
The reference point of the returned value is undefined, so that only the difference between the results of two calls is valid. """and the timestamps being sent out by parts of bitbake may be used as absolute time values (e.g. displayed to the user), not just for comparison.
Cheers,
Richard
Signature · 4 lines
________ This email and any attachments may contain Astranis confidential and/or proprietary information governed by a non-disclosure agreement, and are intended solely for the individual or entity specified by the message.
Quoted 8 lines · Joseph Tilahun
Thank you for the background Michael. I sent this patch to [email protected] per your message.
Richard, I understand the point you cite from the Python manual page. Regarding this patch specifically, only the difference between the results of two calls is used. So the concern you raise is not applicable to this patch specifically. Given that, I'd appreciate it if you could take a look.
Alex's point stands though and relates to my concern. If we use time.time() everywhere we're consistent and less likely to confuse the two and get interesting results.
Is there a real world problem this change is solving? Did you have a build machine where you changed the time part way through a build?
I'm leaning towards being consistent as this time change would seem to be something very rare compared to the risks of people copy and pasting and confusing the usage.
Cheers,
Richard
The point about consistency is fair enough. time.time() is already used in many places, so it's understandable if the desire is to continue using time.time() throughout. I do think these usages of time in scripts are isolated enough to where it's not as much of a concern. The time deltas are computed purely within those functions and simply printed out, with nothing else done with that information.
That being said, if you still insist that monotonic is not the way to go for the sake of consistency, then fine.
Thanks,
Joseph
Quoted 25 lines · Richard Purdie
Quoted 8 lines · Joseph Tilahun
Thank you for the background Michael. I sent this patch to [email protected] per your message.
Richard, I understand the point you cite from the Python manual page. Regarding this patch specifically, only the difference between the results of two calls is used. So the concern you raise is not applicable to this patch specifically. Given that, I'd appreciate it if you could take a look.
Alex's point stands though and relates to my concern. If we use
time.time()everywhere we're consistent and less likely to confuse the two and get interesting results.Is there a real world problem this change is solving? Did you have a build machine where you changed the time part way through a build?
I'm leaning towards being consistent as this time change would seem to be something very rare compared to the risks of people copy and pasting and confusing the usage.
Cheers,
Richard
Signature · 4 lines
________ This email and any attachments may contain Astranis confidential and/or proprietary information governed by a non-disclosure agreement, and are intended solely for the individual or entity specified by the message.