[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20150615201600.GI5845@kernel.org>
Date: Mon, 15 Jun 2015 17:16:00 -0300
From: Arnaldo Carvalho de Melo <acme@...nel.org>
To: Jiri Olsa <jolsa@...nel.org>
Cc: lkml <linux-kernel@...r.kernel.org>,
Adrian Hunter <adrian.hunter@...el.com>,
Andi Kleen <ak@...ux.intel.com>,
David Ahern <dsahern@...il.com>,
Ingo Molnar <mingo@...nel.org>,
Namhyung Kim <namhyung@...nel.org>,
Peter Zijlstra <a.p.zijlstra@...llo.nl>,
Stephane Eranian <eranian@...gle.com>
Subject: Re: [PATCH 12/30] perf stat: Introduce
perf_counts__(alloc|free|reset) functions
Em Sun, Jun 14, 2015 at 10:19:27AM +0200, Jiri Olsa escreveu:
> Move 'struct perf_counts' allocation|free|reset code into
> separate functions.
Applied, after fixing up the Subject to match new/delete.
- Arnaldo
> Link: http://lkml.kernel.org/n/tip-qu64zmm5zbpbkuybusnkg4gl@git.kernel.org
> Signed-off-by: Jiri Olsa <jolsa@...nel.org>
> ---
> tools/perf/builtin-stat.c | 19 +++++++------------
> tools/perf/util/stat.c | 28 +++++++++++++++++++++++-----
> tools/perf/util/stat.h | 3 +++
> 3 files changed, 33 insertions(+), 17 deletions(-)
>
> diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
> index a2f752ae15ca..3e1636cae76b 100644
> --- a/tools/perf/builtin-stat.c
> +++ b/tools/perf/builtin-stat.c
> @@ -168,24 +168,19 @@ static void perf_evsel__free_stat_priv(struct perf_evsel *evsel)
>
> static int perf_evsel__alloc_prev_raw_counts(struct perf_evsel *evsel)
> {
> - void *addr;
> - size_t sz;
> + struct perf_counts *counts;
>
> - sz = sizeof(*evsel->counts) +
> - (perf_evsel__nr_cpus(evsel) * sizeof(struct perf_counts_values));
> + counts = perf_counts__new(perf_evsel__nr_cpus(evsel));
> + if (counts)
> + evsel->prev_raw_counts = counts;
>
> - addr = zalloc(sz);
> - if (!addr)
> - return -ENOMEM;
> -
> - evsel->prev_raw_counts = addr;
> -
> - return 0;
> + return counts ? 0 : -ENOMEM;
> }
>
> static void perf_evsel__free_prev_raw_counts(struct perf_evsel *evsel)
> {
> - zfree(&evsel->prev_raw_counts);
> + perf_counts__delete(evsel->prev_raw_counts);
> + evsel->prev_raw_counts = NULL;
> }
>
> static void perf_evlist__free_stats(struct perf_evlist *evlist)
> 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;
> }
> diff --git a/tools/perf/util/stat.h b/tools/perf/util/stat.h
> index 6a782601c1c7..093dc3cb28dd 100644
> --- a/tools/perf/util/stat.h
> +++ b/tools/perf/util/stat.h
> @@ -62,6 +62,9 @@ void perf_stat__update_shadow_stats(struct perf_evsel *counter, u64 *count,
> void perf_stat__print_shadow_stats(FILE *out, struct perf_evsel *evsel,
> double avg, int cpu, enum aggr_mode aggr);
>
> +struct perf_counts *perf_counts__new(int ncpus);
> +void perf_counts__delete(struct perf_counts *counts);
> +
> void perf_evsel__reset_counts(struct perf_evsel *evsel, int ncpus);
> int perf_evsel__alloc_counts(struct perf_evsel *evsel, int ncpus);
> void perf_evsel__free_counts(struct perf_evsel *evsel);
> --
> 1.9.3
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists