Skip to content

Commit

Permalink
perf stat: Initialize statistics correctly
Browse files Browse the repository at this point in the history
perf stat did initialize the stats structure used to compute
stddev etc. incorrectly. It merely zeroes it. But one member
(min) needs to be set to a non zero value. This causes min
to be not computed at all. Call init_stats() correctly.

It doesn't matter for stat currently because it doesn't use
min, but it's still better to do it correctly.

The other users of statistics are already correct.

Signed-off-by: Andi Kleen <ak@linux.intel.com>
Acked-by: Namhyung Kim <namhyung@kernel.org>
Link: http://lkml.kernel.org/r/1395768699-16060-1-git-send-email-andi@firstfloor.org
Signed-off-by: Jiri Olsa <jolsa@redhat.com>
  • Loading branch information
Andi Kleen authored and Jiri Olsa committed Apr 14, 2014
1 parent 40ba93e commit 90f6bb6
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions tools/perf/builtin-stat.c
Original file line number Diff line number Diff line change
Expand Up @@ -174,13 +174,20 @@ static inline int perf_evsel__nr_cpus(struct perf_evsel *evsel)

static void perf_evsel__reset_stat_priv(struct perf_evsel *evsel)
{
memset(evsel->priv, 0, sizeof(struct perf_stat));
int i;
struct perf_stat *ps = evsel->priv;

for (i = 0; i < 3; i++)
init_stats(&ps->res_stats[i]);
}

static int perf_evsel__alloc_stat_priv(struct perf_evsel *evsel)
{
evsel->priv = zalloc(sizeof(struct perf_stat));
return evsel->priv == NULL ? -ENOMEM : 0;
if (evsel == NULL)
return -ENOMEM;
perf_evsel__reset_stat_priv(evsel);
return 0;
}

static void perf_evsel__free_stat_priv(struct perf_evsel *evsel)
Expand Down

0 comments on commit 90f6bb6

Please sign in to comment.