@@ -19,87 +19,88 @@ static const std::string& make_region_name(const char* moduleName, const char* n
1919void CInstrumenter::enable_instrumenter ()
2020{
2121 const auto callback = [](PyObject* obj, PyFrameObject* frame, int what, PyObject* arg) -> int {
22- return fromPyObject (obj)->onEvent (*frame, what, arg) ? 0 : -1 ;
22+ return from_PyObject (obj)->on_event (*frame, what, arg) ? 0 : -1 ;
2323 };
24- if (tracingOrProfiling )
24+ if (tracing_or_profiling )
2525 {
26- PyEval_SetTrace (callback, toPyObject ());
26+ PyEval_SetTrace (callback, to_PyObject ());
2727 }
2828 else
2929 {
30- PyEval_SetProfile (callback, toPyObject ());
30+ PyEval_SetProfile (callback, to_PyObject ());
3131 }
3232}
3333
3434void CInstrumenter::disable_instrumenter ()
3535{
36- if (tracingOrProfiling )
36+ if (tracing_or_profiling )
3737 PyEval_SetTrace (nullptr , nullptr );
3838 else
3939 PyEval_SetProfile (nullptr , nullptr );
4040}
4141
4242// / Mapping of PyTrace_* to it's string representations
4343// / List taken from CPythons sysmodule.c
44- static const std::array<std::string, 8 > whatStrings = { " call" , " exception" , " line" ,
45- " return" , " c_call" , " c_exception" ,
46- " c_return" , " opcode" };
44+ static const std::array<std::string, 8 > WHAT_STRINGS = { " call" , " exception" , " line" ,
45+ " return" , " c_call" , " c_exception" ,
46+ " c_return" , " opcode" };
4747
4848// Required because: `sys.getprofile()` returns the user object (2nd arg to PyEval_SetTrace)
4949// So `sys.setprofile(sys.getprofile())` will not round-trip as it will try to call the
5050// 2nd arg through pythons dispatch function. Hence make the object callable.
5151// See https://nedbatchelder.com/text/trace-function.html for details
52- PyObject* CInstrumenter::operator ()(PyFrameObject& frame, const char * what , PyObject* arg)
52+ PyObject* CInstrumenter::operator ()(PyFrameObject& frame, const char * what_string , PyObject* arg)
5353{
54- const auto itWhat = std::find (whatStrings.begin (), whatStrings.end (), what);
55- const int iWhat = itWhat == whatStrings.end () ? -1 : std::distance (whatStrings.begin (), itWhat);
54+ const auto it_what = std::find (WHAT_STRINGS.begin (), WHAT_STRINGS.end (), what_string);
55+ const int what =
56+ it_what == WHAT_STRINGS.end () ? -1 : std::distance (WHAT_STRINGS.begin (), it_what);
5657 // To speed up further event processing install this class directly as the handler
5758 // But we might be inside a `sys.settrace` call where the user wanted to set another function
5859 // which would then be overwritten here. Hence use the CALL event which avoids the problem
59- if (iWhat == PyTrace_CALL)
60+ if (what == PyTrace_CALL)
6061 enable_instrumenter ();
61- if (onEvent (frame, iWhat , arg))
62+ if (on_event (frame, what , arg))
6263 {
63- Py_INCREF (toPyObject ());
64- return toPyObject ();
64+ Py_INCREF (to_PyObject ());
65+ return to_PyObject ();
6566 }
6667 else
6768 return nullptr ;
6869}
6970
70- bool CInstrumenter::onEvent (PyFrameObject& frame, int what, PyObject*)
71+ bool CInstrumenter::on_event (PyFrameObject& frame, int what, PyObject*)
7172{
7273 switch (what)
7374 {
7475 case PyTrace_CALL:
7576 {
7677 const PyCodeObject& code = *frame.f_code ;
7778 const char * name = PyUnicode_AsUTF8 (code.co_name );
78- const char * moduleName = get_module_name (frame);
79+ const char * module_name = get_module_name (frame);
7980 assert (name);
80- assert (moduleName );
81+ assert (module_name );
8182 // TODO: Use string_view/CString comparison?
82- if (std::string (name) != " _unsetprofile" && std::string (moduleName , 0 , 6 ) != " scorep" )
83+ if (std::string (name) != " _unsetprofile" && std::string (module_name , 0 , 6 ) != " scorep" )
8384 {
84- const int lineNumber = code.co_firstlineno ;
85- const auto & regionName = make_region_name (moduleName , name);
86- const auto fileName = get_file_name (frame);
87- region_begin (regionName, moduleName, fileName, lineNumber );
85+ const int line_number = code.co_firstlineno ;
86+ const auto & region_name = make_region_name (module_name , name);
87+ const auto file_name = get_file_name (frame);
88+ region_begin (region_name, module_name, file_name, line_number );
8889 }
8990 break ;
9091 }
9192 case PyTrace_RETURN:
9293 {
9394 const PyCodeObject& code = *frame.f_code ;
9495 const char * name = PyUnicode_AsUTF8 (code.co_name );
95- const char * moduleName = get_module_name (frame);
96+ const char * module_name = get_module_name (frame);
9697 assert (name);
97- assert (moduleName );
98+ assert (module_name );
9899 // TODO: Use string_view/CString comparison?
99- if (std::string (name) != " _unsetprofile" && std::string (moduleName , 0 , 6 ) != " scorep" )
100+ if (std::string (name) != " _unsetprofile" && std::string (module_name , 0 , 6 ) != " scorep" )
100101 {
101- const auto & regionName = make_region_name (moduleName , name);
102- region_end (regionName );
102+ const auto & region_name = make_region_name (module_name , name);
103+ region_end (region_name );
103104 }
104105 break ;
105106 }
0 commit comments