Re: [PATCH v2 16/58] perf python: Add syscall name/id to convert syscall number and name

sashiko-bot
2026-04-23T04:25:05Z

Sashiko AI review found 2 potential issue(s):
- [Medium] Hardcoding `EM_HOST` in the new Python API prevents cross-architecture trace analysis.
- [Medium] The new Python methods are artificially restricted by an incorrect `#ifdef HAVE_LIBTRACEEVENT` guard.
--

commit 9353ccc90917e94e1031cafe3957fc3490c205f2
Author: Ian Rogers <irogers@google.com>

perf python: Add syscall name/id to convert syscall number and name

Use perf's syscalltbl support to convert syscall number to name assuming
the number is for the host machine. Avoids python libaudit support as
tools/perf/scripts/python/syscall-counts.py requires.

> diff --git a/tools/perf/util/python.c b/tools/perf/util/python.c
> index 9cd7cca321aa1..d90aa24e53105 100644
> --- a/tools/perf/util/python.c
> +++ b/tools/perf/util/python.c
[ ... ]
> @@ -2632,6 +2634,38 @@ static int pyrf_session__setup_types(void)
> return PyType_Ready(&pyrf_session__type);
> }
>
> +#ifdef HAVE_LIBTRACEEVENT

Is it necessary to restrict these methods behind HAVE_LIBTRACEEVENT?

The underlying syscalltbl API has no dependency on libtraceevent, as it only
uses generated string arrays.

If perf is compiled without libtraceevent, perf.syscall_name will be omitted
from the module. When scripts like syscall-counts.py are later ported to
unconditionally call perf.syscall_name(), they will crash with an
AttributeError.

> +static PyObject *pyrf__syscall_name(PyObject *self, PyObject *args)
> +{
> + const char *name;
> + int id;
> +
> + if (!PyArg_ParseTuple(args, "i", &id))
> + return NULL;
> +
> + name = syscalltbl__name(EM_HOST, id);

Will hardcoding EM_HOST restrict the ability to perform cross-architecture
trace analysis?

Because EM_HOST is hardcoded and the API accepts no optional architecture
argument, scripts are prevented from correctly parsing cross-architecture
traces.

For example, analyzing an ARM64 trace on an x86_64 host will silently
map syscall numbers to the host's syscall table, leading to incorrect
output.

> + if (!name)
> + Py_RETURN_NONE;
> + return PyUnicode_FromString(name);
> +}

--
Sashiko AI review · https://sashiko.dev/#/patchset/20260423035526.1537178-1-irogers@google.com?part=16