[PATCH v9 5/7] perf report/top: Add --lazy-load-symbols
From: Alireza Haghdoost via B4 Relay
Date: Tue Nov 24 2026 - 14:29:44 EST
From: Alireza Haghdoost <haghdoost@xxxxxxxx>
This patch adds the --lazy-load-symbols option of perf script to perf
report and perf top. Like perf script, they load the whole symbol table
of every DSO that appears in a sample and keep every name until exit.
The symbol code already handles both tools. The address lookups that
build the histogram entries and call chains load the names of the
symbols they return, and the TUI map browser gets all names from
dso__named_symbols().
perf top reads the names while it runs, which can be long, so a binary
that is updated in the meantime can show wrong names. The documentation
of perf top says so.
Suggested-by: Namhyung Kim <namhyung@xxxxxxxxxx>
Signed-off-by: Alireza Haghdoost <haghdoost@xxxxxxxx>
---
tools/perf/Documentation/perf-report.txt | 9 +++++++++
tools/perf/Documentation/perf-top.txt | 10 ++++++++++
tools/perf/builtin-report.c | 2 ++
tools/perf/builtin-top.c | 2 ++
4 files changed, 23 insertions(+)
diff --git a/tools/perf/Documentation/perf-report.txt b/tools/perf/Documentation/perf-report.txt
index e145124d6c9a..b8c34bb4cd74 100644
--- a/tools/perf/Documentation/perf-report.txt
+++ b/tools/perf/Documentation/perf-report.txt
@@ -347,6 +347,15 @@ OPTIONS
Default: 127
+--lazy-load-symbols::
+ Read and demangle userspace ELF symbol names only when perf needs
+ them. By default, perf reads every symbol name from each binary
+ referenced by a sample. This option reduces memory use when samples
+ reference only a small fraction of a large binary's symbols. The
+ names are read from the binaries while perf report runs, so the
+ binaries must not change in the meantime. If a binary cannot be
+ opened when a name is needed, perf shows that symbol as unknown.
+
-G::
--inverted::
alias for inverted caller based call graph.
diff --git a/tools/perf/Documentation/perf-top.txt b/tools/perf/Documentation/perf-top.txt
index c5e96da6ed82..9ec039c8e0b9 100644
--- a/tools/perf/Documentation/perf-top.txt
+++ b/tools/perf/Documentation/perf-top.txt
@@ -218,6 +218,16 @@ Default is to monitor all CPUS.
Default: /proc/sys/kernel/perf_event_max_stack when present, 127 otherwise.
+--lazy-load-symbols::
+ Read and demangle userspace ELF symbol names only when perf needs
+ them. By default, perf reads every symbol name from each binary
+ referenced by a sample. This option reduces memory use when samples
+ reference only a small fraction of a large binary's symbols. The
+ names are read from the binaries while perf top runs, so a binary
+ that is updated in the meantime can show wrong names. If a binary
+ cannot be opened when a name is needed, perf shows that symbol as
+ unknown.
+
--ignore-callees=<regex>::
Ignore callees of the function(s) matching the given regex.
This has the effect of collecting the callers of each such
diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c
index 6672a4d16529..8ca54463a84b 100644
--- a/tools/perf/builtin-report.c
+++ b/tools/perf/builtin-report.c
@@ -1414,6 +1414,8 @@ int cmd_report(int argc, const char **argv)
"Set the maximum stack depth when parsing the callchain, "
"anything beyond the specified depth will be ignored. "
"Default: kernel.perf_event_max_stack or " __stringify(PERF_MAX_STACK_DEPTH)),
+ OPT_BOOLEAN(0, "lazy-load-symbols", &symbol_conf.lazy_load_symbols,
+ "Read symbol names only when they are needed"),
OPT_BOOLEAN('G', "inverted", &report.inverted_callchain,
"alias for inverted call graph"),
OPT_CALLBACK(0, "ignore-callees", NULL, "regex",
diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c
index a79230b81300..02363e5c6460 100644
--- a/tools/perf/builtin-top.c
+++ b/tools/perf/builtin-top.c
@@ -1589,6 +1589,8 @@ int cmd_top(int argc, const char **argv)
OPT_INTEGER(0, "max-stack", &top.max_stack,
"Set the maximum stack depth when parsing the callchain. "
"Default: kernel.perf_event_max_stack or " __stringify(PERF_MAX_STACK_DEPTH)),
+ OPT_BOOLEAN(0, "lazy-load-symbols", &symbol_conf.lazy_load_symbols,
+ "Read symbol names only when they are needed"),
OPT_CALLBACK(0, "ignore-callees", NULL, "regex",
"ignore callees of these functions in call graphs",
report_parse_ignore_callees_opt),
--
Git-157)