From: Ian Rogers <irogers@google.com>
To: tmricht@linux.ibm.com
Cc: irogers@google.com, acme@kernel.org, agordeev@linux.ibm.com,
gor@linux.ibm.com, hca@linux.ibm.com, japo@linux.ibm.com,
linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org,
linux-s390@vger.kernel.org, namhyung@kernel.org,
sumanthk@linux.ibm.com
Subject: [PATCH v5 4/5] perf callchain: Refactor callchain option parsing
Date: Mon, 16 Mar 2026 22:53:33 -0700 [thread overview]
Message-ID: <20260317055334.760347-5-irogers@google.com> (raw)
In-Reply-To: <20260317055334.760347-1-irogers@google.com>
record_opts__parse_callchain is shared by builtin-record and
builtin-trace, it is declared in callchain.h. Move the declaration to
callchain.c for consistency with the header. In other cases make the
option callback a small static stub that then calls into callchain.c.
Make the no argument '-g' callchain option just a short-cut for
'--call-graph fp' so that there is consistency in how the arguments
are handled.
Signed-off-by: Ian Rogers <irogers@google.com>
---
tools/perf/builtin-record.c | 58 +++++--------------------------------
tools/perf/builtin-top.c | 14 ++++-----
tools/perf/builtin-trace.c | 9 +++++-
tools/perf/util/callchain.c | 39 +++++++++++++++++++++++++
tools/perf/util/callchain.h | 12 ++------
5 files changed, 64 insertions(+), 68 deletions(-)
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index 40917a0be238..af1fe6b7c65c 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -2975,65 +2975,21 @@ static int __cmd_record(struct record *rec, int argc, const char **argv)
return status;
}
-static void callchain_debug(struct callchain_param *callchain)
-{
- static const char *str[CALLCHAIN_MAX] = { "NONE", "FP", "DWARF", "LBR" };
-
- pr_debug("callchain: type %s\n", str[callchain->record_mode]);
-
- if (callchain->record_mode == CALLCHAIN_DWARF)
- pr_debug("callchain: stack dump size %d\n",
- callchain->dump_size);
-}
-
-int record_opts__parse_callchain(struct record_opts *record,
- struct callchain_param *callchain,
- const char *arg, bool unset)
-{
- int ret;
- callchain->enabled = !unset;
-
- /* --no-call-graph */
- if (unset) {
- callchain->record_mode = CALLCHAIN_NONE;
- pr_debug("callchain: disabled\n");
- return 0;
- }
-
- ret = parse_callchain_record_opt(arg, callchain);
- if (!ret) {
- /* Enable data address sampling for DWARF unwind. */
- if (callchain->record_mode == CALLCHAIN_DWARF &&
- !record->record_data_mmap_set)
- record->record_data_mmap = true;
- callchain_debug(callchain);
- }
-
- return ret;
-}
-
-int record_parse_callchain_opt(const struct option *opt,
+static int record_parse_callchain_opt(const struct option *opt,
const char *arg,
int unset)
{
return record_opts__parse_callchain(opt->value, &callchain_param, arg, unset);
}
-int record_callchain_opt(const struct option *opt,
- const char *arg __maybe_unused,
- int unset __maybe_unused)
+static int record_callchain_opt(const struct option *opt,
+ const char *arg __maybe_unused,
+ int unset)
{
- struct callchain_param *callchain = opt->value;
-
- callchain->enabled = true;
-
- if (callchain->record_mode == CALLCHAIN_NONE)
- callchain->record_mode = CALLCHAIN_FP;
-
- callchain_debug(callchain);
- return 0;
+ return record_opts__parse_callchain(opt->value, &callchain_param, "fp", unset);
}
+
static int perf_record_config(const char *var, const char *value, void *cb)
{
struct record *rec = cb;
@@ -3525,7 +3481,7 @@ static struct option __record_options[] = {
OPT_CALLBACK(0, "mmap-flush", &record.opts, "number",
"Minimal number of bytes that is extracted from mmap data pages (default: 1)",
record__mmap_flush_parse),
- OPT_CALLBACK_NOOPT('g', NULL, &callchain_param,
+ OPT_CALLBACK_NOOPT('g', NULL, &record.opts,
NULL, "enables call-graph recording" ,
&record_callchain_opt),
OPT_CALLBACK(0, "call-graph", &record.opts,
diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c
index 710604c4f6f6..2a949d956d0b 100644
--- a/tools/perf/builtin-top.c
+++ b/tools/perf/builtin-top.c
@@ -1386,13 +1386,6 @@ static int __cmd_top(struct perf_top *top)
return ret;
}
-static int
-callchain_opt(const struct option *opt, const char *arg, int unset)
-{
- symbol_conf.use_callchain = true;
- return record_callchain_opt(opt, arg, unset);
-}
-
static int
parse_callchain_opt(const struct option *opt, const char *arg, int unset)
{
@@ -1413,6 +1406,13 @@ parse_callchain_opt(const struct option *opt, const char *arg, int unset)
return parse_callchain_top_opt(arg);
}
+static int
+callchain_opt(const struct option *opt, const char *arg __maybe_unused, int unset)
+{
+ return parse_callchain_opt(opt, "fp", unset);
+}
+
+
static int perf_top_config(const char *var, const char *value, void *cb __maybe_unused)
{
if (!strcmp(var, "top.call-graph")) {
diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c
index 1c38f3d16a31..f487fbaa0ad6 100644
--- a/tools/perf/builtin-trace.c
+++ b/tools/perf/builtin-trace.c
@@ -5300,6 +5300,13 @@ static int trace__parse_summary_mode(const struct option *opt, const char *str,
return 0;
}
+static int trace_parse_callchain_opt(const struct option *opt,
+ const char *arg,
+ int unset)
+{
+ return record_opts__parse_callchain(opt->value, &callchain_param, arg, unset);
+}
+
static int trace__config(const char *var, const char *value, void *arg)
{
struct trace *trace = arg;
@@ -5447,7 +5454,7 @@ int cmd_trace(int argc, const char **argv)
OPT_BOOLEAN('f', "force", &trace.force, "don't complain, do it"),
OPT_CALLBACK(0, "call-graph", &trace.opts,
"record_mode[,record_size]", record_callchain_help,
- &record_parse_callchain_opt),
+ &trace_parse_callchain_opt),
OPT_BOOLEAN(0, "libtraceevent_print", &trace.libtraceevent_print,
"Use libtraceevent to print the tracepoint arguments."),
OPT_BOOLEAN(0, "kernel-syscall-graph", &trace.kernel_syscallchains,
diff --git a/tools/perf/util/callchain.c b/tools/perf/util/callchain.c
index 8ff0898799ee..d97421fbf159 100644
--- a/tools/perf/util/callchain.c
+++ b/tools/perf/util/callchain.c
@@ -30,6 +30,7 @@
#include "map.h"
#include "callchain.h"
#include "branch.h"
+#include "record.h"
#include "symbol.h"
#include "thread.h"
#include "util.h"
@@ -328,6 +329,44 @@ int parse_callchain_record(const char *arg, struct callchain_param *param)
return ret;
}
+static void callchain_debug(const struct callchain_param *callchain)
+{
+ static const char *str[CALLCHAIN_MAX] = { "NONE", "FP", "DWARF", "LBR" };
+
+ pr_debug("callchain: type %s\n", str[callchain->record_mode]);
+
+ if (callchain->record_mode == CALLCHAIN_DWARF)
+ pr_debug("callchain: stack dump size %d\n",
+ callchain->dump_size);
+}
+
+int record_opts__parse_callchain(struct record_opts *record,
+ struct callchain_param *callchain,
+ const char *arg, bool unset)
+{
+ int ret;
+
+ callchain->enabled = !unset;
+
+ /* --no-call-graph */
+ if (unset) {
+ callchain->record_mode = CALLCHAIN_NONE;
+ pr_debug("callchain: disabled\n");
+ return 0;
+ }
+
+ ret = parse_callchain_record_opt(arg, callchain);
+ if (!ret) {
+ /* Enable data address sampling for DWARF unwind. */
+ if (callchain->record_mode == CALLCHAIN_DWARF &&
+ !record->record_data_mmap_set)
+ record->record_data_mmap = true;
+ callchain_debug(callchain);
+ }
+
+ return ret;
+}
+
int perf_callchain_config(const char *var, const char *value)
{
char *endptr;
diff --git a/tools/perf/util/callchain.h b/tools/perf/util/callchain.h
index df54ddb8c0cb..06d463ccc7a0 100644
--- a/tools/perf/util/callchain.h
+++ b/tools/perf/util/callchain.h
@@ -9,11 +9,13 @@
struct addr_location;
struct evsel;
+struct hist_entry;
+struct hists;
struct ip_callchain;
struct map;
struct perf_sample;
+struct record_opts;
struct thread;
-struct hists;
#define HELP_PAD "\t\t\t\t"
@@ -237,14 +239,6 @@ struct callchain_cursor *get_tls_callchain_cursor(void);
int callchain_cursor__copy(struct callchain_cursor *dst,
struct callchain_cursor *src);
-struct option;
-struct hist_entry;
-
-int record_parse_callchain_opt(const struct option *opt, const char *arg, int unset);
-int record_callchain_opt(const struct option *opt, const char *arg, int unset);
-
-struct record_opts;
-
int record_opts__parse_callchain(struct record_opts *record,
struct callchain_param *callchain,
const char *arg, bool unset);
--
2.53.0.851.ga537e3e6e9-goog
next prev parent reply other threads:[~2026-03-17 5:53 UTC|newest]
Thread overview: 63+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-06 7:10 [PATCH] perf test: Fix test case 120 and 121 for s390 Thomas Richter
2026-03-06 15:51 ` Jan Polensky
2026-03-06 16:53 ` Ian Rogers
2026-03-09 12:59 ` Thomas Richter
2026-03-09 18:18 ` Ian Rogers
2026-03-11 6:09 ` Namhyung Kim
2026-03-11 7:21 ` Thomas Richter
2026-03-12 3:19 ` [PATCH v1 0/2] perf evsel fallback changes Ian Rogers
2026-03-12 3:19 ` [PATCH v1 1/2] perf evsel: Improve falling back from cycles Ian Rogers
2026-03-12 3:19 ` [PATCH v1 2/2] perf evsel: Don't configure framepointer callchains on s390 Ian Rogers
2026-03-12 6:16 ` [PATCH v2 0/2] perf evsel fallback changes Ian Rogers
2026-03-12 6:16 ` [PATCH v2 1/2] perf evsel: Improve falling back from cycles Ian Rogers
2026-03-12 6:16 ` [PATCH v2 2/2] perf evsel: Don't configure framepointer callchains on s390 Ian Rogers
2026-03-12 12:45 ` Thomas Richter
2026-03-12 15:54 ` Ian Rogers
2026-03-12 16:46 ` Ian Rogers
2026-03-12 18:00 ` Namhyung Kim
2026-03-13 9:46 ` Thomas Richter
2026-03-13 21:01 ` Namhyung Kim
2026-03-13 20:28 ` [PATCH v3 0/3] perf evsel fallback changes Ian Rogers
2026-03-13 20:28 ` [PATCH v3 1/3] perf evsel: Improve falling back from cycles Ian Rogers
2026-03-13 20:28 ` [PATCH v3 2/3] perf target: Constify simple check functions Ian Rogers
2026-03-13 20:28 ` [PATCH v3 3/3] perf evlist: Improve default event for s390 Ian Rogers
2026-03-16 12:13 ` Thomas Richter
2026-03-16 18:41 ` Ian Rogers
2026-03-17 3:05 ` [PATCH v4 0/5] perf evsel fallback changes Ian Rogers
2026-03-17 3:05 ` [PATCH v4 1/5] perf evsel: Improve falling back from cycles Ian Rogers
2026-03-17 3:05 ` [PATCH v4 2/5] perf target: Constify simple check functions Ian Rogers
2026-03-17 3:05 ` [PATCH v4 3/5] perf evsel: Constify option arguments to config functions Ian Rogers
2026-03-17 3:06 ` [PATCH v4 4/5] perf callchain: Move callchain option parsing out of builtin Ian Rogers
2026-03-17 3:06 ` [PATCH v4 5/5] perf evlist: Improve default event for s390 Ian Rogers
2026-03-17 5:53 ` [PATCH v5 0/5] perf evsel fallback changes Ian Rogers
2026-03-17 5:53 ` [PATCH v5 1/5] perf evsel: Improve falling back from cycles Ian Rogers
2026-03-17 5:53 ` [PATCH v5 2/5] perf target: Constify simple check functions Ian Rogers
2026-03-17 5:53 ` [PATCH v5 3/5] perf evsel: Constify option arguments to config functions Ian Rogers
2026-03-17 5:53 ` Ian Rogers [this message]
2026-03-17 5:53 ` [PATCH v5 5/5] perf evlist: Improve default event for s390 Ian Rogers
2026-03-17 7:52 ` Thomas Richter
2026-03-17 15:54 ` Ian Rogers
2026-03-17 17:56 ` [PATCH v6 0/5] perf evsel fallback changes, better s390 defaults Ian Rogers
2026-03-17 17:56 ` [PATCH v6 1/5] perf evsel: Improve falling back from cycles Ian Rogers
2026-03-17 17:56 ` [PATCH v6 2/5] perf target: Constify simple check functions Ian Rogers
2026-03-17 17:56 ` [PATCH v6 3/5] perf evsel: Constify option arguments to config functions Ian Rogers
2026-03-17 17:56 ` [PATCH v6 4/5] perf callchain: Refactor callchain option parsing Ian Rogers
2026-03-17 17:56 ` [PATCH v6 5/5] perf evlist: Improve default event for s390 Ian Rogers
2026-03-18 8:20 ` [PATCH v6 0/5] perf evsel fallback changes, better s390 defaults Thomas Richter
2026-03-18 16:29 ` Ian Rogers
2026-03-18 17:58 ` [PATCH v7 " Ian Rogers
2026-03-18 17:58 ` [PATCH v7 1/5] perf evsel: Improve falling back from cycles Ian Rogers
2026-03-18 17:58 ` [PATCH v7 2/5] perf target: Constify simple check functions Ian Rogers
2026-03-18 17:58 ` [PATCH v7 3/5] perf evsel: Constify option arguments to config functions Ian Rogers
2026-03-18 17:58 ` [PATCH v7 4/5] perf callchain: Refactor callchain option parsing Ian Rogers
2026-03-18 17:58 ` [PATCH v7 5/5] perf evlist: Improve default event for s390 Ian Rogers
2026-03-18 23:45 ` [PATCH v8 0/5] perf evsel fallback changes, better s390 defaults Ian Rogers
2026-03-18 23:45 ` [PATCH v8 1/5] perf evsel: Improve falling back from cycles Ian Rogers
2026-03-18 23:45 ` [PATCH v8 2/5] perf target: Constify simple check functions Ian Rogers
2026-03-18 23:45 ` [PATCH v8 3/5] perf evsel: Constify option arguments to config functions Ian Rogers
2026-03-18 23:45 ` [PATCH v8 4/5] perf callchain: Refactor callchain option parsing Ian Rogers
2026-03-18 23:46 ` [PATCH v8 5/5] perf evlist: Improve default event for s390 Ian Rogers
2026-03-19 7:53 ` Thomas Richter
2026-03-19 5:39 ` [PATCH v8 0/5] perf evsel fallback changes, better s390 defaults Ian Rogers
2026-03-19 8:02 ` Thomas Richter
2026-03-20 18:12 ` Namhyung Kim
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=20260317055334.760347-5-irogers@google.com \
--to=irogers@google.com \
--cc=acme@kernel.org \
--cc=agordeev@linux.ibm.com \
--cc=gor@linux.ibm.com \
--cc=hca@linux.ibm.com \
--cc=japo@linux.ibm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=linux-s390@vger.kernel.org \
--cc=namhyung@kernel.org \
--cc=sumanthk@linux.ibm.com \
--cc=tmricht@linux.ibm.com \
/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