Skip to content

Commit 4f918d1

Browse files
committed
Convert method to argument clinic
1 parent f76d894 commit 4f918d1

File tree

2 files changed

+99
-31
lines changed

2 files changed

+99
-31
lines changed

Modules/_lsprof.c

Lines changed: 44 additions & 31 deletions
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,56 @@ 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+
cls: defining_class
570+
571+
list of profiler_entry objects.
572+
573+
getstats() -> list of profiler_entry objects
574+
575+
Return all information collected by the profiler.
576+
Each profiler_entry is a tuple-like object with the
577+
following attributes:
578+
579+
code code object
580+
callcount how many times this was called
581+
reccallcount how many times called recursively
582+
totaltime total time in this entry
583+
inlinetime inline time in this entry (not in subcalls)
584+
calls details of the calls
585+
586+
The calls attribute is either None or a list of
587+
profiler_subentry objects:
588+
589+
code called code object
590+
callcount how many times this is called
591+
reccallcount how many times this is called recursively
592+
totaltime total time spent in this call
593+
inlinetime inline time (not in further subcalls)
594+
[clinic start generated code]*/
595+
596+
static PyObject *
597+
_lsprof_Profiler_getstats_impl(ProfilerObject *self, PyTypeObject *cls)
598+
/*[clinic end generated code: output=1806ef720019ee03 input=445e193ef4522902]*/
585599
{
586600
statscollector_t collect;
587-
if (pending_exception(pObj)) {
601+
if (pending_exception(self)) {
588602
return NULL;
589603
}
590-
if (!pObj->externalTimer || pObj->externalTimerUnit == 0.0) {
604+
if (!self->externalTimer || self->externalTimerUnit == 0.0) {
591605
_PyTime_t onesec = _PyTime_FromSeconds(1);
592606
collect.factor = (double)1 / onesec;
593607
}
594608
else {
595-
collect.factor = pObj->externalTimerUnit;
609+
collect.factor = self->externalTimerUnit;
596610
}
597611

598612
collect.list = PyList_New(0);
599613
if (collect.list == NULL)
600614
return NULL;
601-
if (RotatingTree_Enum(pObj->profilerEntries, statsForEntry, &collect)
615+
if (RotatingTree_Enum(self->profilerEntries, statsForEntry, &collect)
602616
!= 0) {
603617
Py_DECREF(collect.list);
604618
return NULL;
@@ -750,8 +764,7 @@ profiler_init(ProfilerObject *pObj, PyObject *args, PyObject *kw)
750764
}
751765

752766
static PyMethodDef profiler_methods[] = {
753-
{"getstats", (PyCFunction)profiler_getstats,
754-
METH_NOARGS, getstats_doc},
767+
_LSPROF_PROFILER_GETSTATS_METHODDEF
755768
{"enable", (PyCFunction)(void(*)(void))profiler_enable,
756769
METH_VARARGS | METH_KEYWORDS, enable_doc},
757770
{"disable", (PyCFunction)profiler_disable,

Modules/clinic/_lsprof.c.h

Lines changed: 55 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)