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 <[email protected]> Acked-by: Gautam Menghani <[email protected]> Tested-by: Arnaldo Carvalho de Melo <[email protected]> Cc: Adrian Hunter <[email protected]> Cc: Alexander Shishkin <[email protected]> Cc: Howard Chu <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: Kan Liang <[email protected]> Cc: Madhavan Srinivasan <[email protected]> Cc: Mark Rutland <[email protected]> Cc: Namhyung Kim <[email protected]> Cc: Peter Zijlstra <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent 3ee2255 commit 0589aff

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

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)