Skip to content

Commit 18ea7fc

Browse files
committed
Refactor to match coding style
Replace camelCase by snake_case
1 parent 7c6fab0 commit 18ea7fc

7 files changed

Lines changed: 56 additions & 55 deletions

File tree

scorep/_instrumenters/scorep_cProfile.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
class ScorepCProfile(scorep._bindings.CInstrumenter, ScorepInstrumenter):
66
def __init__(self, enable_instrumenter):
7-
scorep._bindings.CInstrumenter.__init__(self, tracingOrProfiling=False)
7+
scorep._bindings.CInstrumenter.__init__(self, tracing_or_profiling=False)
88
ScorepInstrumenter.__init__(self, enable_instrumenter)
99

1010
def _enable_instrumenter(self):

scorep/_instrumenters/scorep_cTrace.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
class ScorepCTrace(scorep._bindings.CInstrumenter, ScorepInstrumenter):
66
def __init__(self, enable_instrumenter):
7-
scorep._bindings.CInstrumenter.__init__(self, tracingOrProfiling=True)
7+
scorep._bindings.CInstrumenter.__init__(self, tracing_or_profiling=True)
88
ScorepInstrumenter.__init__(self, enable_instrumenter)
99

1010
def _enable_instrumenter(self):

src/classes.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,20 @@ extern "C"
2626

2727
static int CInstrumenter_init(scorepy::CInstrumenter* self, PyObject* args, PyObject* kwds)
2828
{
29-
static const char* kwlist[] = { "tracingOrProfiling", nullptr };
30-
int tracingOrProfiling;
29+
static const char* kwlist[] = { "tracing_or_profiling", nullptr };
30+
int tracing_or_profiling;
3131

3232
if (!PyArg_ParseTupleAndKeywords(args, kwds, "p", const_cast<char**>(kwlist),
33-
&tracingOrProfiling))
33+
&tracing_or_profiling))
3434
return -1;
3535

36-
self->init(tracingOrProfiling != 0);
36+
self->init(tracing_or_profiling != 0);
3737
return 0;
3838
}
3939

