summaryrefslogtreecommitdiffstats
path: root/progs/perf/common.c
diff options
context:
space:
mode:
authorKeith Whitwell <[email protected]>2009-09-21 15:51:26 +0100
committerKeith Whitwell <[email protected]>2009-09-21 15:57:13 +0100
commited63bd62d85c92555c1d310ae46064ad3c7d47ee (patch)
treed83613d5f9c350a4f19a94222c3d6c85247154a4 /progs/perf/common.c
parentd17af7d1e19e637e29db47bd8f6e3e579760c530 (diff)
progs/perf: add human-readable float formatter
Diffstat (limited to 'progs/perf/common.c')
-rw-r--r--progs/perf/common.c18
1 files changed, 18 insertions, 0 deletions
diff --git a/progs/perf/common.c b/progs/perf/common.c
index 695b8a99d9d..722f4b7b454 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;
+}