diff options
author | Jiri Olsa <jolsa@kernel.org> | 2015-06-14 10:19:27 +0200 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2015-06-16 10:34:41 -0300 |
commit | 9df38e82e2a103cf42177c164a4de9d58052ac3a (patch) | |
tree | d261b24b6eedf63d9cb8c343870d77b09b90f276 /tools/perf/util/stat.c | |
parent | a9a3a4d92d8f2fb68f4b99d98505bebc70518599 (diff) |
perf stat: Introduce perf_counts__(new|delete|reset) functions
Move 'struct perf_counts' allocation|free|reset code into separate
functions.
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/r/1434269985-521-13-git-send-email-jolsa@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf/util/stat.c')
-rw-r--r-- | tools/perf/util/stat.c | 28 |
1 files changed, 23 insertions, 5 deletions
diff --git a/tools/perf/util/stat.c b/tools/perf/util/stat.c index ac589b6b8bce..4014b709f956 100644 --- a/tools/perf/util/stat.c +++ b/tools/perf/util/stat.c @@ -95,20 +95,38 @@ void perf_stat_evsel_id_init(struct perf_evsel *evsel) } } +struct perf_counts *perf_counts__new(int ncpus) +{ + int size = sizeof(struct perf_counts) + + ncpus * sizeof(struct perf_counts_values); + + return zalloc(size); +} + +void perf_counts__delete(struct perf_counts *counts) +{ + free(counts); +} + +static void perf_counts__reset(struct perf_counts *counts, int ncpus) +{ + memset(counts, 0, (sizeof(*counts) + + (ncpus * sizeof(struct perf_counts_values)))); +} + void perf_evsel__reset_counts(struct perf_evsel *evsel, int ncpus) { - memset(evsel->counts, 0, (sizeof(*evsel->counts) + - (ncpus * sizeof(struct perf_counts_values)))); + perf_counts__reset(evsel->counts, ncpus); } int perf_evsel__alloc_counts(struct perf_evsel *evsel, int ncpus) { - evsel->counts = zalloc((sizeof(*evsel->counts) + - (ncpus * sizeof(struct perf_counts_values)))); + evsel->counts = perf_counts__new(ncpus); return evsel->counts != NULL ? 0 : -ENOMEM; } void perf_evsel__free_counts(struct perf_evsel *evsel) { - zfree(&evsel->counts); + perf_counts__delete(evsel->counts); + evsel->counts = NULL; } |