Skip to contentSkip to conversation

perf: Introduce branch sub commands

PATCH In review Akihiro Nagai 4 participants 16 messages May 26, 2011 – Jun 10, 2011 perf events

lore
Share & tools
lore
#0 lore raw

v4 cover perf: Introduce branch sub commands

Hi,

This patch series provides the commands 'perf branch record' and 'perf branch trace' version 4. These commands record and analyze a BTS (Branch Trace Store) log. And, they provide the interface to use BTS log for application developers.

BTS is a facility of Intel x86 processors, which records the address of 'branch to/from' on every branch/jump instruction and interrupt. This facility is very useful for developers to test their software, for example, coverage test, execution path analysis, dynamic step count ...etc. These test tools have a big advantage, which user doesn't have to modify target executable binaries, because the BTS is a hardware feauture.

But, there are few applications using BTS. Reasons I guess are ...
- Few people know what BTS is.
- Few people know how to use BTS on Linux box.
- It's hard to analyze the BTS log because it includes just a series of addresses.

So, I want to provide a user-friendly interface to BTS for application developers.

About new sub commands
========================
'perf branch record' provides an easy way to record BTS log. Usage is 'perf branch record <command>'. This command is just an alias to 'perf record -e branches:u -c 1 -d <command>'. But, new one is more simple and more intuitive.

'perf branch trace' can parse and analyze recorded BTS log and print various information of execution path. This command can show address, pid, command name, function+offset, file path of elf.
You can choose the printed information with option.

Example: 'perf branch trace'

function+offset

_start+0x3      => _dl_start+0x0
_dl_start+0x71  => _dl_start+0x93
_dl_start+0x97  => _dl_start+0x78
_dl_start+0x97  => _dl_start+0x78
_dl_start+0xa3  => _dl_start+0x3c0

_dl_start+0x3c8 => _dl_start+0x3e8
...

This is the default behavior of 'perf branch trace'. It prints function+offset.

Example2: 'perf branch -cas trace'
command address function+offset

ls      0x0000003e9b000b23 _start+0x3      => 0x0000003e9b004540 _dl_start+0x0
ls      0x0000003e9b0045b1 _dl_start+0x71  => 0x0000003e9b0045d3 _dl_start+0x93
ls      0x0000003e9b0045d7 _dl_start+0x97  => 0x0000003e9b0045b8 _dl_start+0x78
ls      0x0000003e9b0045d7 _dl_start+0x97  => 0x0000003e9b0045b8 _dl_start+0x78
ls      0x0000003e9b0045e3 _dl_start+0xa3  => 0x0000003e9b004900 _dl_start+0x3c0
ls      0x0000003e9b004908 _dl_start+0x3c8 => 0x0000003e9b004928 _dl_start+0x3e8

...

In the future, I'd like to make this more informative. For example
- Show source file path
- Show line number
- Show inlined function name
- Draw call graph
- Browse source code and coloring
- Make BTS record fast
and more!

Changes in V4:
- Add kenel filter
- Print PID and command only once in a line
- Add output TSV mode

Changes in V3:
- Update to the latest -tip tree
- Rename to 'perf branch'
- Process only BTS records
- Fix bug of getting elf_filepath
- Fix return value of __cmd_trace

Changes in V2:
- Update to the latest -tip tree
- Add bts explanation to the subcommand list
- Remove the patch already merged (add OPT_CALLBACK_DEFAULT_NOOPT)
- Add comments
- Add new function to the todo list

Thanks,

---

Akihiro Nagai (7):
perf branch trace: add kernel filter
perf branch trace: add print all option
perf branch trace: print function+offset
perf branch trace: print file path of the executed elf perf branch trace: print pid and command
perf branch: Introduce new sub command 'perf branch trace'
perf: new subcommand perf branch record

 tools/perf/Documentation/perf-branch.txt |   62 +++++
 tools/perf/Makefile                      |    1 
 tools/perf/builtin-branch.c              |  361 ++++++++++++++++++++++++++++++
 tools/perf/builtin.h                     |    1 
 tools/perf/command-list.txt              |    1 
 tools/perf/perf.c                        |    1 
 6 files changed, 427 insertions(+), 0 deletions(-)
 create mode 100644 tools/perf/Documentation/perf-branch.txt
 create mode 100644 tools/perf/builtin-branch.c
Signature · 1 line
Akihiro Nagai ([email protected])
#1 lore raw

PATCH v4 1/7 perf: new subcommand perf branch record

Introduce the easy way to record the bts log, 'perf branch record'. This command records the bts log while the specified command is executing, and save to the file "perf.data"

Usage:
perf branch record <tracee command>

Example:

  # perf branch record ls -l
    (ls -l outputs)
  [ perf record: Woken up 1 times to write data ]
  [ perf record: Captured and wrote 0.007 MB perf.data (~320 samples) ]
  # ls
    perf.data

Changes in V3:
- rename to 'perf branch'

Changes in V2:
- Update to the latest -tip tree
- add bts explanation to the subcommand list

Cc Peter Zijlstra <[email protected]>
Cc Frederic Weisbecker <[email protected]>
Cc Paul Mackerras <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Arnaldo Carvalho de Melo <[email protected]>

---

 tools/perf/Documentation/perf-branch.txt |   25 ++++++++++++
 tools/perf/Makefile                      |    1 
 tools/perf/builtin-branch.c              |   62 ++++++++++++++++++++++++++++++
 tools/perf/builtin.h                     |    1 
 tools/perf/command-list.txt              |    1 
 tools/perf/perf.c                        |    1 
 6 files changed, 91 insertions(+), 0 deletions(-)
 create mode 100644 tools/perf/Documentation/perf-branch.txt
 create mode 100644 tools/perf/builtin-branch.c
