From: duchangbin <changbin.du@huawei.com>
To: Ian Rogers <irogers@google.com>
Cc: duchangbin <changbin.du@huawei.com>,
Peter Zijlstra <peterz@infradead.org>,
Ingo Molnar <mingo@redhat.com>,
"Arnaldo Carvalho de Melo" <acme@kernel.org>,
Namhyung Kim <namhyung@kernel.org>,
Mark Rutland <mark.rutland@arm.com>,
Alexander Shishkin <alexander.shishkin@linux.intel.com>,
Jiri Olsa <jolsa@kernel.org>,
"Adrian Hunter" <adrian.hunter@intel.com>,
James Clark <james.clark@linaro.org>,
"linux-perf-users@vger.kernel.org"
<linux-perf-users@vger.kernel.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] perf: Add match_mode support for --symfs option
Date: Sun, 1 Mar 2026 11:06:43 +0000 [thread overview]
Message-ID: <babef420cf5e4af7bcfec28e2c8d23e8@huawei.com> (raw)
In-Reply-To: <CAP-5=fUr7V7=5CPyW2qm+m6B3NNYqvJ46pKvqQpn4kwWgMzOZQ@mail.gmail.com>
On Sat, Feb 28, 2026 at 05:26:54PM -0800, Ian Rogers wrote:
> On Sat, Feb 28, 2026 at 2:06 AM duchangbin <changbin.du@huawei.com> wrote:
> >
> > After careful consideration, naming the new option as 'layout' is more
> > appropriate than 'match_mode', as it better aligns with the conventions
> > of technical terminology.
> >
> > I'll send patch V2 for this change.
>
> Sgtm, some nits below.
>
[snip]
> > On Fri, Feb 27, 2026 at 11:13:40AM +0000, Changbin Du wrote:
> > > diff --git a/tools/perf/Documentation/tips.txt b/tools/perf/Documentation/tips.txt
> > > index 3fee9b2a88ea..268316596ba0 100644
> > > --- a/tools/perf/Documentation/tips.txt
> > > +++ b/tools/perf/Documentation/tips.txt
> > > @@ -11,7 +11,8 @@ Search options using a keyword: perf report -h <keyword>
> > > Use parent filter to see specific call path: perf report -p <regex>
> > > List events using substring match: perf list <keyword>
> > > To see list of saved events and attributes: perf evlist -v
> > > -Use --symfs <dir> if your symbol files are in non-standard locations
> > > +Use --symfs <dir>[,basename] if your symbol files are in non-standard locations.
> > > + Use ',basename' when debug files are in a flat directory structure.
>
> Should the documentation also mention ",path" ?
>
I changed it to --symfs <dir>[,layout] as below in patch V2.
-Use --symfs <dir> if your symbol files are in non-standard locations
+Use --symfs <dir>[,layout] if your symbol files are in non-standard locations.
> > > To see callchains in a more compact form: perf report -g folded
> > > To see call chains by final symbol taking CPU time (bottom up) use perf report -G
> > > Show individual samples with: perf script
> > > diff --git a/tools/perf/builtin-annotate.c b/tools/perf/builtin-annotate.c
> > > index 9c27bb30b708..f4ce70998423 100644
> > > --- a/tools/perf/builtin-annotate.c
> > > +++ b/tools/perf/builtin-annotate.c
> > > @@ -744,8 +744,7 @@ int cmd_annotate(int argc, const char **argv)
> > > &annotate.group_set,
> > > "Show event group information together"),
> > > OPT_STRING('C', "cpu", &annotate.cpu_list, "cpu", "list of cpus to profile"),
> > > - OPT_CALLBACK(0, "symfs", NULL, "directory",
> > > - "Look for files with symbols relative to this directory",
> > > + OPT_CALLBACK(0, "symfs", NULL, "directory[,match_mode]", SYMFS_HELP,
> > > symbol__config_symfs),
> > > OPT_BOOLEAN(0, "source", &annotate_opts.annotate_src,
> > > "Interleave source code with assembly code (default)"),
> > > diff --git a/tools/perf/builtin-diff.c b/tools/perf/builtin-diff.c
> > > index 59bf1f72d12e..7b7cc3c80dfd 100644
> > > --- a/tools/perf/builtin-diff.c
> > > +++ b/tools/perf/builtin-diff.c
> > > @@ -1280,8 +1280,7 @@ static const struct option options[] = {
> > > OPT_STRING_NOEMPTY('t', "field-separator", &symbol_conf.field_sep, "separator",
> > > "separator for columns, no spaces will be added between "
> > > "columns '.' is reserved."),
> > > - OPT_CALLBACK(0, "symfs", NULL, "directory",
> > > - "Look for files with symbols relative to this directory",
> > > + OPT_CALLBACK(0, "symfs", NULL, "directory[,match_mode]", SYMFS_HELP,
> > > symbol__config_symfs),
> > > OPT_UINTEGER('o', "order", &sort_compute, "Specify compute sorting."),
> > > OPT_CALLBACK(0, "percentage", NULL, "relative|absolute",
> > > diff --git a/tools/perf/builtin-kwork.c b/tools/perf/builtin-kwork.c
> > > index 7f3068264568..838471edb9e5 100644
> > > --- a/tools/perf/builtin-kwork.c
> > > +++ b/tools/perf/builtin-kwork.c
> > > @@ -2423,8 +2423,8 @@ int cmd_kwork(int argc, const char **argv)
> > > "Display call chains if present"),
> > > OPT_UINTEGER(0, "max-stack", &kwork.max_stack,
> > > "Maximum number of functions to display backtrace."),
> > > - OPT_STRING(0, "symfs", &symbol_conf.symfs, "directory",
> > > - "Look for files with symbols relative to this directory"),
> > > + OPT_CALLBACK(0, "symfs", NULL, "directory[,match_mode]", SYMFS_HELP,
> > > + symbol__config_symfs),
> > > OPT_STRING(0, "time", &kwork.time_str, "str",
> > > "Time span for analysis (start,stop)"),
> > > OPT_STRING('C', "cpu", &kwork.cpu_list, "cpu",
> > > diff --git a/tools/perf/builtin-probe.c b/tools/perf/builtin-probe.c
> > > index 1b4ba85ee019..e2912217153a 100644
> > > --- a/tools/perf/builtin-probe.c
> > > +++ b/tools/perf/builtin-probe.c
> > > @@ -597,8 +597,8 @@ __cmd_probe(int argc, const char **argv)
> > > OPT_BOOLEAN(0, "demangle-kernel", &symbol_conf.demangle_kernel,
> > > "Enable kernel symbol demangling"),
> > > OPT_BOOLEAN(0, "cache", &probe_conf.cache, "Manipulate probe cache"),
> > > - OPT_STRING(0, "symfs", &symbol_conf.symfs, "directory",
> > > - "Look for files with symbols relative to this directory"),
> > > + OPT_CALLBACK(0, "symfs", NULL, "directory[,match_mode]", SYMFS_HELP,
> > > + symbol__config_symfs),
> > > OPT_CALLBACK(0, "target-ns", NULL, "pid",
> > > "target pid for namespace contexts", opt_set_target_ns),
> > > OPT_BOOLEAN(0, "bootconfig", &probe_conf.bootconfig,
> > > diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c
> > > index 3b81f4b3dc49..e0d81a8cc3bb 100644
> > > --- a/tools/perf/builtin-report.c
> > > +++ b/tools/perf/builtin-report.c
> > > @@ -1416,8 +1416,7 @@ int cmd_report(int argc, const char **argv)
> > > "columns '.' is reserved."),
> > > OPT_BOOLEAN('U', "hide-unresolved", &symbol_conf.hide_unresolved,
> > > "Only display entries resolved to a symbol"),
> > > - OPT_CALLBACK(0, "symfs", NULL, "directory",
> > > - "Look for files with symbols relative to this directory",
> > > + OPT_CALLBACK(0, "symfs", NULL, "directory[,match_mode]", SYMFS_HELP,
> > > symbol__config_symfs),
> > > OPT_STRING('C', "cpu", &report.cpu_list, "cpu",
> > > "list of cpus to profile"),
> > > diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c
> > > index 3f509cfdd58c..741e9894490c 100644
> > > --- a/tools/perf/builtin-sched.c
> > > +++ b/tools/perf/builtin-sched.c
> > > @@ -4879,8 +4879,8 @@ int cmd_sched(int argc, const char **argv)
> > > "Display call chains if present (default on)"),
> > > OPT_UINTEGER(0, "max-stack", &sched.max_stack,
> > > "Maximum number of functions to display backtrace."),
> > > - OPT_STRING(0, "symfs", &symbol_conf.symfs, "directory",
> > > - "Look for files with symbols relative to this directory"),
> > > + OPT_CALLBACK(0, "symfs", NULL, "directory[,match_mode]", SYMFS_HELP,
> > > + symbol__config_symfs),
> > > OPT_BOOLEAN('s', "summary", &sched.summary_only,
> > > "Show only syscall summary with statistics"),
> > > OPT_BOOLEAN('S', "with-summary", &sched.summary,
> > > diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
> > > index 7c743a303507..4fe79971c97f 100644
> > > --- a/tools/perf/builtin-script.c
> > > +++ b/tools/perf/builtin-script.c
> > > @@ -4074,8 +4074,7 @@ int cmd_script(int argc, const char **argv)
> > > "file", "kallsyms pathname"),
> > > OPT_BOOLEAN('G', "hide-call-graph", &no_callchain,
> > > "When printing symbols do not display call chain"),
> > > - OPT_CALLBACK(0, "symfs", NULL, "directory",
> > > - "Look for files with symbols relative to this directory",
> > > + OPT_CALLBACK(0, "symfs", NULL, "directory[,match_mode]", SYMFS_HELP,
> > > symbol__config_symfs),
> > > OPT_CALLBACK('F', "fields", NULL, "str",
> > > "comma separated output fields prepend with 'type:'. "
> > > diff --git a/tools/perf/builtin-timechart.c b/tools/perf/builtin-timechart.c
> > > index f8b49d69e9a5..b071c66b8dc4 100644
> > > --- a/tools/perf/builtin-timechart.c
> > > +++ b/tools/perf/builtin-timechart.c
> > > @@ -1951,8 +1951,7 @@ int cmd_timechart(int argc, const char **argv)
> > > OPT_CALLBACK('p', "process", NULL, "process",
> > > "process selector. Pass a pid or process name.",
> > > parse_process),
> > > - OPT_CALLBACK(0, "symfs", NULL, "directory",
> > > - "Look for files with symbols relative to this directory",
> > > + OPT_CALLBACK(0, "symfs", NULL, "directory[,match_mode]", SYMFS_HELP,
> > > symbol__config_symfs),
> > > OPT_INTEGER('n', "proc-num", &tchart.proc_num,
> > > "min. number of tasks to print"),
> > > diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c
> > > index 8662001e1e25..0cafa6e630e8 100644
> > > --- a/tools/perf/util/symbol.c
> > > +++ b/tools/perf/util/symbol.c
> > > @@ -66,6 +66,7 @@ struct symbol_conf symbol_conf = {
> > > .time_quantum = 100 * NSEC_PER_MSEC, /* 100ms */
> > > .show_hist_headers = true,
> > > .symfs = "",
> > > + .symfs_match_basename = false,
> > > .event_group = true,
> > > .inline_name = true,
> > > .res_sample = 0,
> > > @@ -2491,16 +2492,41 @@ int symbol__config_symfs(const struct option *opt __maybe_unused,
> > > const char *dir, int unset __maybe_unused)
> > > {
> > > char *bf = NULL;
> > > + char *match_mode_str;
> > > int ret;
> > >
> > > - symbol_conf.symfs = strdup(dir);
> > > - if (symbol_conf.symfs == NULL)
> > > - return -ENOMEM;
> > > + match_mode_str = strchr(dir, ',');
>
> I wonder if using `strstr` or `ends_with` for ",basename" and ",path"
> would work better than `strchr` for ','. That way if a path contains a
> comma (which is very unusual), the old behavior will happen.
>
I fixed by:
1. Using strrchr() to find the last comma instead of first
2. Only treating it as a layout specifier if suffix is "flat" or "hierarchy"
This handles all cases correctly:
- /path,flat → suffix is "flat" → split → symfs=/path, layout=flat
- /path,hierarchy → suffix is "hierarchy" → split → symfs=/path, layout=hierarchy
- ./my,symfs/ → suffix is "symfs/" (not valid) → full path as symfs
- /some,path/file → suffix is "file" (not valid) → full path as symfs
> Thanks,
> Ian
>
--
Cheers,
Changbin Du
prev parent reply other threads:[~2026-03-01 11:06 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-27 11:13 [PATCH] perf: Add match_mode support for --symfs option Changbin Du
2026-02-28 10:06 ` duchangbin
2026-03-01 1:26 ` Ian Rogers
2026-03-01 11:06 ` duchangbin [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=babef420cf5e4af7bcfec28e2c8d23e8@huawei.com \
--to=changbin.du@huawei.com \
--cc=acme@kernel.org \
--cc=adrian.hunter@intel.com \
--cc=alexander.shishkin@linux.intel.com \
--cc=irogers@google.com \
--cc=james.clark@linaro.org \
--cc=jolsa@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=mingo@redhat.com \
--cc=namhyung@kernel.org \
--cc=peterz@infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox