Skip to contentSkip to conversation

perf, tools: Support full source file paths for srcline

PATCH Applied Andi Kleen 3 participants 3 messages Aug 7, 2015 – Aug 12, 2015 perf events

lore
Share & tools
lore

Andi Kleen

author
#0 lore raw

PATCH 1/1 perf, tools: Support full source file paths for srcline

From: Andi Kleen <[email protected]>

For perf report/script srcline currently only the base file name of the source file is printed. This is a good default because it usually fits on the screen.

But in some cases we want to know the full file name, for example to aggregate hits per file.

In the later case we need more than the base file name to resolve file naming collisions: for example the kernel source has ~70 files named "core.c"

It's also useful as input to post processing tools which want to point to the right file.

Add a flag to allow full file name output.

Add an option to perf report/script to enable this option.

---
 tools/perf/Documentation/perf-report.txt | 2 ++
 tools/perf/Documentation/perf-script.txt | 3 +++
 tools/perf/builtin-report.c              | 2 ++
 tools/perf/builtin-script.c              | 2 ++
 tools/perf/util/srcline.c                | 6 +++++-
 tools/perf/util/util.h                   | 1 +
 6 files changed, 15 insertions(+), 1 deletion(-)
tools/perf/Documentation/perf-report.txt +2 -0
index c33b69f..aabb1b4 100644
@@ -353,6 +353,8 @@ OPTIONS
 
 	To disable decoding entirely, use --no-itrace.
 
+--full-source-path::
+	Show the full path for source files for srcline output.
 
 include::callchain-overhead-calculation.txt[]
 
tools/perf/Documentation/perf-script.txt +3 -0
index c82df57..7860274 100644
@@ -256,6 +256,9 @@ OPTIONS
 
 	To disable decoding entirely, use --no-itrace.
 
+--full-source-path::
+	Show the full path for source files for srcline output.
+
 SEE ALSO
 --------
 linkperf:perf-record[1], linkperf:perf-script-perl[1],
tools/perf/builtin-report.c +2 -0
index 95a4771..c8561cb 100644
@@ -728,6 +728,8 @@ int cmd_report(int argc, const char **argv, const char *prefix __maybe_unused)
 	OPT_CALLBACK_OPTARG(0, "itrace", &itrace_synth_opts, NULL, "opts",
 			    "Instruction Tracing options",
 			    itrace_parse_synth_opts),
+	OPT_BOOLEAN(0, "full-source-path", &srcline_full_filename,
+			"Show full source file name path for source lines"),
 	OPT_END()
 	};
 	struct perf_data_file file = {
tools/perf/builtin-script.c +2 -0
index 24809787..220cbff 100644
@@ -1622,6 +1622,8 @@ int cmd_script(int argc, const char **argv, const char *prefix __maybe_unused)
 	OPT_CALLBACK_OPTARG(0, "itrace", &itrace_synth_opts, NULL, "opts",
 			    "Instruction Tracing options",
 			    itrace_parse_synth_opts),
+	OPT_BOOLEAN(0, "full-source-path", &srcline_full_filename,
+			"Show full source file name path for source lines"),
 	OPT_END()
 	};
 	const char * const script_subcommands[] = { "record", "report", NULL };
tools/perf/util/srcline.c +5 -1
index c93fb0c..fc08248 100644
@@ -10,6 +10,8 @@
 
 #include "symbol.h"
 