tools/perf/Documentation/perf-branch.txt new file +25 -0
new file mode 100644
index 0000000..075cfce
@@ -0,0 +1,25 @@
+perf-branch(1)
+==============
+
+NAME
+----
+perf-branch - Record branch-trace-store log
+
+SYNOPSIS
+--------
+[verse]
+'perf branch' record <command>
+
+DESCRIPTION
+-----------
+This command records a branch-trace-store log.
+Branch-trace-store is a facility of processors. It can record
+addresses of from/to which the execution of a program branches,
+at every branch instruction and interrupt.
+
+'perf branch record <command>' records branch-trace-store log while
+the specified command is executing. And, save to the file "perf.data".
+
+SEE ALSO
+--------
+linkperf:perf-record[1]
tools/perf/Makefile +1 -0
index 1455413..d42b04c 100644
@@ -370,6 +370,7 @@ BUILTIN_OBJS += $(OUTPUT)builtin-lock.o
 BUILTIN_OBJS += $(OUTPUT)builtin-kvm.o
 BUILTIN_OBJS += $(OUTPUT)builtin-test.o
 BUILTIN_OBJS += $(OUTPUT)builtin-inject.o
+BUILTIN_OBJS += $(OUTPUT)builtin-branch.o
 
 PERFLIBS = $(LIB_FILE)
 
tools/perf/builtin-branch.c new file +62 -0

62 lines not on this page · raw message

tools/perf/builtin.h +1 -0
index 4702e24..89fefdc 100644
@@ -36,5 +36,6 @@ extern int cmd_lock(int argc, const char **argv, const char *prefix);
 extern int cmd_kvm(int argc, const char **argv, const char *prefix);
 extern int cmd_test(int argc, const char **argv, const char *prefix);
 extern int cmd_inject(int argc, const char **argv, const char *prefix);
+extern int cmd_branch(int argc, const char **argv, const char *prefix);
 
 #endif
tools/perf/command-list.txt +1 -0
index d695fe4..537f655 100644
@@ -23,3 +23,4 @@ perf-kmem			mainporcelain common
 perf-lock			mainporcelain common
 perf-kvm			mainporcelain common
 perf-test			mainporcelain common
+perf-branch			mainporcelain common
tools/perf/perf.c +1 -0
index ec635b7..cfd9318 100644
@@ -332,6 +332,7 @@ static void handle_internal_command(int argc, const char **argv)
 		{ "kvm",	cmd_kvm,	0 },
 		{ "test",	cmd_test,	0 },
 		{ "inject",	cmd_inject,	0 },
+		{ "branch",	cmd_branch,	0 },
 	};
 	unsigned int i;
 	static const char ext[] = STRIP_EXTENSION;
#2 lore raw

PATCH v4 2/7 perf branch: Introduce new sub command 'perf branch trace'

In reply to Akihiro Nagai

Introduce new sub command 'perf branch trace'. This command parses and prints the bts log recorded by 'perf branch record'.

Usage:
- First, record the bts log 'perf branch record <command>'
- Second, parse and print bts log 'perf branch trace'

Output:
0xffffffff8146fe0e => 0x0000003806200b20
0x0000003806200b23 => 0x0000003806204910
0xffffffff8146fe0e => 0x0000003806204910
0xffffffff8146fe0e => 0x0000003806204936
0xffffffff8146fe0e => 0x000000380620493d
0x0000003806204981 => 0x00000038062049a3
0x00000038062049a7 => 0x0000003806204988
...

Changes in V4:
- Update to the latest -tip tree
- Add output TSV mode

Changes in V3:
- Update to the latest -tip tree
- Rename to 'perf branch'
- Process only BTS record
- Fix return value of __cmd_trace

Changes in V2:
- Update to the latest -tip tree

Cc Peter Zijlstra <[email protected]>
Cc Frederic Weisbecker <[email protected]>
Cc Paul Mackerras <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Arnaldo Carvalho de Melo <[email protected]>

---

 tools/perf/Documentation/perf-branch.txt |   17 +++++-
 tools/perf/builtin-branch.c              |   92 +++++++++++++++++++++++++++++-
 2 files changed, 103 insertions(+), 6 deletions(-)
tools/perf/Documentation/perf-branch.txt +14 -3
index 075cfce..15ee496 100644
@@ -3,16 +3,16 @@ perf-branch(1)
 
 NAME
 ----
-perf-branch - Record branch-trace-store log
+perf-branch - Record and print branch-trace-store log
 
 SYNOPSIS
 --------
 [verse]
-'perf branch' record <command>
+'perf branch' [<options>] {record|trace}
 
 DESCRIPTION
 -----------
-This command records a branch-trace-store log.
+This command records and prints a branch-trace-store log.
 Branch-trace-store is a facility of processors. It can record
 addresses of from/to which the execution of a program branches,
 at every branch instruction and interrupt.
@@ -20,6 +20,17 @@ at every branch instruction and interrupt.
 'perf branch record <command>' records branch-trace-store log while
 the specified command is executing. And, save to the file "perf.data".
 
+'perf branch trace' parses recorded branch-trace-store log and prints it.
+
+OPTIONS
+-------
+-i::
+--input=::
+        Specify input file name to analyze.
+-t::
+--tsv::
+	Output TSV format.
+
 SEE ALSO
 --------
 linkperf:perf-record[1]
tools/perf/builtin-branch.c +89 -3

116 lines not on this page · raw message

#3 lore raw

PATCH v4 3/7 perf branch trace: print pid and command

In reply to Akihiro Nagai

Provide the function to print pid and command name to 'perf branch trace'. Users can select items to print with options. For example,
'perf branch -p trace' prints only pid,
'perf branch -ac trace' prints address and comamnd name. 'perf branch trace' prints only address (default)

This is output sample (perf branch -ac trace):

