Skip to contentSkip to conversation

perf script: add BTS analysis features

PATCH Superseded Akihiro Nagai 4 participants 22 messages Jul 17, 2011 – Jul 22, 2011 perf events

v2 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

v2 cover perf script: add BTS analysis features

Hi Frederic, David,

This patch series adds the functions to analyze BTS logs to perf-script and, makes perf-script more informative version 2.
The patches add the following functions.
- Output correct IP address
- Output "(unknown)" as symbol name when perf-script can't resolve symbols.
- Output "[unknown]" as DSO name when perf-script can't resolve DSO path.
- Resolve DSOs and symbols for user-space address
- Resolve DSOs and symbols for BTS's branch_from addresses
- Show the offset of symbols with the 'offs' field specifier.
- Resolve the real path of [kernel.kallsym] using '--show-kernel-path' option.

Usage:
First, get the BTS log with the following command.

# perf record -e branches:u -c 1 -d <command>

Second, analyze that trace data.

# perf script -f ip,addr,sym,offs,dso [--show-kernel-path]
This command's output format is:
<branch_to addr> <branch_to function+offset> <branch_to DSO> <branch_from addr> <branch_from function+offset> <branch_from DSO>

Output sample:

# perf record -e branches:u -c 1 -d ls
[snip]
# perf script -f ip,addr,sym,dso,offs --show-kernel-path

301ec016b0 (unknown) (/lib/modules/3.0.0-rc6-tip+/build/vmlinux) ffffffff81467612 irq_return+0x0 (/lib/modules/3.0.0-rc6-tip+/build/vmlinux)
301ec016b0 _start+0x0 (/lib64/ld-2.14.so) ffffffff81467612 irq_return+0x0 (/lib/modules/3.0.0-rc6-tip+/build/vmlinux)
301ec04b70 _dl_start+0x0 (/lib64/ld-2.14.so) 301ec016b3 _start+0x3 (/lib64/ld-2.14.so)
301ec04b70 _dl_start+0x0 (/lib64/ld-2.14.so) ffffffff81467612 irq_return+0x0 (/lib/modules/3.0.0-rc6-tip+/build/vmlinux) 301ec04b96 _dl_start+0x26 (/lib64/ld-2.14.so) ffffffff81467612 irq_return+0x0 (/lib/modules/3.0.0-rc6-tip+/build/vmlinux) 301ec04b9d _dl_start+0x2d (/lib64/ld-2.14.so) ffffffff81467612 irq_return+0x0 (/lib/modules/3.0.0-rc6-tip+/build/vmlinux)
301ec04c0d _dl_start+0x9d (/lib64/ld-2.14.so) 301ec04beb _dl_start+0x7b (/lib64/ld-2.14.so)
[snip]
401fd0 main+0x0 (/root/bin/ls) 301f021399 __libc_start_main+0xe9 (/lib64/libc-2.14.so)
409ad0 set_program_name+0x0 (/root/bin/ls) 401ff3 main+0x23 (/root/bin/ls)
409ad0 set_program_name+0x0 (/root/bin/ls) ffffffff81467612 irq_return+0x0 (/lib/modules/3.0.0-rc6-tip+/build/vmlinux)

401ca8          strrchr@plt+0x0 (/root/bin/ls)           409ade set_program_name+0xe (/root/bin/ls)
401cae          strrchr@plt+0x6 (/root/bin/ls)           401ca8 strrchr@plt+0x0 (/root/bin/ls)
401a38               _init+0x18 (/root/bin/ls)           401cb3 strrchr@plt+0xb (/root/bin/ls)
301ec13840 _dl_runtime_resolve+0x0 (/lib64/ld-2.14.so)   401a3e _init+0x1e (/root/bin/ls)

301ec0d6a0 _dl_fixup+0x0 (/lib64/ld-2.14.so) 301ec13870 _dl_runtime_resolve+0x30 (/lib64/ld-2.14.so)
[snip]

It shows the tracee application's execution path.

TODO:
- add source code path field, line number field ...etc.
- add record/report script to use easily and, show human-friendly output.
- filtering kernel functions using scripts

Changes in v2:
- add a bug fix patch that prints correct IP address
- output the magic word "(unknown)" as symbol name when perf-script can't resolve symbols.
- output "[unknown]" as DSO name when perf-script can't resolve DSO path.
- change the way to output offset of symbols from '--show-symbol-offset' to 'offs' field.
- clean up codes.

Thanks,

---

Akihiro Nagai (6):
perf script: add option resolving vmlinux path
perf script: add the offset field specifier
perf script: print DSOs and symbols for BTS branch_from addr perf script: resolve DSOs and symbols for user-space
perf script: add magic word to indicate the failure of resolving symbols [BUGFIX] perf script: print correct IP address

 tools/perf/Documentation/perf-script.txt |    5 +++
 tools/perf/builtin-script.c              |   46 +++++++++++++++++++++---------
 tools/perf/util/event.c                  |    5 +++
 tools/perf/util/map.c                    |   15 ++++++++++
 tools/perf/util/map.h                    |    1 +
 tools/perf/util/session.c                |   42 ++++++++++-----------------
 tools/perf/util/session.h                |    3 +-
 tools/perf/util/symbol.c                 |   21 ++++++++++++++
 tools/perf/util/symbol.h                 |    4 +++
 9 files changed, 100 insertions(+), 42 deletions(-)
Signature · 1 line
Akihiro Nagai ([email protected])
#1 lore raw

PATCH v2 1/6 perf script: print correct IP address

perf_session_print_ip() prints addr_location->addr as IP address. It's not always same as IP address. To correct it, this function must print sample->ip.

Changes in v2:
- add this patch

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]>
Cc David Ahern <[email protected]>
Cc Masami Hiramatsu <[email protected]>

---

 tools/perf/util/session.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
