perf tools: Support full source file paths for srcline
authorAndi Kleen <ak@linux.intel.com>
Fri, 7 Aug 2015 22:24:05 +0000 (15:24 -0700)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Mon, 10 Aug 2015 14:58:05 +0000 (11:58 -0300)
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.

Signed-off-by: Andi Kleen <ak@linux.intel.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Link: http://lkml.kernel.org/r/1438986245-15191-1-git-send-email-andi@firstfloor.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/Documentation/perf-report.txt
tools/perf/Documentation/perf-script.txt
tools/perf/builtin-report.c
tools/perf/builtin-script.c
tools/perf/util/srcline.c
tools/perf/util/util.h

index 960da203ec11143ea529bfbf80b0fab0503322d5..1a782ef02b68b05989837a4e23814e32284636c0 100644 (file)
@@ -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[]
 
index e2fec5fc21e718b16e6b66d898376e92e9ac67b0..8e9be1f9c1dd54245c56dd0b40f71cb119148134 100644 (file)
@@ -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],
index 3a9d1b659fcd353a1b4df9222c13b83cda045efb..f301e865001f7f25f989523ced1c48b8cb1db113 100644 (file)
@@ -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 = {
index 7912feb9a0245c8fc3ecad51c652a6ff4a4d9387..7b376d215e9498417001c6c2cb7ab5ba2f770f53 100644 (file)
@@ -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 };
index c93fb0c5bd0b197190f7fbe6af9cf1840d274c4d..fc08248f08ca703b0a4330169535264854d5478c 100644 (file)
@@ -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;
        }
index 81487037acf7b84fa1b4c96311198f08a8453dae..88a891562a47c010774d85b068fda72c0b31d871 100644 (file)
@@ -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);