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

sashiko-bot
2026-04-20T00:35:58Z

Sashiko AI review found 3 potential issue(s):
- [Low] Unconditional use of `syscalltbl__name` and `syscalltbl__id` breaks the perf Python extension build when `CONFIG_TRACE` is disabled.
- [Low] `pyrf__syscall_id` incorrectly raises a `TypeError` instead of a `ValueError` when a syscall is not found.
- [Low] The docstring for the `syscall_id` Python method contains a confusing typo.
--

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

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

This commit adds syscall name and id conversions to the perf Python
extension using the syscalltbl support. This avoids the need for python
libaudit support in scripts.

> diff --git a/tools/perf/util/python.c b/tools/perf/util/python.c
> index b68668c267d83..84a186532353e 100644
> --- a/tools/perf/util/python.c
> +++ b/tools/perf/util/python.c

[ ... ]

> +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);

If CONFIG_TRACE is disabled, syscalltbl.o is not compiled. Will this
cause a linker error since there are no HAVE_LIBTRACEEVENT guards or
fallback stubs in syscalltbl.h?

> + if (!name)
> + Py_RETURN_NONE;
> + return PyUnicode_FromString(name);
> +}
> +
> +static PyObject *pyrf__syscall_id(PyObject *self, PyObject *args)
> +{
> + const char *name;
> + int id;
> +
> + if (!PyArg_ParseTuple(args, "s", &name))
> + return NULL;
> +
> + id = syscalltbl__id(EM_HOST, name);
> + if (id < 0) {
> + PyErr_Format(PyExc_TypeError, "Failed to find syscall %s", name);

This isn't a bug, but should this raise a ValueError instead of a
TypeError since the argument type is correct but the value itself
is unrecognized?

> + return NULL;
> + }
> + return PyLong_FromLong(id);
> +}

[ ... ]

> @@ -2614,6 +2646,18 @@ static PyMethodDef perf__methods[] = {
> .ml_flags = METH_NOARGS,
> .ml_doc = PyDoc_STR("Returns a sequence of pmus.")
> },
> + {
> + .ml_name = "syscall_name",
> + .ml_meth = (PyCFunction) pyrf__syscall_name,
> + .ml_flags = METH_VARARGS,
> + .ml_doc = PyDoc_STR("Turns a syscall number to a string.")
> + },
> + {
> + .ml_name = "syscall_id",
> + .ml_meth = (PyCFunction) pyrf__syscall_id,
> + .ml_flags = METH_VARARGS,
> + .ml_doc = PyDoc_STR("Turns a syscall name number to a number.")

This isn't a bug, but there is a typo in the docstring ("name number").

> + },
> { .ml_name = NULL, }
> };
>

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