[PATCH 22/38] perf callchain: Use session__find_addr_location() and friends

From: Namhyung Kim
Date: Mon Mar 02 2015 - 22:15:45 EST


Pass session struct to callchain resolve routines and find correct
thread/map/symbol using proper functions.

Cc: Frederic Weisbecker <fweisbec@xxxxxxxxx>
Signed-off-by: Namhyung Kim <namhyung@xxxxxxxxxx>
---
tools/perf/builtin-script.c | 4 +--
tools/perf/tests/dwarf-unwind.c | 2 +-
tools/perf/util/callchain.c | 6 ++--
tools/perf/util/callchain.h | 4 ++-
tools/perf/util/hist.c | 5 +--
tools/perf/util/machine.c | 41 +++++++++++++---------
tools/perf/util/machine.h | 1 +
.../util/scripting-engines/trace-event-python.c | 27 +++++++-------
tools/perf/util/session.c | 6 ++--
tools/perf/util/session.h | 2 +-
tools/perf/util/unwind-libdw.c | 14 ++++----
tools/perf/util/unwind-libdw.h | 1 +
tools/perf/util/unwind-libunwind.c | 32 +++++++++--------
tools/perf/util/unwind.h | 3 +-
14 files changed, 86 insertions(+), 62 deletions(-)

diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
index 65b3a07be2bf..90a401a52868 100644
--- a/tools/perf/builtin-script.c
+++ b/tools/perf/builtin-script.c
@@ -429,7 +429,7 @@ static void print_sample_bts(union perf_event *event,
print_opts &= ~PRINT_IP_OPT_SRCLINE;
}
}
- perf_evsel__print_ip(evsel, sample, al, print_opts,
+ perf_evsel__print_ip(evsel, sample, session, al, print_opts,
PERF_MAX_STACK_DEPTH);
}

@@ -483,7 +483,7 @@ static void process_event(union perf_event *event, struct perf_sample *sample,
else
printf("\n");

- perf_evsel__print_ip(evsel, sample, al,
+ perf_evsel__print_ip(evsel, sample, session, al,
output[attr->type].print_ip_opts,
PERF_MAX_STACK_DEPTH);
}
diff --git a/tools/perf/tests/dwarf-unwind.c b/tools/perf/tests/dwarf-unwind.c
index 7e04feb431cb..241270374e93 100644
--- a/tools/perf/tests/dwarf-unwind.c
+++ b/tools/perf/tests/dwarf-unwind.c
@@ -75,7 +75,7 @@ static int unwind_thread(struct thread *thread)
goto out;
}

