[PATCH -tip 6/8] perf-probe: Show symbol+offset for address onlykprobes

From: Masami Hiramatsu
Date: Wed Jan 22 2014 - 21:30:17 EST


Show the symbol+offset information for address only kprobe
events when --list operation without debuginfo. Currently
those events are shown by the address itself. With this change
perf probe finds symbols on those addresses and shows it.

E.g. without this change (when debuginfo is not available);
# ./perf probe -l
probe:t_show (on 0xffffffff810d9720 with m v)
probe:t_show_1 (on 0xffffffff810e2e40 with m v t)
probe:t_show_2 (on 0xffffffff810ece30 with m v fmt)
probe:t_show_3 (on 0xffffffff810f4ad0 with m v file)

With this change;
# ./perf probe -l
probe:t_show (on t_show with m v)
probe:t_show_1 (on t_show with m v t)
probe:t_show_2 (on t_show with m v fmt)
probe:t_show_3 (on t_show with m v file)

Signed-off-by: Masami Hiramatsu <masami.hiramatsu.pt@xxxxxxxxxxx>
---
tools/perf/util/probe-event.c | 35 +++++++++++++++++++++++++++--------
1 file changed, 27 insertions(+), 8 deletions(-)

diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c
index 3470934..bf1d73b 100644
--- a/tools/perf/util/probe-event.c
+++ b/tools/perf/util/probe-event.c
@@ -118,6 +118,7 @@ static void exit_symbol_maps(void)
symbol__exit();
}

+/* Caller must call init_symbol_maps before use this */
static struct symbol *__find_kernel_function_by_name(const char *name,
struct map **mapp)
{
@@ -125,6 +126,12 @@ static struct symbol *__find_kernel_function_by_name(const char *name,
NULL);
}

+/* Caller must call init_symbol_maps before use this */
+static struct symbol *__find_kernel_function(u64 addr, struct map **mapp)
+{
+ return machine__find_kernel_function(host_machine, addr, mapp, NULL);
+}
+
static struct map *kernel_get_module_map(const char *module)
{
struct rb_node *nd;
@@ -222,17 +229,29 @@ static int convert_to_perf_probe_point(struct probe_trace_point *tp,
{
char buf[128];
int ret;
-
- if (tp->symbol) {
+ struct symbol *sym;
+ struct map *map;
+ u64 addr;
+
+ if (!tp->symbol) {
+ sym = __find_kernel_function(tp->address, &map);
+ if (sym) {
+ pp->function = strdup(sym->name);
+ addr = map->unmap_ip(map, sym->start);
+ pp->offset = tp->address - addr;
+ } else {
+ ret = e_snprintf(buf, 128, "0x%" PRIx64,
+ (u64)tp->address);
+ if (ret < 0)
+ return ret;
+ pp->function = strdup(buf);
+ pp->offset = 0;
+ }
+ } else {
pp->function = strdup(tp->symbol);
pp->offset = tp->offset;
- } else {
- ret = e_snprintf(buf, 128, "0x%" PRIx64, (u64)tp->address);
- if (ret < 0)
- return ret;
- pp->function = strdup(buf);
- pp->offset = 0;
}
+
if (pp->function == NULL)
return -ENOMEM;



--
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/