Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf stat: Introduce perf_evsel__alloc_stats function

Move all stat allocation logic related to stat object under single
function. This way we can use it separately for stat object out of
evlist object.

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/1435310967-14570-13-git-send-email-jolsa@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Jiri Olsa and committed by
Arnaldo Carvalho de Melo
a7d0a102 24e34f68

+16 -6
+14 -6
tools/perf/util/stat.c
··· 189 189 evsel->prev_raw_counts = NULL; 190 190 } 191 191 192 + int perf_evsel__alloc_stats(struct perf_evsel *evsel, bool alloc_raw) 193 + { 194 + int ncpus = perf_evsel__nr_cpus(evsel); 195 + int nthreads = thread_map__nr(evsel->threads); 196 + 197 + if (perf_evsel__alloc_stat_priv(evsel) < 0 || 198 + perf_evsel__alloc_counts(evsel, ncpus, nthreads) < 0 || 199 + (alloc_raw && perf_evsel__alloc_prev_raw_counts(evsel, ncpus, nthreads) < 0)) 200 + return -ENOMEM; 201 + 202 + return 0; 203 + } 204 + 192 205 int perf_evlist__alloc_stats(struct perf_evlist *evlist, bool alloc_raw) 193 206 { 194 207 struct perf_evsel *evsel; 195 - int nthreads = thread_map__nr(evlist->threads); 196 208 197 209 evlist__for_each(evlist, evsel) { 198 - int ncpus = perf_evsel__nr_cpus(evsel); 199 - 200 - if (perf_evsel__alloc_stat_priv(evsel) < 0 || 201 - perf_evsel__alloc_counts(evsel, ncpus, nthreads) < 0 || 202 - (alloc_raw && perf_evsel__alloc_prev_raw_counts(evsel, ncpus, nthreads) < 0)) 210 + if (perf_evsel__alloc_stats(evsel, alloc_raw)) 203 211 goto out_free; 204 212 } 205 213
+2
tools/perf/util/stat.h
··· 103 103 int ncpus, int nthreads); 104 104 void perf_evsel__free_prev_raw_counts(struct perf_evsel *evsel); 105 105 106 + int perf_evsel__alloc_stats(struct perf_evsel *evsel, bool alloc_raw); 107 + 106 108 int perf_evlist__alloc_stats(struct perf_evlist *evlist, bool alloc_raw); 107 109 void perf_evlist__free_stats(struct perf_evlist *evlist); 108 110 void perf_evlist__reset_stats(struct perf_evlist *evlist);