Skip to content

Commit 1b328ea

Browse files
authored
bpo-1635741: Convert an _lsprof method to argument clinic (GH-22240)
1 parent c322948 commit 1b328ea

File tree

2 files changed

+86
-31
lines changed

2 files changed

+86
-31
lines changed

Modules/_lsprof.c

+42-31
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,15 @@ typedef struct {
5050
#define POF_BUILTINS 0x004
5151
#define POF_NOMEMORY 0x100
5252

53+
/*[clinic input]
54+
module _lsprof
55+
class _lsprof.Profiler "ProfilerObject *" "&ProfilerType"
56+
[clinic start generated code]*/
57+
/*[clinic end generated code: output=da39a3ee5e6b4b0d input=e349ac952152f336]*/
5358
static PyTypeObject PyProfiler_Type;
5459

60+
#include "clinic/_lsprof.c.h"
61+
5562
#define PyProfiler_Check(op) PyObject_TypeCheck(op, &PyProfiler_Type)
5663
#define PyProfiler_CheckExact(op) Py_IS_TYPE(op, &PyProfiler_Type)
5764

@@ -556,49 +563,54 @@ static int statsForEntry(rotating_node_t *node, void *arg)
556563
return err;
557564
}
558565

559-
PyDoc_STRVAR(getstats_doc, "\
560-
getstats() -> list of profiler_entry objects\n\
561-
\n\
562-
Return all information collected by the profiler.\n\
563-
Each profiler_entry is a tuple-like object with the\n\
564-
following attributes:\n\
565-
\n\
566-
code code object\n\
567-
callcount how many times this was called\n\
568-
reccallcount how many times called recursively\n\
569-
totaltime total time in this entry\n\
570-
inlinetime inline time in this entry (not in subcalls)\n\
571-
calls details of the calls\n\
572-
\n\
573-
The calls attribute is either None or a list of\n\
574-
profiler_subentry objects:\n\
575-
\n\
576-
code called code object\n\
577-
callcount how many times this is called\n\
578-
reccallcount how many times this is called recursively\n\
579-
totaltime total time spent in this call\n\
580-
inlinetime inline time (not in further subcalls)\n\
581-
");
566+
/*[clinic input]
567+
_lsprof.Profiler.getstats
582568
583-
static PyObject*
584-
profiler_getstats(ProfilerObject *pObj, PyObject* noarg)
569+
list of profiler_entry objects.
570+
571+
getstats() -> list of profiler_entry objects
572+
573+
Return all information collected by the profiler.
574+
Each profiler_entry is a tuple-like object with the
575+
following attributes:
576+
577+
code code object
578+
callcount how many times this was called
579+
reccallcount how many times called recursively
580+
totaltime total time in this entry
581+
inlinetime inline time in this entry (not in subcalls)
582+
calls details of the calls
583+
584+
The calls attribute is either None or a list of
585+
profiler_subentry objects:
586+
587+
code called code object
588+
callcount how many times this is called
589+
reccallcount how many times this is called recursively
590+
totaltime total time spent in this call
591+
inlinetime inline time (not in further subcalls)
592+
[clinic start generated code]*/
593+
594+
static PyObject *
595+
_lsprof_Profiler_getstats_impl(ProfilerObject *self)
596+
/*[clinic end generated code: output=9461b451e9ef0f24 input=ade04fa384ce450a]*/
585597
{
586598
statscollector_t collect;
587-
if (pending_exception(pObj)) {
599+
if (pending_exception(self)) {
588600
return NULL;
589601
}
590-
if (!pObj->externalTimer || pObj->externalTimerUnit == 0.0) {
602+
if (!self->externalTimer || self->externalTimerUnit == 0.0) {
591603
_PyTime_t onesec = _PyTime_FromSeconds(1);
592604
collect.factor = (double)1 / onesec;
593605
}
594606
else {
595-
collect.factor = pObj->externalTimerUnit;
607+
collect.factor = self->externalTimerUnit;
596608
}
597609

598610
collect.list = PyList_New(0);
599611
if (collect.list == NULL)
600612
return NULL;
601-
if (RotatingTree_Enum(pObj->profilerEntries, statsForEntry, &collect)
613+
if (RotatingTree_Enum(self->profilerEntries, statsForEntry, &collect)
602614
!= 0) {
603615
Py_DECREF(collect.list);
604616
return NULL;
@@ -750,8 +762,7 @@ profiler_init(ProfilerObject *pObj, PyObject *args, PyObject *kw)
750762
}
751763

752764
static PyMethodDef profiler_methods[] = {
753-
{"getstats", (PyCFunction)profiler_getstats,
754-
METH_NOARGS, getstats_doc},
765+
_LSPROF_PROFILER_GETSTATS_METHODDEF
755766
{"enable", (PyCFunction)(void(*)(void))profiler_enable,
756767
METH_VARARGS | METH_KEYWORDS, enable_doc},
757768
{"disable", (PyCFunction)profiler_disable,

Modules/clinic/_lsprof.c.h

+44
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)