Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

perf python: Add evsel read method

Add the evsel read method to enable python to read counter data for the
given evsel.

Signed-off-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/linux-perf-users/20250512055748.479786-1-gautam@linux.ibm.com/
Link: https://lore.kernel.org/r/20250519195148.1708988-6-irogers@google.com
[ make the API take a CPU and thread then compute from these the appropriate indices. ]
Signed-off-by: Ian Rogers <irogers@google.com>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Gautam Menghani and committed by
Arnaldo Carvalho de Melo
739621f6 3b4991dc

+37
+37
tools/perf/util/python.c
··· 888 888 return (PyObject *)pthread_map; 889 889 } 890 890 891 + static PyObject *pyrf_evsel__read(struct pyrf_evsel *pevsel, 892 + PyObject *args, PyObject *kwargs) 893 + { 894 + struct evsel *evsel = &pevsel->evsel; 895 + int cpu = 0, cpu_idx, thread = 0, thread_idx; 896 + struct perf_counts_values counts; 897 + struct pyrf_counts_values *count_values = PyObject_New(struct pyrf_counts_values, 898 + &pyrf_counts_values__type); 899 + 900 + if (!count_values) 901 + return NULL; 902 + 903 + if (!PyArg_ParseTuple(args, "ii", &cpu, &thread)) 904 + return NULL; 905 + 906 + cpu_idx = perf_cpu_map__idx(evsel->core.cpus, (struct perf_cpu){.cpu = cpu}); 907 + if (cpu_idx < 0) { 908 + PyErr_Format(PyExc_TypeError, "CPU %d is not part of evsel's CPUs", cpu); 909 + return NULL; 910 + } 911 + thread_idx = perf_thread_map__idx(evsel->core.threads, thread); 912 + if (cpu_idx < 0) { 913 + PyErr_Format(PyExc_TypeError, "Thread %d is not part of evsel's threads", 914 + thread); 915 + return NULL; 916 + } 917 + perf_evsel__read(&(evsel->core), cpu_idx, thread_idx, &counts); 918 + count_values->values = counts; 919 + return (PyObject *)count_values; 920 + } 921 + 891 922 static PyObject *pyrf_evsel__str(PyObject *self) 892 923 { 893 924 struct pyrf_evsel *pevsel = (void *)self; ··· 948 917 .ml_meth = (PyCFunction)pyrf_evsel__threads, 949 918 .ml_flags = METH_NOARGS, 950 919 .ml_doc = PyDoc_STR("threads the event is to be used with.") 920 + }, 921 + { 922 + .ml_name = "read", 923 + .ml_meth = (PyCFunction)pyrf_evsel__read, 924 + .ml_flags = METH_VARARGS | METH_KEYWORDS, 925 + .ml_doc = PyDoc_STR("read counters") 951 926 }, 952 927 { .ml_name = NULL, } 953 928 };