bpo-1635741: Convert an _lsprof method to argument clinic (GH-22240)

This commit is contained in:
Mohamed Koubaa 2020-09-21 07:40:42 -05:00 committed by GitHub
parent c322948892
commit 1b328ea9a7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 86 additions and 31 deletions

View file

@ -50,8 +50,15 @@ typedef struct {
#define POF_BUILTINS 0x004 #define POF_BUILTINS 0x004
#define POF_NOMEMORY 0x100 #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; static PyTypeObject PyProfiler_Type;
#include "clinic/_lsprof.c.h"
#define PyProfiler_Check(op) PyObject_TypeCheck(op, &PyProfiler_Type) #define PyProfiler_Check(op) PyObject_TypeCheck(op, &PyProfiler_Type)
#define PyProfiler_CheckExact(op) Py_IS_TYPE(op, &PyProfiler_Type) #define PyProfiler_CheckExact(op) Py_IS_TYPE(op, &PyProfiler_Type)
@ -556,49 +563,54 @@ static int statsForEntry(rotating_node_t *node, void *arg)
return err; return err;
} }
PyDoc_STRVAR(getstats_doc, "\ /*[clinic input]
getstats() -> list of profiler_entry objects\n\ _lsprof.Profiler.getstats
\n\
Return all information collected by the profiler.\n\ list of profiler_entry objects.
Each profiler_entry is a tuple-like object with the\n\
following attributes:\n\ getstats() -> list of profiler_entry objects
\n\
code code object\n\ Return all information collected by the profiler.
callcount how many times this was called\n\ Each profiler_entry is a tuple-like object with the
reccallcount how many times called recursively\n\ following attributes:
totaltime total time in this entry\n\
inlinetime inline time in this entry (not in subcalls)\n\ code code object
calls details of the calls\n\ callcount how many times this was called
\n\ reccallcount how many times called recursively
The calls attribute is either None or a list of\n\ totaltime total time in this entry
profiler_subentry objects:\n\ inlinetime inline time in this entry (not in subcalls)
\n\ calls details of the calls
code called code object\n\
callcount how many times this is called\n\ The calls attribute is either None or a list of
reccallcount how many times this is called recursively\n\ profiler_subentry objects:
totaltime total time spent in this call\n\
inlinetime inline time (not in further subcalls)\n\ 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 * static PyObject *
profiler_getstats(ProfilerObject *pObj, PyObject* noarg) _lsprof_Profiler_getstats_impl(ProfilerObject *self)
/*[clinic end generated code: output=9461b451e9ef0f24 input=ade04fa384ce450a]*/
{ {
statscollector_t collect; statscollector_t collect;
if (pending_exception(pObj)) { if (pending_exception(self)) {
return NULL; return NULL;
} }
if (!pObj->externalTimer || pObj->externalTimerUnit == 0.0) { if (!self->externalTimer || self->externalTimerUnit == 0.0) {
_PyTime_t onesec = _PyTime_FromSeconds(1); _PyTime_t onesec = _PyTime_FromSeconds(1);
collect.factor = (double)1 / onesec; collect.factor = (double)1 / onesec;
} }
else { else {
collect.factor = pObj->externalTimerUnit; collect.factor = self->externalTimerUnit;
} }
collect.list = PyList_New(0); collect.list = PyList_New(0);
if (collect.list == NULL) if (collect.list == NULL)
return NULL; return NULL;
if (RotatingTree_Enum(pObj->profilerEntries, statsForEntry, &collect) if (RotatingTree_Enum(self->profilerEntries, statsForEntry, &collect)
!= 0) { != 0) {
Py_DECREF(collect.list); Py_DECREF(collect.list);
return NULL; return NULL;
@ -750,8 +762,7 @@ profiler_init(ProfilerObject *pObj, PyObject *args, PyObject *kw)
} }
static PyMethodDef profiler_methods[] = { static PyMethodDef profiler_methods[] = {
{"getstats", (PyCFunction)profiler_getstats, _LSPROF_PROFILER_GETSTATS_METHODDEF
METH_NOARGS, getstats_doc},
{"enable", (PyCFunction)(void(*)(void))profiler_enable, {"enable", (PyCFunction)(void(*)(void))profiler_enable,
METH_VARARGS | METH_KEYWORDS, enable_doc}, METH_VARARGS | METH_KEYWORDS, enable_doc},
{"disable", (PyCFunction)profiler_disable, {"disable", (PyCFunction)profiler_disable,

44
Modules/clinic/_lsprof.c.h generated Normal file
View file

@ -0,0 +1,44 @@
/*[clinic input]
preserve
[clinic start generated code]*/
PyDoc_STRVAR(_lsprof_Profiler_getstats__doc__,
"getstats($self, /)\n"
"--\n"
"\n"
"list of profiler_entry objects.\n"
"\n"
"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)");
#define _LSPROF_PROFILER_GETSTATS_METHODDEF \
{"getstats", (PyCFunction)_lsprof_Profiler_getstats, METH_NOARGS, _lsprof_Profiler_getstats__doc__},
static PyObject *
_lsprof_Profiler_getstats_impl(ProfilerObject *self);
static PyObject *
_lsprof_Profiler_getstats(ProfilerObject *self, PyObject *Py_UNUSED(ignored))
{
return _lsprof_Profiler_getstats_impl(self);
}
/*[clinic end generated code: output=24c525812713e00f input=a9049054013a1b77]*/