mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Akihiro Nagai <akihiro.nagai.hw@hitachi.com>
To: Arnaldo Carvalho de Melo <acme@infradead.org>,
	Ingo Molnar <mingo@elte.hu>,
	Peter Zijlstra <peterz@infradead.org>,
	Frederic Weisbecker <fweisbec@gmail.com>
Cc: linux-kernel@vger.kernel.org,
	Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>,
	pp-manager@sdl.hitachi.co.jp,
	Akihiro Nagai <akihiro.nagai.hw@hitachi.com>,
	Peter Zijlstra <peterz@infradead.org>,
	Frederic Weisbecker <fweisbec@gmail.com>,
	Paul Mackerras <paulus@samba.org>, Ingo Molnar <mingo@elte.hu>,
	Arnaldo Carvalho de Melo <acme@infradead.org>
Subject: [PATCH -tip v4 4/7] perf branch trace: print file path of the executed elf
Date: Thu, 26 May 2011 14:03:22 +0900	[thread overview]
Message-ID: <20110526050322.30011.58833.stgit@localhost6.localdomain6> (raw)
In-Reply-To: <20110526050246.30011.86048.stgit@localhost6.localdomain6>

Provide the function to print file path to the executed elf.
Users can enable it with option '-e' or '--elfpath'.
For example,
    'perf branch -ae trace'
This command prints address and file path of elf.
And, output is:

address            elf_filepath
0xffffffff81458f4e /lib/modules/2.6.39-rc3-tip+/build/vmlinux => 0x0000003806200b20 /lib64/ld-2.12.90.so
0xffffffff81458f4e /lib/modules/2.6.39-rc3-tip+/build/vmlinux => 0x0000003806200b20 /lib64/ld-2.12.90.so
0x0000003806200b23 /lib64/ld-2.12.90.so             => 0x0000003806204910 /lib64/ld-2.12.90.so
0xffffffff81458f4e /lib/modules/2.6.39-rc3-tip+/build/vmlinux => 0x0000003806204910 /lib64/ld-2.12.90.so
0xffffffff81458f4e /lib/modules/2.6.39-rc3-tip+/build/vmlinux => 0x0000003806204936 /lib64/ld-2.12.90.so
0xffffffff81458f4e /lib/modules/2.6.39-rc3-tip+/build/vmlinux => 0x000000380620493d /lib64/ld-2.12.90.so
0x0000003806204981 /lib64/ld-2.12.90.so             => 0x00000038062049a3 /lib64/ld-2.12.90.so
0x00000038062049a7 /lib64/ld-2.12.90.so             => 0x0000003806204988 /lib64/ld-2.12.90.so
...

Changes in V4
 - support output tsv mode

Changes in V3:
 - Update to latest -tip tree

Changes in V2:
 - add comment

Signed-off-by: Akihiro Nagai <akihiro.nagai.hw@hitachi.com>
Reviewed-by: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Arnaldo Carvalho de Melo <acme@infradead.org>
---

 tools/perf/Documentation/perf-branch.txt |    3 +++
 tools/perf/builtin-branch.c              |   32 ++++++++++++++++++++++++++++++
 2 files changed, 35 insertions(+), 0 deletions(-)

diff --git a/tools/perf/Documentation/perf-branch.txt b/tools/perf/Documentation/perf-branch.txt
index f3a4e13..b3e5cf33 100644
--- a/tools/perf/Documentation/perf-branch.txt
+++ b/tools/perf/Documentation/perf-branch.txt
@@ -42,6 +42,9 @@ OPTIONS
 -p::
 --pid::
 	Print pid.
+-e::
+--elfpath::
+	Print file path of executed elf.
 
 SEE ALSO
 --------
diff --git a/tools/perf/builtin-branch.c b/tools/perf/builtin-branch.c
index 6e37c775..0b96461 100644
--- a/tools/perf/builtin-branch.c
+++ b/tools/perf/builtin-branch.c
@@ -22,6 +22,7 @@ struct exec_info {
 	u64		addr;		/* recorded address by bts */
 	pid_t		pid;		/* tracee process pid */
 	const char	*comm;		/* command name */
+	const char	*elfpath;	/* file path to elf */
 };
 
 #define EI_PID_UNSET	-1