tools/perf/util/session.c +1 -1
index 080e533..453a010 100644
@@ -1263,7 +1263,7 @@ void perf_session__print_ip(union perf_event *event,
 		}
 
 	} else {
-		printf("%16" PRIx64, al.addr);
+		printf("%16" PRIx64, sample->ip);
 		if (print_sym) {
 			if (al.sym && al.sym->name)
 				symname = al.sym->name;
#2 lore raw

Re: [PATCH -tip v2 1/6] [BUGFIX] perf script: print correct IP address

Quoted 6 lines · Akihiro Nagai

perf_session_print_ip() prints addr_location->addr as IP address. It's not always same as IP address. To correct it, this function must print sample->ip.

Changes in v2:
- add this patch

I submitted a patch for this back in May that was not picked up:
https://lkml.org/lkml/2011/5/30/223

David

Quoted 28 lines
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]>
Cc David Ahern <[email protected]>
Cc Masami Hiramatsu <[email protected]>

---

 tools/perf/util/session.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
tools/perf/util/session.c +1 -1
index 080e533..453a010 100644
@@ -1263,7 +1263,7 @@ void perf_session__print_ip(union perf_event *event,
 		}
 
 	} else {
-		printf("%16" PRIx64, al.addr);
+		printf("%16" PRIx64, sample->ip);
 		if (print_sym) {
 			if (al.sym && al.sym->name)
 				symname = al.sym->name;
#3 lore raw

Re: [PATCH -tip v2 1/6] [BUGFIX] perf script: print correct IP address

Quoted 5 lines · David Ahern
Quoted 4 lines · Akihiro Nagai

perf_session_print_ip() prints addr_location->addr as IP address. It's not always same as IP address. To correct it, this function must print sample->ip.

Quoted 7 lines
Quoted 2 lines

Changes in v2:
- add this patch

I submitted a patch for this back in May that was not picked up:
https://lkml.org/lkml/2011/5/30/223

David

Oops, I'm going to bounce it to Peter / Ingo / Arnaldo...

#4 lore raw

PATCH v2 2/6 perf script: add magic word to indicate the failure of resolving symbols

In reply to Akihiro Nagai

Latest perf-script doesn't output symbol name when it failed to resolve symbol name. This output is not friendly for external scripts because it causes misaligment. So, this patch adds the magic word "(unknown)" when perf-script failed to resolve symbols.

At the same time, this patch changes perf-script to output "[unknown]" in the DSO field, when it failed to resolve the path of DSOs.

Changes in v2:
- add this patch

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]>
Cc David Ahern <[email protected]>
Cc Masami Hiramatsu <[email protected]>

---

 tools/perf/builtin-script.c |   18 +++++-------------
 tools/perf/util/map.c       |   12 ++++++++++++
 tools/perf/util/map.h       |    1 +
 tools/perf/util/session.c   |   35 ++++++++++-------------------------
 tools/perf/util/symbol.c    |   12 ++++++++++++
 tools/perf/util/symbol.h    |    1 +
 6 files changed, 41 insertions(+), 38 deletions(-)
tools/perf/builtin-script.c +5 -13
index 09024ec..b3e0951 100644
@@ -320,7 +320,6 @@ static void print_sample_addr(union perf_event *event,
 {
 	struct addr_location al;
 	u8 cpumode = event->header.misc & PERF_RECORD_MISC_CPUMODE_MASK;
-	const char *symname, *dsoname;
 
 	printf("%16" PRIx64, sample->addr);
 
@@ -340,21 +339,14 @@ static void print_sample_addr(union perf_event *event,
 		al.sym = map__find_symbol(al.map, al.addr, NULL);
 
 	if (PRINT_FIELD(SYM)) {
-		if (al.sym && al.sym->name)
-			symname = al.sym->name;
-		else
-			symname = "";
-
-		printf(" %16s", symname);
+		printf(" ");
+		symbol__print_symname(al.sym);
 	}
 
 	if (PRINT_FIELD(DSO)) {
-		if (al.map && al.map->dso && al.map->dso->name)
-			dsoname = al.map->dso->name;
-		else
-			dsoname = "";
-
-		printf(" (%s)", dsoname);
+		printf(" (");
+		map__print_dsoname(al.map);
+		printf(")");
 	}
 }
 
tools/perf/util/map.c +12 -0
index a16ecab..dddc0f3 100644
@@ -200,6 +200,18 @@ size_t map__fprintf(struct map *self, FILE *fp)
 		       self->start, self->end, self->pgoff, self->dso->name);
 }
 
+void map__print_dsoname(struct map *self)
+{
+	const char *dsoname;
+
+	if (self && self->dso && self->dso->name)
+			dsoname = self->dso->name;
+	else
+		dsoname = "[unknown]";
+
+	printf("%s", dsoname);
+}
+
 /*
  * objdump wants/reports absolute IPs for ET_EXEC, and RIPs for ET_DYN.
  * map->dso->adjust_symbols==1 for ET_EXEC-like cases.
tools/perf/util/map.h +1 -0
index b397c03..6f452b9 100644
@@ -112,6 +112,7 @@ void map__delete(struct map *self);
 struct map *map__clone(struct map *self);
 int map__overlap(struct map *l, struct map *r);
 size_t map__fprintf(struct map *self, FILE *fp);
+void map__print_dsoname(struct map *self);
 
 int map__load(struct map *self, symbol_filter_t filter);
 struct symbol *map__find_symbol(struct map *self,
tools/perf/util/session.c +10 -25
index 453a010..442be3a 100644
@@ -1214,7 +1214,6 @@ void perf_session__print_ip(union perf_event *event,
 			    int print_sym, int print_dso)
 {
 	struct addr_location al;
-	const char *symname, *dsoname;
 	struct callchain_cursor *cursor = &session->callchain_cursor;
 	struct callchain_cursor_node *node;
 
@@ -1242,20 +1241,13 @@ void perf_session__print_ip(union perf_event *event,
 
 			printf("\t%16" PRIx64, node->ip);
 			if (print_sym) {
-				if (node->sym && node->sym->name)
-					symname = node->sym->name;
-				else
-					symname = "";
-
-				printf(" %s", symname);
+				printf(" ");
+				symbol__print_symname(node->sym);
 			}
 			if (print_dso) {
-				if (node->map && node->map->dso && node->map->dso->name)
-					dsoname = node->map->dso->name;
-				else
-					dsoname = "";
-
-				printf(" (%s)", dsoname);
+				printf(" (");
+				map__print_dsoname(al.map);
+				printf(")");
 			}
 			printf("\n");
 
@@ -1265,21 +1257,14 @@ void perf_session__print_ip(union perf_event *event,
 	} else {
 		printf("%16" PRIx64, sample->ip);
 		if (print_sym) {
-			if (al.sym && al.sym->name)
-				symname = al.sym->name;
-			else
-				symname = "";
-
-			printf(" %s", symname);
+			printf(" ");
+			symbol__print_symname(al.sym);
 		}
 
 		if (print_dso) {
-			if (al.map && al.map->dso && al.map->dso->name)
-				dsoname = al.map->dso->name;
-			else
-				dsoname = "";
-
-			printf(" (%s)", dsoname);
+			printf(" (");
+			map__print_dsoname(al.map);
+			printf(")");
 		}
 	}
 }
tools/perf/util/symbol.c +12 -0
index eec1963..85e19c4 100644
@@ -175,6 +175,18 @@ static size_t symbol__fprintf(struct symbol *sym, FILE *fp)
 		       sym->name);
 }
 
+void symbol__print_symname(const struct symbol *sym)
+{
+	const char *symname;
+
+	if (sym && sym->name)
+		symname = sym->name;
+	else
+		symname = "(unknown)";
+
+	printf("%s", symname);
+}
+
 void dso__set_long_name(struct dso *dso, char *name)
 {
 	if (name == NULL)
tools/perf/util/symbol.h +1 -0
index 325ee36..1ec17b4 100644
@@ -238,6 +238,7 @@ void machines__destroy_guest_kernel_maps(struct rb_root *machines);
 
 int symbol__init(void);
 void symbol__exit(void);
+void symbol__print_symname(const struct symbol *sym);
 bool symbol_type__is_a(char symbol_type, enum map_type map_type);
 
 size_t machine__fprintf_vmlinux_path(struct machine *machine, FILE *fp);
Acked-by on v2 2/6
#5 lore raw

Re: [PATCH -tip v2 2/6] perf script: add magic word to indicate the failure of resolving symbols

Quoted 4 lines · Akihiro Nagai

Latest perf-script doesn't output symbol name when it failed to resolve symbol name. This output is not friendly for external scripts because it causes misaligment. So, this patch adds the magic word "(unknown)" when perf-script failed to resolve symbols.

Code has [unknown] with {}, not ().

Quoted 69 lines

At the same time, this patch changes perf-script to output "[unknown]" in the DSO field, when it failed to resolve the path of DSOs.

Changes in v2:
- add this patch

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]>
Cc David Ahern <[email protected]>
Cc Masami Hiramatsu <[email protected]>

---

 tools/perf/builtin-script.c |   18 +++++-------------
 tools/perf/util/map.c       |   12 ++++++++++++
 tools/perf/util/map.h       |    1 +
 tools/perf/util/session.c   |   35 ++++++++++-------------------------
 tools/perf/util/symbol.c    |   12 ++++++++++++
 tools/perf/util/symbol.h    |    1 +
 6 files changed, 41 insertions(+), 38 deletions(-)
tools/perf/builtin-script.c +5 -13
index 09024ec..b3e0951 100644
@@ -320,7 +320,6 @@ static void print_sample_addr(union perf_event *event,
 {
 	struct addr_location al;
 	u8 cpumode = event->header.misc & PERF_RECORD_MISC_CPUMODE_MASK;
-	const char *symname, *dsoname;
 
 	printf("%16" PRIx64, sample->addr);
 
@@ -340,21 +339,14 @@ static void print_sample_addr(union perf_event *event,
 		al.sym = map__find_symbol(al.map, al.addr, NULL);
 
 	if (PRINT_FIELD(SYM)) {
-		if (al.sym && al.sym->name)
-			symname = al.sym->name;
-		else
-			symname = "";
-
-		printf(" %16s", symname);
+		printf(" ");
+		symbol__print_symname(al.sym);
 	}
 
 	if (PRINT_FIELD(DSO)) {
-		if (al.map && al.map->dso && al.map->dso->name)
-			dsoname = al.map->dso->name;
-		else
-			dsoname = "";
-
-		printf(" (%s)", dsoname);
+		printf(" (");
+		map__print_dsoname(al.map);
+		printf(")");
 	}
 }
 
tools/perf/util/map.c +0 -0
index a16ecab..dddc0f3 100644

tools/perf/util/map.c size_t map__fprintf(struct map *self, FILE *fp) · line 208

Quoted 9 lines
tools/perf/util/map.c +6 -0
@@ -200,6 +200,18 @@ size_t map__fprintf(struct map *self, FILE *fp)
 		       self->start, self->end, self->pgoff, self->dso->name);
 }
 
+void map__print_dsoname(struct map *self)
+{
+	const char *dsoname;
+
+	if (self && self->dso && self->dso->name)
+			dsoname = self->dso->name;

extra tab in the above line.

Otherwise looks good to me.

Quoted 122 lines
tools/perf/util/map.c +6 -0
+	else
+		dsoname = "[unknown]";
+
+	printf("%s", dsoname);
+}
+
 /*
  * objdump wants/reports absolute IPs for ET_EXEC, and RIPs for ET_DYN.
  * map->dso->adjust_symbols==1 for ET_EXEC-like cases.
tools/perf/util/map.h +1 -0
index b397c03..6f452b9 100644
@@ -112,6 +112,7 @@ void map__delete(struct map *self);
 struct map *map__clone(struct map *self);
 int map__overlap(struct map *l, struct map *r);
 size_t map__fprintf(struct map *self, FILE *fp);
+void map__print_dsoname(struct map *self);
 
 int map__load(struct map *self, symbol_filter_t filter);
 struct symbol *map__find_symbol(struct map *self,
tools/perf/util/session.c +10 -25
index 453a010..442be3a 100644
@@ -1214,7 +1214,6 @@ void perf_session__print_ip(union perf_event *event,
 			    int print_sym, int print_dso)
 {
 	struct addr_location al;
-	const char *symname, *dsoname;
 	struct callchain_cursor *cursor = &session->callchain_cursor;
 	struct callchain_cursor_node *node;
 
@@ -1242,20 +1241,13 @@ void perf_session__print_ip(union perf_event *event,
 
 			printf("\t%16" PRIx64, node->ip);
 			if (print_sym) {
-				if (node->sym && node->sym->name)
-					symname = node->sym->name;
-				else
-					symname = "";
-
-				printf(" %s", symname);
+				printf(" ");
+				symbol__print_symname(node->sym);
 			}
 			if (print_dso) {
-				if (node->map && node->map->dso && node->map->dso->name)
-					dsoname = node->map->dso->name;
-				else
-					dsoname = "";
-
-				printf(" (%s)", dsoname);
+				printf(" (");
+				map__print_dsoname(al.map);
+				printf(")");
 			}
 			printf("\n");
 
@@ -1265,21 +1257,14 @@ void perf_session__print_ip(union perf_event *event,
 	} else {
 		printf("%16" PRIx64, sample->ip);
 		if (print_sym) {
-			if (al.sym && al.sym->name)
-				symname = al.sym->name;
-			else
-				symname = "";
-
-			printf(" %s", symname);
+			printf(" ");
+			symbol__print_symname(al.sym);
 		}
 
 		if (print_dso) {
-			if (al.map && al.map->dso && al.map->dso->name)
-				dsoname = al.map->dso->name;
-			else
-				dsoname = "";
-
-			printf(" (%s)", dsoname);
+			printf(" (");
+			map__print_dsoname(al.map);
+			printf(")");
 		}
 	}
 }
tools/perf/util/symbol.c +12 -0
index eec1963..85e19c4 100644
@@ -175,6 +175,18 @@ static size_t symbol__fprintf(struct symbol *sym, FILE *fp)
 		       sym->name);
 }
 
+void symbol__print_symname(const struct symbol *sym)
+{
+	const char *symname;
+
+	if (sym && sym->name)
+		symname = sym->name;
+	else
+		symname = "(unknown)";
+
+	printf("%s", symname);
+}
+
 void dso__set_long_name(struct dso *dso, char *name)
 {
 	if (name == NULL)
tools/perf/util/symbol.h +1 -0
index 325ee36..1ec17b4 100644
@@ -238,6 +238,7 @@ void machines__destroy_guest_kernel_maps(struct rb_root *machines);
 
 int symbol__init(void);
 void symbol__exit(void);
+void symbol__print_symname(const struct symbol *sym);
 bool symbol_type__is_a(char symbol_type, enum map_type map_type);
 
 size_t machine__fprintf_vmlinux_path(struct machine *machine, FILE *fp);
#6 lore raw

Re: [PATCH -tip v2 2/6] perf script: add magic word to indicate the failure of resolving symbols

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

Latest perf-script doesn't output symbol name when it failed to resolve symbol name. This output is not friendly for external scripts because it causes misaligment. So, this patch adds the magic word "(unknown)" when perf-script failed to resolve symbols.

Code has [unknown] with {}, not ().

Evidently I had the shift key down -- s/{}/[]/. :-) And I see now, for dsoname you have [unknown] and for symname (unknown). Use the same for both. Since () is already used for separating dsoname, use [unknown] for both

David

Quoted 208 lines
Quoted 70 lines

At the same time, this patch changes perf-script to output "[unknown]" in the DSO field, when it failed to resolve the path of DSOs.

Changes in v2:
- add this patch

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]>
Cc David Ahern <[email protected]>
Cc Masami Hiramatsu <[email protected]>

---

 tools/perf/builtin-script.c |   18 +++++-------------
 tools/perf/util/map.c       |   12 ++++++++++++
 tools/perf/util/map.h       |    1 +
 tools/perf/util/session.c   |   35 ++++++++++-------------------------
 tools/perf/util/symbol.c    |   12 ++++++++++++
 tools/perf/util/symbol.h    |    1 +
 6 files changed, 41 insertions(+), 38 deletions(-)
tools/perf/builtin-script.c +5 -13
index 09024ec..b3e0951 100644
@@ -320,7 +320,6 @@ static void print_sample_addr(union perf_event *event,
 {
 	struct addr_location al;
 	u8 cpumode = event->header.misc & PERF_RECORD_MISC_CPUMODE_MASK;
-	const char *symname, *dsoname;
 
 	printf("%16" PRIx64, sample->addr);
 
@@ -340,21 +339,14 @@ static void print_sample_addr(union perf_event *event,
 		al.sym = map__find_symbol(al.map, al.addr, NULL);
 
 	if (PRINT_FIELD(SYM)) {
-		if (al.sym && al.sym->name)
-			symname = al.sym->name;
-		else
-			symname = "";
-
-		printf(" %16s", symname);
+		printf(" ");
+		symbol__print_symname(al.sym);
 	}
 
 	if (PRINT_FIELD(DSO)) {
-		if (al.map && al.map->dso && al.map->dso->name)
-			dsoname = al.map->dso->name;
-		else
-			dsoname = "";
-
-		printf(" (%s)", dsoname);
+		printf(" (");
+		map__print_dsoname(al.map);
+		printf(")");
 	}
 }
 
tools/perf/util/map.c +0 -0
index a16ecab..dddc0f3 100644

tools/perf/util/map.c size_t map__fprintf(struct map *self, FILE *fp) · line 208

Quoted 9 lines
tools/perf/util/map.c +6 -0
@@ -200,6 +200,18 @@ size_t map__fprintf(struct map *self, FILE *fp)
 		       self->start, self->end, self->pgoff, self->dso->name);
 }
 
+void map__print_dsoname(struct map *self)
+{
+	const char *dsoname;
+
+	if (self && self->dso && self->dso->name)
+			dsoname = self->dso->name;

extra tab in the above line.

Otherwise looks good to me.

Quoted 122 lines
tools/perf/util/map.c +6 -0
+	else
+		dsoname = "[unknown]";
+
+	printf("%s", dsoname);
+}
+
 /*
  * objdump wants/reports absolute IPs for ET_EXEC, and RIPs for ET_DYN.
  * map->dso->adjust_symbols==1 for ET_EXEC-like cases.
tools/perf/util/map.h +1 -0
index b397c03..6f452b9 100644
@@ -112,6 +112,7 @@ void map__delete(struct map *self);
 struct map *map__clone(struct map *self);
 int map__overlap(struct map *l, struct map *r);
 size_t map__fprintf(struct map *self, FILE *fp);
+void map__print_dsoname(struct map *self);
 
 int map__load(struct map *self, symbol_filter_t filter);
 struct symbol *map__find_symbol(struct map *self,
tools/perf/util/session.c +10 -25
index 453a010..442be3a 100644
@@ -1214,7 +1214,6 @@ void perf_session__print_ip(union perf_event *event,
 			    int print_sym, int print_dso)
 {
 	struct addr_location al;
-	const char *symname, *dsoname;
 	struct callchain_cursor *cursor = &session->callchain_cursor;
 	struct callchain_cursor_node *node;
 
@@ -1242,20 +1241,13 @@ void perf_session__print_ip(union perf_event *event,
 
 			printf("\t%16" PRIx64, node->ip);
 			if (print_sym) {
-				if (node->sym && node->sym->name)
-					symname = node->sym->name;
-				else
-					symname = "";
-
-				printf(" %s", symname);
+				printf(" ");
+				symbol__print_symname(node->sym);
 			}
 			if (print_dso) {
-				if (node->map && node->map->dso && node->map->dso->name)
-					dsoname = node->map->dso->name;
-				else
-					dsoname = "";
-
-				printf(" (%s)", dsoname);
+				printf(" (");
+				map__print_dsoname(al.map);
+				printf(")");
 			}
 			printf("\n");
 
@@ -1265,21 +1257,14 @@ void perf_session__print_ip(union perf_event *event,
 	} else {
 		printf("%16" PRIx64, sample->ip);
 		if (print_sym) {
-			if (al.sym && al.sym->name)
-				symname = al.sym->name;
-			else
-				symname = "";
-
-			printf(" %s", symname);
+			printf(" ");
+			symbol__print_symname(al.sym);
 		}
 
 		if (print_dso) {
-			if (al.map && al.map->dso && al.map->dso->name)
-				dsoname = al.map->dso->name;
-			else
-				dsoname = "";
-
-			printf(" (%s)", dsoname);
+			printf(" (");
+			map__print_dsoname(al.map);
+			printf(")");
 		}
 	}
 }
tools/perf/util/symbol.c +12 -0
index eec1963..85e19c4 100644
@@ -175,6 +175,18 @@ static size_t symbol__fprintf(struct symbol *sym, FILE *fp)
 		       sym->name);
 }
 
+void symbol__print_symname(const struct symbol *sym)
+{
+	const char *symname;
+
+	if (sym && sym->name)
+		symname = sym->name;
+	else
+		symname = "(unknown)";
+
+	printf("%s", symname);
+}
+
 void dso__set_long_name(struct dso *dso, char *name)
 {
 	if (name == NULL)
tools/perf/util/symbol.h +1 -0
index 325ee36..1ec17b4 100644
@@ -238,6 +238,7 @@ void machines__destroy_guest_kernel_maps(struct rb_root *machines);
 
 int symbol__init(void);
 void symbol__exit(void);
+void symbol__print_symname(const struct symbol *sym);
 bool symbol_type__is_a(char symbol_type, enum map_type map_type);
 
 size_t machine__fprintf_vmlinux_path(struct machine *machine, FILE *fp);
#7 lore raw

Re: [PATCH -tip v2 2/6] perf script: add magic word to indicate the failure of resolving symbols

Quoted 9 lines · David Ahern
Quoted 8 lines · David Ahern
Quoted 4 lines · Akihiro Nagai

Latest perf-script doesn't output symbol name when it failed to resolve symbol name. This output is not friendly for external scripts because it causes misaligment. So, this patch adds the magic word "(unknown)" when perf-script failed to resolve symbols.

Quoted 6 lines
Quoted 1 line

Code has [unknown] with {}, not ().

Evidently I had the shift key down -- s/{}/[]/. :-) And I see now, for dsoname you have [unknown] and for symname (unknown). Use the same for both. Since () is already used for separating dsoname, use [unknown] for both

At print_sample_start() in builtin-script.c, there is the code that print "(unknown)" when perf cannnot resolve the event name.

    printf("%s: ", evname ? evname : "(unknown)");

On the other hand, at hist_entry__dso_snprintf() in util/sort.c, there is the code prints "[unknown]" for unresolvable DSO name.

    return repsep_snprintf(bf, size, "%-*s", width, "[unknown]");

In addition, perf uses "[]" for DSO name for example "[kernel.kallsyms]". So, I chose it. However, this specification is not easy for user-scripts. Should I unify this expression?

Thank you.

Quoted 87 lines

David

Quoted 83 lines
Quoted 70 lines

At the same time, this patch changes perf-script to output "[unknown]" in the DSO field, when it failed to resolve the path of DSOs.

Changes in v2:
- add this patch

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]>
Cc David Ahern<[email protected]>
Cc Masami Hiramatsu<[email protected]>

---

  tools/perf/builtin-script.c |   18 +++++-------------
  tools/perf/util/map.c       |   12 ++++++++++++
  tools/perf/util/map.h       |    1 +
  tools/perf/util/session.c   |   35 ++++++++++-------------------------
  tools/perf/util/symbol.c    |   12 ++++++++++++
  tools/perf/util/symbol.h    |    1 +
  6 files changed, 41 insertions(+), 38 deletions(-)
tools/perf/builtin-script.c +5 -13
index 09024ec..b3e0951 100644
@@ -320,7 +320,6 @@ static void print_sample_addr(union perf_event *event,
  {
  	struct addr_location al;
  	u8 cpumode = event->header.misc&  PERF_RECORD_MISC_CPUMODE_MASK;
-	const char *symname, *dsoname;
 
  	printf("%16" PRIx64, sample->addr);
 
@@ -340,21 +339,14 @@ static void print_sample_addr(union perf_event *event,
  		al.sym = map__find_symbol(al.map, al.addr, NULL);
 
  	if (PRINT_FIELD(SYM)) {
-		if (al.sym&&  al.sym->name)
-			symname = al.sym->name;
-		else
-			symname = "";
-
-		printf(" %16s", symname);
+		printf(" ");
+		symbol__print_symname(al.sym);
  	}
 
  	if (PRINT_FIELD(DSO)) {
-		if (al.map&&  al.map->dso&&  al.map->dso->name)
-			dsoname = al.map->dso->name;
-		else
-			dsoname = "";
-
-		printf(" (%s)", dsoname);
+		printf(" (");
+		map__print_dsoname(al.map);
+		printf(")");
  	}
  }
 
tools/perf/util/map.c +0 -0
index a16ecab..dddc0f3 100644

tools/perf/util/map.c size_t map__fprintf(struct map *self, FILE *fp) · line 208

Quoted 9 lines
tools/perf/util/map.c +6 -0
@@ -200,6 +200,18 @@ size_t map__fprintf(struct map *self, FILE *fp)
  		       self->start, self->end, self->pgoff, self->dso->name);
  }
 
+void map__print_dsoname(struct map *self)
+{
+	const char *dsoname;
+
+	if (self&&  self->dso&&  self->dso->name)
+			dsoname = self->dso->name;

extra tab in the above line.

Otherwise looks good to me.

Oops! I fix it. Thank you.

Quoted 125 lines
Quoted 125 lines
Quoted 122 lines
tools/perf/util/map.c +6 -0
+	else
+		dsoname = "[unknown]";
+
+	printf("%s", dsoname);
+}
+
  /*
   * objdump wants/reports absolute IPs for ET_EXEC, and RIPs for ET_DYN.
   * map->dso->adjust_symbols==1 for ET_EXEC-like cases.
tools/perf/util/map.h +1 -0
index b397c03..6f452b9 100644
@@ -112,6 +112,7 @@ void map__delete(struct map *self);
  struct map *map__clone(struct map *self);
  int map__overlap(struct map *l, struct map *r);
  size_t map__fprintf(struct map *self, FILE *fp);
+void map__print_dsoname(struct map *self);
 
  int map__load(struct map *self, symbol_filter_t filter);
  struct symbol *map__find_symbol(struct map *self,
tools/perf/util/session.c +10 -25
index 453a010..442be3a 100644
@@ -1214,7 +1214,6 @@ void perf_session__print_ip(union perf_event *event,
  			    int print_sym, int print_dso)
  {
  	struct addr_location al;
-	const char *symname, *dsoname;
  	struct callchain_cursor *cursor =&session->callchain_cursor;
  	struct callchain_cursor_node *node;
 
@@ -1242,20 +1241,13 @@ void perf_session__print_ip(union perf_event *event,
 
  			printf("\t%16" PRIx64, node->ip);
  			if (print_sym) {
-				if (node->sym&&  node->sym->name)
-					symname = node->sym->name;
-				else
-					symname = "";
-
-				printf(" %s", symname);
+				printf(" ");
+				symbol__print_symname(node->sym);
  			}
  			if (print_dso) {
-				if (node->map&&  node->map->dso&&  node->map->dso->name)
-					dsoname = node->map->dso->name;
-				else
-					dsoname = "";
-
-				printf(" (%s)", dsoname);
+				printf(" (");
+				map__print_dsoname(al.map);
+				printf(")");
  			}
  			printf("\n");
 
@@ -1265,21 +1257,14 @@ void perf_session__print_ip(union perf_event *event,
  	} else {
  		printf("%16" PRIx64, sample->ip);
  		if (print_sym) {
-			if (al.sym&&  al.sym->name)
-				symname = al.sym->name;
-			else
-				symname = "";
-
-			printf(" %s", symname);
+			printf(" ");
+			symbol__print_symname(al.sym);
  		}
 
  		if (print_dso) {
-			if (al.map&&  al.map->dso&&  al.map->dso->name)
-				dsoname = al.map->dso->name;
-			else
-				dsoname = "";
-
-			printf(" (%s)", dsoname);
+			printf(" (");
+			map__print_dsoname(al.map);
+			printf(")");
  		}
  	}
  }
tools/perf/util/symbol.c +12 -0
index eec1963..85e19c4 100644
@@ -175,6 +175,18 @@ static size_t symbol__fprintf(struct symbol *sym, FILE *fp)
  		       sym->name);
  }
 
+void symbol__print_symname(const struct symbol *sym)
+{
+	const char *symname;
+
+	if (sym&&  sym->name)
+		symname = sym->name;
+	else
+		symname = "(unknown)";
+
+	printf("%s", symname);
+}
+
  void dso__set_long_name(struct dso *dso, char *name)
  {
  	if (name == NULL)
tools/perf/util/symbol.h +1 -0
index 325ee36..1ec17b4 100644
@@ -238,6 +238,7 @@ void machines__destroy_guest_kernel_maps(struct rb_root *machines);
 
  int symbol__init(void);
  void symbol__exit(void);
+void symbol__print_symname(const struct symbol *sym);
  bool symbol_type__is_a(char symbol_type, enum map_type map_type);
 
  size_t machine__fprintf_vmlinux_path(struct machine *machine, FILE *fp);
maintainer
#8 lore raw

Re: [PATCH -tip v2 2/6] perf script: add magic word to indicate the failure of resolving symbols

Quoted 2 lines · Akihiro Nagai

In addition, perf uses "[]" for DSO name for example "[kernel.kallsyms]".

We only use that for kernel dsos iirc.

#9 lore raw

Re: [PATCH -tip v2 2/6] perf script: add magic word to indicate the failure of resolving symbols

In reply to Akihiro Nagai

On 07/21/2011 03:36 AM, Akihiro Nagai wrote

Quoted 14 lines
Quoted 4 lines

Evidently I had the shift key down -- s/{}/[]/. :-) And I see now, for dsoname you have [unknown] and for symname (unknown). Use the same for both. Since () is already used for separating dsoname, use [unknown] for both

At print_sample_start() in builtin-script.c, there is the code that print "(unknown)"
when perf cannnot resolve the event name.

    printf("%s: ", evname ? evname : "(unknown)");

On the other hand, at hist_entry__dso_snprintf() in util/sort.c, there is the code
prints "[unknown]" for unresolvable DSO name.

Quoted 5 lines
    return repsep_snprintf(bf, size, "%-*s", width, "[unknown]");

In addition, perf uses "[]" for DSO name for example "[kernel.kallsyms]". So, I chose it. However, this specification is not easy for user-scripts. Should I unify this expression?

That was my thought -- to use the same for both dso and sym if it is unknown. And since DSO names are wrapped in () use "[unknown]" for both -- ie., right now the format is "symname (dsoname)" (though kernel syms from kallsyms come out as "symname ([kernel.kallsyms])"). With an unknown it will be "[unknown] (dsoname)" or "[unknown] ([unknown])" which retains the number of fields in a uniquely parse-able way.

David

#10 lore raw

Re: [PATCH -tip v2 2/6] perf script: add magic word to indicate the failure of resolving symbols

Quoted 21 lines · David Ahern

On 07/21/2011 03:36 AM, Akihiro Nagai wrote

Quoted 14 lines
Quoted 4 lines

Evidently I had the shift key down -- s/{}/[]/. :-) And I see now, for dsoname you have [unknown] and for symname (unknown). Use the same for both. Since () is already used for separating dsoname, use [unknown] for both

At print_sample_start() in builtin-script.c, there is the code that print "(unknown)"
when perf cannnot resolve the event name.

     printf("%s: ", evname ? evname : "(unknown)");

On the other hand, at hist_entry__dso_snprintf() in util/sort.c, there is the code
prints "[unknown]" for unresolvable DSO name.

Quoted 5 lines
     return repsep_snprintf(bf, size, "%-*s", width, "[unknown]");

In addition, perf uses "[]" for DSO name for example "[kernel.kallsyms]". So, I chose it. However, this specification is not easy for user-scripts. Should I unify this expression?

Quoted 6 lines

That was my thought -- to use the same for both dso and sym if it is unknown. And since DSO names are wrapped in () use "[unknown]" for both -- ie., right now the format is "symname (dsoname)" (though kernel syms from kallsyms come out as "symname ([kernel.kallsyms])"). With an unknown it will be "[unknown] (dsoname)" or "[unknown] ([unknown])" which retains the number of fields in a uniquely parse-able way.

I agree.
In the next patch set, I'd like to unify the all expressions to "[unknown]".

Thank you.

Quoted 2 lines

David

#11 lore raw

PATCH v2 3/6 perf script: resolve DSOs and symbols for user-space

In reply to Akihiro Nagai

Resolve user-space DSOs and symbols.
Latest perf-script can resolve DSOs and symbols for only kernel and kernel modules. This patch resolves them for other executable binaries.

# perf script -f ip,addr,sym,dso
3f03e016b0 ffffffff814675d2 irq_return ([kernel.kallsyms])
3f03e016b0 ffffffff814675d2 irq_return ([kernel.kallsyms])
3f03e04b80       3f03e016b3 _start (/lib64/ld-2.14.so)
3f03e04b80 ffffffff814675d2 irq_return ([kernel.kallsyms])
3f03e04ba6 ffffffff814675d2 irq_return ([kernel.kallsyms])
3f03e04bad ffffffff814675d2 irq_return ([kernel.kallsyms])
3f03e04c1d       3f03e04bfb _dl_start (/lib64/ld-2.14.so)
3f03e04c00       3f03e04c21 _dl_start (/lib64/ld-2.14.so)
3f03e04c00       3f03e04c21 _dl_start (/lib64/ld-2.14.so)
[snip]
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]>
Cc David Ahern <[email protected]>
Cc Masami Hiramatsu <[email protected]>

---

 tools/perf/builtin-script.c |    4 ++++
 tools/perf/util/event.c     |    5 +++++
 2 files changed, 9 insertions(+), 0 deletions(-)
tools/perf/builtin-script.c +4 -0
index b3e0951..2356198 100644
@@ -328,6 +328,10 @@ static void print_sample_addr(union perf_event *event,
 
 	thread__find_addr_map(thread, session, cpumode, MAP__FUNCTION,
 			      event->ip.pid, sample->addr, &al);
+	/* try to resolve for user space */
+	if (!al.map)
+		thread__find_addr_map(thread, session, PERF_RECORD_MISC_USER,
+			MAP__FUNCTION, event->ip.pid, sample->addr, &al);
 	if (!al.map)
 		thread__find_addr_map(thread, session, cpumode, MAP__VARIABLE,
 				      event->ip.pid, sample->addr, &al);
tools/perf/util/event.c +5 -0
index 3c1b8a6..49a9315 100644
@@ -771,6 +771,11 @@ int perf_event__preprocess_sample(const union perf_event *event,
 
 	thread__find_addr_map(thread, session, cpumode, MAP__FUNCTION,
 			      event->ip.pid, event->ip.ip, al);
+	/* try to resolve for user space */
+	if (!al->map)
+		thread__find_addr_map(thread, session, PERF_RECORD_MISC_USER,
+				MAP__FUNCTION, event->ip.pid, event->ip.ip, al);
+
 	dump_printf(" ...... dso: %s\n",
 		    al->map ? al->map->dso->long_name :
 			al->level == 'H' ? "[hypervisor]" : "<not found>");
#12 lore raw

Re: [PATCH -tip v2 3/6] perf script: resolve DSOs and symbols for user-space

Quoted 4 lines · Akihiro Nagai

Resolve user-space DSOs and symbols.
Latest perf-script can resolve DSOs and symbols for only kernel and kernel modules. This patch resolves them for other executable binaries.

The description is a bit misleading. perf script does resolve symbols for userspace. e.g., the example in the bug fix I submitted in May:
https://lkml.org/lkml/2011/5/30/223

Do you look into why the cpumode setting is not working that you have to try specific settings?

David

Quoted 59 lines
# perf script -f ip,addr,sym,dso
3f03e016b0 ffffffff814675d2 irq_return ([kernel.kallsyms])
3f03e016b0 ffffffff814675d2 irq_return ([kernel.kallsyms])
3f03e04b80       3f03e016b3 _start (/lib64/ld-2.14.so)
3f03e04b80 ffffffff814675d2 irq_return ([kernel.kallsyms])
3f03e04ba6 ffffffff814675d2 irq_return ([kernel.kallsyms])
3f03e04bad ffffffff814675d2 irq_return ([kernel.kallsyms])
3f03e04c1d       3f03e04bfb _dl_start (/lib64/ld-2.14.so)
3f03e04c00       3f03e04c21 _dl_start (/lib64/ld-2.14.so)
3f03e04c00       3f03e04c21 _dl_start (/lib64/ld-2.14.so)
[snip]
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]>
Cc David Ahern <[email protected]>
Cc Masami Hiramatsu <[email protected]>

---

 tools/perf/builtin-script.c |    4 ++++
 tools/perf/util/event.c     |    5 +++++
 2 files changed, 9 insertions(+), 0 deletions(-)
tools/perf/builtin-script.c +4 -0
index b3e0951..2356198 100644
@@ -328,6 +328,10 @@ static void print_sample_addr(union perf_event *event,
 
 	thread__find_addr_map(thread, session, cpumode, MAP__FUNCTION,
 			      event->ip.pid, sample->addr, &al);
+	/* try to resolve for user space */
+	if (!al.map)
+		thread__find_addr_map(thread, session, PERF_RECORD_MISC_USER,
+			MAP__FUNCTION, event->ip.pid, sample->addr, &al);
 	if (!al.map)
 		thread__find_addr_map(thread, session, cpumode, MAP__VARIABLE,
 				      event->ip.pid, sample->addr, &al);
tools/perf/util/event.c +5 -0
index 3c1b8a6..49a9315 100644
@@ -771,6 +771,11 @@ int perf_event__preprocess_sample(const union perf_event *event,
 
 	thread__find_addr_map(thread, session, cpumode, MAP__FUNCTION,
 			      event->ip.pid, event->ip.ip, al);
+	/* try to resolve for user space */
+	if (!al->map)
+		thread__find_addr_map(thread, session, PERF_RECORD_MISC_USER,
+				MAP__FUNCTION, event->ip.pid, event->ip.ip, al);
+
 	dump_printf(" ...... dso: %s\n",
 		    al->map ? al->map->dso->long_name :
 			al->level == 'H' ? "[hypervisor]" : "<not found>");
#13 lore raw

Re: [PATCH -tip v2 3/6] perf script: resolve DSOs and symbols for user-space

Quoted 6 lines · David Ahern
Quoted 4 lines · Akihiro Nagai

Resolve user-space DSOs and symbols.
Latest perf-script can resolve DSOs and symbols for only kernel and kernel modules. This patch resolves them for other executable binaries.

Quoted 6 lines

The description is a bit misleading. perf script does resolve symbols for userspace. e.g., the example in the bug fix I submitted in May:
https://lkml.org/lkml/2011/5/30/223

Do you look into why the cpumode setting is not working that you have to try specific settings?

Indeed, perf already can resolve user-space symbols and DSOs if cpumode has the flag PERF_RECORD_MISC_USER. I found this change is incorrect. To solve this, I'd like to set both flags PERF_RECORD_MISC_KERNEL and USER to BTS records, because BTS traces both kernel and user space while it generates interrupts.

And also, I think there is the probrem in thread__find_addr_map().
When this function is called with cpumode that is set (PERF_RECORD_MISC_KERNEL | USER), this function processes only PERF_RECORD_MISC_KERNEL. So, I'd like to fix it too.

Thank you.

Quoted 63 lines

David

Quoted 59 lines
# perf script -f ip,addr,sym,dso
3f03e016b0 ffffffff814675d2 irq_return ([kernel.kallsyms])
3f03e016b0 ffffffff814675d2 irq_return ([kernel.kallsyms])
3f03e04b80       3f03e016b3 _start (/lib64/ld-2.14.so)
3f03e04b80 ffffffff814675d2 irq_return ([kernel.kallsyms])
3f03e04ba6 ffffffff814675d2 irq_return ([kernel.kallsyms])
3f03e04bad ffffffff814675d2 irq_return ([kernel.kallsyms])
3f03e04c1d       3f03e04bfb _dl_start (/lib64/ld-2.14.so)
3f03e04c00       3f03e04c21 _dl_start (/lib64/ld-2.14.so)
3f03e04c00       3f03e04c21 _dl_start (/lib64/ld-2.14.so)
[snip]
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]>
Cc David Ahern<[email protected]>
Cc Masami Hiramatsu<[email protected]>

---

  tools/perf/builtin-script.c |    4 ++++
  tools/perf/util/event.c     |    5 +++++
  2 files changed, 9 insertions(+), 0 deletions(-)
tools/perf/builtin-script.c +4 -0
index b3e0951..2356198 100644
@@ -328,6 +328,10 @@ static void print_sample_addr(union perf_event *event,
 
  	thread__find_addr_map(thread, session, cpumode, MAP__FUNCTION,
  			      event->ip.pid, sample->addr,&al);
+	/* try to resolve for user space */
+	if (!al.map)
+		thread__find_addr_map(thread, session, PERF_RECORD_MISC_USER,
+			MAP__FUNCTION, event->ip.pid, sample->addr,&al);
  	if (!al.map)
  		thread__find_addr_map(thread, session, cpumode, MAP__VARIABLE,
  				      event->ip.pid, sample->addr,&al);
tools/perf/util/event.c +5 -0
index 3c1b8a6..49a9315 100644
@@ -771,6 +771,11 @@ int perf_event__preprocess_sample(const union perf_event *event,
 
  	thread__find_addr_map(thread, session, cpumode, MAP__FUNCTION,
  			      event->ip.pid, event->ip.ip, al);
+	/* try to resolve for user space */
+	if (!al->map)
+		thread__find_addr_map(thread, session, PERF_RECORD_MISC_USER,
+				MAP__FUNCTION, event->ip.pid, event->ip.ip, al);
+
  	dump_printf(" ...... dso: %s\n",
  		    al->map ? al->map->dso->long_name :
  			al->level == 'H' ? "[hypervisor]" : "<not found>");
#14 lore raw

PATCH v2 4/6 perf script: print DSOs and symbols for BTS branch_from addr

In reply to Akihiro Nagai

Print DSOs and symbols for branch_from address of BTS. BTS records branch_from address in 'addr' fields, and branch_to address in 'ip' field. Latest perf-script resolves DSOs and symbols only for 'ip' field. This patch resolves them for 'addr' field too.

# perf script -f ip,addr,dso,sym
3f03e016b0 (unknown) ([kernel.kallsyms]) ffffffff814675d2 irq_return ([kernel.kallsyms])
3f03e016b0    _start (/lib64/ld-2.14.so) ffffffff814675d2 irq_return ([kernel.kallsyms])
3f03e04b80 _dl_start (/lib64/ld-2.14.so)       3f03e016b3 _start (/lib64/ld-2.14.so)
3f03e04b80 _dl_start (/lib64/ld-2.14.so) ffffffff814675d2 irq_return ([kernel.kallsyms])
3f03e04ba6 _dl_start (/lib64/ld-2.14.so) ffffffff814675d2 irq_return ([kernel.kallsyms])
3f03e04bad _dl_start (/lib64/ld-2.14.so) ffffffff814675d2 irq_return ([kernel.kallsyms])
3f03e04c1d _dl_start (/lib64/ld-2.14.so)       3f03e04bfb _dl_start (/lib64/ld-2.14.so)
[snip]
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]>
Cc David Ahern <[email protected]>
Cc Masami Hiramatsu <[email protected]>

---

 tools/perf/builtin-script.c |    8 +++++++-
 tools/perf/util/event.c     |    2 +-
 2 files changed, 8 insertions(+), 2 deletions(-)
tools/perf/builtin-script.c +7 -1
index 2356198..7708d89 100644
@@ -309,6 +309,12 @@ static bool sample_addr_correlates_sym(struct perf_event_attr *attr)
 	     (attr->config == PERF_COUNT_SW_PAGE_FAULTS_MAJ)))
 		return true;
 
+	/* BTS Events */
+	if ((attr->type == PERF_TYPE_HARDWARE) &&
+	    (attr->config & PERF_COUNT_HW_BRANCH_INSTRUCTIONS) &&
+	    (attr->sample_period == 1))
+		return true;
+
 	return false;
 }
 
