[PATCH v1 2/2] perf annotate: Honor explicit --source option

Kohei Enju <[email protected]>
Newsgroups org.kernel.vger.linux-perf-users
Message-ID <[email protected]>
Source annotation is hidden by default to avoid forcing objdump -S, but
currently an explicit --source doesn't override annotate.hide_src_code.

In TUI mode, source code can be shown later with the 's' hotkey, which
re-runs annotation with hide_src_code cleared. In --stdio/--stdio2 mode,
there is no such interactive fallback, so --source did not show source
code unless users also set annotate.hide_src_code=false globally in
advance.

Track whether --source/--no-source was specified and synchronize
hide_src_code only in that case.

Fixes: e201757f7a0a ("perf annotate: Fix source code annotate with objdump")
Signed-off-by: Kohei Enju <[email protected]>
---
 tools/perf/Documentation/perf-annotate.txt | 4 ++--
 tools/perf/Documentation/perf-report.txt   | 4 ++--
 tools/perf/Documentation/perf-top.txt      | 4 ++--
 tools/perf/builtin-annotate.c              | 7 +++++--
 tools/perf/builtin-report.c                | 7 +++++--
 tools/perf/builtin-top.c                   | 7 +++++--
 6 files changed, 21 insertions(+), 12 deletions(-)

diff --git a/tools/perf/Documentation/perf-annotate.txt b/tools/perf/Documentation/perf-annotate.txt
index a688738809c4..dc5866cf6666 100644
--- a/tools/perf/Documentation/perf-annotate.txt
+++ b/tools/perf/Documentation/perf-annotate.txt
@@ -107,8 +107,8 @@ include::itrace.txt[]
 --show-total-period:: Show a column with the sum of periods.
 
 --source::
-	Interleave source code with assembly code. Enabled by default,
-	disable with --no-source.
+	Interleave source code with assembly code. This may use objdump and be
+	slower than the default disassembly. Disable with --no-source.
 
 --symfs=<directory[,layout]>::
         Look for files with symbols relative to this directory. The optional
diff --git a/tools/perf/Documentation/perf-report.txt b/tools/perf/Documentation/perf-report.txt
index 22f87eaa3279..d494b9a37663 100644
--- a/tools/perf/Documentation/perf-report.txt
+++ b/tools/perf/Documentation/perf-report.txt
@@ -388,8 +388,8 @@ OPTIONS
 --disassembler-style=:: Set disassembler style for objdump.
 
 --source::
-	Interleave source code with assembly code. Enabled by default,
-	disable with --no-source.
+	Interleave source code with assembly code. This may use objdump and be
+	slower than the default disassembly. Disable with --no-source.
 
 --asm-raw::
 	Show raw instruction encoding of assembly instructions.
diff --git a/tools/perf/Documentation/perf-top.txt b/tools/perf/Documentation/perf-top.txt
index af3e4230c72f..0e5372988a1f 100644
--- a/tools/perf/Documentation/perf-top.txt
+++ b/tools/perf/Documentation/perf-top.txt
@@ -178,8 +178,8 @@ Default is to monitor all CPUS.
         with different file system layout.
 
 --source::
-	Interleave source code with assembly code. Enabled by default,
-	disable with --no-source.
+	Interleave source code with assembly code. This may use objdump and be
+	slower than the default disassembly. Disable with --no-source.
 
 --asm-raw::
 	Show raw instruction encoding of assembly instructions.
