diff mbox series

knotty/uihelper: use monotonic time to report task duration

Message ID 20230125084725.2262388-1-michael.opdenacker@bootlin.com
State New
Headers show
Series knotty/uihelper: use monotonic time to report task duration | expand

Commit Message

Michael Opdenacker Jan. 25, 2023, 8:47 a.m. UTC
From: Michael Opdenacker <michael.opdenacker@bootlin.com>

Without this, if the host machine is suspended to RAM,
BitBake reports a task duration which includes the time
the system remained suspended, not actually running the task.

This is addressed by getting the time from a monotonic
clock, which ignores time elapsed during suspend.

This fixes [YOCTO 15015]

Signed-off-by: Michael Opdenacker <michael.opdenacker@bootlin.com>

---

Note that while a successful build was obtained with this change,
it might have side effects in places I didn't foresee (in logs?).
---
 lib/bb/ui/knotty.py   | 2 +-
 lib/bb/ui/uihelper.py | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

Comments

Richard Purdie Jan. 26, 2023, 4:49 p.m. UTC | #1
On Wed, 2023-01-25 at 09:47 +0100, Michael Opdenacker via
lists.openembedded.org wrote:
> From: Michael Opdenacker <michael.opdenacker@bootlin.com>
> 
> Without this, if the host machine is suspended to RAM,
> BitBake reports a task duration which includes the time
> the system remained suspended, not actually running the task.
> 
> This is addressed by getting the time from a monotonic
> clock, which ignores time elapsed during suspend.
> 
> This fixes [YOCTO 15015]
> 
> Signed-off-by: Michael Opdenacker <michael.opdenacker@bootlin.com>
> 
> ---
> 
> Note that while a successful build was obtained with this change,
> it might have side effects in places I didn't foresee (in logs?).

There was some discussion about this in the bugzilla entry. I'm worried
that two different concepts of time inside bitbake is going to end up
causing a lot of confusion for what is a relatively minor issue. As
such I'd prefer not to do this.

Cheers,

Richard
diff mbox series

Patch

diff --git a/lib/bb/ui/knotty.py b/lib/bb/ui/knotty.py
index 431baa15..3174d977 100644
--- a/lib/bb/ui/knotty.py
+++ b/lib/bb/ui/knotty.py
@@ -239,7 +239,7 @@  class TerminalFilter(object):
         activetasks = self.helper.running_tasks
         failedtasks = self.helper.failed_tasks
         runningpids = self.helper.running_pids
-        currenttime = time.time()
+        currenttime = time.monotonic()
         if not self.lasttime or (currenttime - self.lasttime > 5):
             self.helper.needUpdate = True
             self.lasttime = currenttime
diff --git a/lib/bb/ui/uihelper.py b/lib/bb/ui/uihelper.py
index 82913e0d..5524f8d6 100644
--- a/lib/bb/ui/uihelper.py
+++ b/lib/bb/ui/uihelper.py
@@ -32,9 +32,9 @@  class BBUIHelper:
         if isinstance(event, bb.build.TaskStarted):
             tid = event._fn + ":" + event._task
             if event._mc != "default":
-                self.running_tasks[tid] = { 'title' : "mc:%s:%s %s" % (event._mc, event._package, event._task), 'starttime' : time.time(), 'pid' : event.pid }
+                self.running_tasks[tid] = { 'title' : "mc:%s:%s %s" % (event._mc, event._package, event._task), 'starttime' : time.monotonic(), 'pid' : event.pid }
             else:
-                self.running_tasks[tid] = { 'title' : "%s %s" % (event._package, event._task), 'starttime' : time.time(), 'pid' : event.pid }
+                self.running_tasks[tid] = { 'title' : "%s %s" % (event._package, event._task), 'starttime' : time.monotonic(), 'pid' : event.pid }
             self.running_pids.append(tid)
             self.pidmap[event.pid] = tid
             self.needUpdate = True