Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1278073

[tip:perf/core] perf callchain: Add order support for libdw DWARF unwinder

From tip-bot for Jiri Olsa <tipbot@zytor.com>
Newsgroups linux.kernel
Subject [tip:perf/core] perf callchain: Add order support for libdw DWARF unwinder
Date 2015-11-26 09:30 +0100
Message-ID <qz06e-2tb-27@gated-at.bofh.it> (permalink)
References <qwx8m-1jR-23@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


Commit-ID:  8bd508b001629a5d836987d9a0702a6bfc4fc705
Gitweb:     http://git.kernel.org/tip/8bd508b001629a5d836987d9a0702a6bfc4fc705
Author:     Jiri Olsa <jolsa@redhat.com>
AuthorDate: Thu, 19 Nov 2015 14:01:19 +0100
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Mon, 23 Nov 2015 18:31:13 -0300

perf callchain: Add order support for libdw DWARF unwinder

As reported by Milian, currently for DWARF unwind (both libdw and
libunwind) we display callchain in callee order only.

Adding the support to follow callchain order setup to libdw DWARF
unwinder, so we could get following output for report:

  $ perf record --call-graph dwarf ls
  ...

  $ perf report --no-children --stdio

    21.12%  ls       libc-2.21.so      [.] __strcoll_l
                 |
                 ---__strcoll_l
                    mpsort_with_tmp
                    mpsort_with_tmp
                    mpsort_with_tmp
                    sort_files
                    main
                    __libc_start_main
                    _start

  $ perf report --stdio --no-children -g caller

    21.12%  ls       libc-2.21.so      [.] __strcoll_l
                 |
                 ---_start
                    __libc_start_main
                    main
                    sort_files
                    mpsort_with_tmp
                    mpsort_with_tmp
                    mpsort_with_tmp
                    __strcoll_l

Reported-and-Tested-by: Milian Wolff <milian.wolff@kdab.com>
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Tested-by: Wang Nan <wangnan0@huawei.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Jan Kratochvil <jkratoch@redhat.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/r/20151119130119.GA26617@krava.brq.redhat.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/util/unwind-libdw.c | 53 ++++++++++++++++++++++++++++++------------
 tools/perf/util/unwind-libdw.h |  2 ++
 2 files changed, 40 insertions(+), 15 deletions(-)

diff --git a/tools/perf/util/unwind-libdw.c b/tools/perf/util/unwind-libdw.c
index 2dcfe9a..db8142b 100644
--- a/tools/perf/util/unwind-libdw.c
+++ b/tools/perf/util/unwind-libdw.c
@@ -11,6 +11,7 @@
 #include <linux/types.h>
 #include "event.h"
 #include "perf_regs.h"
+#include "callchain.h"
 
 static char *debuginfo_path;
 
@@ -52,25 +53,28 @@ static int report_module(u64 ip, struct unwind_info *ui)
 	return __report_module(&al, ip, ui);
 }
 
+/*
+ * Store all entries within entries array,
+ * we will process it after we finish unwind.
+ */
 static int entry(u64 ip, struct unwind_info *ui)
 
 {
-	struct unwind_entry e;
+	struct unwind_entry *e = &ui->entries[ui->idx++];
 	struct addr_location al;
 
 	if (__report_module(&al, ip, ui))
 		return -1;
 
-	e.ip  = ip;
-	e.map = al.map;
-	e.sym = al.sym;
+	e->ip  = ip;
+	e->map = al.map;
+	e->sym = al.sym;
 
 	pr_debug("unwind: %s:ip = 0x%" PRIx64 " (0x%" PRIx64 ")\n",
 		 al.sym ? al.sym->name : "''",
 		 ip,
 		 al.map ? al.map->map_ip(al.map, ip) : (u64) 0);
-
-	return ui->cb(&e, ui->arg);
+	return 0;
 }
 
 static pid_t next_thread(Dwfl *dwfl, void *arg, void **thread_argp)
