[Piglit] [PATCH] framework: Humanize time values in the HTML report
Damien Lespiau
damien.lespiau at intel.com
Fri Nov 15 01:06:51 PST 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
42s
7min 25s
...
Signed-off-by: Damien Lespiau <damien.lespiau at intel.com>
---
framework/summary.py | 36 ++++++++++++++++++++++++++++++++++--
1 file changed, 34 insertions(+), 2 deletions(-)
diff --git a/framework/summary.py b/framework/summary.py
index 8fbe2a8..c42ee03 100644
--- a/framework/summary.py
+++ b/framework/summary.py
@@ -38,6 +38,38 @@ __all__ = [
]
+INTERVALS = (1, 60, 3600, 86400, 604800, 2419200, 29030400)
+NAMES = ('s', 'min', 'hr', 'day', 'week', 'month', 'year')
+
+# 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
+
+ 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 +452,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 +479,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 Piglit
mailing list