- err = unwind__get_entries(unwind_entry, &cnt, thread,
+ err = unwind__get_entries(unwind_entry, &cnt, thread, NULL,
&sample, MAX_STACK);
if (err)
pr_debug("unwind failed\n");
diff --git a/tools/perf/util/callchain.c b/tools/perf/util/callchain.c
index 9f643ee77001..f95b27037dc8 100644
--- a/tools/perf/util/callchain.c
+++ b/tools/perf/util/callchain.c
@@ -757,7 +757,9 @@ int callchain_cursor_append(struct callchain_cursor *cursor,
return 0;
}

-int sample__resolve_callchain(struct perf_sample *sample, struct symbol **parent,
+int sample__resolve_callchain(struct perf_sample *sample,
+ struct perf_session *session,
+ struct symbol **parent,
struct perf_evsel *evsel, struct addr_location *al,
int max_stack)
{
@@ -767,7 +769,7 @@ int sample__resolve_callchain(struct perf_sample *sample, struct symbol **parent
if (symbol_conf.use_callchain || symbol_conf.cumulate_callchain ||
sort__has_parent) {
return thread__resolve_callchain(al->thread, evsel, sample,
- parent, al, max_stack);
+ session, parent, al, max_stack);
}
return 0;
}
diff --git a/tools/perf/util/callchain.h b/tools/perf/util/callchain.h
index 6033a0a212ca..ca9048f84cb5 100644
--- a/tools/perf/util/callchain.h
+++ b/tools/perf/util/callchain.h
@@ -165,7 +165,9 @@ struct hist_entry;
int record_parse_callchain_opt(const struct option *opt, const char *arg, int unset);
int record_callchain_opt(const struct option *opt, const char *arg, int unset);

-int sample__resolve_callchain(struct perf_sample *sample, struct symbol **parent,
+int sample__resolve_callchain(struct perf_sample *sample,
+ struct perf_session *session,
+ struct symbol **parent,
struct perf_evsel *evsel, struct addr_location *al,
int max_stack);
int hist_entry__append_callchain(struct hist_entry *he, struct perf_sample *sample);
diff --git a/tools/perf/util/hist.c b/tools/perf/util/hist.c
index 0d189ae76922..dbe7f3744bf1 100644
--- a/tools/perf/util/hist.c
+++ b/tools/perf/util/hist.c
@@ -861,8 +861,9 @@ int hist_entry_iter__add(struct hist_entry_iter *iter, struct addr_location *al,
{
int err, err2;

- err = sample__resolve_callchain(iter->sample, &iter->parent,
- iter->evsel, al, max_stack_depth);
+ err = sample__resolve_callchain(iter->sample, iter->session,
+ &iter->parent, iter->evsel, al,
+ max_stack_depth);
if (err)
return err;

diff --git a/tools/perf/util/machine.c b/tools/perf/util/machine.c
index 4743718d4bf1..63d860dca74b 100644
--- a/tools/perf/util/machine.c
+++ b/tools/perf/util/machine.c
@@ -1540,10 +1540,11 @@ struct mem_info *sample__resolve_mem(struct perf_sample *sample,
}

static int add_callchain_ip(struct thread *thread,
+ struct perf_session *session,
struct symbol **parent,
struct addr_location *root_al,
bool branch_history,
- u64 ip)
+ u64 ip, u64 timestamp)
{
struct addr_location al;

@@ -1551,8 +1552,9 @@ static int add_callchain_ip(struct thread *thread,
al.sym = NULL;

if (branch_history)
- thread__find_cpumode_addr_location(thread, MAP__FUNCTION,
- ip, &al);
+ session__find_cpumode_addr_location(session, thread,
+ MAP__FUNCTION, ip, &al,
+ timestamp);
else {
u8 cpumode = PERF_RECORD_MISC_USER;

@@ -1579,8 +1581,8 @@ static int add_callchain_ip(struct thread *thread,
}
return 0;
}
- thread__find_addr_location(thread, cpumode, MAP__FUNCTION,
- ip, &al);
+ session__find_addr_location(session,thread, cpumode,
+ MAP__FUNCTION, ip, &al, timestamp);
}

if (al.sym != NULL) {
@@ -1670,6 +1672,7 @@ static int remove_loops(struct branch_entry *l, int nr)
*/
static int resolve_lbr_callchain_sample(struct thread *thread,
struct perf_sample *sample,
+ struct perf_session *session,
struct symbol **parent,
struct addr_location *root_al,
int max_stack)
@@ -1722,7 +1725,8 @@ static int resolve_lbr_callchain_sample(struct thread *thread,
ip = lbr_stack->entries[0].to;
}

- err = add_callchain_ip(thread, parent, root_al, false, ip);
+ err = add_callchain_ip(thread, session, parent, root_al,
+ false, ip, sample->time);
if (err)
return (err < 0) ? err : 0;
}
@@ -1735,6 +1739,7 @@ static int resolve_lbr_callchain_sample(struct thread *thread,
static int thread__resolve_callchain_sample(struct thread *thread,
struct perf_evsel *evsel,
struct perf_sample *sample,
+ struct perf_session *session,
struct symbol **parent,
struct addr_location *root_al,
int max_stack)
@@ -1742,6 +1747,7 @@ static int thread__resolve_callchain_sample(struct thread *thread,
struct branch_stack *branch = sample->branch_stack;
struct ip_callchain *chain = sample->callchain;
int chain_nr = min(max_stack, (int)chain->nr);
+ u64 timestamp = sample->time;
int i, j, err;
int skip_idx = -1;
int first_call = 0;
@@ -1749,8 +1755,8 @@ static int thread__resolve_callchain_sample(struct thread *thread,
callchain_cursor_reset(&callchain_cursor);

if (has_branch_callstack(evsel)) {
- err = resolve_lbr_callchain_sample(thread, sample, parent,
- root_al, max_stack);
+ err = resolve_lbr_callchain_sample(thread, sample, session,
+ parent, root_al, max_stack);
if (err)
return (err < 0) ? err : 0;
}
@@ -1806,11 +1812,12 @@ static int thread__resolve_callchain_sample(struct thread *thread,
nr = remove_loops(be, nr);

for (i = 0; i < nr; i++) {
- err = add_callchain_ip(thread, parent, root_al,
- true, be[i].to);
+ err = add_callchain_ip(thread, session, parent, root_al,
+ true, be[i].to, timestamp);
if (!err)
- err = add_callchain_ip(thread, parent, root_al,
- true, be[i].from);
+ err = add_callchain_ip(thread, session, parent,
+ root_al, true,
+ be[i].from, timestamp);
if (err == -EINVAL)
break;
if (err)
@@ -1839,7 +1846,8 @@ static int thread__resolve_callchain_sample(struct thread *thread,
#endif
ip = chain->ips[j];

- err = add_callchain_ip(thread, parent, root_al, false, ip);
+ err = add_callchain_ip(thread, session, parent, root_al, false,
+ ip, timestamp);
if (err)
return (err < 0) ? err : 0;
}
@@ -1857,12 +1865,13 @@ static int unwind_entry(struct unwind_entry *entry, void *arg)
int thread__resolve_callchain(struct thread *thread,
struct perf_evsel *evsel,
struct perf_sample *sample,
+ struct perf_session *session,
struct symbol **parent,
struct addr_location *root_al,
int max_stack)
{
- int ret = thread__resolve_callchain_sample(thread, evsel,
- sample, parent,
+ int ret = thread__resolve_callchain_sample(thread, evsel, sample,
+ session, parent,
root_al, max_stack);
if (ret)
return ret;
@@ -1878,7 +1887,7 @@ int thread__resolve_callchain(struct thread *thread,
return 0;

return unwind__get_entries(unwind_entry, &callchain_cursor,
- thread, sample, max_stack);
+ thread, session, sample, max_stack);

}

diff --git a/tools/perf/util/machine.h b/tools/perf/util/machine.h
index 45aee0c329ef..38ead24f0f47 100644
--- a/tools/perf/util/machine.h
+++ b/tools/perf/util/machine.h
@@ -129,6 +129,7 @@ struct mem_info *sample__resolve_mem(struct perf_sample *sample,
int thread__resolve_callchain(struct thread *thread,
struct perf_evsel *evsel,
struct perf_sample *sample,
+ struct perf_session *session,
struct symbol **parent,
struct addr_location *root_al,
int max_stack);
diff --git a/tools/perf/util/scripting-engines/trace-event-python.c b/tools/perf/util/scripting-engines/trace-event-python.c
index 802def46af7b..e8c2896055c5 100644
--- a/tools/perf/util/scripting-engines/trace-event-python.c
+++ b/tools/perf/util/scripting-engines/trace-event-python.c
@@ -298,9 +298,10 @@ static PyObject *get_field_numeric_entry(struct event_format *event,
}


-static PyObject *python_process_callchain(struct perf_sample *sample,
- struct perf_evsel *evsel,
- struct addr_location *al)
+static PyObject *python_process_callchain(struct perf_session *session,
+ struct perf_sample *sample,
+ struct perf_evsel *evsel,
+ struct addr_location *al)
{
PyObject *pylist;

@@ -311,9 +312,8 @@ static PyObject *python_process_callchain(struct perf_sample *sample,
if (!symbol_conf.use_callchain || !sample->callchain)
goto exit;

- if (thread__resolve_callchain(al->thread, evsel,
- sample, NULL, NULL,
- PERF_MAX_STACK_DEPTH) != 0) {
+ if (thread__resolve_callchain(al->thread, evsel, sample, session,
+ NULL, NULL, PERF_MAX_STACK_DEPTH) != 0) {
pr_err("Failed to resolve callchain. Skipping\n");
goto exit;
}
@@ -374,7 +374,8 @@ static PyObject *python_process_callchain(struct perf_sample *sample,
}


-static void python_process_tracepoint(struct perf_sample *sample,
+static void python_process_tracepoint(struct perf_session *session,
+ struct perf_sample *sample,
struct perf_evsel *evsel,
struct thread *thread,
struct addr_location *al)
@@ -424,7 +425,7 @@ static void python_process_tracepoint(struct perf_sample *sample,
PyTuple_SetItem(t, n++, context);

/* ip unwinding */
- callchain = python_process_callchain(sample, evsel, al);
+ callchain = python_process_callchain(session, sample, evsel, al);

if (handler) {
PyTuple_SetItem(t, n++, PyInt_FromLong(cpu));
@@ -759,7 +760,8 @@ static int python_process_call_return(struct call_return *cr, void *data)
return db_export__call_return(dbe, cr);
}

-static void python_process_general_event(struct perf_sample *sample,
+static void python_process_general_event(struct perf_session *session,
+ struct perf_sample *sample,
struct perf_evsel *evsel,
struct thread *thread,
struct addr_location *al)
@@ -822,7 +824,7 @@ static void python_process_general_event(struct perf_sample *sample,
}

/* ip unwinding */
- callchain = python_process_callchain(sample, evsel, al);
+ callchain = python_process_callchain(session, sample, evsel, al);
pydict_set_item_string_decref(dict, "callchain", callchain);

PyTuple_SetItem(t, n++, dict);
@@ -846,7 +848,7 @@ static void python_process_event(union perf_event *event,

switch (evsel->attr.type) {
case PERF_TYPE_TRACEPOINT:
- python_process_tracepoint(sample, evsel, thread, al);
+ python_process_tracepoint(session, sample, evsel, thread, al);
break;
/* Reserve for future process_hw/sw/raw APIs */
default:
@@ -854,7 +856,8 @@ static void python_process_event(union perf_event *event,
db_export__sample(&tables->dbe, event, sample, evsel,
thread, al, session);
else
- python_process_general_event(sample, evsel, thread, al);
+ python_process_general_event(session, sample, evsel,
+ thread, al);
}
}

diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c
index 46761a39fbae..d89dfa8592a9 100644
--- a/tools/perf/util/session.c
+++ b/tools/perf/util/session.c
@@ -1550,7 +1550,7 @@ struct perf_evsel *perf_session__find_first_evtype(struct perf_session *session,
}

void perf_evsel__print_ip(struct perf_evsel *evsel, struct perf_sample *sample,
- struct addr_location *al,
+ struct perf_session *session, struct addr_location *al,
unsigned int print_opts, unsigned int stack_depth)
{
struct callchain_cursor_node *node;
@@ -1565,8 +1565,8 @@ void perf_evsel__print_ip(struct perf_evsel *evsel, struct perf_sample *sample,
if (symbol_conf.use_callchain && sample->callchain) {
struct addr_location node_al;

- if (thread__resolve_callchain(al->thread, evsel,
- sample, NULL, NULL,
+ if (thread__resolve_callchain(al->thread, evsel, sample,
+ session, NULL, NULL,
PERF_MAX_STACK_DEPTH) != 0) {
if (verbose)
error("Failed to resolve callchain. Skipping\n");
diff --git a/tools/perf/util/session.h b/tools/perf/util/session.h
index dbd21f8e7cf1..4d264fef8968 100644
--- a/tools/perf/util/session.h
+++ b/tools/perf/util/session.h
@@ -102,7 +102,7 @@ struct perf_evsel *perf_session__find_first_evtype(struct perf_session *session,
unsigned int type);

void perf_evsel__print_ip(struct perf_evsel *evsel, struct perf_sample *sample,
- struct addr_location *al,
+ struct perf_session *session, struct addr_location *al,
unsigned int print_opts, unsigned int stack_depth);

int perf_session__cpu_bitmap(struct perf_session *session,
diff --git a/tools/perf/util/unwind-libdw.c b/tools/perf/util/unwind-libdw.c
index 2dcfe9a7c8d0..ebaf51b58c92 100644
--- a/tools/perf/util/unwind-libdw.c
+++ b/tools/perf/util/unwind-libdw.c
@@ -8,6 +8,7 @@
#include "unwind-libdw.h"
#include "machine.h"
#include "thread.h"
+#include "session.h"
#include <linux/types.h>
#include "event.h"
#include "perf_regs.h"
@@ -26,10 +27,9 @@ static int __report_module(struct addr_location *al, u64 ip,
Dwfl_Module *mod;
struct dso *dso = NULL;

- thread__find_addr_location(ui->thread,
- PERF_RECORD_MISC_USER,
- MAP__FUNCTION, ip, al);
-
+ session__find_addr_location(ui->session, ui->thread,
+ PERF_RECORD_MISC_USER, MAP__FUNCTION,
+ ip, al, ui->sample->time);
if (al->map)
dso = al->map->dso;

@@ -89,8 +89,8 @@ static int access_dso_mem(struct unwind_info *ui, Dwarf_Addr addr,
struct addr_location al;
ssize_t size;

- thread__find_addr_map(ui->thread, PERF_RECORD_MISC_USER,
- MAP__FUNCTION, addr, &al);
+ session__find_addr_map(ui->session, ui->thread, PERF_RECORD_MISC_USER,
+ MAP__FUNCTION, addr, &al, ui->sample->time);
if (!al.map) {
pr_debug("unwind: no map for %lx\n", (unsigned long)addr);
return -1;
@@ -165,12 +165,14 @@ frame_callback(Dwfl_Frame *state, void *arg)

int unwind__get_entries(unwind_entry_cb_t cb, void *arg,
struct thread *thread,
+ struct perf_session *session,
struct perf_sample *data,
int max_stack)
{
struct unwind_info ui = {
.sample = data,
.thread = thread,
+ .session = session,
.machine = thread->mg->machine,
.cb = cb,
.arg = arg,
diff --git a/tools/perf/util/unwind-libdw.h b/tools/perf/util/unwind-libdw.h
index 417a1426f3ad..806e522713a2 100644
--- a/tools/perf/util/unwind-libdw.h
+++ b/tools/perf/util/unwind-libdw.h
@@ -11,6 +11,7 @@ bool libdw__arch_set_initial_registers(Dwfl_Thread *thread, void *arg);
struct unwind_info {
Dwfl *dwfl;
struct perf_sample *sample;
+ struct perf_session *session;
struct machine *machine;
struct thread *thread;
unwind_entry_cb_t cb;
diff --git a/tools/perf/util/unwind-libunwind.c b/tools/perf/util/unwind-libunwind.c
index e3c40a520a25..9ee63179383e 100644
--- a/tools/perf/util/unwind-libunwind.c
+++ b/tools/perf/util/unwind-libunwind.c
@@ -86,6 +86,7 @@ UNW_OBJ(dwarf_find_debug_frame) (int found, unw_dyn_info_t *di_debug,

struct unwind_info {
struct perf_sample *sample;
+ struct perf_session *session;
struct machine *machine;
struct thread *thread;
};
@@ -315,8 +316,8 @@ static struct map *find_map(unw_word_t ip, struct unwind_info *ui)
{
struct addr_location al;

- thread__find_addr_map(ui->thread, PERF_RECORD_MISC_USER,
- MAP__FUNCTION, ip, &al);
+ session__find_addr_map(ui->session, ui->thread, PERF_RECORD_MISC_USER,
+ MAP__FUNCTION, ip, &al, ui->sample->time);
return al.map;
}

@@ -406,20 +407,19 @@ get_proc_name(unw_addr_space_t __maybe_unused as,
static int access_dso_mem(struct unwind_info *ui, unw_word_t addr,
unw_word_t *data)
{
- struct addr_location al;
+ struct map *map;
ssize_t size;

- thread__find_addr_map(ui->thread, PERF_RECORD_MISC_USER,
- MAP__FUNCTION, addr, &al);
- if (!al.map) {
+ map = find_map(addr, ui);
+ if (!map) {
pr_debug("unwind: no map for %lx\n", (unsigned long)addr);
return -1;
}

- if (!al.map->dso)
+ if (!map->dso)
return -1;

- size = dso__data_read_addr(al.map->dso, al.map, ui->machine,
+ size = dso__data_read_addr(map->dso, map, ui->machine,
addr, (u8 *) data, sizeof(*data));

return !(size == sizeof(*data));
@@ -511,14 +511,14 @@ static void put_unwind_info(unw_addr_space_t __maybe_unused as,
pr_debug("unwind: put_unwind_info called\n");
}

-static int entry(u64 ip, struct thread *thread,
- unwind_entry_cb_t cb, void *arg)
+static int entry(u64 ip, struct thread *thread, struct perf_session *session,
+ u64 timestamp, unwind_entry_cb_t cb, void *arg)
{
struct unwind_entry e;
struct addr_location al;

- thread__find_addr_location(thread, PERF_RECORD_MISC_USER,
- MAP__FUNCTION, ip, &al);
+ session__find_addr_location(session, thread, PERF_RECORD_MISC_USER,
+ MAP__FUNCTION, ip, &al, timestamp);

e.ip = ip;
e.map = al.map;
@@ -620,20 +620,22 @@ static int get_entries(struct unwind_info *ui, unwind_entry_cb_t cb,
unw_word_t ip;

unw_get_reg(&c, UNW_REG_IP, &ip);
- ret = ip ? entry(ip, ui->thread, cb, arg) : 0;
+ ret = ip ? entry(ip, ui->thread, ui->session,
+ ui->sample->time, cb, arg) : 0;
}

return ret;
}

int unwind__get_entries(unwind_entry_cb_t cb, void *arg,
- struct thread *thread,
+ struct thread *thread, struct perf_session *session,
struct perf_sample *data, int max_stack)
{
u64 ip;
struct unwind_info ui = {
.sample = data,
.thread = thread,
+ .session = session,
.machine = thread->mg->machine,
};
int ret;
@@ -645,7 +647,7 @@ int unwind__get_entries(unwind_entry_cb_t cb, void *arg,
if (ret)
return ret;

- ret = entry(ip, thread, cb, arg);
+ ret = entry(ip, thread, session, data->time, cb, arg);
if (ret)
return -ENOMEM;

diff --git a/tools/perf/util/unwind.h b/tools/perf/util/unwind.h
index 12790cf94618..c619890e60ad 100644
--- a/tools/perf/util/unwind.h
+++ b/tools/perf/util/unwind.h
@@ -16,7 +16,7 @@ typedef int (*unwind_entry_cb_t)(struct unwind_entry *entry, void *arg);

#ifdef HAVE_DWARF_UNWIND_SUPPORT
int unwind__get_entries(unwind_entry_cb_t cb, void *arg,
- struct thread *thread,
+ struct thread *thread, struct perf_session *session,
struct perf_sample *data, int max_stack);
/* libunwind specific */
#ifdef HAVE_LIBUNWIND_SUPPORT
@@ -38,6 +38,7 @@ static inline int
unwind__get_entries(unwind_entry_cb_t cb __maybe_unused,
void *arg __maybe_unused,
struct thread *thread __maybe_unused,
+ struct perf_session *session __maybe_unused,
struct perf_sample *data __maybe_unused,
int max_stack __maybe_unused)
{
--
2.2.2

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/