@@ -168,7 +172,7 @@ int unwind__get_entries(unwind_entry_cb_t cb, void *arg,
 			struct perf_sample *data,
 			int max_stack)
 {
-	struct unwind_info ui = {
+	struct unwind_info *ui, ui_buf = {
 		.sample		= data,
 		.thread		= thread,
 		.machine	= thread->mg->machine,
@@ -177,35 +181,54 @@ int unwind__get_entries(unwind_entry_cb_t cb, void *arg,
 		.max_stack	= max_stack,
 	};
 	Dwarf_Word ip;
-	int err = -EINVAL;
+	int err = -EINVAL, i;
 
 	if (!data->user_regs.regs)
 		return -EINVAL;
 
-	ui.dwfl = dwfl_begin(&offline_callbacks);
-	if (!ui.dwfl)
+	ui = zalloc(sizeof(ui_buf) + sizeof(ui_buf.entries[0]) * max_stack);
+	if (!ui)
+		return -ENOMEM;
+
+	*ui = ui_buf;
+
+	ui->dwfl = dwfl_begin(&offline_callbacks);
+	if (!ui->dwfl)
 		goto out;
 
 	err = perf_reg_value(&ip, &data->user_regs, PERF_REG_IP);
 	if (err)
 		goto out;
 
-	err = report_module(ip, &ui);
+	err = report_module(ip, ui);
 	if (err)
 		goto out;
 
-	if (!dwfl_attach_state(ui.dwfl, EM_NONE, thread->tid, &callbacks, &ui))
+	if (!dwfl_attach_state(ui->dwfl, EM_NONE, thread->tid, &callbacks, ui))
 		goto out;
 
-	err = dwfl_getthread_frames(ui.dwfl, thread->tid, frame_callback, &ui);
+	err = dwfl_getthread_frames(ui->dwfl, thread->tid, frame_callback, ui);
 
-	if (err && !ui.max_stack)
+	if (err && !ui->max_stack)
 		err = 0;
 
+	/*
+	 * Display what we got based on the order setup.
+	 */
+	for (i = 0; i < ui->idx && !err; i++) {
+		int j = i;
+
+		if (callchain_param.order == ORDER_CALLER)
+			j = ui->idx - i - 1;
+
+		err = ui->entries[j].ip ? ui->cb(&ui->entries[j], ui->arg) : 0;
+	}
+
  out:
 	if (err)
 		pr_debug("unwind: failed with '%s'\n", dwfl_errmsg(-1));
 
-	dwfl_end(ui.dwfl);
+	dwfl_end(ui->dwfl);
+	free(ui);
 	return 0;
 }
diff --git a/tools/perf/util/unwind-libdw.h b/tools/perf/util/unwind-libdw.h
index 417a142..5832866 100644
--- a/tools/perf/util/unwind-libdw.h
+++ b/tools/perf/util/unwind-libdw.h
@@ -16,6 +16,8 @@ struct unwind_info {
 	unwind_entry_cb_t	cb;
 	void			*arg;
 	int			max_stack;
+	int			idx;
+	struct unwind_entry	entries[];
 };
 
 #endif /* __PERF_UNWIND_LIBDW_H */
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH 0/3] perf tools DWARF libunwind: Add callchain order support Jiri Olsa <jolsa@kernel.org> - 2015-11-17 16:10 +0100
  [PATCH 3/3] perf test: Add callchain order setup for DWARF unwinder test Jiri Olsa <jolsa@kernel.org> - 2015-11-17 16:10 +0100
    [tip:perf/core] perf test:   Add callchain order setup for DWARF unwinder test tip-bot for Jiri Olsa <tipbot@zytor.com> - 2015-11-26 09:30 +0100
  Re: [PATCH 0/3] perf tools DWARF libunwind: Add callchain order support "Wangnan (F)" <wangnan0@huawei.com> - 2015-11-18 05:30 +0100
  [PATCH 4/3] perf tools: Add callchain order support for libdw DWARF  unwinder Jiri Olsa <jolsa@redhat.com> - 2015-11-19 12:30 +0100
    Re: [PATCH 4/3] perf tools: Add callchain order support for libdw  DWARF unwinder "Wangnan (F)" <wangnan0@huawei.com> - 2015-11-19 13:20 +0100
    Re: [PATCH 4/3] perf tools: Add callchain order support for libdw  DWARF unwinder "Wangnan (F)" <wangnan0@huawei.com> - 2015-11-19 13:20 +0100
      [PATCHv2 4/3] perf tools: Add callchain order support for libdw  DWARF unwinder Jiri Olsa <jolsa@redhat.com> - 2015-11-19 14:10 +0100
        [tip:perf/core] perf callchain:   Add order support for libdw DWARF unwinder tip-bot for Jiri Olsa <tipbot@zytor.com> - 2015-11-26 09:30 +0100
  Re: [PATCH 0/3] perf tools DWARF libunwind: Add callchain order  support Arnaldo Carvalho de Melo <acme@kernel.org> - 2015-11-19 20:20 +0100
    Re: [PATCH 0/3] perf tools DWARF libunwind: Add callchain order  support Jiri Olsa <jolsa@redhat.com> - 2015-11-20 09:40 +0100
    Re: [PATCH 0/3] perf tools DWARF libunwind: Add callchain order support Milian Wolff <milian.wolff@kdab.com> - 2015-11-22 20:20 +0100

csiph-web