perf report: Introduce helpers for processing callchains

Continuing to try to remove the code duplication introduced with mem and
branch hist entry code, this time providing prologue and epilogues to
deal with callchains when processing samples.
Acked-by: default avatarNamhyung Kim <namhyung@kernel.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/n/tip-js3pour59yk2aibqzb1tpumh@git.kernel.orgSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 44e83039
...@@ -75,6 +75,24 @@ static int perf_report_config(const char *var, const char *value, void *cb) ...@@ -75,6 +75,24 @@ static int perf_report_config(const char *var, const char *value, void *cb)
return perf_default_config(var, value, cb); return perf_default_config(var, value, cb);
} }
static int report__resolve_callchain(struct perf_report *rep, struct symbol **parent,
struct perf_evsel *evsel, struct addr_location *al,
struct perf_sample *sample, struct machine *machine)
{
if ((sort__has_parent || symbol_conf.use_callchain) && sample->callchain) {
return machine__resolve_callchain(machine, evsel, al->thread, sample,
parent, al, rep->max_stack);
}
return 0;
}
static int hist_entry__append_callchain(struct hist_entry *he, struct perf_sample *sample)
{
if (!symbol_conf.use_callchain)
return 0;
return callchain_append(he->callchain, &callchain_cursor, sample->period);
}
static int perf_report__add_mem_hist_entry(struct perf_tool *tool, static int perf_report__add_mem_hist_entry(struct perf_tool *tool,
struct addr_location *al, struct addr_location *al,
struct perf_sample *sample, struct perf_sample *sample,
...@@ -85,19 +103,13 @@ static int perf_report__add_mem_hist_entry(struct perf_tool *tool, ...@@ -85,19 +103,13 @@ static int perf_report__add_mem_hist_entry(struct perf_tool *tool,
struct perf_report *rep = container_of(tool, struct perf_report, tool); struct perf_report *rep = container_of(tool, struct perf_report, tool);
struct symbol *parent = NULL; struct symbol *parent = NULL;
u8 cpumode = event->header.misc & PERF_RECORD_MISC_CPUMODE_MASK; u8 cpumode = event->header.misc & PERF_RECORD_MISC_CPUMODE_MASK;
int err = 0;
struct hist_entry *he; struct hist_entry *he;
struct mem_info *mi, *mx; struct mem_info *mi, *mx;
uint64_t cost; uint64_t cost;
int err = report__resolve_callchain(rep, &parent, evsel, al, sample, machine);
if ((sort__has_parent || symbol_conf.use_callchain) && if (err)
sample->callchain) { return err;
err = machine__resolve_callchain(machine, evsel, al->thread,
sample, &parent, al,
rep->max_stack);
if (err)
return err;
}
mi = machine__resolve_mem(machine, al->thread, sample, cpumode); mi = machine__resolve_mem(machine, al->thread, sample, cpumode);
if (!mi) if (!mi)
...@@ -133,13 +145,7 @@ static int perf_report__add_mem_hist_entry(struct perf_tool *tool, ...@@ -133,13 +145,7 @@ static int perf_report__add_mem_hist_entry(struct perf_tool *tool,
evsel->hists.stats.total_period += cost; evsel->hists.stats.total_period += cost;
hists__inc_nr_events(&evsel->hists, PERF_RECORD_SAMPLE); hists__inc_nr_events(&evsel->hists, PERF_RECORD_SAMPLE);
err = 0; err = hist_entry__append_callchain(he, sample);
if (symbol_conf.use_callchain) {
err = callchain_append(he->callchain,
&callchain_cursor,
sample->period);
}
out: out:
return err; return err;
} }
...@@ -152,19 +158,13 @@ static int perf_report__add_branch_hist_entry(struct perf_tool *tool, ...@@ -152,19 +158,13 @@ static int perf_report__add_branch_hist_entry(struct perf_tool *tool,
{ {
struct perf_report *rep = container_of(tool, struct perf_report, tool); struct perf_report *rep = container_of(tool, struct perf_report, tool);
struct symbol *parent = NULL; struct symbol *parent = NULL;
int err = 0;
unsigned i; unsigned i;
struct hist_entry *he; struct hist_entry *he;
struct branch_info *bi, *bx; struct branch_info *bi, *bx;
int err = report__resolve_callchain(rep, &parent, evsel, al, sample, machine);
if ((sort__has_parent || symbol_conf.use_callchain) if (err)
&& sample->callchain) { return err;
err = machine__resolve_callchain(machine, evsel, al->thread,
sample, &parent, al,
rep->max_stack);
if (err)
return err;
}
bi = machine__resolve_bstack(machine, al->thread, bi = machine__resolve_bstack(machine, al->thread,
sample->branch_stack); sample->branch_stack);
...@@ -216,16 +216,11 @@ static int perf_evsel__add_hist_entry(struct perf_tool *tool, ...@@ -216,16 +216,11 @@ static int perf_evsel__add_hist_entry(struct perf_tool *tool,
{ {
struct perf_report *rep = container_of(tool, struct perf_report, tool); struct perf_report *rep = container_of(tool, struct perf_report, tool);
struct symbol *parent = NULL; struct symbol *parent = NULL;
int err = 0;
struct hist_entry *he; struct hist_entry *he;
int err = report__resolve_callchain(rep, &parent, evsel, al, sample, machine);
if ((sort__has_parent || symbol_conf.use_callchain) && sample->callchain) { if (err)
err = machine__resolve_callchain(machine, evsel, al->thread, return err;
sample, &parent, al,
rep->max_stack);
if (err)
return err;
}
he = __hists__add_entry(&evsel->hists, al, parent, NULL, NULL, he = __hists__add_entry(&evsel->hists, al, parent, NULL, NULL,
sample->period, sample->weight, sample->period, sample->weight,
...@@ -233,17 +228,14 @@ static int perf_evsel__add_hist_entry(struct perf_tool *tool, ...@@ -233,17 +228,14 @@ static int perf_evsel__add_hist_entry(struct perf_tool *tool,
if (he == NULL) if (he == NULL)
return -ENOMEM; return -ENOMEM;
if (symbol_conf.use_callchain) { err = hist_entry__append_callchain(he, sample);
err = callchain_append(he->callchain, if (err)
&callchain_cursor, goto out;
sample->period);
if (err)
return err;
}
err = hist_entry__inc_addr_samples(he, evsel->idx, al->addr); err = hist_entry__inc_addr_samples(he, evsel->idx, al->addr);
evsel->hists.stats.total_period += sample->period; evsel->hists.stats.total_period += sample->period;
hists__inc_nr_events(&evsel->hists, PERF_RECORD_SAMPLE); hists__inc_nr_events(&evsel->hists, PERF_RECORD_SAMPLE);
out:
return err; return err;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment