I also wonder about maintaining consistency. We may fix everything to monotonic() now, but further newly introduced usages of time() may creep in in the future. time() is simply standard practice, and I would use that without thinking or consulting manuals.
Alex On Thu, 17 Aug 2023 at 09:27, Richard Purdie <[email protected]> wrote: > > On Wed, 2023-08-16 at 23:11 -0700, jtilahun via lists.openembedded.org > wrote: > > From: Joseph Tilahun <[email protected]> > > > > The monotonic clock is preferable over the system clock when computing the > > time elapsed. > > > > Signed-off-by: Joseph Tilahun <[email protected]> > > --- > > meta/classes-global/buildstats.bbclass | 4 +-- > > meta/classes/buildhistory.bbclass | 4 +-- > > meta/lib/oeqa/core/context.py | 4 +-- > > meta/lib/oeqa/core/runner.py | 4 +-- > > meta/lib/oeqa/core/target/ssh.py | 14 ++++---- > > meta/lib/oeqa/runtime/cases/ltp.py | 4 +-- > > meta/lib/oeqa/runtime/cases/ltp_compliance.py | 4 +-- > > meta/lib/oeqa/runtime/cases/ltp_stress.py | 4 +-- > > meta/lib/oeqa/runtime/cases/oe_syslog.py | 4 +-- > > meta/lib/oeqa/runtime/cases/rpm.py | 4 +-- > > meta/lib/oeqa/runtime/cases/systemd.py | 4 +-- > > meta/lib/oeqa/selftest/cases/binutils.py | 4 +-- > > meta/lib/oeqa/selftest/cases/gcc.py | 4 +-- > > meta/lib/oeqa/selftest/cases/glibc.py | 4 +-- > > meta/lib/oeqa/selftest/cases/runcmd.py | 12 +++---- > > meta/lib/oeqa/selftest/cases/rust.py | 4 +-- > > meta/lib/oeqa/selftest/cases/tinfoil.py | 4 +-- > > meta/lib/oeqa/utils/commands.py | 4 +-- > > meta/lib/oeqa/utils/qemurunner.py | 34 +++++++++---------- > > meta/lib/oeqa/utils/qemutinyrunner.py | 8 ++--- > > meta/lib/oeqa/utils/sshcontrol.py | 10 +++--- > > meta/recipes-rt/rt-tests/files/rt_bmark.py | 4 +-- > > 22 files changed, 73 insertions(+), 73 deletions(-) > > > > diff --git a/meta/classes-global/buildstats.bbclass > > b/meta/classes-global/buildstats.bbclass > > index f49a67aa4f..1abd52c72a 100644 > > --- a/meta/classes-global/buildstats.bbclass > > +++ b/meta/classes-global/buildstats.bbclass > > @@ -64,7 +64,7 @@ def get_timedata(var, d, end_time): > > > > def set_buildtimedata(var, d): > > import time > > - time = time.time() > > + time = time.monotonic() > > cputime = get_cputime() > > proctime = get_buildprocess_cputime(os.getpid()) > > d.setVar(var, (time, cputime, proctime)) > > @@ -77,7 +77,7 @@ def get_buildtimedata(var, d): > > oldtime, oldcpu, oldproc = timedata > > procdiff = get_buildprocess_cputime(os.getpid()) - oldproc > > cpudiff = get_cputime() - oldcpu > > - end_time = time.time() > > + end_time = time.monotonic() > > timediff = end_time - oldtime > > if cpudiff > 0: > > cpuperc = float(procdiff) * 100 / cpudiff > > Looking at the python man page, it says: > > """ > The reference point of the returned value is undefined, so that only > the difference between the results of two calls is valid. > """ > > so we have to be really careful none of this data is data which is > compared against bitbake's event timestamps for example. > > Is there a real world issue you ran into using time.time()? > > In the above case it is true we're just computing a difference but did > you look into all these cases and check that the value isn't used > elsewhere after the return value? > > I'm just a bit worried there may be leakage of these values where it is > compared with time.time() or it is used in logs for absolute time data. > > Cheers, > > Richard > > >
-=-=-=-=-=-=-=-=-=-=-=- Links: You receive all messages sent to this group. View/Reply Online (#186293): https://lists.openembedded.org/g/openembedded-core/message/186293 Mute This Topic: https://lists.openembedded.org/mt/100795709/21656 Group Owner: [email protected] Unsubscribe: https://lists.openembedded.org/g/openembedded-core/unsub [[email protected]] -=-=-=-=-=-=-=-=-=-=-=-
