Skip to content

bpo-1635741: convert an _lsprof method to argument clinic #22240

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 42 additions & 31 deletions Modules/_lsprof.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,15 @@ typedef struct {
#define POF_BUILTINS 0x004
#define POF_NOMEMORY 0x100

/*[clinic input]
module _lsprof
class _lsprof.Profiler "ProfilerObject *" "&ProfilerType"
[clinic start generated code]*/
/*[clinic end generated code: output=da39a3ee5e6b4b0d input=e349ac952152f336]*/
static PyTypeObject PyProfiler_Type;

#include "clinic/_lsprof.c.h"

#define PyProfiler_Check(op) PyObject_TypeCheck(op, &PyProfiler_Type)
#define PyProfiler_CheckExact(op) Py_IS_TYPE(op, &PyProfiler_Type)

Expand Down Expand Up @@ -556,49 +563,54 @@ static int statsForEntry(rotating_node_t *node, void *arg)
return err;
}

PyDoc_STRVAR(getstats_doc, "\
getstats() -> list of profiler_entry objects\n\
\n\
Return all information collected by the profiler.\n\
Each profiler_entry is a tuple-like object with the\n\
following attributes:\n\
\n\
code code object\n\
callcount how many times this was called\n\
reccallcount how many times called recursively\n\
totaltime total time in this entry\n\
inlinetime inline time in this entry (not in subcalls)\n\
calls details of the calls\n\
\n\
The calls attribute is either None or a list of\n\
profiler_subentry objects:\n\
\n\
code called code object\n\
callcount how many times this is called\n\
reccallcount how many times this is called recursively\n\
totaltime total time spent in this call\n\
inlinetime inline time (not in further subcalls)\n\
");
/*[clinic input]
_lsprof.Profiler.getstats

static PyObject*
profiler_getstats(ProfilerObject *pObj, PyObject* noarg)
list of profiler_entry objects.

getstats() -> list of profiler_entry objects

Return all information collected by the profiler.
Each profiler_entry is a tuple-like object with the
following attributes:

code code object
callcount how many times this was called
reccallcount how many times called recursively
totaltime total time in this entry
inlinetime inline time in this entry (not in subcalls)
calls details of the calls

The calls attribute is either None or a list of
profiler_subentry objects:

code called code object
callcount how many times this is called
reccallcount how many times this is called recursively
totaltime total time spent in this call
inlinetime inline time (not in further subcalls)
[clinic start generated code]*/

static PyObject *
_lsprof_Profiler_getstats_impl(ProfilerObject *self)
/*[clinic end generated code: output=9461b451e9ef0f24 input=ade04fa384ce450a]*/
{
statscollector_t collect;
if (pending_exception(pObj)) {
if (pending_exception(self)) {
return NULL;
}
if (!pObj->externalTimer || pObj->externalTimerUnit == 0.0) {
if (!self->externalTimer || self->externalTimerUnit == 0.0) {
_PyTime_t onesec = _PyTime_FromSeconds(1);
collect.factor = (double)1 / onesec;
}
else {
collect.factor = pObj->externalTimerUnit;
collect.factor = self->externalTimerUnit;
}

collect.list = PyList_New(0);
if (collect.list == NULL)
return NULL;
if (RotatingTree_Enum(pObj->profilerEntries, statsForEntry, &collect)
if (RotatingTree_Enum(self->profilerEntries, statsForEntry, &collect)
!= 0) {
Py_DECREF(collect.list);
return NULL;
Expand Down Expand Up @@ -750,8 +762,7 @@ profiler_init(ProfilerObject *pObj, PyObject *args, PyObject *kw)
}

static PyMethodDef profiler_methods[] = {
{"getstats", (PyCFunction)profiler_getstats,
METH_NOARGS, getstats_doc},
_LSPROF_PROFILER_GETSTATS_METHODDEF
{"enable", (PyCFunction)(void(*)(void))profiler_enable,
METH_VARARGS | METH_KEYWORDS, enable_doc},
{"disable", (PyCFunction)profiler_disable,
Expand Down
44 changes: 44 additions & 0 deletions Modules/clinic/_lsprof.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.