diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c index a43c68051078fb2c0add4683fba0e980ea998049..af0d65b414162cbde11fe3f17de72a3aee0feb79 100644 --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c @@ -254,8 +254,13 @@ static double avg_stats(struct stats *stats) */ static double stddev_stats(struct stats *stats) { - double variance = stats->M2 / (stats->n - 1); - double variance_mean = variance / stats->n; + double variance, variance_mean; + + if (!stats->n) + return 0.0; + + variance = stats->M2 / (stats->n - 1); + variance_mean = variance / stats->n; return sqrt(variance_mean); }