4040
static PyObject* CInstrumenter_get_tracingOrProfiling(scorepy::CInstrumenter* self, void*)
4141
{
42-
scorepy::PyRefObject result(self->tracingOrProfiling ? Py_True : Py_False,
42+
scorepy::PyRefObject result(self->tracing_or_profiling ? Py_True : Py_False,
4343
scorepy::retain_object);
4444
return result;
4545
}
@@ -78,14 +78,14 @@ namespace scorepy
7878
PyTypeObject& getCInstrumenterType()
7979
{
8080
static PyMethodDef methods[] = {
81-
{ "_enable_instrumenter", scorepy::castToPyFunc(CInstrumenter_enable_instrumenter),
81+
{ "_enable_instrumenter", scorepy::cast_to_PyFunc(CInstrumenter_enable_instrumenter),
8282
METH_NOARGS, "Enable the instrumenter" },
83-
{ "_disable_instrumenter", scorepy::castToPyFunc(CInstrumenter_disable_instrumenter),
83+
{ "_disable_instrumenter", scorepy::cast_to_PyFunc(CInstrumenter_disable_instrumenter),
8484
METH_NOARGS, "Disable the instrumenter" },
8585
{ nullptr } /* Sentinel */
8686
};
8787
static PyGetSetDef getseters[] = {
88-
{ "tracingOrProfiling", scorepy::castToPyFunc(CInstrumenter_get_tracingOrProfiling),
88+
{ "tracing_or_profiling", scorepy::cast_to_PyFunc(CInstrumenter_get_tracingOrProfiling),
8989
nullptr, "Return whether the trace (True) or profile (False) instrumentation is used",
9090
nullptr },
9191
{ nullptr } /* Sentinel */
@@ -97,9 +97,9 @@ PyTypeObject& getCInstrumenterType()
9797
sizeof(CInstrumenter), /* tp_basicsize */
9898
};
9999
type.tp_new = call_object_new;
100-
type.tp_init = scorepy::castToPyFunc(CInstrumenter_init);
100+
type.tp_init = scorepy::cast_to_PyFunc(CInstrumenter_init);
101101
type.tp_methods = methods;
102-
type.tp_call = scorepy::castToPyFunc(CInstrumenter_call);
102+
type.tp_call = scorepy::cast_to_PyFunc(CInstrumenter_call);
103103
type.tp_getset = getseters;
104104
type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
105105
type.tp_doc = "Class for the C instrumenter interface of Score-P";

src/scorepy/cInstrumenter.cpp

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -19,87 +19,88 @@ static const std::string& make_region_name(const char* moduleName, const char* n
1919
void 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

3434
void 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
}

src/scorepy/cInstrumenter.hpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ namespace scorepy
88
struct CInstrumenter
99
{
1010
PyObject_HEAD;
11-
bool tracingOrProfiling;
11+
bool tracing_or_profiling;
1212

13-
void init(bool tracingOrProfiling)
13+
void init(bool tracing_or_profiling)
1414
{
15-
this->tracingOrProfiling = tracingOrProfiling;
15+
this->tracing_or_profiling = tracing_or_profiling;
1616
}
1717
void enable_instrumenter();
1818
void disable_instrumenter();
@@ -21,18 +21,18 @@ struct CInstrumenter
2121
PyObject* operator()(PyFrameObject& frame, const char* what, PyObject* arg);
2222

2323
/// These casts are valid as long as `PyObject_HEAD` is the first entry in this struct
24-
PyObject* toPyObject()
24+
PyObject* to_PyObject()
2525
{
2626
return reinterpret_cast<PyObject*>(this);
2727
}
28-
static CInstrumenter* fromPyObject(PyObject* o)
28+
static CInstrumenter* from_PyObject(PyObject* o)
2929
{
3030
return reinterpret_cast<CInstrumenter*>(o);
3131
}
3232

3333
private:
3434
/// Callback for Python trace/profile events. Return true for success
35-
bool onEvent(PyFrameObject& frame, int what, PyObject* arg);
35+
bool on_event(PyFrameObject& frame, int what, PyObject* arg);
3636
};
3737

3838
} // namespace scorepy

src/scorepy/pythonHelpers.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ namespace scorepy
55
{
66
const char* get_module_name(const PyFrameObject& frame)
77
{
8-
PyObject* moduleName = PyDict_GetItemString(frame.f_globals, "__name__");
9-
if (moduleName)
10-
return PyUnicode_AsUTF8(moduleName);
8+
PyObject* module_name = PyDict_GetItemString(frame.f_globals, "__name__");
9+
if (module_name)
10+
return PyUnicode_AsUTF8(module_name);
1111

1212
// this is a NUMPY special situation, see NEP-18, and Score-P issue #63
1313
// TODO: Use string_view/C-String to avoid creating 2 std::strings
@@ -20,11 +20,11 @@ const char* get_module_name(const PyFrameObject& frame)
2020

2121
std::string get_file_name(const PyFrameObject& frame)
2222
{
23-
PyObject* fileName = frame.f_code->co_filename;
24-
if (fileName == Py_None)
23+
PyObject* filename = frame.f_code->co_filename;
24+
if (filename == Py_None)
2525
return "None";
26-
char actualpath[PATH_MAX];
27-
const char* full_file_name = realpath(PyUnicode_AsUTF8(fileName), actualpath);
26+
char actual_path[PATH_MAX];
27+
const char* full_file_name = realpath(PyUnicode_AsUTF8(filename), actual_path);
2828
return full_file_name ? full_file_name : "ErrorPath";
2929
}
3030
} // namespace scorepy

src/scorepy/pythonHelpers.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ namespace detail
6666
/// Cast a function pointer to a python-bindings compatible function pointer
6767
/// Replaces all Foo* by PyObject* for all types Foo that are PyObject compatible
6868
template <typename TFunc>
69-
auto castToPyFunc(TFunc* func) -> detail::ReplaceArgsToPyObject_t<TFunc>*
69+
auto cast_to_PyFunc(TFunc* func) -> detail::ReplaceArgsToPyObject_t<TFunc>*
7070
{
7171
return reinterpret_cast<detail::ReplaceArgsToPyObject_t<TFunc>*>(func);
7272
}
@@ -99,7 +99,7 @@ namespace detail
9999
};
100100

101101
template <class T>
102-
struct IsPyObject<T, void_t<decltype(std::declval<T>().toPyObject())>> : std::true_type
102+
struct IsPyObject<T, void_t<decltype(std::declval<T>().to_PyObject())>> : std::true_type
103103
{
104104
};
105105

0 commit comments

Comments
 (0)