@@ -328,7 +334,7 @@ static void print_sample_addr(union perf_event *event,
 
 	thread__find_addr_map(thread, session, cpumode, MAP__FUNCTION,
 			      event->ip.pid, sample->addr, &al);
-	/* try to resolve for user space */
+	/* try to resolve addr_location for user space */
 	if (!al.map)
 		thread__find_addr_map(thread, session, PERF_RECORD_MISC_USER,
 			MAP__FUNCTION, event->ip.pid, sample->addr, &al);
tools/perf/util/event.c +1 -1
index 49a9315..c541d02 100644
@@ -771,7 +771,7 @@ int perf_event__preprocess_sample(const union perf_event *event,
 
 	thread__find_addr_map(thread, session, cpumode, MAP__FUNCTION,
 			      event->ip.pid, event->ip.ip, al);
-	/* try to resolve for user space */
+	/* try to resolve addr_location for user space */
 	if (!al->map)
 		thread__find_addr_map(thread, session, PERF_RECORD_MISC_USER,
 				MAP__FUNCTION, event->ip.pid, event->ip.ip, al);
#15 lore raw

Re: [PATCH -tip v2 4/6] perf script: print DSOs and symbols for BTS branch_from addr

Quoted 5 lines · Akihiro Nagai

Print DSOs and symbols for branch_from address of BTS. BTS records branch_from address in 'addr' fields, and branch_to address in 'ip' field. Latest perf-script resolves DSOs and symbols only for 'ip' field. This patch resolves them for 'addr' field too.

Description does not match code change. What you are doing is enhancing the detection of when a sample address should correlate to a symbol. In this case you are adding HW_BRANCH_INSTRUCTIONS event.

David

Quoted 65 lines
# perf script -f ip,addr,dso,sym
3f03e016b0 (unknown) ([kernel.kallsyms]) ffffffff814675d2 irq_return ([kernel.kallsyms])
3f03e016b0    _start (/lib64/ld-2.14.so) ffffffff814675d2 irq_return ([kernel.kallsyms])
3f03e04b80 _dl_start (/lib64/ld-2.14.so)       3f03e016b3 _start (/lib64/ld-2.14.so)
3f03e04b80 _dl_start (/lib64/ld-2.14.so) ffffffff814675d2 irq_return ([kernel.kallsyms])
3f03e04ba6 _dl_start (/lib64/ld-2.14.so) ffffffff814675d2 irq_return ([kernel.kallsyms])
3f03e04bad _dl_start (/lib64/ld-2.14.so) ffffffff814675d2 irq_return ([kernel.kallsyms])
3f03e04c1d _dl_start (/lib64/ld-2.14.so)       3f03e04bfb _dl_start (/lib64/ld-2.14.so)
[snip]
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]>
Cc David Ahern <[email protected]>
Cc Masami Hiramatsu <[email protected]>

---

 tools/perf/builtin-script.c |    8 +++++++-
 tools/perf/util/event.c     |    2 +-
 2 files changed, 8 insertions(+), 2 deletions(-)
tools/perf/builtin-script.c +7 -1
index 2356198..7708d89 100644
@@ -309,6 +309,12 @@ static bool sample_addr_correlates_sym(struct perf_event_attr *attr)
 	     (attr->config == PERF_COUNT_SW_PAGE_FAULTS_MAJ)))
 		return true;
 
