[Piglit] [PATCH] framework: Humanize time values in the HTML report

Daniel Vetter daniel at ffwll.ch
Fri Nov 15 02:00:24 PST 2013


On Fri, Nov 15, 2013 at 09:06:51AM +0000, Damien Lespiau wrote:
> 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')

I'd kill everything above hr, at least I didn't bother checking them ;-)

> +
> +# 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

Since you've gone overboard so much, what about %.01fs if it's less than
60 s?

With or without any of these bikesheds:

Reviewed-by: Daniel Vetter <daniel.vetter at ffwll.ch>

> +
> +    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
> 
> _______________________________________________
> Piglit mailing list
> Piglit at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/piglit

-- 
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch


More information about the Piglit mailing list