perf python: Add optional cpus and threads arguments to parse_events
authorIan Rogers <irogers@google.com>
Fri, 28 Feb 2025 22:23:03 +0000 (14:23 -0800)
committerNamhyung Kim <namhyung@kernel.org>
Wed, 12 Mar 2025 01:55:37 +0000 (18:55 -0700)
Used for the evlist initialization.

Reviewed-by: Howard Chu <howardchu95@gmail.com>
Signed-off-by: Ian Rogers <irogers@google.com>
Reviewed-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Link: https://lore.kernel.org/r/20250228222308.626803-7-irogers@google.com
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
tools/perf/util/python.c

index b600b6379b4e8105df1340159be07da31efcb24d..4a3015e7dc83e0ac2c30ce3ffd332ae1d477dece 100644 (file)
@@ -1339,12 +1339,18 @@ static PyObject *pyrf__parse_events(PyObject *self, PyObject *args)
        struct evlist evlist = {};
        struct parse_events_error err;
        PyObject *result;
+       PyObject *pcpus = NULL, *pthreads = NULL;
+       struct perf_cpu_map *cpus;
+       struct perf_thread_map *threads;
 
-       if (!PyArg_ParseTuple(args, "s", &input))
+       if (!PyArg_ParseTuple(args, "s|OO", &input, &pcpus, &pthreads))
                return NULL;
 
+       threads = pthreads ? ((struct pyrf_thread_map *)pthreads)->threads : NULL;
+       cpus = pcpus ? ((struct pyrf_cpu_map *)pcpus)->cpus : NULL;
+
        parse_events_error__init(&err);
-       evlist__init(&evlist, NULL, NULL);
+       evlist__init(&evlist, cpus, threads);
        if (parse_events(&evlist, input, &err)) {
                parse_events_error__print(&err, input);
                PyErr_SetFromErrno(PyExc_OSError);