+	/* BTS Events */
+	if ((attr->type == PERF_TYPE_HARDWARE) &&
+	    (attr->config & PERF_COUNT_HW_BRANCH_INSTRUCTIONS) &&
+	    (attr->sample_period == 1))
+		return true;
+
 	return false;
 }
 
@@ -328,7 +334,7 @@ static void print_sample_addr(union perf_event *event,
 
 	thread__find_addr_map(thread, session, cpumode, MAP__FUNCTION,
 			      event->ip.pid, sample->addr, &al);
-	/* try to resolve for user space */
+	/* try to resolve addr_location for user space */
 	if (!al.map)
 		thread__find_addr_map(thread, session, PERF_RECORD_MISC_USER,
 			MAP__FUNCTION, event->ip.pid, sample->addr, &al);
tools/perf/util/event.c +1 -1
index 49a9315..c541d02 100644
@@ -771,7 +771,7 @@ int perf_event__preprocess_sample(const union perf_event *event,
 
 	thread__find_addr_map(thread, session, cpumode, MAP__FUNCTION,
 			      event->ip.pid, event->ip.ip, al);
-	/* try to resolve for user space */
+	/* try to resolve addr_location for user space */
 	if (!al->map)
 		thread__find_addr_map(thread, session, PERF_RECORD_MISC_USER,
 				MAP__FUNCTION, event->ip.pid, event->ip.ip, al);
#16 lore raw

Re: [PATCH -tip v2 4/6] perf script: print DSOs and symbols for BTS branch_from addr

Quoted 9 lines · David Ahern
Quoted 5 lines · Akihiro Nagai

Print DSOs and symbols for branch_from address of BTS. BTS records branch_from address in 'addr' fields, and branch_to address in 'ip' field. Latest perf-script resolves DSOs and symbols only for 'ip' field. This patch resolves them for 'addr' field too.

Quoted 3 lines

Description does not match code change. What you are doing is enhancing the detection of when a sample address should correlate to a symbol. In this case you are adding HW_BRANCH_INSTRUCTIONS event.

I see. In the next patch set, I'd like to fix it. For example, "Enhance IP and ADDR correlation detection of BTS event"

Thank you.

Quoted 23 lines

David

Quoted 19 lines
# perf script -f ip,addr,dso,sym
3f03e016b0 (unknown) ([kernel.kallsyms]) ffffffff814675d2 irq_return ([kernel.kallsyms])
3f03e016b0    _start (/lib64/ld-2.14.so) ffffffff814675d2 irq_return ([kernel.kallsyms])
3f03e04b80 _dl_start (/lib64/ld-2.14.so)       3f03e016b3 _start (/lib64/ld-2.14.so)
3f03e04b80 _dl_start (/lib64/ld-2.14.so) ffffffff814675d2 irq_return ([kernel.kallsyms])
3f03e04ba6 _dl_start (/lib64/ld-2.14.so) ffffffff814675d2 irq_return ([kernel.kallsyms])
3f03e04bad _dl_start (/lib64/ld-2.14.so) ffffffff814675d2 irq_return ([kernel.kallsyms])
3f03e04c1d _dl_start (/lib64/ld-2.14.so)       3f03e04bfb _dl_start (/lib64/ld-2.14.so)
[snip]
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]>
Cc David Ahern<[email protected]>
Cc Masami Hiramatsu<[email protected]>
#17 lore raw

PATCH v2 5/6 perf script: add the offset field specifier

In reply to Akihiro Nagai

Add the offset field specifier 'offs' to show the offset from the symbols in the output of perf-script. We can get the more detailed address information.

Output sample:

# perf script -f ip,addr,sym,offs
301ec016b0             (unknown) ffffffff81467612 irq_return+0x0
301ec016b0            _start+0x0 ffffffff81467612 irq_return+0x0
301ec04b70         _dl_start+0x0       301ec016b3 _start+0x3
301ec04b70         _dl_start+0x0 ffffffff81467612 irq_return+0x0
301ec04b96        _dl_start+0x26 ffffffff81467612 irq_return+0x0
301ec04b9d        _dl_start+0x2d ffffffff81467612 irq_return+0x0
301ec04c0d        _dl_start+0x9d       301ec04beb _dl_start+0x7b
301ec04bf0        _dl_start+0x80       301ec04c11 _dl_start+0xa1
[snip]

Changes in v2:
- change the way to output offset from '--show-symbol-offset' to 'offs' field.
- clean up codes.

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]>
Cc David Ahern <[email protected]>
Cc Masami Hiramatsu <[email protected]>

