[Intel-gfx] [PATCH 14/23] framework: Humanize time values in the HTML report

Damien Lespiau damien.lespiau at intel.com
Fri Nov 15 17:33:31 CET 2013


It's a bit hard to parse raw seconds, so make those time values easier
to read while trying to preserve roughly enough relevant precision to be
useful.

It gives strings like:

  22.4ms
  7.798s
  42.3s
  7min 25s
  ...

v2: Remove support for days, weeks, months and years, surely no test
    should be that long! (Daniel Vetter)
    Display 1 decimal if the duration is < 60s (Daniel Vetter)

Sent to the piglit ml:
  http://lists.freedesktop.org/archives/piglit/2013-November/008464.html

Signed-off-by: Damien Lespiau <damien.lespiau at intel.com>
---
 piglit/framework/summary.py | 40 ++++++++++++++++++++++++++++++++++++++--
 1 file changed, 38 insertions(+), 2 deletions(-)

diff --git a/piglit/framework/summary.py b/piglit/framework/summary.py
index 8fbe2a8..a85353a 100644
--- a/piglit/framework/summary.py
+++ b/piglit/framework/summary.py
@@ -38,6 +38,42 @@ __all__ = [
 ]
 
 
+INTERVALS = (1, 60, 3600)
+NAMES = ('s', 'min', 'hr')
+
+# Gives a human readable elapsed time
+# @amount is a string with a number of seconds
+def humanize_time(amount):
+    result = []
+
+    if amount == 'None':
+        return 'None'
+
+    amount_f = float(amount)
+    if (amount_f < 1):
+        amount_ms = amount_f * 1000
+        if amount_ms < 1:
+            return "< 1ms"
+        return "%.1fms" % amount_ms
+
+    # if < 10s, consider ms are important
+    if amount_f < 10:
+        return "%.03fs" % amount_f
+
+    # still display 1 decimal when < 60s
+    if amount_f < 60:
+        return "%.01fs" % amount_f
+
+    amount = int(amount_f)
+
+    for i in range(len(NAMES) - 1, -1, -1):
+       a = amount / INTERVALS[i]
+       if a > 0:
+          result.append("%d%s" % (a, NAMES[i]))
+          amount -= a * INTERVALS[i]
+
+    return " ".join(result)
+
 class HTMLIndex(list):
     """
     Builds HTML output to be passed to the index mako template, which will be
@@ -420,7 +456,7 @@ class Summary:
 
             with open(path.join(destination, each.name, "index.html"), 'w') as out:
                 out.write(testindex.render(name=each.name,
-                                           time=each.time_elapsed,
+                                           time=humanize_time(each.time_elapsed),
                                            options=each.options,
                                            glxinfo=each.glxinfo,
                                            lspci=each.lspci))
@@ -447,7 +483,7 @@ class Summary:
                             # disapear at somepoint
                             env=value.get('environment', None),
                             returncode=value.get('returncode', 'None'),
-                            time=value.get('time', 'None'),
+                            time=humanize_time(value.get('time', 'None')),
                             info=value.get('info', 'None'),
                             traceback=value.get('traceback', 'None'),
                             command=value.get('command', 'None'),
-- 
1.8.3.1




More information about the Intel-gfx mailing list