public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Akihiro Nagai <akihiro.nagai.hw@hitachi.com>
To: linux-kernel@vger.kernel.org
Cc: Akihiro Nagai <akihiro.nagai.hw@hitachi.com>,
	Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>,
	Peter Zijlstra <peterz@infradead.org>,
	Paul Mackerras <paulus@samba.org>, Ingo Molnar <mingo@elte.hu>,
	Arnaldo Carvalho de Melo <acme@ghostprotocols.net>,
	linux-kernel@vger.kernel.org
Subject: [PATCH -tip  6/7] perf bts trace: print function+offset
Date: Fri, 03 Dec 2010 13:00:15 +0900	[thread overview]
Message-ID: <20101203040015.7827.38870.stgit@localhost6.localdomain6> (raw)
In-Reply-To: <20101203035832.7827.16528.stgit@localhost6.localdomain6>

Provide the function to print function+offset.
And, set it as the default behavior of 'perf bts trace'.
To use this function, users can also specify the option '-s' or '--symbol'.

Example: 'perf bts -as trace'
This command prints address and function+offset.

Output sample:
address            function+offset
0xffffffff8146fe0e irq_return+0x0         => 0x00007fd4038e3b20 _start+0x0
...
0x000000380661ee79 __libc_start_main+0xf9 => 0x00000000004035c3 main+0x0
0xffffffff8146ef4e irq_return+0x0         => 0x00000000004035c3 main+0x0
0x00000000004035e8 main+0x25              => 0x000000000040bca0 set_program_name+0x0
0xffffffff8146ef4e irq_return+0x0         => 0x000000000040bca0 set_program_name+0x0
0x000000000040bcae set_program_name+0xe   => 0x00000000004023d0 strrchr@plt+0x0
0x00000000004023d0 strrchr@plt+0x0        => 0x00000000004023d6 strrchr@plt+0x6
...
0x0000000000403e0c main+0x849             => 0x00000000004021f0 exit@plt+0x0
0x00000000004021f0 exit@plt+0x0           => 0x00000000004021f6 exit@plt+0x6
0x00000000004021fb exit@plt+0xb           => 0x00000000004020d0 _init+0x18
0x00000000004020d6 _init+0x1e             => 0x00000038062149d0 _dl_runtime_resolve+0x0
...

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

 tools/perf/Documentation/perf-bts.txt |    5 +++-
 tools/perf/builtin-bts.c              |   44 ++++++++++++++++++++++++++++++---
 2 files changed, 44 insertions(+), 5 deletions(-)

diff --git a/tools/perf/Documentation/perf-bts.txt b/tools/perf/Documentation/perf-bts.txt
index acabffc..13ee862 100644
--- a/tools/perf/Documentation/perf-bts.txt
+++ b/tools/perf/Documentation/perf-bts.txt
@@ -31,7 +31,7 @@ OPTIONS
         Specify input file name to analyze.
 -a::
 --addr::
-	Print address. (default)
+	Print address.
 -c::
 --comm::
 	Print command name.
@@ -41,6 +41,9 @@ OPTIONS
 -e::
 --elfpath::
 	Print file path of executed elf.
+-s::
+--symbol::
+	Print function name and offset. (default)
 
 SEE ALSO
 --------
diff --git a/tools/perf/builtin-bts.c b/tools/perf/builtin-bts.c
index 3b2a21e..71c7fbe 100644
--- a/tools/perf/builtin-bts.c
+++ b/tools/perf/builtin-bts.c
@@ -21,6 +21,8 @@ struct exec_info {
 	pid_t		pid;		/* tracee process pid */
 	const char	*comm;		/* command name */
 	const char	*elfpath;	/* file path to elf */
+	const char	*function;	/* function name */
+	u64		offset;		/* offset from top of the function */
 };
 
 #define EI_PID_UNSET	-1