---

 tools/perf/Documentation/perf-script.txt |    2 +-
 tools/perf/builtin-script.c              |   20 +++++++++++++++++---
 tools/perf/util/session.c                |    7 +++++--
 tools/perf/util/session.h                |    3 ++-
 tools/perf/util/symbol.c                 |   22 +++++++++++++++-------
 tools/perf/util/symbol.h                 |    2 ++
 6 files changed, 42 insertions(+), 14 deletions(-)
tools/perf/Documentation/perf-script.txt +1 -1
index db01786..ee4d477 100644
@@ -115,7 +115,7 @@ OPTIONS
 -f::
 --fields::
         Comma separated list of fields to print. Options are:
-        comm, tid, pid, time, cpu, event, trace, ip, sym, dso, addr.
+        comm, tid, pid, time, cpu, event, trace, ip, sym, dso, addr, offs.
         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 +17 -3
index 7708d89..fd68185 100644
@@ -37,6 +37,7 @@ enum perf_output_field {
 	PERF_OUTPUT_SYM             = 1U << 8,
 	PERF_OUTPUT_DSO             = 1U << 9,
 	PERF_OUTPUT_ADDR            = 1U << 10,
+	PERF_OUTPUT_OFFSET          = 1U << 11,
 };
 
 struct output_option {
@@ -54,6 +55,7 @@ struct output_option {
 	{.str = "sym",   .field = PERF_OUTPUT_SYM},
 	{.str = "dso",   .field = PERF_OUTPUT_DSO},
 	{.str = "addr",  .field = PERF_OUTPUT_ADDR},
+	{.str = "offs",  .field = PERF_OUTPUT_OFFSET},
 };
 
 /* default set to maintain compatibility with current format */
@@ -190,6 +192,11 @@ static int perf_evsel__check_attr(struct perf_evsel *evsel,
 		       "to symbols.\n");
 		return -EINVAL;
 	}