command      address
ls           0xffffffff8146fe0e => 0x0000003806200b20
ls           0xffffffff8146fe0e => 0x0000003806200b20
ls           0x0000003806200b23 => 0x0000003806204910
ls           0xffffffff8146fe0e => 0x0000003806204910
ls           0xffffffff8146fe0e => 0x0000003806204936
ls           0xffffffff8146fe0e => 0x000000380620493d
ls           0x0000003806204981 => 0x00000038062049a3
ls           0x00000038062049a7 => 0x0000003806204988

Pid and command are never changed between branch_to and branch_from. So perf branch prints them only branch_from field.

Changes in V4
- comm and pid are only printed in branch_from field
- support output tsv mode

Cc Peter Zijlstra <[email protected]>
Cc Frederic Weisbecker <[email protected]>
Cc Paul Mackerras <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Arnaldo Carvalho de Melo <[email protected]>

---

 tools/perf/Documentation/perf-branch.txt |   18 +++-
 tools/perf/builtin-branch.c              |  138 +++++++++++++++++++++++++++++-
 2 files changed, 148 insertions(+), 8 deletions(-)
tools/perf/Documentation/perf-branch.txt +15 -3
index 15ee496..f3a4e13 100644
@@ -3,7 +3,7 @@ perf-branch(1)
 
 NAME
 ----
-perf-branch - Record and print branch-trace-store log
+perf-branch - Record and analyze branch-trace-store log
 
 SYNOPSIS
 --------
@@ -12,7 +12,7 @@ SYNOPSIS
 
 DESCRIPTION
 -----------
-This command records and prints a branch-trace-store log.
+This command records and analyzes a branch-trace-store log.
 Branch-trace-store is a facility of processors. It can record
 addresses of from/to which the execution of a program branches,
 at every branch instruction and interrupt.
@@ -20,7 +20,10 @@ at every branch instruction and interrupt.
 'perf branch record <command>' records branch-trace-store log while
 the specified command is executing. And, save to the file "perf.data".
 
-'perf branch trace' parses recorded branch-trace-store log and prints it.
+'perf branch trace' analyzes recorded branch-trace-store log and prints it.
+The command can select the item to print. For example,
+  'perf branch -a trace'	: prints only address
+  'perf branch -acp trace'	: prints address, command name and pid
 
 OPTIONS
 -------
@@ -30,6 +33,15 @@ OPTIONS
 -t::
 --tsv::
 	Output TSV format.
+-a::
+--addr::
+	Print address. (default)
+-c::
+--comm::
+	Print command name.
+-p::
+--pid::
+	Print pid.
 
 SEE ALSO
 --------
tools/perf/builtin-branch.c +133 -5

186 lines not on this page · raw message

#4 lore raw

PATCH v4 4/7 perf branch trace: print file path of the executed elf

In reply to Akihiro Nagai

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

Cc Peter Zijlstra <[email protected]>
Cc Frederic Weisbecker <[email protected]>
Cc Paul Mackerras <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Arnaldo Carvalho de Melo <[email protected]>

---

 tools/perf/Documentation/perf-branch.txt |    3 +++
 tools/perf/builtin-branch.c              |   32 ++++++++++++++++++++++++++++++
 2 files changed, 35 insertions(+), 0 deletions(-)
tools/perf/Documentation/perf-branch.txt +3 -0
index f3a4e13..b3e5cf33 100644
@@ -42,6 +42,9 @@ OPTIONS
 -p::
 --pid::
 	Print pid.
+-e::
+--elfpath::
+	Print file path of executed elf.
 
 SEE ALSO
 --------
tools/perf/builtin-branch.c +32 -0
index 6e37c775..0b96461 100644
@@ -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);
#5 lore raw

PATCH v4 5/7 perf branch trace: print function+offset

In reply to Akihiro Nagai

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

Example: 'perf branch -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

...

Changes in V4:
- support output tsv mode

Changes in V3:
- rename to 'perf branch'
- fix getting elf_path bug

Cc Peter Zijlstra <[email protected]>
Cc Frederic Weisbecker <[email protected]>
Cc Paul Mackerras <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Arnaldo Carvalho de Melo <[email protected]>

---

 tools/perf/Documentation/perf-branch.txt |    5 +++
 tools/perf/builtin-branch.c              |   45 +++++++++++++++++++++++++++---
 2 files changed, 45 insertions(+), 5 deletions(-)
tools/perf/Documentation/perf-branch.txt +4 -1
index b3e5cf33..9b7b1e1 100644
@@ -35,7 +35,7 @@ OPTIONS
 	Output TSV format.
 -a::
 --addr::
-	Print address. (default)
+	Print address.
 -c::
 --comm::
 	Print command name.
@@ -45,6 +45,9 @@ OPTIONS
 -e::
 --elfpath::
 	Print file path of executed elf.
+-s::
+--symbol::
+	Print function name and offset. (default)
 
 SEE ALSO
 --------
tools/perf/builtin-branch.c +41 -4

112 lines not on this page · raw message

#6 lore raw

PATCH v4 6/7 perf branch trace: add print all option

In reply to Akihiro Nagai

For ease of use, add option printing all information '-A' or '--all'. This option can print following information.
- pid
- command name
- address
- function+offset
- elf file path

Cc Peter Zijlstra <[email protected]>
Cc Frederic Weisbecker <[email protected]>
Cc Paul Mackerras <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Arnaldo Carvalho de Melo <[email protected]>

---

 tools/perf/Documentation/perf-branch.txt |    3 +++
 tools/perf/builtin-branch.c              |    6 ++++++
 2 files changed, 9 insertions(+), 0 deletions(-)
tools/perf/Documentation/perf-branch.txt +3 -0
index 9b7b1e1..a034f12 100644
@@ -48,6 +48,9 @@ OPTIONS
 -s::
 --symbol::
 	Print function name and offset. (default)
+-A::
+--all::
+	Print all information.
 
 SEE ALSO
 --------
