Commit 3b0b16bf authored by Andi Kleen's avatar Andi Kleen Committed by Arnaldo Carvalho de Melo
Browse files

perf tools: Support --prefix/--prefix-strip



The objdump utility has useful --prefix / --prefix-strip options to
allow changing source code file names hardcoded into executables' debug
info. Add options to 'perf report', 'perf top' and 'perf annotate',
which are then passed to objdump.

  $ mkdir foo
  $ echo 'main() { for (;;); }' > foo/foo.c
  $ gcc -g foo/foo.c
  foo/foo.c:1:1: warning: return type defaults to ‘int’ [-Wimplicit-int]
      1 | main() { for (;;); }
        | ^~~~
  $ perf record ./a.out
  ^C[ perf record: Woken up 1 times to write data ]
  [ perf record: Captured and wrote 0.230 MB perf.data (5721 samples) ]
  $ mv foo bar
  $ perf annotate
  <does not show source code>
  $ perf annotate --prefix=/home/ak/lsrc/git/bar --prefix-strip=5
  <does show source code>

Signed-off-by: default avatarAndi Kleen <ak@linux.intel.com>
Tested-by: default avatarJiri Olsa <jolsa@redhat.com>
LPU-Reference: 20200107210444.214071-1-andi@firstfloor.org
Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent aa9d1f83
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -112,6 +112,12 @@ OPTIONS
--objdump=<path>::
        Path to objdump binary.

--prefix=PREFIX::
--prefix-strip=N::
	Remove first N entries from source file path names in executables
	and add PREFIX. This allows to display source code compiled on systems
	with different file system layout.

--skip-missing::
	Skip symbols that cannot be annotated.

+6 −0
Original line number Diff line number Diff line
@@ -367,6 +367,12 @@ OPTIONS
--objdump=<path>::
        Path to objdump binary.

--prefix=PREFIX::
--prefix-strip=N::
	Remove first N entries from source file path names in executables
	and add PREFIX. This allows to display source code compiled on systems
	with different file system layout.

--group::
	Show event group information together. It forces group output also
	if there are no groups defined in data file.
+6 −0
Original line number Diff line number Diff line
@@ -158,6 +158,12 @@ Default is to monitor all CPUS.
-M::
--disassembler-style=:: Set disassembler style for objdump.

--prefix=PREFIX::
--prefix-strip=N::
        Remove first N entries from source file path names in executables
        and add PREFIX. This allows to display source code compiled on systems
        with different file system layout.

--source::
	Interleave source code with assembly code. Enabled by default,
	disable with --no-source.
+7 −0
Original line number Diff line number Diff line
@@ -535,6 +535,10 @@ int cmd_annotate(int argc, const char **argv)
		    "Display raw encoding of assembly instructions (default)"),
	OPT_STRING('M', "disassembler-style", &annotate.opts.disassembler_style, "disassembler style",
		   "Specify disassembler style (e.g. -M intel for intel syntax)"),
	OPT_STRING(0, "prefix", &annotate.opts.prefix, "prefix",
		    "Add prefix to source file path names in programs (with --prefix-strip)"),
	OPT_STRING(0, "prefix-strip", &annotate.opts.prefix_strip, "N",
		    "Strip first N entries of source file path name in programs (with --prefix)"),
	OPT_STRING(0, "objdump", &annotate.opts.objdump_path, "path",
		   "objdump binary to use for disassembly and annotations"),
	OPT_BOOLEAN(0, "group", &symbol_conf.event_group,
@@ -574,6 +578,9 @@ int cmd_annotate(int argc, const char **argv)
		annotate.sym_hist_filter = argv[0];
	}

	if (annotate_check_args(&annotate.opts) < 0)
		return -EINVAL;

	if (symbol_conf.show_nr_samples && annotate.use_gtk) {
		pr_err("--show-nr-samples is not available in --gtk mode at this time\n");
		return ret;
+7 −0
Original line number Diff line number Diff line
@@ -1208,6 +1208,10 @@ int cmd_report(int argc, const char **argv)
		    "Display raw encoding of assembly instructions (default)"),
	OPT_STRING('M', "disassembler-style", &report.annotation_opts.disassembler_style, "disassembler style",
		   "Specify disassembler style (e.g. -M intel for intel syntax)"),
	OPT_STRING(0, "prefix", &report.annotation_opts.prefix, "prefix",
		    "Add prefix to source file path names in programs (with --prefix-strip)"),
	OPT_STRING(0, "prefix-strip", &report.annotation_opts.prefix_strip, "N",
		    "Strip first N entries of source file path name in programs (with --prefix)"),
	OPT_BOOLEAN(0, "show-total-period", &symbol_conf.show_total_period,
		    "Show a column with the sum of periods"),
	OPT_BOOLEAN_SET(0, "group", &symbol_conf.event_group, &report.group_set,
@@ -1287,6 +1291,9 @@ int cmd_report(int argc, const char **argv)
		report.symbol_filter_str = argv[0];
	}

	if (annotate_check_args(&report.annotation_opts) < 0)
		return -EINVAL;

	if (report.mmaps_mode)
		report.tasks_mode = true;

Loading