From: Stephen Brennan <stephen.s.brennan@oracle.com>
To: Peter Zijlstra <peterz@infradead.org>,
Namhyung Kim <namhyung@kernel.org>,
Arnaldo Carvalho de Melo <acme@kernel.org>,
Ingo Molnar <mingo@redhat.com>
Cc: Stephen Brennan <stephen.s.brennan@oracle.com>,
linux-kernel@vger.kernel.org,
James Clark <james.clark@linaro.org>,
Mark Rutland <mark.rutland@arm.com>, Jiri Olsa <jolsa@kernel.org>,
Ian Rogers <irogers@google.com>,
Alexander Shishkin <alexander.shishkin@linux.intel.com>,
Adrian Hunter <adrian.hunter@intel.com>,
linux-perf-users@vger.kernel.org
Subject: [PATCH 1/2] tools: perf: add perf_input_name() helper
Date: Thu, 1 Oct 2026 11:20:00 -0700 [thread overview]
Message-ID: <20261001182004.1160406-2-stephen.s.brennan@oracle.com> (raw)
In-Reply-To: <20261001182004.1160406-1-stephen.s.brennan@oracle.com>
The perf scripting API does not expose the name of the input file being
processed. Some scripts, like flamegraph.py, assume that the "-i" option
will be passed through, but when perf actually processes "-i", it does
not keep it on the command line for the script. (This could break some
scripts which do not expect it.)
To allow scripts to know what file they're processing, add a new helper
perf_input_name(), which returns either the filename being processed, or
None for an unnamed pipe.
Signed-off-by: Stephen Brennan <stephen.s.brennan@oracle.com>
---
tools/perf/Documentation/perf-script-python.txt | 1 +
.../scripts/python/Perf-Trace-Util/Context.c | 16 ++++++++++++++++
2 files changed, 17 insertions(+)
diff --git a/tools/perf/Documentation/perf-script-python.txt b/tools/perf/Documentation/perf-script-python.txt
index 27a1cac6fe763..3f127024f640d 100644
--- a/tools/perf/Documentation/perf-script-python.txt
+++ b/tools/perf/Documentation/perf-script-python.txt
@@ -622,6 +622,7 @@ as perf_trace_context.perf_script_context .
common_lock_depth(context) - returns common_lock_depth for the current event
perf_sample_insn(context) - returns the machine code instruction
perf_set_itrace_options(context, itrace_options) - set --itrace options if they have not been set already
+ perf_input_name(context) - returns the input file name (or None for an unnamed pipe)
perf_sample_srcline(context) - returns source_file_name, line_number
perf_sample_srccode(context) - returns source_file_name, line_number, source_line
perf_config_get(config_name) - returns the value of the named config item, or None if unset
diff --git a/tools/perf/scripts/python/Perf-Trace-Util/Context.c b/tools/perf/scripts/python/Perf-Trace-Util/Context.c
index c19f446109831..c50c2432c1f60 100644
--- a/tools/perf/scripts/python/Perf-Trace-Util/Context.c
+++ b/tools/perf/scripts/python/Perf-Trace-Util/Context.c
@@ -20,6 +20,7 @@
#include "../../../util/map.h"
#include "../../../util/maps.h"
#include "../../../util/auxtrace.h"
+#include "../../../util/data.h"
#include "../../../util/session.h"
#include "../../../util/srcline.h"
#include "../../../util/srccode.h"
@@ -181,6 +182,19 @@ static PyObject *__perf_config_get(PyObject *obj, PyObject *args)
return Py_BuildValue("s", perf_config_get(config_name));
}
+static PyObject *perf_input_name(PyObject *obj, PyObject *args)
+{
+ struct scripting_context *c = get_scripting_context(args);
+
+ if (!c)
+ return NULL;
+
+ if (!c->session || !c->session->data || !c->session->data->path)
+ Py_RETURN_NONE;
+
+ return PyUnicode_DecodeFSDefault(c->session->data->path);
+}
+
static PyMethodDef ContextMethods[] = {
#ifdef HAVE_LIBTRACEEVENT
{ "common_pc", perf_trace_context_common_pc, METH_VARARGS,
@@ -199,6 +213,8 @@ static PyMethodDef ContextMethods[] = {
{ "perf_sample_srccode", perf_sample_srccode,
METH_VARARGS, "Get source file name, line number and line."},
{ "perf_config_get", __perf_config_get, METH_VARARGS, "Get perf config entry"},
+ { "perf_input_name", perf_input_name,
+ METH_VARARGS, "Get the input file name, or None for a pipe"},
{ NULL, NULL, 0, NULL}
};
--
2.52.0
next prev parent reply other threads:[~2026-10-01 18:21 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-01 18:19 [PATCH 0/2] perf script flamegraph: Fix input file name errors Stephen Brennan
2026-10-01 18:20 ` Stephen Brennan [this message]
2026-10-02 9:12 ` [PATCH 1/2] tools: perf: add perf_input_name() helper sashiko-bot
2026-10-01 18:20 ` [PATCH 2/2] tools: perf: flamegraph.py: fix "Error reading report header" Stephen Brennan
2026-10-02 9:12 ` sashiko-bot
2026-10-02 5:24 ` [PATCH 0/2] perf script flamegraph: Fix input file name errors Ian Rogers
2026-10-02 18:27 ` Stephen Brennan
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=20261001182004.1160406-2-stephen.s.brennan@oracle.com \
--to=stephen.s.brennan@oracle.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