+bool srcline_full_filename;
+
 #ifdef HAVE_LIBBFD_SUPPORT
 
 /*
@@ -277,7 +279,9 @@ char *get_srcline(struct dso *dso, u64 addr, struct symbol *sym,
 	if (!addr2line(dso_name, addr, &file, &line, dso))
 		goto out;
 
-	if (asprintf(&srcline, "%s:%u", basename(file), line) < 0) {
+	if (asprintf(&srcline, "%s:%u",
+				srcline_full_filename ? file : basename(file),
+				line) < 0) {
 		free(file);
 		goto out;
 	}
tools/perf/util/util.h +1 -0
index 20d625a..282f737 100644
@@ -318,6 +318,7 @@ static inline int path__join3(char *bf, size_t size,
 struct dso;
 struct symbol;
 
+extern bool srcline_full_filename;
 char *get_srcline(struct dso *dso, u64 addr, struct symbol *sym,
 		  bool show_sym);
 void free_srcline(char *srcline);
Signature · 1 line
2.4.3
maintainer Applied
#1 lore raw

Em Fri, Aug 07, 2015 at 03:24:05PM -0700, Andi Kleen escreveu:

Quoted 13 lines

From: Andi Kleen <[email protected]>

For perf report/script srcline currently only the base file name of the source file is printed. This is a good default because it usually fits on the screen.

But in some cases we want to know the full file name, for example to aggregate hits per file.

In the later case we need more than the base file name to resolve file naming collisions: for example the kernel source has ~70 files named "core.c"

Quoted 6 lines

It's also useful as input to post processing tools which want to point to the right file.

Add a flag to allow full file name output.

Add an option to perf report/script to enable this option.

Applied

#2 lore raw

[tip:perf/core] perf tools: Support full source file paths for srcline

In reply to Andi Kleen
perf tools: Support full source file paths for srcline
Commit-ID:  a9710ba091b0dcdace90f791706e9192313ffb7c
Gitweb:     http://git.kernel.org/tip/a9710ba091b0dcdace90f791706e9192313ffb7c
Author:     Andi Kleen <[email protected]>
AuthorDate: Fri, 7 Aug 2015 15:24:05 -0700
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Mon, 10 Aug 2015 11:58:05 -0300

perf tools: Support full source file paths for srcline

For perf report/script srcline currently only the base file name of the source file is printed. This is a good default because it usually fits on the screen.

But in some cases we want to know the full file name, for example to aggregate hits per file.

In the later case we need more than the base file name to resolve file naming collisions: for example the kernel source has ~70 files named "core.c"

It's also useful as input to post processing tools which want to point to the right file.

Add a flag to allow full file name output.

Add an option to perf report/script to enable this option.

---
 tools/perf/Documentation/perf-report.txt | 2 ++
 tools/perf/Documentation/perf-script.txt | 3 +++
 tools/perf/builtin-report.c              | 2 ++
 tools/perf/builtin-script.c              | 2 ++
 tools/perf/util/srcline.c                | 6 +++++-
 tools/perf/util/util.h                   | 1 +
 6 files changed, 15 insertions(+), 1 deletion(-)
tools/perf/Documentation/perf-report.txt +2 -0
index 960da20..1a782ef 100644
@@ -354,6 +354,8 @@ OPTIONS
 
 	To disable decoding entirely, use --no-itrace.
 
+--full-source-path::
+	Show the full path for source files for srcline output.
 
 include::callchain-overhead-calculation.txt[]
 
tools/perf/Documentation/perf-script.txt +3 -0
index e2fec5f..8e9be1f 100644
@@ -260,6 +260,9 @@ OPTIONS
 
 	To disable decoding entirely, use --no-itrace.
 
+--full-source-path::
+	Show the full path for source files for srcline output.
+
 SEE ALSO
 --------
 linkperf:perf-record[1], linkperf:perf-script-perl[1],
tools/perf/builtin-report.c +2 -0
index 3a9d1b6..f301e86 100644
@@ -738,6 +738,8 @@ int cmd_report(int argc, const char **argv, const char *prefix __maybe_unused)
 	OPT_CALLBACK_OPTARG(0, "itrace", &itrace_synth_opts, NULL, "opts",
 			    "Instruction Tracing options",
 			    itrace_parse_synth_opts),
+	OPT_BOOLEAN(0, "full-source-path", &srcline_full_filename,
+			"Show full source file name path for source lines"),
 	OPT_END()
 	};
 	struct perf_data_file file = {
tools/perf/builtin-script.c +2 -0
index 7912feb..7b376d2 100644
@@ -1653,6 +1653,8 @@ int cmd_script(int argc, const char **argv, const char *prefix __maybe_unused)
 	OPT_CALLBACK_OPTARG(0, "itrace", &itrace_synth_opts, NULL, "opts",
 			    "Instruction Tracing options",
 			    itrace_parse_synth_opts),
+	OPT_BOOLEAN(0, "full-source-path", &srcline_full_filename,
+			"Show full source file name path for source lines"),
 	OPT_END()
 	};
 	const char * const script_subcommands[] = { "record", "report", NULL };
tools/perf/util/srcline.c +5 -1
index c93fb0c..fc08248 100644
@@ -10,6 +10,8 @@
 
 #include "symbol.h"
 
+bool srcline_full_filename;
+
 #ifdef HAVE_LIBBFD_SUPPORT
 
 /*
@@ -277,7 +279,9 @@ char *get_srcline(struct dso *dso, u64 addr, struct symbol *sym,
 	if (!addr2line(dso_name, addr, &file, &line, dso))
 		goto out;
 
-	if (asprintf(&srcline, "%s:%u", basename(file), line) < 0) {
+	if (asprintf(&srcline, "%s:%u",
+				srcline_full_filename ? file : basename(file),
+				line) < 0) {
 		free(file);
 		goto out;
 	}
tools/perf/util/util.h +1 -0
index 8148703..88a8915 100644
@@ -318,6 +318,7 @@ static inline int path__join3(char *bf, size_t size,
 struct dso;
 struct symbol;
 
+extern bool srcline_full_filename;
 char *get_srcline(struct dso *dso, u64 addr, struct symbol *sym,
 		  bool show_sym);
 void free_srcline(char *srcline);