From: Ian Rogers <irogers@google.com>
To: Peter Zijlstra <peterz@infradead.org>,
Ingo Molnar <mingo@redhat.com>,
Arnaldo Carvalho de Melo <acme@kernel.org>,
Namhyung Kim <namhyung@kernel.org>,
Alexander Shishkin <alexander.shishkin@linux.intel.com>,
Jiri Olsa <jolsa@kernel.org>, Ian Rogers <irogers@google.com>,
Adrian Hunter <adrian.hunter@intel.com>,
James Clark <james.clark@linaro.org>,
Sandipan Das <sandipan.das@amd.com>, Leo Yan <leo.yan@arm.com>,
Yujie Liu <yujie.liu@intel.com>,
linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org
Subject: [PATCH v1 1/3] perf script: Allow the generated script to be a path
Date: Mon, 9 Feb 2026 12:22:06 -0800 [thread overview]
Message-ID: <20260209202208.2027001-2-irogers@google.com> (raw)
In-Reply-To: <20260209202208.2027001-1-irogers@google.com>
Allow the script generated by "perf script -g <language>" to be a file
path and the language determined by the file extension. This is useful
in testing so that the generated script file can be written to a test
directory.
Signed-off-by: Ian Rogers <irogers@google.com>
---
tools/perf/Documentation/perf-script.txt | 6 ++++--
tools/perf/builtin-script.c | 24 ++++++++++++++++++++----
2 files changed, 24 insertions(+), 6 deletions(-)
diff --git a/tools/perf/Documentation/perf-script.txt b/tools/perf/Documentation/perf-script.txt
index 03d112960632..ddf92f9c7821 100644
--- a/tools/perf/Documentation/perf-script.txt
+++ b/tools/perf/Documentation/perf-script.txt
@@ -98,8 +98,10 @@ OPTIONS
-g::
--gen-script=::
- Generate perf-script.[ext] starter script for given language,
- using current perf.data.
+ Generate a starter script. If a language is given then the
+ script is named perf-script.[ext] according to the
+ language. If a file path is given then python is used for
+ files ending '.py' and perl used for files ending '.pl'.
--dlfilter=<file>::
Filter sample events using the given shared object file.
diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
index 14c6f6c3c4f2..7c743a303507 100644
--- a/tools/perf/builtin-script.c
+++ b/tools/perf/builtin-script.c
@@ -4489,6 +4489,7 @@ int cmd_script(int argc, const char **argv)
if (generate_script_lang) {
struct stat perf_stat;
int input;
+ char *filename = strdup("perf-script");
if (output_set_by_user()) {
fprintf(stderr,
@@ -4516,17 +4517,32 @@ int cmd_script(int argc, const char **argv)
}
scripting_ops = script_spec__lookup(generate_script_lang);
+ if (!scripting_ops && ends_with(generate_script_lang, ".py")) {
+ scripting_ops = script_spec__lookup("python");
+ free(filename);
+ filename = strdup(generate_script_lang);
+ filename[strlen(filename) - 3] = '\0';
+ } else if (!scripting_ops && ends_with(generate_script_lang, ".pl")) {
+ scripting_ops = script_spec__lookup("perl");
+ free(filename);
+ filename = strdup(generate_script_lang);
+ filename[strlen(filename) - 3] = '\0';
+ }
if (!scripting_ops) {
- fprintf(stderr, "invalid language specifier");
+ fprintf(stderr, "invalid language specifier '%s'\n", generate_script_lang);
err = -ENOENT;
goto out_delete;
}
+ if (!filename) {
+ err = -ENOMEM;
+ goto out_delete;
+ }
#ifdef HAVE_LIBTRACEEVENT
- err = scripting_ops->generate_script(session->tevent.pevent,
- "perf-script");
+ err = scripting_ops->generate_script(session->tevent.pevent, filename);
#else
- err = scripting_ops->generate_script(NULL, "perf-script");
+ err = scripting_ops->generate_script(NULL, filename);
#endif
+ free(filename);
goto out_delete;
}
--
2.53.0.rc2.204.g2597b5adb4-goog
next prev parent reply other threads:[~2026-02-09 20:22 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-09 20:22 [PATCH v1 0/3] perf script engine testing Ian Rogers
2026-02-09 20:22 ` Ian Rogers [this message]
2026-02-09 20:22 ` [PATCH v1 2/3] perf test script: Add perl script testing support Ian Rogers
2026-02-09 20:22 ` [PATCH v1 3/3] perf test script: Add python " Ian Rogers
2026-02-11 16:44 ` [PATCH v1 0/3] perf script engine testing Arnaldo Carvalho de Melo
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=20260209202208.2027001-2-irogers@google.com \
--to=irogers@google.com \
--cc=acme@kernel.org \
--cc=adrian.hunter@intel.com \
--cc=alexander.shishkin@linux.intel.com \
--cc=james.clark@linaro.org \
--cc=jolsa@kernel.org \
--cc=leo.yan@arm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=namhyung@kernel.org \
--cc=peterz@infradead.org \
--cc=sandipan.das@amd.com \
--cc=yujie.liu@intel.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