tools/perf/builtin-branch.c +6 -0
index 708b056..51cdcd4 100644
@@ -36,6 +36,9 @@ struct exec_info {
 #define EI_FLAG_PRINT_ELFPATH		(1 << 3)
 #define EI_FLAG_PRINT_SYMBOL		(1 << 4)
 
+/* all print flags are enabled */
+#define	 EI_FLAG_PRINT_ALL		-1UL
+
 /*
  * It's used when no print item specified.
  * It must be selected from EI_FLAG_REQUIRED.
@@ -114,6 +117,9 @@ static const struct option branch_options[] = {
 				   "print function+offset (default)",
 				   set_print_flags,
 				   (void *)EI_FLAG_PRINT_SYMBOL),
+	OPT_CALLBACK_DEFAULT_NOOPT('A', "all", NULL, NULL,
+				   "print all items", set_print_flags,
+				   (void *)EI_FLAG_PRINT_ALL),
 	OPT_END()
 };
 
#7 lore raw

PATCH v4 7/7 perf branch trace: add kernel filter

In reply to Akihiro Nagai

This patch introduces filter to eliminate kernel functions from 'perf branch trace' output. 'perf branch record' records 'kernel to user' logs, but it doesn't record 'user to kernel' logs. So users may be surprised at kernel functions which are appeared suddenly.

If you want to see all recorded BTS logs, you can disable this filter with the option '--no-kernel-filter'.
Usage:

 # perf branch --no-kernel-filter trace
Cc Peter Zijlstra <[email protected]>
Cc Frederic Weisbecker <[email protected]>
Cc Paul Mackerras <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Arnaldo Carvalho de Melo <[email protected]>

---

 tools/perf/Documentation/perf-branch.txt |    5 +++++
 tools/perf/builtin-branch.c              |   12 +++++++++++-
 2 files changed, 16 insertions(+), 1 deletions(-)
tools/perf/Documentation/perf-branch.txt +5 -0
index a034f12..9635f22 100644
@@ -51,6 +51,11 @@ OPTIONS
 -A::
 --all::
 	Print all information.
+--no-kernel-filter::
+	Disable kernel filter and print all recorded branch-trace-store logs.
+	The logs recorded by 'perf branch record' include 'kernel to user'
+	logs because of processors' specification. In the default behavior,
+	'perf branch trace' doesn't show it. This option disables this filter.
 
 SEE ALSO
 --------
tools/perf/builtin-branch.c +11 -1
index 51cdcd4..8b49c30 100644
@@ -25,6 +25,7 @@ struct exec_info {
 	const char	*elfpath;	/* file path to elf */
 	const char	*function;	/* function name */
 	u64		offset;		/* offset from top of the function */
+	enum dso_kernel_type kernel;	/* to distingish kernel or user*/
 };
 
 #define EI_PID_UNSET	-1
@@ -60,6 +61,9 @@ static unsigned long print_flags;
 
 #define is_flags_unset(flags)		((flags) == 0)
 
+/* kernel filter is disabled or not */
+static bool no_kernel_filter;
+
 /* print it when we cannnot analyze and get the information */
 #define EI_UNKNOWN_TEXT			"(unknown)"
 #define EI_UNKNOWN_TEXT_LEN		(sizeof(EI_UNKNOWN_TEXT))
@@ -120,6 +124,8 @@ static const struct option branch_options[] = {
 	OPT_CALLBACK_DEFAULT_NOOPT('A', "all", NULL, NULL,
 				   "print all items", set_print_flags,
 				   (void *)EI_FLAG_PRINT_ALL),
+	OPT_BOOLEAN('\0', "no-kernel-filter", &no_kernel_filter,
+		    "disable kernel filter"),
 	OPT_END()
 };
 
@@ -148,6 +154,7 @@ static void init_exec_info(struct exec_info *ei)
 {
 	memset(ei, 0, sizeof(*ei));
 	ei->pid = EI_PID_UNSET;
+	ei->kernel = DSO_TYPE_USER;
 }
 
 /* collect printable items to struct exec_info */
