]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
perf python: Add evsel cpus and threads functions
authorIan Rogers <irogers@google.com>
Mon, 19 May 2025 19:51:40 +0000 (12:51 -0700)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Wed, 21 May 2025 18:07:13 +0000 (15:07 -0300)
Allow access to cpus and thread_map structs associated with an evsel.

Signed-off-by: Ian Rogers <irogers@google.com>
Acked-by: Gautam Menghani <gautam@linux.ibm.com>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Howard Chu <howardchu95@gmail.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Madhavan Srinivasan <maddy@linux.ibm.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: https://lore.kernel.org/r/20250519195148.1708988-4-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/util/python.c

index f3c05da25b4af8c000dd64eea75e127565114258..ead3afd2d996e46a56a2087bd469c06a8ef550ab 100644 (file)
@@ -781,6 +781,27 @@ static PyObject *pyrf_evsel__open(struct pyrf_evsel *pevsel,
        return Py_None;
 }
 
+static PyObject *pyrf_evsel__cpus(struct pyrf_evsel *pevsel)
+{
+       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(pevsel->evsel.core.cpus);
+
+       return (PyObject *)pcpu_map;
+}
+
+static PyObject *pyrf_evsel__threads(struct pyrf_evsel *pevsel)
+{
+       struct pyrf_thread_map *pthread_map =
+               PyObject_New(struct pyrf_thread_map, &pyrf_thread_map__type);
+
+       if (pthread_map)
+               pthread_map->threads = perf_thread_map__get(pevsel->evsel.core.threads);
+
+       return (PyObject *)pthread_map;
+}
+
 static PyObject *pyrf_evsel__str(PyObject *self)
 {
        struct pyrf_evsel *pevsel = (void *)self;
@@ -799,6 +820,18 @@ static PyMethodDef pyrf_evsel__methods[] = {
                .ml_flags = METH_VARARGS | METH_KEYWORDS,
                .ml_doc   = PyDoc_STR("open the event selector file descriptor table.")
        },
+       {
+               .ml_name  = "cpus",
+               .ml_meth  = (PyCFunction)pyrf_evsel__cpus,
+               .ml_flags = METH_NOARGS,
+               .ml_doc   = PyDoc_STR("CPUs the event is to be used with.")
+       },
+       {
+               .ml_name  = "threads",
+               .ml_meth  = (PyCFunction)pyrf_evsel__threads,
+               .ml_flags = METH_NOARGS,
+               .ml_doc   = PyDoc_STR("threads the event is to be used with.")
+       },
        { .ml_name = NULL, }
 };