Commit 71ad0f5e authored by Jiri Olsa's avatar Jiri Olsa Committed by Arnaldo Carvalho de Melo

perf tools: Support for DWARF CFI unwinding on post processing

This brings the support for DWARF cfi unwinding on perf post
processing. Call frame informations are retrieved and then passed
to libunwind that requests memory and register content from the
applications.

Adding unwind object to handle the user stack backtrace based
on the user register values and user stack dump.

The unwind object access the libunwind via remote interface
and provides to it all the necessary data to unwind the stack.

The unwind interface provides following function:
	unwind__get_entries

And callback (specified in above function) to retrieve
the backtrace entries:
	typedef int (*unwind_entry_cb_t)(struct unwind_entry *entry,
					 void *arg);
Signed-off-by: default avatarJiri Olsa <jolsa@redhat.com>
Original-patch-by: default avatarFrederic Weisbecker <fweisbec@gmail.com>
Cc: "Frank Ch. Eigler" <fche@redhat.com>
Cc: Arun Sharma <asharma@fb.com>
Cc: Benjamin Redelings <benjamin.redelings@nescent.org>
Cc: Corey Ashford <cjashfor@linux.vnet.ibm.com>
Cc: Cyrill Gorcunov <gorcunov@openvz.org>
Cc: Frank Ch. Eigler <fche@redhat.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Robert Richter <robert.richter@amd.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Tom Zanussi <tzanussi@gmail.com>
Cc: Ulrich Drepper <drepper@gmail.com>
Link: http://lkml.kernel.org/r/1344345647-11536-12-git-send-email-jolsa@redhat.com
[ Replaced use of perf_session by usage of perf_evsel ]
Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 0f6a3015
...@@ -334,6 +334,7 @@ LIB_H += util/target.h ...@@ -334,6 +334,7 @@ LIB_H += util/target.h
LIB_H += util/rblist.h LIB_H += util/rblist.h
LIB_H += util/intlist.h LIB_H += util/intlist.h
LIB_H += util/perf_regs.h LIB_H += util/perf_regs.h
LIB_H += util/unwind.h
LIB_OBJS += $(OUTPUT)util/abspath.o LIB_OBJS += $(OUTPUT)util/abspath.o
LIB_OBJS += $(OUTPUT)util/alias.o LIB_OBJS += $(OUTPUT)util/alias.o
...@@ -547,6 +548,7 @@ else ...@@ -547,6 +548,7 @@ else
EXTLIBS += $(LIBUNWIND_LIBS) EXTLIBS += $(LIBUNWIND_LIBS)
BASIC_CFLAGS := $(LIBUNWIND_CFLAGS) $(BASIC_CFLAGS) BASIC_CFLAGS := $(LIBUNWIND_CFLAGS) $(BASIC_CFLAGS)
BASIC_LDFLAGS := $(LIBUNWIND_LDFLAGS) $(BASIC_LDFLAGS) BASIC_LDFLAGS := $(LIBUNWIND_LDFLAGS) $(BASIC_LDFLAGS)
LIB_OBJS += $(OUTPUT)util/unwind.o
endif endif
ifdef NO_NEWT ifdef NO_NEWT
......
...@@ -2,4 +2,7 @@ ifndef NO_DWARF ...@@ -2,4 +2,7 @@ ifndef NO_DWARF
PERF_HAVE_DWARF_REGS := 1 PERF_HAVE_DWARF_REGS := 1
LIB_OBJS += $(OUTPUT)arch/$(ARCH)/util/dwarf-regs.o LIB_OBJS += $(OUTPUT)arch/$(ARCH)/util/dwarf-regs.o
endif endif
ifndef NO_LIBUNWIND
LIB_OBJS += $(OUTPUT)arch/$(ARCH)/util/unwind.o
endif
LIB_OBJS += $(OUTPUT)arch/$(ARCH)/util/header.o LIB_OBJS += $(OUTPUT)arch/$(ARCH)/util/header.o
#include <errno.h>
#include <libunwind.h>
#include "perf_regs.h"
#include "../../util/unwind.h"
#ifdef ARCH_X86_64
int unwind__arch_reg_id(int regnum)
{
int id;
switch (regnum) {
case UNW_X86_64_RAX:
id = PERF_REG_X86_AX;
break;
case UNW_X86_64_RDX:
id = PERF_REG_X86_DX;
break;
case UNW_X86_64_RCX:
id = PERF_REG_X86_CX;
break;
case UNW_X86_64_RBX:
id = PERF_REG_X86_BX;
break;
case UNW_X86_64_RSI:
id = PERF_REG_X86_SI;
break;
case UNW_X86_64_RDI:
id = PERF_REG_X86_DI;
break;
case UNW_X86_64_RBP:
id = PERF_REG_X86_BP;
break;
case UNW_X86_64_RSP:
id = PERF_REG_X86_SP;
break;
case UNW_X86_64_R8:
id = PERF_REG_X86_R8;
break;
case UNW_X86_64_R9:
id = PERF_REG_X86_R9;
break;
case UNW_X86_64_R10:
id = PERF_REG_X86_R10;
break;
case UNW_X86_64_R11:
id = PERF_REG_X86_R11;
break;
case UNW_X86_64_R12:
id = PERF_REG_X86_R12;
break;
case UNW_X86_64_R13:
id = PERF_REG_X86_R13;
break;
case UNW_X86_64_R14:
id = PERF_REG_X86_R14;
break;
case UNW_X86_64_R15:
id = PERF_REG_X86_R15;
break;
case UNW_X86_64_RIP:
id = PERF_REG_X86_IP;
break;
default:
pr_err("unwind: invalid reg id %d\n", regnum);
return -EINVAL;
}
return id;
}
#else
int unwind__arch_reg_id(int regnum)
{
int id;
switch (regnum) {
case UNW_X86_EAX:
id = PERF_REG_X86_AX;
break;
case UNW_X86_EDX:
id = PERF_REG_X86_DX;
break;
case UNW_X86_ECX:
id = PERF_REG_X86_CX;
break;
case UNW_X86_EBX:
id = PERF_REG_X86_BX;
break;
case UNW_X86_ESI:
id = PERF_REG_X86_SI;
break;
case UNW_X86_EDI:
id = PERF_REG_X86_DI;
break;
case UNW_X86_EBP:
id = PERF_REG_X86_BP;
break;
case UNW_X86_ESP:
id = PERF_REG_X86_SP;
break;
case UNW_X86_EIP:
id = PERF_REG_X86_IP;
break;
default:
pr_err("unwind: invalid reg id %d\n", regnum);
return -EINVAL;
}
return id;
}
#endif /* ARCH_X86_64 */
...@@ -69,8 +69,8 @@ static int perf_report__add_branch_hist_entry(struct perf_tool *tool, ...@@ -69,8 +69,8 @@ static int perf_report__add_branch_hist_entry(struct perf_tool *tool,
if ((sort__has_parent || symbol_conf.use_callchain) if ((sort__has_parent || symbol_conf.use_callchain)
&& sample->callchain) { && sample->callchain) {
err = machine__resolve_callchain(machine, al->thread, err = machine__resolve_callchain(machine, evsel, al->thread,
sample->callchain, &parent); sample, &parent);
if (err) if (err)
return err; return err;
} }
...@@ -140,8 +140,8 @@ static int perf_evsel__add_hist_entry(struct perf_evsel *evsel, ...@@ -140,8 +140,8 @@ static int perf_evsel__add_hist_entry(struct perf_evsel *evsel,
struct hist_entry *he; struct hist_entry *he;
if ((sort__has_parent || symbol_conf.use_callchain) && sample->callchain) { if ((sort__has_parent || symbol_conf.use_callchain) && sample->callchain) {
err = machine__resolve_callchain(machine, al->thread, err = machine__resolve_callchain(machine, evsel, al->thread,
sample->callchain, &parent); sample, &parent);
if (err) if (err)
return err; return err;
} }
...@@ -397,17 +397,17 @@ static int __cmd_report(struct perf_report *rep) ...@@ -397,17 +397,17 @@ static int __cmd_report(struct perf_report *rep)
desc); desc);
} }
if (dump_trace) {
perf_session__fprintf_nr_events(session, stdout);
goto out_delete;
}
if (verbose > 3) if (verbose > 3)
perf_session__fprintf(session, stdout); perf_session__fprintf(session, stdout);
if (verbose > 2) if (verbose > 2)
perf_session__fprintf_dsos(session, stdout); perf_session__fprintf_dsos(session, stdout);
if (dump_trace) {
perf_session__fprintf_nr_events(session, stdout);
goto out_delete;
}
nr_samples = 0; nr_samples = 0;
list_for_each_entry(pos, &session->evlist->entries, node) { list_for_each_entry(pos, &session->evlist->entries, node) {
struct hists *hists = &pos->hists; struct hists *hists = &pos->hists;
......
...@@ -380,7 +380,7 @@ static void print_sample_bts(union perf_event *event, ...@@ -380,7 +380,7 @@ static void print_sample_bts(union perf_event *event,
printf(" "); printf(" ");
else else
printf("\n"); printf("\n");
perf_event__print_ip(event, sample, machine, perf_evsel__print_ip(evsel, event, sample, machine,
PRINT_FIELD(SYM), PRINT_FIELD(DSO), PRINT_FIELD(SYM), PRINT_FIELD(DSO),
PRINT_FIELD(SYMOFFSET)); PRINT_FIELD(SYMOFFSET));
} }
...@@ -422,7 +422,7 @@ static void process_event(union perf_event *event, struct perf_sample *sample, ...@@ -422,7 +422,7 @@ static void process_event(union perf_event *event, struct perf_sample *sample,
printf(" "); printf(" ");
else else
printf("\n"); printf("\n");
perf_event__print_ip(event, sample, machine, perf_evsel__print_ip(evsel, event, sample, machine,
PRINT_FIELD(SYM), PRINT_FIELD(DSO), PRINT_FIELD(SYM), PRINT_FIELD(DSO),
PRINT_FIELD(SYMOFFSET)); PRINT_FIELD(SYMOFFSET));
} }
......
...@@ -783,8 +783,10 @@ static void perf_event__process_sample(struct perf_tool *tool, ...@@ -783,8 +783,10 @@ static void perf_event__process_sample(struct perf_tool *tool,
if ((sort__has_parent || symbol_conf.use_callchain) && if ((sort__has_parent || symbol_conf.use_callchain) &&
sample->callchain) { sample->callchain) {
err = machine__resolve_callchain(machine, al.thread, err = machine__resolve_callchain(machine, evsel,
sample->callchain, &parent); al.thread, sample,
&parent);
if (err) if (err)
return; return;
} }
......
...@@ -10,5 +10,6 @@ ...@@ -10,5 +10,6 @@
#endif #endif
#define __used __attribute__((__unused__)) #define __used __attribute__((__unused__))
#define __packed __attribute__((__packed__))
#endif #endif
...@@ -158,9 +158,12 @@ int machine__init(struct machine *self, const char *root_dir, pid_t pid); ...@@ -158,9 +158,12 @@ int machine__init(struct machine *self, const char *root_dir, pid_t pid);
void machine__exit(struct machine *self); void machine__exit(struct machine *self);
void machine__delete(struct machine *self); void machine__delete(struct machine *self);
struct perf_evsel;
struct perf_sample;
int machine__resolve_callchain(struct machine *machine, int machine__resolve_callchain(struct machine *machine,
struct perf_evsel *evsel,
struct thread *thread, struct thread *thread,
struct ip_callchain *chain, struct perf_sample *sample,
struct symbol **parent); struct symbol **parent);
int maps__set_kallsyms_ref_reloc_sym(struct map **maps, const char *symbol_name, int maps__set_kallsyms_ref_reloc_sym(struct map **maps, const char *symbol_name,
u64 addr); u64 addr);
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#include "cpumap.h" #include "cpumap.h"
#include "event-parse.h" #include "event-parse.h"
#include "perf_regs.h" #include "perf_regs.h"
#include "unwind.h"
static int perf_session__open(struct perf_session *self, bool force) static int perf_session__open(struct perf_session *self, bool force)
{ {
...@@ -289,10 +290,11 @@ struct branch_info *machine__resolve_bstack(struct machine *self, ...@@ -289,10 +290,11 @@ struct branch_info *machine__resolve_bstack(struct machine *self,
return bi; return bi;
} }
int machine__resolve_callchain(struct machine *self, static int machine__resolve_callchain_sample(struct machine *machine,
struct thread *thread, struct thread *thread,
struct ip_callchain *chain, struct ip_callchain *chain,
struct symbol **parent) struct symbol **parent)
{ {
u8 cpumode = PERF_RECORD_MISC_USER; u8 cpumode = PERF_RECORD_MISC_USER;
unsigned int i; unsigned int i;
...@@ -317,11 +319,14 @@ int machine__resolve_callchain(struct machine *self, ...@@ -317,11 +319,14 @@ int machine__resolve_callchain(struct machine *self,
if (ip >= PERF_CONTEXT_MAX) { if (ip >= PERF_CONTEXT_MAX) {
switch (ip) { switch (ip) {
case PERF_CONTEXT_HV: case PERF_CONTEXT_HV:
cpumode = PERF_RECORD_MISC_HYPERVISOR; break; cpumode = PERF_RECORD_MISC_HYPERVISOR;
break;
case PERF_CONTEXT_KERNEL: case PERF_CONTEXT_KERNEL:
cpumode = PERF_RECORD_MISC_KERNEL; break; cpumode = PERF_RECORD_MISC_KERNEL;
break;
case PERF_CONTEXT_USER: case PERF_CONTEXT_USER:
cpumode = PERF_RECORD_MISC_USER; break; cpumode = PERF_RECORD_MISC_USER;
break;
default: default:
pr_debug("invalid callchain context: " pr_debug("invalid callchain context: "
"%"PRId64"\n", (s64) ip); "%"PRId64"\n", (s64) ip);
...@@ -336,7 +341,7 @@ int machine__resolve_callchain(struct machine *self, ...@@ -336,7 +341,7 @@ int machine__resolve_callchain(struct machine *self,
} }
al.filtered = false; al.filtered = false;
thread__find_addr_location(thread, self, cpumode, thread__find_addr_location(thread, machine, cpumode,
MAP__FUNCTION, ip, &al, NULL); MAP__FUNCTION, ip, &al, NULL);
if (al.sym != NULL) { if (al.sym != NULL) {
if (sort__has_parent && !*parent && if (sort__has_parent && !*parent &&
...@@ -355,6 +360,40 @@ int machine__resolve_callchain(struct machine *self, ...@@ -355,6 +360,40 @@ int machine__resolve_callchain(struct machine *self,
return 0; return 0;
} }
static int unwind_entry(struct unwind_entry *entry, void *arg)
{
struct callchain_cursor *cursor = arg;
return callchain_cursor_append(cursor, entry->ip,
entry->map, entry->sym);
}
int machine__resolve_callchain(struct machine *machine,
struct perf_evsel *evsel,
struct thread *thread,
struct perf_sample *sample,
struct symbol **parent)
{
int ret;
callchain_cursor_reset(&callchain_cursor);
ret = machine__resolve_callchain_sample(machine, thread,
sample->callchain, parent);
if (ret)
return ret;
/* Can we do dwarf post unwind? */
if (!((evsel->attr.sample_type & PERF_SAMPLE_REGS_USER) &&
(evsel->attr.sample_type & PERF_SAMPLE_STACK_USER)))
return 0;
return unwind__get_entries(unwind_entry, &callchain_cursor, machine,
thread, evsel->attr.sample_regs_user,
sample);
}
static int process_event_synth_tracing_data_stub(union perf_event *event __used, static int process_event_synth_tracing_data_stub(union perf_event *event __used,
struct perf_session *session __used) struct perf_session *session __used)
{ {
...@@ -1533,9 +1572,9 @@ struct perf_evsel *perf_session__find_first_evtype(struct perf_session *session, ...@@ -1533,9 +1572,9 @@ struct perf_evsel *perf_session__find_first_evtype(struct perf_session *session,
return NULL; return NULL;
} }
void perf_event__print_ip(union perf_event *event, struct perf_sample *sample, void perf_evsel__print_ip(struct perf_evsel *evsel, union perf_event *event,
struct machine *machine, int print_sym, struct perf_sample *sample, struct machine *machine,
int print_dso, int print_symoffset) int print_sym, int print_dso, int print_symoffset)
{ {
struct addr_location al; struct addr_location al;
struct callchain_cursor_node *node; struct callchain_cursor_node *node;
...@@ -1549,8 +1588,9 @@ void perf_event__print_ip(union perf_event *event, struct perf_sample *sample, ...@@ -1549,8 +1588,9 @@ void perf_event__print_ip(union perf_event *event, struct perf_sample *sample,
if (symbol_conf.use_callchain && sample->callchain) { if (symbol_conf.use_callchain && sample->callchain) {
if (machine__resolve_callchain(machine, al.thread,
sample->callchain, NULL) != 0) { if (machine__resolve_callchain(machine, evsel, al.thread,
sample, NULL) != 0) {
if (verbose) if (verbose)
error("Failed to resolve callchain. Skipping\n"); error("Failed to resolve callchain. Skipping\n");
return; return;
......
...@@ -129,9 +129,9 @@ size_t perf_session__fprintf_nr_events(struct perf_session *session, FILE *fp); ...@@ -129,9 +129,9 @@ size_t perf_session__fprintf_nr_events(struct perf_session *session, FILE *fp);
struct perf_evsel *perf_session__find_first_evtype(struct perf_session *session, struct perf_evsel *perf_session__find_first_evtype(struct perf_session *session,
unsigned int type); unsigned int type);
void perf_event__print_ip(union perf_event *event, struct perf_sample *sample, void perf_evsel__print_ip(struct perf_evsel *evsel, union perf_event *event,
struct machine *machine, int print_sym, struct perf_sample *sample, struct machine *machine,
int print_dso, int print_symoffset); int print_sym, int print_dso, int print_symoffset);
int perf_session__cpu_bitmap(struct perf_session *session, int perf_session__cpu_bitmap(struct perf_session *session,
const char *cpu_list, unsigned long *cpu_bitmap); const char *cpu_list, unsigned long *cpu_bitmap);
......
...@@ -77,6 +77,8 @@ void tracing_data_put(struct tracing_data *tdata); ...@@ -77,6 +77,8 @@ void tracing_data_put(struct tracing_data *tdata);
struct addr_location; struct addr_location;
struct perf_session;
struct scripting_ops { struct scripting_ops {
const char *name; const char *name;
int (*start_script) (const char *script, int argc, const char **argv); int (*start_script) (const char *script, int argc, const char **argv);
......
This diff is collapsed.
#ifndef __UNWIND_H
#define __UNWIND_H
#include "types.h"
#include "event.h"
#include "symbol.h"
struct unwind_entry {
struct map *map;
struct symbol *sym;
u64 ip;
};
typedef int (*unwind_entry_cb_t)(struct unwind_entry *entry, void *arg);
#ifndef NO_LIBUNWIND_SUPPORT
int unwind__get_entries(unwind_entry_cb_t cb, void *arg,
struct machine *machine,
struct thread *thread,
u64 sample_uregs,
struct perf_sample *data);
int unwind__arch_reg_id(int regnum);
#else
static inline int
unwind__get_entries(unwind_entry_cb_t cb __used, void *arg __used,
struct machine *machine __used,
struct thread *thread __used,
u64 sample_uregs __used,
struct perf_sample *data __used)
{
return 0;
}
#endif /* NO_LIBUNWIND_SUPPORT */
#endif /* __UNWIND_H */
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