diff --git a/tools/perf/builtin-annotate.c b/tools/perf/builtin-annotate.c
index 8a0eb30eac24..cb8ce851a81e 100644
--- a/tools/perf/builtin-annotate.c
+++ b/tools/perf/builtin-annotate.c
@@ -692,6 +692,7 @@ static const char * const annotate_usage[] = {
 int cmd_annotate(int argc, const char **argv)
 {
 	struct perf_annotate annotate = {};
+	bool source_set = false;
 	struct perf_data data = {
 		.mode  = PERF_DATA_MODE_READ,
 	};
@@ -738,8 +739,8 @@ int cmd_annotate(int argc, const char **argv)
 	OPT_STRING('C', "cpu", &annotate.cpu_list, "cpu", "list of cpus to profile"),
 	OPT_CALLBACK(0, "symfs", NULL, "directory[,layout]", SYMFS_HELP,
 		     symbol__config_symfs),
-	OPT_BOOLEAN(0, "source", &annotate_opts.annotate_src,
-		    "Interleave source code with assembly code (default)"),
+	OPT_BOOLEAN_SET(0, "source", &annotate_opts.annotate_src, &source_set,
+			"Interleave source code with assembly code"),
 	OPT_BOOLEAN(0, "asm-raw", &annotate_opts.show_asm_raw,
 		    "Display raw encoding of assembly instructions (default)"),
 	OPT_STRING('M', "disassembler-style", &disassembler_style, "disassembler style",
@@ -798,6 +799,8 @@ int cmd_annotate(int argc, const char **argv)
 	annotation_config__init();
 
 	argc = parse_options(argc, argv, options, annotate_usage, 0);
+	if (source_set)
+		annotate_opts.hide_src_code = !annotate_opts.annotate_src;
 	if (argc) {
 		/*
 		 * Special case: if there's an argument left then assume that
diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c
index dd1309c32094..cfd611ca6ffe 100644
--- a/tools/perf/builtin-report.c
+++ b/tools/perf/builtin-report.c
@@ -1306,6 +1306,7 @@ int cmd_report(int argc, const char **argv)
 	struct itrace_synth_opts itrace_synth_opts = { .set = 0, };
 	struct stat st;
 	bool has_br_stack = false;
+	bool source_set = false;
 	int branch_mode = -1;
 	int last_key = 0;
 	bool branch_call_mode = false;
@@ -1420,8 +1421,8 @@ int cmd_report(int argc, const char **argv)
 		   "only consider these parallelism levels (cpu set format)"),
 	OPT_BOOLEAN('I', "show-info", &report.show_full_info,
 		    "Display extended information about perf.data file"),
-	OPT_BOOLEAN(0, "source", &annotate_opts.annotate_src,
-		    "Interleave source code with assembly code (default)"),
+	OPT_BOOLEAN_SET(0, "source", &annotate_opts.annotate_src, &source_set,
+			"Interleave source code with assembly code"),
 	OPT_BOOLEAN(0, "asm-raw", &annotate_opts.show_asm_raw,
 		    "Display raw encoding of assembly instructions (default)"),
 	OPT_STRING('M', "disassembler-style", &disassembler_style, "disassembler style",
@@ -1853,6 +1854,8 @@ int cmd_report(int argc, const char **argv)
 			symbol_conf.priv_size += sizeof(u32);
 		}
 		annotation_config__init();
+		if (source_set)
+			annotate_opts.hide_src_code = !annotate_opts.annotate_src;
 	}
 
 	if (symbol__init(perf_session__env(session)) < 0)
diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c
index 1211401616ee..cc06e7332e47 100644
--- a/tools/perf/builtin-top.c
+++ b/tools/perf/builtin-top.c
@@ -1483,6 +1483,7 @@ int cmd_top(int argc, const char **argv)
 		.evlistp = &top.evlist,
 	};
 	bool branch_call_mode = false;
+	bool source_set = false;
 	struct record_opts *opts = &top.record_opts;
 	struct target *target = &opts->target;
 	const char *disassembler_style = NULL, *objdump_path = NULL, *addr2line_path = NULL;
@@ -1566,8 +1567,8 @@ int cmd_top(int argc, const char **argv)
 		   "only consider symbols in these comms"),
 	OPT_STRING(0, "symbols", &symbol_conf.sym_list_str, "symbol[,symbol...]",
 		   "only consider these symbols"),
-	OPT_BOOLEAN(0, "source", &annotate_opts.annotate_src,
-		    "Interleave source code with assembly code (default)"),
+	OPT_BOOLEAN_SET(0, "source", &annotate_opts.annotate_src, &source_set,
+			"Interleave source code with assembly code"),
 	OPT_BOOLEAN(0, "asm-raw", &annotate_opts.show_asm_raw,
 		    "Display raw encoding of assembly instructions (default)"),
 	OPT_BOOLEAN(0, "demangle-kernel", &symbol_conf.demangle_kernel,
@@ -1851,6 +1852,8 @@ int cmd_top(int argc, const char **argv)
 		goto out_delete_evlist;
 
 	annotation_config__init();
+	if (source_set)
+		annotate_opts.hide_src_code = !annotate_opts.annotate_src;
 
 	symbol_conf.try_vmlinux_path = (symbol_conf.vmlinux_name == NULL);
 	status = symbol__init(NULL);
-- 
2.53.0
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.