@@ -30,9 +32,10 @@ struct exec_info {
 #define EI_FLAG_PRINT_PID		(1 << 1)
 #define EI_FLAG_PRINT_COMM		(1 << 2)
 #define EI_FLAG_PRINT_ELFPATH		(1 << 3)
+#define EI_FLAG_PRINT_SYMBOL		(1 << 4)
 
 /* it's used when no print item specified */
-#define EI_FLAG_PRINT_DEFAULT		EI_FLAG_PRINT_ADDR
+#define EI_FLAG_PRINT_DEFAULT		EI_FLAG_PRINT_SYMBOL
 
 /* print item flags */
 static unsigned long print_flags;
@@ -43,6 +46,9 @@ static unsigned long print_flags;
 #define EI_UNKNOWN_TEXT			"(unknown)"
 #define EI_UNKNOWN_TEXT_LEN		(sizeof(EI_UNKNOWN_TEXT))
 
+/* 'function+offset' lengh = function + '+' + %#18llx + '\0' */
+#define symbol_buf_size(func_name)	(strlen(func_name) + 1 + 18 + 1)
+
 /* default input file name to analyze */
 static const char *input_name = "perf.data";
 
@@ -71,7 +77,7 @@ static int set_print_flags(const struct option *opt, const char *str __unused,
 static const struct option bts_options[] = {
 	OPT_STRING('i', "input", &input_name, "file", "input file name"),
 	OPT_CALLBACK_DEFAULT_NOOPT('a', "addr", NULL, NULL,
-				   "print address (default)", set_print_flags,
+				   "print address", set_print_flags,
 				   (void *)EI_FLAG_PRINT_ADDR),
 	OPT_CALLBACK_DEFAULT_NOOPT('p', "pid", NULL, NULL,
 				   "print pid", set_print_flags,
@@ -82,6 +88,10 @@ static const struct option bts_options[] = {
 	OPT_CALLBACK_DEFAULT_NOOPT('e', "elfpath", NULL, NULL,
 				   "print file path to elf", set_print_flags,
 				   (void *)EI_FLAG_PRINT_ELFPATH),
+	OPT_CALLBACK_DEFAULT_NOOPT('s', "symbol", NULL, NULL,
+				   "print function+offset (default)",
+				   set_print_flags,
+				   (void *)EI_FLAG_PRINT_SYMBOL),
 	OPT_END()
 };
 
@@ -106,7 +116,7 @@ static void fill_exec_info(struct exec_info *ei, struct perf_session *session,
 		return;
 	ei->comm = thread->comm;
 
-	/* get file path to elf */
+	/* get file path to elf, and symbol information */
 	memset(&al, 0, sizeof(al));
 	thread__find_addr_map(thread, session, PERF_RECORD_MISC_USER,
 			      MAP__FUNCTION, event->ip.pid, addr, &al);
@@ -115,8 +125,14 @@ static void fill_exec_info(struct exec_info *ei, struct perf_session *session,
 				      MAP__FUNCTION, event->ip.pid, addr, &al);
 	if (!al.map)
 		return;
-	map__load(al.map, NULL);
+
+	al.addr = al.map->map_ip(al.map, addr);
+	al.sym = map__find_symbol(al.map, al.addr, NULL);
+	if (!al.sym)
+		return;
 	ei->elfpath = al.map->dso->long_name;
+	ei->function = al.sym->name;
+	ei->offset = al.addr - al.sym->start;
 }
 
 static void __print_exec_info(struct exec_info *ei)
@@ -124,6 +140,8 @@ static void __print_exec_info(struct exec_info *ei)
 	char pid[16];
 	const char *comm;
 	const char *elfpath;
+	char *symbol;
+	int symbol_len;
 
 	if (print_flags & EI_FLAG_PRINT_PID) {
 		if (ei->pid == EI_PID_UNSET)
@@ -138,6 +156,22 @@ static void __print_exec_info(struct exec_info *ei)
 	}
 	if (print_flags & EI_FLAG_PRINT_ADDR)
 		printf(FMT_ADDR " ", ei->addr);
+	if (print_flags & EI_FLAG_PRINT_SYMBOL) {
+		if (!ei->function) {
+			/* when function is unknown, offset must be unknown */
+			printf("%-32s ", EI_UNKNOWN_TEXT);
+			goto print_elfpath;
+		}
+
+		symbol_len = symbol_buf_size(ei->function);
+		symbol = malloc(symbol_len);
+		snprintf(symbol, symbol_len, "%s+0x%llx",
+			 ei->function, ei->offset);
+		printf("%-32s ", symbol);
+		free(symbol);
+	}
+
+print_elfpath:
 	if (print_flags & EI_FLAG_PRINT_ELFPATH) {
 		elfpath = ei->elfpath ? : EI_UNKNOWN_TEXT;
 		printf("%-32s ", elfpath);
@@ -160,6 +194,8 @@ static void print_exec_info_header(void)
 		printf("%-12s ", "command");
 	if (print_flags & EI_FLAG_PRINT_ADDR)
 		printf("%-" FMT_ADDR_WIDTH "s ", "address");
+	if (print_flags & EI_FLAG_PRINT_SYMBOL)
+		printf("%-32s ", "function+offset");
 	if (print_flags & EI_FLAG_PRINT_ELFPATH)
 		printf("%-32s ", "elf_filepath");
 	printf("\n");


  parent reply	other threads:[~2010-12-03  4:02 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-12-03  3:58 [PATCH -tip 0/7] perf: Introduce bts sub commands Akihiro Nagai
2010-12-03  3:58 ` [PATCH -tip 1/7] perf: add OPT_CALLBACK_DEFAULT_NOOPT Akihiro Nagai
2010-12-06  2:23   ` Masami Hiramatsu
2010-12-07  6:56   ` [tip:perf/core] perf options: " tip-bot for Akihiro Nagai
2010-12-03  3:59 ` [PATCH -tip 2/7] perf: Introduce perf sub command 'bts record' Akihiro Nagai
2010-12-06  2:26   ` Masami Hiramatsu
2010-12-03  3:59 ` [PATCH -tip 3/7] perf bts: Introduce new sub command 'perf bts trace' Akihiro Nagai
2010-12-06  3:10   ` Masami Hiramatsu
2010-12-03  3:59 ` [PATCH -tip 4/7] perf bts trace: print pid and command Akihiro Nagai
2010-12-06  3:16   ` Masami Hiramatsu
2010-12-03  3:59 ` [PATCH -tip 5/7] perf bts trace: print file path of the executed elf Akihiro Nagai
2010-12-06  3:17   ` Masami Hiramatsu
2010-12-03  4:00 ` Akihiro Nagai [this message]
2010-12-03 13:00   ` [PATCH -tip 6/7] perf bts trace: print function+offset Peter Zijlstra
2010-12-06 10:08     ` Akihiro Nagai
2010-12-06  2:42   ` Frederic Weisbecker
2010-12-06 10:28     ` Akihiro Nagai
2010-12-06  3:20   ` Masami Hiramatsu
2010-12-03  4:00 ` [PATCH -tip 7/7] perf bts trace: add print all option Akihiro Nagai
2010-12-06  3:20   ` Masami Hiramatsu

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=20101203040015.7827.38870.stgit@localhost6.localdomain6 \
    --to=akihiro.nagai.hw@hitachi.com \
    --cc=acme@ghostprotocols.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=masami.hiramatsu.pt@hitachi.com \
    --cc=mingo@elte.hu \
    --cc=paulus@samba.org \
    --cc=peterz@infradead.org \
    /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