@@ -177,6 +184,7 @@ static void fill_exec_info(struct exec_info *ei,
 	/* resolve vmlinux path */
 	map__load(al.map, NULL);
 	ei->elfpath = al.map->dso->long_name;
+	ei->kernel = al.map->dso->kernel;
 
 	al.addr = al.map->map_ip(al.map, addr);
 	al.sym = map__find_symbol(al.map, al.addr, NULL);
@@ -269,7 +277,9 @@ static int process_sample_event(union perf_event *event __unused,
 	fill_exec_info(&ei_from, session, event, sample->ip);
 	fill_exec_info(&ei_to, session, event, sample->addr);
 
-	print_exec_info(&ei_from, &ei_to);
+	if (no_kernel_filter || (ei_from.kernel == DSO_TYPE_USER &&
+					ei_to.kernel == DSO_TYPE_USER))
+		print_exec_info(&ei_from, &ei_to);
 
 	return 0;
 }
#8 lore raw
In reply to Akihiro Nagai

(Adding David Ahern in Cc)

Ok that's all good except this needs to use the "perf script" centralized dump.

Currently running "perf script" without an actual script dumps the events by default, whatever kind of event they are: hardware, software, tracepoints, ...
So we want the branch output to be supported there, so we can reuse some code and interface.

For example, "perf script -f branch:comm,tid,sym" would print the comm, tid and the sym for to and from addresses.

That's better than creating a new set of options in a new command that people need to relearn while everybody could simply get familiarized with common perf script options.

Of course we can still have a "perf branch" command, which could be a tiny shortcut that maps to perf record and perf script.

Like:

perf branch record
perf branch [trace] -f tid,sym,comm

Would map to:

perf record branch:u
perf script -f branch:tid,sym,comm

And may be if one day we can do something more tricky than a linear output for branches (like source code coloring/browsing), then it may be implemented inside perf branch and not rely on another subcommand. Until then we are only dealing with raw linear dump, and that's a core job for perf script where we want to centralize that kind of facility.

Thanks.

Quoted 113 lines · Akihiro Nagai

Hi,

This patch series provides the commands 'perf branch record' and 'perf branch trace' version 4. These commands record and analyze a BTS (Branch Trace Store) log. And, they provide the interface to use BTS log for application developers.

BTS is a facility of Intel x86 processors, which records the address of 'branch to/from' on every branch/jump instruction and interrupt. This facility is very useful for developers to test their software, for example, coverage test, execution path analysis, dynamic step count ...etc. These test tools have a big advantage, which user doesn't have to modify target executable binaries, because the BTS is a hardware feauture.

But, there are few applications using BTS. Reasons I guess are ...
- Few people know what BTS is.
- Few people know how to use BTS on Linux box.
- It's hard to analyze the BTS log because it includes just a series of addresses.

So, I want to provide a user-friendly interface to BTS for application developers.

About new sub commands
========================
'perf branch record' provides an easy way to record BTS log. Usage is 'perf branch record <command>'. This command is just an alias to 'perf record -e branches:u -c 1 -d <command>'. But, new one is more simple and more intuitive.

'perf branch trace' can parse and analyze recorded BTS log and print various information of execution path. This command can show address, pid, command name, function+offset, file path of elf.
You can choose the printed information with option.

Example: 'perf branch trace'

function+offset

_start+0x3      => _dl_start+0x0
_dl_start+0x71  => _dl_start+0x93
_dl_start+0x97  => _dl_start+0x78
_dl_start+0x97  => _dl_start+0x78
_dl_start+0xa3  => _dl_start+0x3c0

_dl_start+0x3c8 => _dl_start+0x3e8
...

This is the default behavior of 'perf branch trace'. It prints function+offset.

Example2: 'perf branch -cas trace'
command address function+offset

ls      0x0000003e9b000b23 _start+0x3      => 0x0000003e9b004540 _dl_start+0x0
ls      0x0000003e9b0045b1 _dl_start+0x71  => 0x0000003e9b0045d3 _dl_start+0x93
ls      0x0000003e9b0045d7 _dl_start+0x97  => 0x0000003e9b0045b8 _dl_start+0x78
ls      0x0000003e9b0045d7 _dl_start+0x97  => 0x0000003e9b0045b8 _dl_start+0x78
ls      0x0000003e9b0045e3 _dl_start+0xa3  => 0x0000003e9b004900 _dl_start+0x3c0
ls      0x0000003e9b004908 _dl_start+0x3c8 => 0x0000003e9b004928 _dl_start+0x3e8

...

In the future, I'd like to make this more informative. For example
- Show source file path
- Show line number
- Show inlined function name
- Draw call graph
- Browse source code and coloring
- Make BTS record fast
and more!

Changes in V4:
- Add kenel filter
- Print PID and command only once in a line
- Add output TSV mode

Changes in V3:
- Update to the latest -tip tree
- Rename to 'perf branch'
- Process only BTS records
- Fix bug of getting elf_filepath
- Fix return value of __cmd_trace

Changes in V2:
- Update to the latest -tip tree
- Add bts explanation to the subcommand list
- Remove the patch already merged (add OPT_CALLBACK_DEFAULT_NOOPT)
- Add comments
- Add new function to the todo list

Thanks,

---

Akihiro Nagai (7):
perf branch trace: add kernel filter
perf branch trace: add print all option
perf branch trace: print function+offset
perf branch trace: print file path of the executed elf perf branch trace: print pid and command
perf branch: Introduce new sub command 'perf branch trace'
perf: new subcommand perf branch record

 tools/perf/Documentation/perf-branch.txt |   62 +++++
 tools/perf/Makefile                      |    1 
 tools/perf/builtin-branch.c              |  361 ++++++++++++++++++++++++++++++
 tools/perf/builtin.h                     |    1 
 tools/perf/command-list.txt              |    1 
 tools/perf/perf.c                        |    1 
 6 files changed, 427 insertions(+), 0 deletions(-)
 create mode 100644 tools/perf/Documentation/perf-branch.txt
 create mode 100644 tools/perf/builtin-branch.c
Signature · 1 line
Akihiro Nagai ([email protected])
#9 lore raw
Quoted 31 lines · Frederic Weisbecker

(Adding David Ahern in Cc)

Ok that's all good except this needs to use the "perf script" centralized dump.

Currently running "perf script" without an actual script dumps the events by default, whatever kind of event they are: hardware, software, tracepoints, ...
So we want the branch output to be supported there, so we can reuse some code and interface.

For example, "perf script -f branch:comm,tid,sym" would print the comm, tid and the sym for to and from addresses.

That's better than creating a new set of options in a new command that people need to relearn while everybody could simply get familiarized with common perf script options.

Of course we can still have a "perf branch" command, which could be a tiny shortcut that maps to perf record and perf script.

Like:

perf branch record
perf branch [trace] -f tid,sym,comm

Would map to:

perf record branch:u
perf script -f branch:tid,sym,comm

Quoted 6 lines

And may be if one day we can do something more tricky than a linear output for branches (like source code coloring/browsing), then it may be implemented inside perf branch and not rely on another subcommand. Until then we are only dealing with raw linear dump, and that's a core job for perf script where we want to centralize that kind of facility.

I mentioned that when v3 was posted.

The sample address can be converted to symbols and the output can be added to perf-script rather easily. Attached is an example. I was going to submit it back in April and got distracted. I'll rebase, move the addr->sym conversion to a function and submit later today.

David

Quoted 117 lines

Thanks.

Quoted 113 lines · Akihiro Nagai

Hi,

This patch series provides the commands 'perf branch record' and 'perf branch trace' version 4. These commands record and analyze a BTS (Branch Trace Store) log. And, they provide the interface to use BTS log for application developers.

BTS is a facility of Intel x86 processors, which records the address of 'branch to/from' on every branch/jump instruction and interrupt. This facility is very useful for developers to test their software, for example, coverage test, execution path analysis, dynamic step count ...etc. These test tools have a big advantage, which user doesn't have to modify target executable binaries, because the BTS is a hardware feauture.

But, there are few applications using BTS. Reasons I guess are ...
- Few people know what BTS is.
- Few people know how to use BTS on Linux box.
- It's hard to analyze the BTS log because it includes just a series of addresses.

So, I want to provide a user-friendly interface to BTS for application developers.

About new sub commands
========================
'perf branch record' provides an easy way to record BTS log. Usage is 'perf branch record <command>'. This command is just an alias to 'perf record -e branches:u -c 1 -d <command>'. But, new one is more simple and more intuitive.

'perf branch trace' can parse and analyze recorded BTS log and print various information of execution path. This command can show address, pid, command name, function+offset, file path of elf.
You can choose the printed information with option.

Example: 'perf branch trace'

function+offset

_start+0x3      => _dl_start+0x0
_dl_start+0x71  => _dl_start+0x93
_dl_start+0x97  => _dl_start+0x78
_dl_start+0x97  => _dl_start+0x78
_dl_start+0xa3  => _dl_start+0x3c0

_dl_start+0x3c8 => _dl_start+0x3e8
...

This is the default behavior of 'perf branch trace'. It prints function+offset.

Example2: 'perf branch -cas trace'
command address function+offset

ls      0x0000003e9b000b23 _start+0x3      => 0x0000003e9b004540 _dl_start+0x0
ls      0x0000003e9b0045b1 _dl_start+0x71  => 0x0000003e9b0045d3 _dl_start+0x93
ls      0x0000003e9b0045d7 _dl_start+0x97  => 0x0000003e9b0045b8 _dl_start+0x78
ls      0x0000003e9b0045d7 _dl_start+0x97  => 0x0000003e9b0045b8 _dl_start+0x78
ls      0x0000003e9b0045e3 _dl_start+0xa3  => 0x0000003e9b004900 _dl_start+0x3c0
ls      0x0000003e9b004908 _dl_start+0x3c8 => 0x0000003e9b004928 _dl_start+0x3e8

...

In the future, I'd like to make this more informative. For example
- Show source file path
- Show line number
- Show inlined function name
- Draw call graph
- Browse source code and coloring
- Make BTS record fast
and more!

Changes in V4:
- Add kenel filter
- Print PID and command only once in a line
- Add output TSV mode

Changes in V3:
- Update to the latest -tip tree
- Rename to 'perf branch'
- Process only BTS records
- Fix bug of getting elf_filepath
- Fix return value of __cmd_trace

Changes in V2:
- Update to the latest -tip tree
- Add bts explanation to the subcommand list
- Remove the patch already merged (add OPT_CALLBACK_DEFAULT_NOOPT)
- Add comments
- Add new function to the todo list

Thanks,

---

Akihiro Nagai (7):
perf branch trace: add kernel filter
perf branch trace: add print all option
perf branch trace: print function+offset
perf branch trace: print file path of the executed elf perf branch trace: print pid and command
perf branch: Introduce new sub command 'perf branch trace'
perf: new subcommand perf branch record

 tools/perf/Documentation/perf-branch.txt |   62 +++++
 tools/perf/Makefile                      |    1 
 tools/perf/builtin-branch.c              |  361 ++++++++++++++++++++++++++++++
 tools/perf/builtin.h                     |    1 
 tools/perf/command-list.txt              |    1 
 tools/perf/perf.c                        |    1 
 6 files changed, 427 insertions(+), 0 deletions(-)
 create mode 100644 tools/perf/Documentation/perf-branch.txt
 create mode 100644 tools/perf/builtin-branch.c
Signature · 1 line
Akihiro Nagai ([email protected])
tools/perf/builtin-script.c +36 -3
index 6debb9c..55f9967 100644
@@ -32,6 +32,7 @@ enum perf_output_field {
 	PERF_OUTPUT_EVNAME          = 1U << 5,
 	PERF_OUTPUT_TRACE           = 1U << 6,
 	PERF_OUTPUT_SYM             = 1U << 7,
+	PERF_OUTPUT_ADDR            = 1U << 8,
 };
 
 struct output_option {
@@ -46,6 +47,7 @@ struct output_option {
 	{.str = "event", .field = PERF_OUTPUT_EVNAME},
 	{.str = "trace", .field = PERF_OUTPUT_TRACE},
 	{.str = "sym",   .field = PERF_OUTPUT_SYM},
+	{.str = "addr",  .field = PERF_OUTPUT_ADDR},
 };
 
 /* default set to maintain compatibility with current format */
@@ -71,7 +73,8 @@ static struct {
 
 		.fields = PERF_OUTPUT_COMM | PERF_OUTPUT_TID |
 			      PERF_OUTPUT_CPU | PERF_OUTPUT_TIME |
-			      PERF_OUTPUT_EVNAME | PERF_OUTPUT_SYM,
+			      PERF_OUTPUT_EVNAME | PERF_OUTPUT_SYM |
+			      PERF_OUTPUT_ADDR,
 
 		.invalid_fields = PERF_OUTPUT_TRACE,
 	},
@@ -173,6 +176,11 @@ static int perf_evsel__check_attr(struct perf_session *session,
 				       PERF_OUTPUT_CPU))
 		return -EINVAL;
 
+	if (PRINT_FIELD(ADDR) &&
+		perf_attr__check_stype(attr, PERF_SAMPLE_ADDR, "ADDR",
+				       PERF_OUTPUT_ADDR))
+		return -EINVAL;
+
 	return 0;
 }
 
