@@ -888,6 +888,37 @@ static PyObject *pyrf_evsel__threads(struct pyrf_evsel *pevsel)
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 ;
@@ -918,6 +949,12 @@ static PyMethodDef pyrf_evsel__methods[] = {
918
949
.ml_flags = METH_NOARGS ,
919
950
.ml_doc = PyDoc_STR ("threads the event is to be used with." )
920
951
},
952
+ {
953
+ .ml_name = "read" ,
954
+ .ml_meth = (PyCFunction )pyrf_evsel__read ,
955
+ .ml_flags = METH_VARARGS | METH_KEYWORDS ,
956
+ .ml_doc = PyDoc_STR ("read counters" )
957
+ },
921
958
{ .ml_name = NULL , }
922
959
};
923
960
0 commit comments