From: Damien Lespiau Subject: [PATCH 14/23] framework: Humanize time values in the HTML report Date: Fri, 15 Nov 2013 16:33:31 +0000 Message-ID: <1384533220-20780-15-git-send-email-damien.lespiau@intel.com> References: <1384533220-20780-1-git-send-email-damien.lespiau@intel.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by gabe.freedesktop.org (Postfix) with ESMTP id 169D7FB8FF for ; Fri, 15 Nov 2013 08:33:58 -0800 (PST) In-Reply-To: <1384533220-20780-1-git-send-email-damien.lespiau@intel.com> List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: intel-gfx-bounces@lists.freedesktop.org Errors-To: intel-gfx-bounces@lists.freedesktop.org To: intel-gfx@lists.freedesktop.org List-Id: intel-gfx@lists.freedesktop.org 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 --- 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