@@ -260,7 +268,7 @@ static void print_sample_start(struct perf_sample *sample,
 	}
 }
 
-static void process_event(union perf_event *event __unused,
+static void process_event(union perf_event *event,
 			  struct perf_sample *sample,
 			  struct perf_evsel *evsel,
 			  struct perf_session *session,
@@ -273,6 +281,31 @@ static void process_event(union perf_event *event __unused,
 
 	print_sample_start(sample, thread, attr);
 
+	if (PRINT_FIELD(ADDR)) {
+		struct addr_location al;
+		u8 cpumode = event->header.misc & PERF_RECORD_MISC_CPUMODE_MASK;
+		const char *symname, *dsoname;
+
+		thread__find_addr_map(thread, session, cpumode, MAP__FUNCTION,
+				      event->ip.pid, sample->addr, &al);
+		if (al.map)
+			al.sym = map__find_symbol(al.map, al.addr, NULL);
+		else
+			al.sym = NULL;
+
+		if (al.sym && al.sym->name)
+			symname = al.sym->name;
+		else
+			symname = "";
+
+		if (al.map && al.map->dso && al.map->dso->name)
+			dsoname = al.map->dso->name;
+		else
+			dsoname = "";
+
+		printf("%16" PRIx64 " %s (%s)", al.addr, symname, dsoname);
+	}
+
 	if (PRINT_FIELD(TRACE))
 		print_trace_event(sample->cpu, sample->raw_data,
 				  sample->raw_size);
@@ -972,7 +1005,7 @@ static const struct option options[] = {
 	OPT_STRING(0, "symfs", &symbol_conf.symfs, "directory",
 		    "Look for files with symbols relative to this directory"),
 	OPT_CALLBACK('f', "fields", NULL, "str",
-		     "comma separated output fields prepend with 'type:'. Valid types: hw,sw,trace. Fields: comm,tid,pid,time,cpu,event,trace,sym",
+		     "comma separated output fields prepend with 'type:'. Valid types: hw,sw,trace. Fields: comm,tid,pid,time,cpu,event,trace,sym,addr",
 		     parse_output_fields),
 
 	OPT_END()
#10 lore raw
Quoted 41 lines · David Ahern
Quoted 31 lines · Frederic Weisbecker

(Adding David Ahern in Cc)

Ok that's all good except this needs to use the "perf script" centralized dump.

Currently running "perf script" without an actual script dumps the events by default, whatever kind of event they are: hardware, software, tracepoints, ...
So we want the branch output to be supported there, so we can reuse some code and interface.

For example, "perf script -f branch:comm,tid,sym" would print the comm, tid and the sym for to and from addresses.

That's better than creating a new set of options in a new command that people need to relearn while everybody could simply get familiarized with common perf script options.

Of course we can still have a "perf branch" command, which could be a tiny shortcut that maps to perf record and perf script.

Like:

perf branch record
perf branch [trace] -f tid,sym,comm

Would map to:

perf record branch:u
perf script -f branch:tid,sym,comm

Quoted 6 lines

And may be if one day we can do something more tricky than a linear output for branches (like source code coloring/browsing), then it may be implemented inside perf branch and not rely on another subcommand. Until then we are only dealing with raw linear dump, and that's a core job for perf script where we want to centralize that kind of facility.

Quoted 6 lines

I mentioned that when v3 was posted.

The sample address can be converted to symbols and the output can be added to perf-script rather easily. Attached is an example. I was going to submit it back in April and got distracted. I'll rebase, move the addr->sym conversion to a function and submit later today.

OK.
I agreed with implementing it on perf script.
I'd like to try it.

Thank you.

Quoted 6 lines

David

Quoted 3 lines

Thanks.

#11 lore raw
Quoted 7 lines · Akihiro Nagai
Quoted 4 lines

The sample address can be converted to symbols and the output can be added to perf-script rather easily. Attached is an example. I was going to submit it back in April and got distracted. I'll rebase, move the addr->sym conversion to a function and submit later today.

OK.
I agreed with implementing it on perf script.
I'd like to try it.

Updated patch. It applies on top of:
http://lkml.org/lkml/2011/5/27/385

Hopefully for BTS you only have to change the sample_addr_correlates_sym function.

I still need to look into out why some of the addresses for page-faults are not resolving to symbols.

David

tools/perf/Documentation/perf-script.txt +2 -2
index 1e744c2..c6068cb 100644
@@ -115,8 +115,8 @@ OPTIONS
 -f::
 --fields::
         Comma separated list of fields to print. Options are:
-        comm, tid, pid, time, cpu, event, trace, ip, sym, dso. Field
-        list can be prepended with the type, trace, sw or hw,
+        comm, tid, pid, time, cpu, event, trace, ip, sym, dso, addr.
+        Field list can be prepended with the type, trace, sw or hw,
         to indicate to which event type the field list applies.
         e.g., -f sw:comm,tid,time,ip,sym  and -f trace:time,cpu,trace
 
tools/perf/builtin-script.c +73 -7

118 lines not on this page · raw message

tools/perf/util/evsel.c +1 -0
index cca29ed..669e18a 100644
@@ -361,6 +361,7 @@ int perf_event__parse_sample(const union perf_event *event, u64 type,
 		array++;
 	}
 
+	data->addr = 0;
 	if (type & PERF_SAMPLE_ADDR) {
 		data->addr = *array;
 		array++;
tools/perf/util/session.c +2 -2
index 360d8c4..21e6c91 100644
@@ -698,9 +698,9 @@ static void dump_sample(struct perf_session *session, union perf_event *event,
 	if (!dump_trace)
 		return;
 
-	printf("(IP, %d): %d/%d: %#" PRIx64 " period: %" PRIu64 "\n",
+	printf("(IP, %d): %d/%d: %#" PRIx64 " period: %" PRIu64 " addr: %#" PRIx64 "\n",
 	       event->header.misc, sample->pid, sample->tid, sample->ip,
-	       sample->period);
+	       sample->period, sample->addr);
 
 	if (session->sample_type & PERF_SAMPLE_CALLCHAIN)
 		callchain__printf(sample);
#12 lore raw
Quoted 9 lines · David Ahern
Quoted 7 lines · Akihiro Nagai
Quoted 4 lines

The sample address can be converted to symbols and the output can be added to perf-script rather easily. Attached is an example. I was going to submit it back in April and got distracted. I'll rebase, move the addr->sym conversion to a function and submit later today.

OK.
I agreed with implementing it on perf script.
I'd like to try it.

Quoted 8 lines

Updated patch. It applies on top of:
http://lkml.org/lkml/2011/5/27/385

Hopefully for BTS you only have to change the sample_addr_correlates_sym function.

I still need to look into out why some of the addresses for page-faults are not resolving to symbols.

Perhaps it only resolves instruction faults because you only resolve with MAP__FUNCTION. You can try MAP__VARIABLE as well when that fails.

But that is going to only help with faults on global vars, ie: only a few part of them. Further information would require some dwarf processing.

Your patch looks good though. Mind resending it with appropriate title/changelog and signed-off-by tag?

thanks.

#13 lore raw

Em Mon, May 30, 2011 at 06:11:49PM +0200, Frederic Weisbecker escreveu:

Quoted 19 lines · David Ahern
Quoted 9 lines · Akihiro Nagai
Quoted 7 lines
Quoted 4 lines

The sample address can be converted to symbols and the output can be added to perf-script rather easily. Attached is an example. I was going to submit it back in April and got distracted. I'll rebase, move the addr->sym conversion to a function and submit later today.

OK.
I agreed with implementing it on perf script.
I'd like to try it.

Quoted 8 lines

Updated patch. It applies on top of:
http://lkml.org/lkml/2011/5/27/385

Hopefully for BTS you only have to change the sample_addr_correlates_sym function.

I still need to look into out why some of the addresses for page-faults are not resolving to symbols.

Quoted 8 lines

Perhaps it only resolves instruction faults because you only resolve with MAP__FUNCTION. You can try MAP__VARIABLE as well when that fails.

But that is going to only help with faults on global vars, ie: only a few part of them. Further information would require some dwarf processing.

Your patch looks good though. Mind resending it with appropriate title/changelog and signed-off-by tag?

Just for reference: I thought about removing this split but David Miller told me that there are architectures where we can't do that, i.e. there is no guarantee of an unified addr space for variables and code, such as SPARC.

- Arnaldo

#14 lore raw
In reply to David Ahern
Quoted 11 lines · David Ahern
Quoted 7 lines · Akihiro Nagai
Quoted 4 lines

The sample address can be converted to symbols and the output can be added to perf-script rather easily. Attached is an example. I was going to submit it back in April and got distracted. I'll rebase, move the addr->sym conversion to a function and submit later today.

OK.
I agreed with implementing it on perf script.
I'd like to try it.

Updated patch. It applies on top of:

   http://lkml.org/lkml/2011/5/27/385

It looks good.

Quoted 3 lines

Hopefully for BTS you only have to change the sample_addr_correlates_sym function.

Yes.
I'd like to enhance perf-script like this:

# perf script -f ip,addr,comm,sym,dso

output format is:
<comm> <ip> <sym_ip> <dso_ip> <addr> <sym_addr> <dso_addr>

actual output sample is:
ls 0xffffffff81460b92 common_interrupt /lib/modules/3.0/build/vmlinux 0x0000003e9b000b20 _start /lib64/ld-2.13.so ls 0x0000003e9b000b23 _start /lib64/ld-2.13.so 0x0000003e9b004540 _dl_start /lib64/ld-2.13.so
...

By specifying 'ip' and 'addr' together, perf-script resolves symbol and dso's path about both of 'ip' and 'addr'.

Quoted 3 lines

I still need to look into out why some of the addresses for page-faults are not resolving to symbols.

I'd like to improve it referring perf branch's source codes.

Thank you.

Quoted 2 lines

David

#15 lore raw
In reply to Frederic Weisbecker
Quoted 31 lines · Frederic Weisbecker

(Adding David Ahern in Cc)

Ok that's all good except this needs to use the "perf script" centralized dump.

Currently running "perf script" without an actual script dumps the events by default, whatever kind of event they are: hardware, software, tracepoints, ...
So we want the branch output to be supported there, so we can reuse some code and interface.

For example, "perf script -f branch:comm,tid,sym" would print the comm, tid and the sym for to and from addresses.

That's better than creating a new set of options in a new command that people need to relearn while everybody could simply get familiarized with common perf script options.

Of course we can still have a "perf branch" command, which could be a tiny shortcut that maps to perf record and perf script.

Like:

perf branch record
perf branch [trace] -f tid,sym,comm

Would map to:

perf record branch:u
perf script -f branch:tid,sym,comm

Quoted 6 lines

And may be if one day we can do something more tricky than a linear output for branches (like source code coloring/browsing), then it may be implemented inside perf branch and not rely on another subcommand. Until then we are only dealing with raw linear dump, and that's a core job for perf script where we want to centralize that kind of facility.

OK.
I agreed that the core job is dumpimg BTS logs on perf script.

Next, I'd like to implement the perf-branch's functions and additional interfaces to perf script.
For example, resoving symbols and dso about branch_to address and, adding interfaces to get source file path, line number using debuginfo.

I presented about perf-branch's future plan in LinuxCon Japan 2011, please refer the follwing slide.
http://events.linuxfoundation.org/events/linuxcon-japan/nagai
(The slide will be available soon)

Thank you.

Quoted 3 lines

Thanks.