Module: Mesa Branch: master Commit: ed63bd62d85c92555c1d310ae46064ad3c7d47ee URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=ed63bd62d85c92555c1d310ae46064ad3c7d47ee
Author: Keith Whitwell <kei...@vmware.com> Date: Mon Sep 21 15:51:26 2009 +0100 progs/perf: add human-readable float formatter --- progs/perf/common.c | 18 ++++++++++++++++++ progs/perf/common.h | 2 ++ 2 files changed, 20 insertions(+), 0 deletions(-) diff --git a/progs/perf/common.c b/progs/perf/common.c index 695b8a9..722f4b7 100644 --- a/progs/perf/common.c +++ b/progs/perf/common.c @@ -113,3 +113,21 @@ PerfMeasureRate(PerfRateFunc f) } +/* Note static buffer, can only use once per printf. + */ +const char * +PerfHumanFloat( double d ) +{ + static char buf[80]; + + if (d > 1000000000.0) + snprintf(buf, sizeof(buf), "%.1f billion", d / 1000000000.0); + else if (d > 1000000.0) + snprintf(buf, sizeof(buf), "%.1f million", d / 1000000.0); + else if (d > 1000.0) + snprintf(buf, sizeof(buf), "%.1f thousand", d / 1000.0); + else + snprintf(buf, sizeof(buf), "%.1f", d); + + return buf; +} diff --git a/progs/perf/common.h b/progs/perf/common.h index 85db678..fc49bbe 100644 --- a/progs/perf/common.h +++ b/progs/perf/common.h @@ -30,6 +30,8 @@ typedef void (*PerfRateFunc)(unsigned count); extern double PerfMeasureRate(PerfRateFunc f); +const char * +PerfHumanFloat( double d ); extern void perf_printf(const char *format, ...); _______________________________________________ mesa-commit mailing list mesa-commit@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/mesa-commit