@@ -30,6 +31,7 @@ struct exec_info {
 #define EI_FLAG_PRINT_ADDR		(1 << 0)
 #define EI_FLAG_PRINT_PID		(1 << 1)
 #define EI_FLAG_PRINT_COMM		(1 << 2)
+#define EI_FLAG_PRINT_ELFPATH		(1 << 3)
 
 /*
  * It's used when no print item specified.
@@ -99,6 +101,9 @@ static const struct option branch_options[] = {
 	OPT_CALLBACK_DEFAULT_NOOPT('c', "comm", NULL, NULL,
 				   "print command name", set_print_flags,
 				   (void *)EI_FLAG_PRINT_COMM),
+	OPT_CALLBACK_DEFAULT_NOOPT('e', "elfpath", NULL, NULL,
+				   "print file path to elf", set_print_flags,
+				   (void *)EI_FLAG_PRINT_ELFPATH),
 	OPT_END()
 };
 
@@ -134,6 +139,7 @@ static void fill_exec_info(struct exec_info *ei,
 		struct perf_session *session, union perf_event *event, u64 addr)
 {
 	struct thread *thread;
+	struct addr_location al;
 
 	ei->addr = addr;
 	ei->pid = event->ip.pid;
@@ -142,12 +148,26 @@ static void fill_exec_info(struct exec_info *ei,
 	if (!thread)
 		return;
 	ei->comm = thread->comm;
+
+	/* get file path to elf */
+	memset(&al, 0, sizeof(al));
+	thread__find_addr_map(thread, session, PERF_RECORD_MISC_USER,
+			      MAP__FUNCTION, event->ip.pid, addr, &al);
+	if (!al.map)
+		thread__find_addr_map(thread, session, PERF_RECORD_MISC_KERNEL,
+				      MAP__FUNCTION, event->ip.pid, addr, &al);
+	if (!al.map)
+		return;
+	/* resolve vmlinux path */
+	map__load(al.map, NULL);
+	ei->elfpath = al.map->dso->long_name;
 }
 
 static void __print_exec_info(struct exec_info *ei, int ei_print_flags)
 {
 	char pid[16];
 	const char *comm;
+	const char *elfpath;
 
 	if (ei_print_flags & EI_FLAG_PRINT_PID) {
 		if (ei->pid == EI_PID_UNSET)
@@ -162,6 +182,10 @@ static void __print_exec_info(struct exec_info *ei, int ei_print_flags)
 	}
 	if (ei_print_flags & EI_FLAG_PRINT_ADDR)
 		output_item_addr(ei->addr);
+	if (ei_print_flags & EI_FLAG_PRINT_ELFPATH) {
+		elfpath = ei->elfpath ? : EI_UNKNOWN_TEXT;
+		output_item_str("%-32s ", elfpath);
+	}
 }
 
 static void print_exec_info(struct exec_info *ei_from, struct exec_info *ei_to)
@@ -181,6 +205,8 @@ static void print_exec_info_header(void)
 		output_item_str("%-12s ", "command");
 	if (print_flags & EI_FLAG_PRINT_ADDR)
 		output_item_str("%-" FMT_ADDR_WIDTH "s ", "address");
+	if (print_flags & EI_FLAG_PRINT_ELFPATH)
+		output_item_str("%-32s ", "elf_filepath");
 	printf("\n");
 }
 
@@ -208,6 +234,7 @@ static int process_sample_event(union perf_event *event __unused,
 static struct perf_event_ops event_ops = {
 	.sample			= process_sample_event,
 	.comm			= perf_event__process_comm,
+	.mmap			= perf_event__process_mmap,
 	.ordered_samples	= false,
 };
 
@@ -225,6 +252,11 @@ static int __cmd_trace(void)
 	if (is_flags_unset(print_flags & EI_FLAG_REQUIRED))
 		print_flags |= EI_FLAG_PRINT_DEFAULT;
 
+	/* setup kernel maps to resolve vmlinux file path */
+	perf_session__create_kernel_maps(session);
+	if (symbol__init() < 0)
+		fprintf(stderr, "failed to initialize symbol.\n");
+
 	setup_pager();
 	print_exec_info_header();
 	perf_session__process_events(session, &event_ops);


  parent reply	other threads:[~2011-05-26  5:05 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-05-26  5:02 [PATCH -tip v4 0/7] perf: Introduce branch sub commands Akihiro Nagai
2011-05-26  5:03 ` [PATCH -tip v4 1/7] perf: new subcommand perf branch record Akihiro Nagai
2011-05-26  5:03 ` [PATCH -tip v4 2/7] perf branch: Introduce new sub command 'perf branch trace' Akihiro Nagai
2011-05-26  5:03 ` [PATCH -tip v4 3/7] perf branch trace: print pid and command Akihiro Nagai
2011-05-26  5:03 ` Akihiro Nagai [this message]
2011-05-26  5:03 ` [PATCH -tip v4 5/7] perf branch trace: print function+offset Akihiro Nagai
2011-05-26  5:03 ` [PATCH -tip v4 6/7] perf branch trace: add print all option Akihiro Nagai
2011-05-26  5:03 ` [PATCH -tip v4 7/7] perf branch trace: add kernel filter Akihiro Nagai
2011-05-26 13:28 ` [PATCH -tip v4 0/7] perf: Introduce branch sub commands Frederic Weisbecker
2011-05-26 16:24   ` David Ahern
2011-05-30 13:31     ` Akihiro Nagai
2011-05-30 15:26       ` David Ahern
2011-05-30 16:11         ` Frederic Weisbecker
2011-05-30 19:00           ` Arnaldo Carvalho de Melo
2011-06-10  4:24         ` Akihiro Nagai
2011-06-10  7:17   ` Akihiro Nagai

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20110526050322.30011.58833.stgit@localhost6.localdomain6 \
    --to=akihiro.nagai.hw@hitachi.com \
    --cc=acme@infradead.org \
    --cc=fweisbec@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=masami.hiramatsu.pt@hitachi.com \
    --cc=mingo@elte.hu \
    --cc=paulus@samba.org \
    --cc=peterz@infradead.org \
    --cc=pp-manager@sdl.hitachi.co.jp \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome