Skip to content

Commit 0589aff

Browse files
captain5050acmel
authored andcommitted
perf python: Add evsel cpus and threads functions
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>
1 parent 3ee2255 commit 0589aff

1 file changed

Lines changed: 33 additions & 0 deletions

File tree

tools/perf/util/python.c

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -781,6 +781,27 @@ static PyObject *pyrf_evsel__open(struct pyrf_evsel *pevsel,
781781
return Py_None;
782782
}
783783

784+
static PyObject *pyrf_evsel__cpus(struct pyrf_evsel *pevsel)
785+
{
786+
struct pyrf_cpu_map *pcpu_map = PyObject_New(struct pyrf_cpu_map, &pyrf_cpu_map__type);
787+
788+
if (pcpu_map)
789+
pcpu_map->cpus = perf_cpu_map__get(pevsel->evsel.core.cpus);
790+
791+
return (PyObject *)pcpu_map;
792+
}
793+
794+
static PyObject *pyrf_evsel__threads(struct pyrf_evsel *pevsel)
795+
{
796+
struct pyrf_thread_map *pthread_map =
797+
PyObject_New(struct pyrf_thread_map, &pyrf_thread_map__type);
798+
799+
if (pthread_map)
800+
pthread_map->threads = perf_thread_map__get(pevsel->evsel.core.threads);
801+
802+
return (PyObject *)pthread_map;
803+
}
804+
784805
static PyObject *pyrf_evsel__str(PyObject *self)
785806
{
786807
struct pyrf_evsel *pevsel = (void *)self;
@@ -799,6 +820,18 @@ static PyMethodDef pyrf_evsel__methods[] = {
799820
.ml_flags = METH_VARARGS | METH_KEYWORDS,
800821
.ml_doc = PyDoc_STR("open the event selector file descriptor table.")
801822
},
823+
{
824+
.ml_name = "cpus",
825+
.ml_meth = (PyCFunction)pyrf_evsel__cpus,
826+
.ml_flags = METH_NOARGS,
827+
.ml_doc = PyDoc_STR("CPUs the event is to be used with.")
828+
},
829+
{
830+
.ml_name = "threads",
831+
.ml_meth = (PyCFunction)pyrf_evsel__threads,
832+
.ml_flags = METH_NOARGS,
833+
.ml_doc = PyDoc_STR("threads the event is to be used with.")
834+
},
802835
{ .ml_name = NULL, }
803836
};
804837

0 commit comments

Comments
 (0)