[PATCH v1 09/11] perf python: Add evlist all_cpus accessor
From: Ian Rogers
Date: Thu Jan 09 2025 - 02:53:27 EST
Add a means to get the reference counted all_cpus CPU map from an
evlist in its python form.
Signed-off-by: Ian Rogers <irogers@xxxxxxxxxx>
---
tools/perf/util/python.c | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
diff --git a/tools/perf/util/python.c b/tools/perf/util/python.c
index d1ce3b6b5bf1..1e8ab5291637 100644
--- a/tools/perf/util/python.c
+++ b/tools/perf/util/python.c
@@ -865,6 +865,16 @@ static void pyrf_evlist__delete(struct pyrf_evlist *pevlist)
Py_TYPE(pevlist)->tp_free((PyObject*)pevlist);
}
+static PyObject *pyrf_evlist__all_cpus(struct pyrf_evlist *pevlist)
+{
+ struct pyrf_cpu_map *pcpu_map = PyObject_New(struct pyrf_cpu_map, &pyrf_cpu_map__type);
+
+ if (pcpu_map)
+ pcpu_map->cpus = perf_cpu_map__get(pevlist->evlist.core.all_cpus);
+
+ return (PyObject *)pcpu_map;
+}
+
static PyObject *pyrf_evlist__mmap(struct pyrf_evlist *pevlist,
PyObject *args, PyObject *kwargs)
{
@@ -1048,6 +1058,12 @@ static PyObject *pyrf_evlist__enable(struct pyrf_evlist *pevlist)
}
static PyMethodDef pyrf_evlist__methods[] = {
+ {
+ .ml_name = "all_cpus",
+ .ml_meth = (PyCFunction)pyrf_evlist__all_cpus,
+ .ml_flags = METH_NOARGS,
+ .ml_doc = PyDoc_STR("CPU map union of all evsel CPU maps.")
+ },
{
.ml_name = "mmap",
.ml_meth = (PyCFunction)pyrf_evlist__mmap,
--
2.47.1.613.gc27f4b7a9f-goog