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>
This commit is contained in:
parent
a9a3a4d92d
commit
9df38e82e2
|
@ -178,24 +178,19 @@ static void perf_evsel__free_stat_priv(struct perf_evsel *evsel)
|
||||||
|
|
||||||
static int perf_evsel__alloc_prev_raw_counts(struct perf_evsel *evsel)
|
static int perf_evsel__alloc_prev_raw_counts(struct perf_evsel *evsel)
|
||||||
{
|
{
|
||||||
void *addr;
|
struct perf_counts *counts;
|
||||||
size_t sz;
|
|
||||||
|
|
||||||
sz = sizeof(*evsel->counts) +
|
counts = perf_counts__new(perf_evsel__nr_cpus(evsel));
|
||||||
(perf_evsel__nr_cpus(evsel) * sizeof(struct perf_counts_values));
|
if (counts)
|
||||||
|
evsel->prev_raw_counts = counts;
|
||||||
|
|
||||||
addr = zalloc(sz);
|
return counts ? 0 : -ENOMEM;
|
||||||
if (!addr)
|
|
||||||
return -ENOMEM;
|
|
||||||
|
|
||||||
evsel->prev_raw_counts = addr;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void perf_evsel__free_prev_raw_counts(struct perf_evsel *evsel)
|
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)
|
static void perf_evlist__free_stats(struct perf_evlist *evlist)
|
||||||
|
|
|
@ -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)
|
void perf_evsel__reset_counts(struct perf_evsel *evsel, int ncpus)
|
||||||
{
|
{
|
||||||
memset(evsel->counts, 0, (sizeof(*evsel->counts) +
|
perf_counts__reset(evsel->counts, ncpus);
|
||||||
(ncpus * sizeof(struct perf_counts_values))));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int perf_evsel__alloc_counts(struct perf_evsel *evsel, int ncpus)
|
int perf_evsel__alloc_counts(struct perf_evsel *evsel, int ncpus)
|
||||||
{
|
{
|
||||||
evsel->counts = zalloc((sizeof(*evsel->counts) +
|
evsel->counts = perf_counts__new(ncpus);
|
||||||
(ncpus * sizeof(struct perf_counts_values))));
|
|
||||||
return evsel->counts != NULL ? 0 : -ENOMEM;
|
return evsel->counts != NULL ? 0 : -ENOMEM;
|
||||||
}
|
}
|
||||||
|
|
||||||
void perf_evsel__free_counts(struct perf_evsel *evsel)
|
void perf_evsel__free_counts(struct perf_evsel *evsel)
|
||||||
{
|
{
|
||||||
zfree(&evsel->counts);
|
perf_counts__delete(evsel->counts);
|
||||||
|
evsel->counts = NULL;
|
||||||
}
|
}
|
||||||
|
|
|
@ -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,
|
void perf_stat__print_shadow_stats(FILE *out, struct perf_evsel *evsel,
|
||||||
double avg, int cpu, enum aggr_mode aggr);
|
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);
|
void perf_evsel__reset_counts(struct perf_evsel *evsel, int ncpus);
|
||||||
int perf_evsel__alloc_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);
|
void perf_evsel__free_counts(struct perf_evsel *evsel);
|
||||||
|
|
Loading…
Reference in New Issue