perf stats: Fix divide by 0 in variance
authorDavid Ahern <dsahern@gmail.com>
Sun, 26 May 2013 00:24:48 +0000 (18:24 -0600)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Tue, 28 May 2013 13:24:04 +0000 (16:24 +0300)
Number of samples needs to be greater 1 to have a variance.

Fixes nan% in perf-kvm-live output.

Signed-off-by: David Ahern <dsahern@gmail.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Runzhen Wang <runzhen@linux.vnet.ibm.com>
Cc: Xiao Guangrong <xiaoguangrong@linux.vnet.ibm.com>
Link: http://lkml.kernel.org/r/1369527896-3650-9-git-send-email-dsahern@gmail.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/util/stat.c

index 23742126f47c848b81f38a15af23f30593230354..7c59c28afcc524467f6d1824dccc2442e540c6a6 100644 (file)
@@ -37,7 +37,7 @@ double stddev_stats(struct stats *stats)
 {
        double variance, variance_mean;
 
-       if (!stats->n)
+       if (stats->n < 2)
                return 0.0;
 
        variance = stats->M2 / (stats->n - 1);