@@ -26,22 +26,35 @@ extern "C"
2626
2727 static int CInstrumenter_init (scorepy::CInstrumenter* self, PyObject* args, PyObject* kwds)
2828 {
29- static const char * kwlist[] = { " tracing_or_profiling " , nullptr };
30- int tracing_or_profiling ;
29+ static const char * kwlist[] = { " interface " , nullptr };
30+ const char * interface_cstring ;
3131
32- if (!PyArg_ParseTupleAndKeywords (args, kwds, " p " , const_cast <char **>(kwlist),
33- &tracing_or_profiling ))
32+ if (!PyArg_ParseTupleAndKeywords (args, kwds, " s " , const_cast <char **>(kwlist),
33+ &interface_cstring ))
3434 return -1 ;
3535
36- self->init (tracing_or_profiling != 0 );
36+ const std::string interface_string = interface_cstring;
37+ scorepy::InstrumenterInterface interface;
38+ if (interface_string == " Trace" )
39+ interface = scorepy::InstrumenterInterface::Trace;
40+ else if (interface_string == " Profile" )
41+ interface = scorepy::InstrumenterInterface::Profile;
42+ else
43+ {
44+ PyErr_Format (PyExc_TypeError, " Expected 'Trace' or 'Profile', got '%s'" ,
45+ interface_cstring);
46+ return -1 ;
47+ }
48+
49+ self->init (interface);
3750 return 0 ;
3851 }
3952
40- static PyObject* CInstrumenter_get_tracingOrProfiling (scorepy::CInstrumenter* self, void *)
53+ static PyObject* CInstrumenter_get_interface (scorepy::CInstrumenter* self, void *)
4154 {
42- scorepy::PyRefObject result (self-> tracing_or_profiling ? Py_True : Py_False,
43- scorepy::retain_object) ;
44- return result;
55+ const char * result =
56+ self-> interface == scorepy::InstrumenterInterface::Trace ? " Trace " : " Profile " ;
57+ return PyUnicode_FromString ( result) ;
4558 }
4659
4760 static PyObject* CInstrumenter_enable_instrumenter (scorepy::CInstrumenter* self, PyObject*)
@@ -85,9 +98,8 @@ PyTypeObject& getCInstrumenterType()
8598 { nullptr } /* Sentinel */
8699 };
87100 static PyGetSetDef getseters[] = {
88- { " tracing_or_profiling" , scorepy::cast_to_PyFunc (CInstrumenter_get_tracingOrProfiling),
89- nullptr , " Return whether the trace (True) or profile (False) instrumentation is used" ,
90- nullptr },
101+ { " interface" , scorepy::cast_to_PyFunc (CInstrumenter_get_interface), nullptr ,
102+ " Return the used interface for instrumentation" , nullptr },
91103 { nullptr } /* Sentinel */
92104 };
93105 // Sets the first few fields explicitely and remaining ones to zero
0 commit comments