+	if (PRINT_FIELD(OFFSET) && !PRINT_FIELD(SYM)) {
+		pr_err("Display of offsets requested but symbol is not"
+		       "selected.\n");
+		return -EINVAL;
+	}
 	if (PRINT_FIELD(DSO) && !PRINT_FIELD(IP) && !PRINT_FIELD(ADDR)) {
 		pr_err("Display of DSO requested but neither sample IP nor "
 			   "sample address\nis selected. Hence, no addresses to convert "
@@ -350,7 +357,10 @@ static void print_sample_addr(union perf_event *event,
 
 	if (PRINT_FIELD(SYM)) {
 		printf(" ");
-		symbol__print_symname(al.sym);
+		if (PRINT_FIELD(OFFSET))
+			symbol__print_symname_offs(al.sym, &al);
+		else
+			symbol__print_symname(al.sym);
 	}
 
 	if (PRINT_FIELD(DSO)) {
@@ -386,7 +396,8 @@ static void process_event(union perf_event *event __unused,
 		else
 			printf("\n");
 		perf_session__print_ip(event, sample, session,
-					      PRINT_FIELD(SYM), PRINT_FIELD(DSO));
+				       PRINT_FIELD(SYM), PRINT_FIELD(DSO),
+				       PRINT_FIELD(OFFSET));
 	}
 
 	printf("\n");
@@ -1082,7 +1093,10 @@ 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,raw. Fields: comm,tid,pid,time,cpu,event,trace,ip,sym,dso,addr",
+		     "comma separated output fields prepend with 'type:'. "
+		     "Valid types: hw,sw,trace,raw. "
+		     "Fields: comm,tid,pid,time,cpu,event,trace,ip,sym,dso,"
+		     "addr,offs",
 		     parse_output_fields),
 	OPT_STRING('c', "cpu", &cpu_list, "cpu", "list of cpus to profile"),
 
tools/perf/util/session.c +5 -2
index 442be3a..3728e67 100644
@@ -1211,7 +1211,7 @@ struct perf_evsel *perf_session__find_first_evtype(struct perf_session *session,
 void perf_session__print_ip(union perf_event *event,
 			    struct perf_sample *sample,
 			    struct perf_session *session,
-			    int print_sym, int print_dso)
+			    int print_sym, int print_dso, int print_offset)
 {
 	struct addr_location al;
 	struct callchain_cursor *cursor = &session->callchain_cursor;
@@ -1258,7 +1258,10 @@ void perf_session__print_ip(union perf_event *event,
 		printf("%16" PRIx64, sample->ip);
 		if (print_sym) {
 			printf(" ");
-			symbol__print_symname(al.sym);
+			if (print_offset)
+				symbol__print_symname_offs(al.sym, &al);
+			else
+				symbol__print_symname(al.sym);
 		}
 
 		if (print_dso) {
tools/perf/util/session.h +2 -1
index 5de754f..e6e5586 100644
@@ -170,7 +170,8 @@ struct perf_evsel *perf_session__find_first_evtype(struct perf_session *session,
 void perf_session__print_ip(union perf_event *event,
 				 struct perf_sample *sample,
 				 struct perf_session *session,
-				 int print_sym, int print_dso);
+				 int print_sym, int print_dso,
+				 int print_offset);
 
 int perf_session__cpu_bitmap(struct perf_session *session,
 			     const char *cpu_list, unsigned long *cpu_bitmap);
tools/perf/util/symbol.c +15 -7
index 85e19c4..abfecf6 100644
@@ -175,16 +175,24 @@ static size_t symbol__fprintf(struct symbol *sym, FILE *fp)
 		       sym->name);
 }
 
-void symbol__print_symname(const struct symbol *sym)
+void symbol__print_symname_offs(const struct symbol *sym,
+				const struct addr_location *al)
 {
-	const char *symname;
+	unsigned long offset;
 
-	if (sym && sym->name)
-		symname = sym->name;
-	else
-		symname = "(unknown)";
+	if (sym && sym->name) {
+		printf("%s", sym->name);
+		if (al) {
+			offset = al->addr - sym->start;
+			printf("+0x%lx", offset);
+		}
+	} else
+		printf("(unknown)");
+}
 
-	printf("%s", symname);
+void symbol__print_symname(const struct symbol *sym)
+{
+	symbol__print_symname_offs(sym, NULL);
 }
 
 void dso__set_long_name(struct dso *dso, char *name)
tools/perf/util/symbol.h +2 -0
index 1ec17b4..554b2fe 100644
@@ -238,6 +238,8 @@ void machines__destroy_guest_kernel_maps(struct rb_root *machines);
 
 int symbol__init(void);
 void symbol__exit(void);
+void symbol__print_symname_offs(const struct symbol *sym,
+				const struct addr_location *al);
 void symbol__print_symname(const struct symbol *sym);
 bool symbol_type__is_a(char symbol_type, enum map_type map_type);
 
Acked-by on v2 5/6
#18 lore raw

Re: [PATCH -tip v2 5/6] perf script: add the offset field specifier

Quoted 16 lines · Akihiro Nagai

Add the offset field specifier 'offs' to show the offset from the symbols in the output of perf-script. We can get the more detailed address information.

Output sample:

# perf script -f ip,addr,sym,offs
301ec016b0             (unknown) ffffffff81467612 irq_return+0x0
301ec016b0            _start+0x0 ffffffff81467612 irq_return+0x0
301ec04b70         _dl_start+0x0       301ec016b3 _start+0x3
301ec04b70         _dl_start+0x0 ffffffff81467612 irq_return+0x0
301ec04b96        _dl_start+0x26 ffffffff81467612 irq_return+0x0
301ec04b9d        _dl_start+0x2d ffffffff81467612 irq_return+0x0
301ec04c0d        _dl_start+0x9d       301ec04beb _dl_start+0x7b
301ec04bf0        _dl_start+0x80       301ec04c11 _dl_start+0xa1
[snip]
Quoted 4 lines

Changes in v2:
- change the way to output offset from '--show-symbol-offset' to 'offs' field.
- clean up codes.

Looks ok to me.

David

Quoted 187 lines
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]>
Cc David Ahern <[email protected]>
Cc Masami Hiramatsu <[email protected]>

---

 tools/perf/Documentation/perf-script.txt |    2 +-
 tools/perf/builtin-script.c              |   20 +++++++++++++++++---
 tools/perf/util/session.c                |    7 +++++--
 tools/perf/util/session.h                |    3 ++-
 tools/perf/util/symbol.c                 |   22 +++++++++++++++-------
 tools/perf/util/symbol.h                 |    2 ++
 6 files changed, 42 insertions(+), 14 deletions(-)
tools/perf/Documentation/perf-script.txt +1 -1
index db01786..ee4d477 100644
@@ -115,7 +115,7 @@ OPTIONS
 -f::
 --fields::
         Comma separated list of fields to print. Options are:
-        comm, tid, pid, time, cpu, event, trace, ip, sym, dso, addr.
+        comm, tid, pid, time, cpu, event, trace, ip, sym, dso, addr, offs.
         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 +17 -3
index 7708d89..fd68185 100644
@@ -37,6 +37,7 @@ enum perf_output_field {
 	PERF_OUTPUT_SYM             = 1U << 8,
 	PERF_OUTPUT_DSO             = 1U << 9,
 	PERF_OUTPUT_ADDR            = 1U << 10,
+	PERF_OUTPUT_OFFSET          = 1U << 11,
 };
 
 struct output_option {
@@ -54,6 +55,7 @@ struct output_option {
 	{.str = "sym",   .field = PERF_OUTPUT_SYM},
 	{.str = "dso",   .field = PERF_OUTPUT_DSO},
 	{.str = "addr",  .field = PERF_OUTPUT_ADDR},
+	{.str = "offs",  .field = PERF_OUTPUT_OFFSET},
 };
 
 /* default set to maintain compatibility with current format */
@@ -190,6 +192,11 @@ static int perf_evsel__check_attr(struct perf_evsel *evsel,
 		       "to symbols.\n");
 		return -EINVAL;
 	}
+	if (PRINT_FIELD(OFFSET) && !PRINT_FIELD(SYM)) {
+		pr_err("Display of offsets requested but symbol is not"
+		       "selected.\n");
+		return -EINVAL;
+	}
 	if (PRINT_FIELD(DSO) && !PRINT_FIELD(IP) && !PRINT_FIELD(ADDR)) {
 		pr_err("Display of DSO requested but neither sample IP nor "
 			   "sample address\nis selected. Hence, no addresses to convert "
@@ -350,7 +357,10 @@ static void print_sample_addr(union perf_event *event,
 
 	if (PRINT_FIELD(SYM)) {
 		printf(" ");
-		symbol__print_symname(al.sym);
+		if (PRINT_FIELD(OFFSET))
+			symbol__print_symname_offs(al.sym, &al);
+		else
+			symbol__print_symname(al.sym);
 	}
 
 	if (PRINT_FIELD(DSO)) {
@@ -386,7 +396,8 @@ static void process_event(union perf_event *event __unused,
 		else
 			printf("\n");
 		perf_session__print_ip(event, sample, session,
-					      PRINT_FIELD(SYM), PRINT_FIELD(DSO));
+				       PRINT_FIELD(SYM), PRINT_FIELD(DSO),
+				       PRINT_FIELD(OFFSET));
 	}
 
 	printf("\n");
@@ -1082,7 +1093,10 @@ 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,raw. Fields: comm,tid,pid,time,cpu,event,trace,ip,sym,dso,addr",
+		     "comma separated output fields prepend with 'type:'. "
+		     "Valid types: hw,sw,trace,raw. "
+		     "Fields: comm,tid,pid,time,cpu,event,trace,ip,sym,dso,"
+		     "addr,offs",
 		     parse_output_fields),
 	OPT_STRING('c', "cpu", &cpu_list, "cpu", "list of cpus to profile"),
 
tools/perf/util/session.c +5 -2
index 442be3a..3728e67 100644
@@ -1211,7 +1211,7 @@ struct perf_evsel *perf_session__find_first_evtype(struct perf_session *session,
 void perf_session__print_ip(union perf_event *event,
 			    struct perf_sample *sample,
 			    struct perf_session *session,
-			    int print_sym, int print_dso)
+			    int print_sym, int print_dso, int print_offset)
 {
 	struct addr_location al;
 	struct callchain_cursor *cursor = &session->callchain_cursor;
@@ -1258,7 +1258,10 @@ void perf_session__print_ip(union perf_event *event,
 		printf("%16" PRIx64, sample->ip);
 		if (print_sym) {
 			printf(" ");
-			symbol__print_symname(al.sym);
+			if (print_offset)
+				symbol__print_symname_offs(al.sym, &al);
+			else
+				symbol__print_symname(al.sym);
 		}
 
 		if (print_dso) {
tools/perf/util/session.h +2 -1
index 5de754f..e6e5586 100644
@@ -170,7 +170,8 @@ struct perf_evsel *perf_session__find_first_evtype(struct perf_session *session,
 void perf_session__print_ip(union perf_event *event,
 				 struct perf_sample *sample,
 				 struct perf_session *session,
-				 int print_sym, int print_dso);
+				 int print_sym, int print_dso,
+				 int print_offset);
 
 int perf_session__cpu_bitmap(struct perf_session *session,
 			     const char *cpu_list, unsigned long *cpu_bitmap);
tools/perf/util/symbol.c +15 -7
index 85e19c4..abfecf6 100644
@@ -175,16 +175,24 @@ static size_t symbol__fprintf(struct symbol *sym, FILE *fp)
 		       sym->name);
 }
 
-void symbol__print_symname(const struct symbol *sym)
+void symbol__print_symname_offs(const struct symbol *sym,
+				const struct addr_location *al)
 {
-	const char *symname;
+	unsigned long offset;
 
-	if (sym && sym->name)
-		symname = sym->name;
-	else
-		symname = "(unknown)";
+	if (sym && sym->name) {
+		printf("%s", sym->name);
+		if (al) {
+			offset = al->addr - sym->start;
+			printf("+0x%lx", offset);
+		}
+	} else
+		printf("(unknown)");
+}
 
-	printf("%s", symname);
+void symbol__print_symname(const struct symbol *sym)
+{
+	symbol__print_symname_offs(sym, NULL);
 }
 
 void dso__set_long_name(struct dso *dso, char *name)
tools/perf/util/symbol.h +2 -0
index 1ec17b4..554b2fe 100644
@@ -238,6 +238,8 @@ void machines__destroy_guest_kernel_maps(struct rb_root *machines);
 
 int symbol__init(void);
 void symbol__exit(void);
+void symbol__print_symname_offs(const struct symbol *sym,
+				const struct addr_location *al);
 void symbol__print_symname(const struct symbol *sym);
 bool symbol_type__is_a(char symbol_type, enum map_type map_type);
 
#19 lore raw

PATCH v2 6/6 perf script: add option resolving vmlinux path

In reply to Akihiro Nagai

Add the option get the path of [kernel.kallsyms]. Specify '--show-kernel-path' option to use this function. This patch enables other applications to use this output easily.

Without --show-kernel-path option

# perf script -f ip,dso
ffffffff81467612 irq_return ([kernel.kallsyms])
ffffffff81467612 irq_return ([kernel.kallsyms])
    7f24fc02a6b3 _start (/lib64/ld-2.14.so)
[snip]

With --show-kernel-path option

# perf script -f ip,dso --show-kernel-path
ffffffff81467612 irq_return (/lib/modules/3.0.0-rc6-tip+/build/vmlinux)
ffffffff81467612 irq_return (/lib/modules/3.0.0-rc6-tip+/build/vmlinux)
    7f24fc02a6b3 _start (/lib64/ld-2.14.so)
[snip]
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]>
Cc David Ahern <[email protected]>
Cc Masami Hiramatsu <[email protected]>

---

 tools/perf/Documentation/perf-script.txt |    3 +++
 tools/perf/builtin-script.c              |    2 ++
 tools/perf/util/map.c                    |    7 +++++--
 tools/perf/util/session.c                |    2 ++
 tools/perf/util/symbol.c                 |    1 +
 tools/perf/util/symbol.h                 |    1 +
 6 files changed, 14 insertions(+), 2 deletions(-)
tools/perf/Documentation/perf-script.txt +3 -0
index ee4d477..5383671 100644
@@ -188,6 +188,9 @@ OPTIONS
 	CPUs are specified with -: 0-2. Default is to report samples on all
 	CPUs.
 
+--show-kernel-path::
+	Try to resolve the path of [kernel.kallsyms]
+
 SEE ALSO
 --------
 linkperf:perf-record[1], linkperf:perf-script-perl[1],
tools/perf/builtin-script.c +2 -0
index fd68185..0d04788 100644
@@ -1099,6 +1099,8 @@ static const struct option options[] = {
 		     "addr,offs",
 		     parse_output_fields),
 	OPT_STRING('c', "cpu", &cpu_list, "cpu", "list of cpus to profile"),
+	OPT_BOOLEAN('\0', "show-kernel-path", &show_kernel_path,
+		    "Show the path of [kernel.kallsyms]"),
 
 	OPT_END()
 };
tools/perf/util/map.c +5 -2
index dddc0f3..1645967 100644
@@ -204,9 +204,12 @@ void map__print_dsoname(struct map *self)
 {
 	const char *dsoname;
 
-	if (self && self->dso && self->dso->name)
+	if (self && self->dso && (self->dso->name || self->dso->long_name)) {
+		if (show_kernel_path && self->dso->long_name)
+			dsoname = self->dso->long_name;
+		else if (self->dso->name)
 			dsoname = self->dso->name;
-	else
+	} else
 		dsoname = "[unknown]";
 
 	printf("%s", dsoname);
tools/perf/util/session.c +2 -0
index 3728e67..34c5887 100644
@@ -14,6 +14,8 @@
 #include "util.h"
 #include "cpumap.h"
 
+bool show_kernel_path;
+
 static int perf_session__open(struct perf_session *self, bool force)
 {
 	struct stat input_stat;
tools/perf/util/symbol.c +1 -0
index abfecf6..3356d6e 100644
@@ -41,6 +41,7 @@ static int dso__load_guest_kernel_sym(struct dso *dso, struct map *map,
 			symbol_filter_t filter);
 static int vmlinux_path__nr_entries;
 static char **vmlinux_path;
+bool show_kernel_path;
 
 struct symbol_conf symbol_conf = {
 	.exclude_other	  = true,
tools/perf/util/symbol.h +1 -0
index 554b2fe..88000e5 100644
@@ -96,6 +96,7 @@ struct symbol_conf {
 };
 
 extern struct symbol_conf symbol_conf;
+extern bool show_kernel_path;
 
 static inline void *symbol__priv(struct symbol *sym)
 {
#20 lore raw

Re: [PATCH -tip v2 6/6] perf script: add option resolving vmlinux path

Quoted 102 lines · Akihiro Nagai

Add the option get the path of [kernel.kallsyms]. Specify '--show-kernel-path' option to use this function. This patch enables other applications to use this output easily.

Without --show-kernel-path option

# perf script -f ip,dso
ffffffff81467612 irq_return ([kernel.kallsyms])
ffffffff81467612 irq_return ([kernel.kallsyms])
    7f24fc02a6b3 _start (/lib64/ld-2.14.so)
[snip]

With --show-kernel-path option

# perf script -f ip,dso --show-kernel-path
ffffffff81467612 irq_return (/lib/modules/3.0.0-rc6-tip+/build/vmlinux)
ffffffff81467612 irq_return (/lib/modules/3.0.0-rc6-tip+/build/vmlinux)
    7f24fc02a6b3 _start (/lib64/ld-2.14.so)
[snip]
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]>
Cc David Ahern <[email protected]>
Cc Masami Hiramatsu <[email protected]>

---

 tools/perf/Documentation/perf-script.txt |    3 +++
 tools/perf/builtin-script.c              |    2 ++
 tools/perf/util/map.c                    |    7 +++++--
 tools/perf/util/session.c                |    2 ++
 tools/perf/util/symbol.c                 |    1 +
 tools/perf/util/symbol.h                 |    1 +
 6 files changed, 14 insertions(+), 2 deletions(-)
tools/perf/Documentation/perf-script.txt +3 -0
index ee4d477..5383671 100644
@@ -188,6 +188,9 @@ OPTIONS
 	CPUs are specified with -: 0-2. Default is to report samples on all
 	CPUs.
 
+--show-kernel-path::
+	Try to resolve the path of [kernel.kallsyms]
+
 SEE ALSO
 --------
 linkperf:perf-record[1], linkperf:perf-script-perl[1],
tools/perf/builtin-script.c +2 -0
index fd68185..0d04788 100644
@@ -1099,6 +1099,8 @@ static const struct option options[] = {
 		     "addr,offs",
 		     parse_output_fields),
 	OPT_STRING('c', "cpu", &cpu_list, "cpu", "list of cpus to profile"),
+	OPT_BOOLEAN('\0', "show-kernel-path", &show_kernel_path,
+		    "Show the path of [kernel.kallsyms]"),
 
 	OPT_END()
 };
tools/perf/util/map.c +5 -2
index dddc0f3..1645967 100644
@@ -204,9 +204,12 @@ void map__print_dsoname(struct map *self)
 {
 	const char *dsoname;
 
-	if (self && self->dso && self->dso->name)
+	if (self && self->dso && (self->dso->name || self->dso->long_name)) {
+		if (show_kernel_path && self->dso->long_name)
+			dsoname = self->dso->long_name;
+		else if (self->dso->name)
 			dsoname = self->dso->name;
-	else
+	} else
 		dsoname = "[unknown]";
 
 	printf("%s", dsoname);
tools/perf/util/session.c +2 -0
index 3728e67..34c5887 100644
@@ -14,6 +14,8 @@
 #include "util.h"
 #include "cpumap.h"
 
+bool show_kernel_path;
+
 static int perf_session__open(struct perf_session *self, bool force)
 {
 	struct stat input_stat;
tools/perf/util/symbol.c +0 -0
index abfecf6..3356d6e 100644

tools/perf/util/symbol.c static int dso__load_guest_kernel_sym(struct dso *dso, struct map *map, · line 44

Quoted 4 lines
tools/perf/util/symbol.c +1 -0
@@ -41,6 +41,7 @@ static int dso__load_guest_kernel_sym(struct dso *dso, struct map *map,
 			symbol_filter_t filter);
 static int vmlinux_path__nr_entries;
 static char **vmlinux_path;
+bool show_kernel_path;

declared twice. See above in session.c. I suggest removing the one in session.c

David

Quoted 16 lines
tools/perf/util/symbol.c +0 -0
 struct symbol_conf symbol_conf = {
 	.exclude_other	  = true,
tools/perf/util/symbol.h +1 -0
index 554b2fe..88000e5 100644
@@ -96,6 +96,7 @@ struct symbol_conf {
 };
 
 extern struct symbol_conf symbol_conf;
+extern bool show_kernel_path;
 
 static inline void *symbol__priv(struct symbol *sym)
 {
#21 lore raw

Re: [PATCH -tip v2 6/6] perf script: add option resolving vmlinux path

Quoted 102 lines · David Ahern
Quoted 101 lines · Akihiro Nagai

Add the option get the path of [kernel.kallsyms]. Specify '--show-kernel-path' option to use this function. This patch enables other applications to use this output easily.

Without --show-kernel-path option

# perf script -f ip,dso
ffffffff81467612 irq_return ([kernel.kallsyms])
ffffffff81467612 irq_return ([kernel.kallsyms])
     7f24fc02a6b3 _start (/lib64/ld-2.14.so)
[snip]

With --show-kernel-path option

# perf script -f ip,dso --show-kernel-path
ffffffff81467612 irq_return (/lib/modules/3.0.0-rc6-tip+/build/vmlinux)
ffffffff81467612 irq_return (/lib/modules/3.0.0-rc6-tip+/build/vmlinux)
     7f24fc02a6b3 _start (/lib64/ld-2.14.so)
[snip]
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]>
Cc David Ahern<[email protected]>
Cc Masami Hiramatsu<[email protected]>

---

  tools/perf/Documentation/perf-script.txt |    3 +++
  tools/perf/builtin-script.c              |    2 ++
  tools/perf/util/map.c                    |    7 +++++--
  tools/perf/util/session.c                |    2 ++
  tools/perf/util/symbol.c                 |    1 +
  tools/perf/util/symbol.h                 |    1 +
  6 files changed, 14 insertions(+), 2 deletions(-)
tools/perf/Documentation/perf-script.txt +3 -0
index ee4d477..5383671 100644
@@ -188,6 +188,9 @@ OPTIONS
  	CPUs are specified with -: 0-2. Default is to report samples on all
  	CPUs.
 
+--show-kernel-path::
+	Try to resolve the path of [kernel.kallsyms]
+
  SEE ALSO
  --------
  linkperf:perf-record[1], linkperf:perf-script-perl[1],
tools/perf/builtin-script.c +2 -0
index fd68185..0d04788 100644
@@ -1099,6 +1099,8 @@ static const struct option options[] = {
  		     "addr,offs",
  		     parse_output_fields),
  	OPT_STRING('c', "cpu",&cpu_list, "cpu", "list of cpus to profile"),
+	OPT_BOOLEAN('\0', "show-kernel-path",&show_kernel_path,
+		    "Show the path of [kernel.kallsyms]"),
 
  	OPT_END()
  };
tools/perf/util/map.c +5 -2
index dddc0f3..1645967 100644
@@ -204,9 +204,12 @@ void map__print_dsoname(struct map *self)
  {
  	const char *dsoname;
 
-	if (self&&  self->dso&&  self->dso->name)
+	if (self&&  self->dso&&  (self->dso->name || self->dso->long_name)) {
+		if (show_kernel_path&&  self->dso->long_name)
+			dsoname = self->dso->long_name;
+		else if (self->dso->name)
  			dsoname = self->dso->name;
-	else
+	} else
  		dsoname = "[unknown]";
 
  	printf("%s", dsoname);
tools/perf/util/session.c +2 -0
index 3728e67..34c5887 100644
@@ -14,6 +14,8 @@
  #include "util.h"
  #include "cpumap.h"
 
+bool show_kernel_path;
+
  static int perf_session__open(struct perf_session *self, bool force)
  {
  	struct stat input_stat;
tools/perf/util/symbol.c +0 -0
index abfecf6..3356d6e 100644
Quoted 8 lines

tools/perf/util/symbol.c static int dso__load_guest_kernel_sym(struct dso *dso, struct map *map, · line 44

Quoted 5 lines
tools/perf/util/symbol.c +1 -0
@@ -41,6 +41,7 @@ static int dso__load_guest_kernel_sym(struct dso *dso, struct map *map,
  			symbol_filter_t filter);
  static int vmlinux_path__nr_entries;
  static char **vmlinux_path;
+bool show_kernel_path;

declared twice. See above in session.c. I suggest removing the one in session.c

Oops. I forgot to delete it.
Thank you.

Quoted 20 lines

David

Quoted 16 lines
tools/perf/util/symbol.c +0 -0
  struct symbol_conf symbol_conf = {
  	.exclude_other	  = true,
tools/perf/util/symbol.h +1 -0
index 554b2fe..88000e5 100644
@@ -96,6 +96,7 @@ struct symbol_conf {
  };
 
  extern struct symbol_conf symbol_conf;
+extern bool show_kernel_path;
 
  static inline void *symbol__priv(struct symbol *sym)
  {