Skip to contentSkip to conversation

knotty: Pretty print task elapsed time

PATCH New Jacob Kroon 1 participant 1 message Apr 26, 2019

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 knotty: Pretty print task elapsed time

A task's runtime is currently printed in seconds. Change it to include minutes and hours for easier reading.

---
 lib/bb/ui/knotty.py | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)
lib/bb/ui/knotty.py +13 -1
index fa88e6cc..f362c23a 100644
@@ -222,6 +222,18 @@ class TerminalFilter(object):
             sys.stdout.flush()
         self.footer_present = False
 
+    def elapsed(self, sec):
+        hrs = int(sec / 3600.0)
+        sec -= hrs * 3600
+        min = int(sec / 60.0)
+        sec -= min * 60
+        if hrs > 0:
+            return "%dh%dm%ds" % (hrs, min, sec)
+        elif min > 0:
+            return "%dm%ds" % (min, sec)
+        else:
+            return "%ds" % (sec)
+
     def updateFooter(self):
         if not self.cuu:
             return
@@ -258,7 +270,7 @@ class TerminalFilter(object):
             else:
                 start_time = activetasks[t].get("starttime", None)
                 if start_time:
-                    tasks.append("%s - %ds (pid %s)" % (activetasks[t]["title"], currenttime - start_time, t))
+                    tasks.append("%s - %s (pid %s)" % (activetasks[t]["title"], self.elapsed(currenttime - start_time), t))
                 else:
                     tasks.append("%s (pid %s)" % (activetasks[t]["title"], t))
 
Signature · 1 line
2.20.1