]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
script/build-with-container: add log line with time taken
authorJohn Mulligan <jmulligan@redhat.com>
Thu, 20 Mar 2025 21:03:43 +0000 (17:03 -0400)
committerJohn Mulligan <jmulligan@redhat.com>
Thu, 12 Jun 2025 13:37:00 +0000 (09:37 -0400)
Add a log line with time taken to the output of the script, this can
help to see at a glance how long a particular bwc step took.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
src/script/build-with-container.py

index 92d8419059e0aa3ef7ea2454239d6188a6e8566e..157e8199f669eba8ffb5c6a58c6abca43b14ec34 100755 (executable)
@@ -78,6 +78,7 @@ import shlex
 import shutil
 import subprocess
 import sys
+import time
 
 log = logging.getLogger()
 
@@ -396,6 +397,7 @@ class Builder:
 
     def __init__(self):
         self._did_steps = set()
+        self._reported_failed = False
 
     def wants(self, step, ctx, *, force=False, top=False):
         log.info("want to execute build step: %s", step)
@@ -407,13 +409,35 @@ class Builder:
             return
         if not self._did_steps:
             prepare_env_once(ctx)
-        self._steps[step](ctx)
-        self._did_steps.add(step)
-        log.info("step done: %s", step)
+        with self._timer(step):
+            self._steps[step](ctx)
+            self._did_steps.add(step)
 
     def available_steps(self):
         return [str(k) for k in self._steps]
 
+    @contextlib.contextmanager
+    def _timer(self, step):
+        ns = argparse.Namespace(start=time.monotonic())
+        status = "not-started"
+        try:
+            yield ns
+            status = "completed"
+        except Exception:
+            status = "failed"
+            raise
+        finally:
+            ns.end = time.monotonic()
+            ns.duration = int(ns.end - ns.start)
+            hrs, _rest = map(int, divmod(ns.duration, 3600))
+            mins, secs = map(int, divmod(_rest, 60))
+            ns.duration_hms = f"{hrs:02}:{mins:02}:{secs:02}"
+            if not self._reported_failed:
+                log.info(
+                    "step done: %s %s in %s", step, status, ns.duration_hms
+                )
+            self._reported_failed = status == "failed"
+
     @classmethod
     def set(self, step):
         def wrap(f):