cpython/Modules/_lsprof.c

#ifndef Py_BUILD_CORE_BUILTIN
#define Py_BUILD_CORE_MODULE
#endif

#include "Python.h"
#include "pycore_call.h"          // _PyObject_CallNoArgs()
#include "pycore_ceval.h"         // _PyEval_SetProfile()
#include "pycore_pystate.h"       // _PyThreadState_GET()
#include "pycore_time.h"          // _PyTime_FromLong()

#include "rotatingtree.h"

/************************************************************/
/* Written by Brett Rosen and Ted Czotter */

struct _ProfilerEntry;

/* represents a function called from another function */
ProfilerSubEntry;

/* represents a function or user defined block */
ProfilerEntry;

ProfilerContext;

ProfilerObject;

#define POF_ENABLED
#define POF_SUBCALLS
#define POF_BUILTINS
#define POF_EXT_TIMER
#define POF_NOMEMORY

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

#include "clinic/_lsprof.c.h"

_lsprof_state;

static inline _lsprof_state*
_lsprof_get_state(PyObject *module)
{}

/*** External Timers ***/

static PyTime_t CallExternalTimer(ProfilerObject *pObj)
{}

static inline PyTime_t
call_timer(ProfilerObject *pObj)
{}


/*** ProfilerObject ***/

static PyObject *
normalizeUserObj(PyObject *obj)
{}

static ProfilerEntry*
newProfilerEntry(ProfilerObject *pObj, void *key, PyObject *userObj)
{}

static ProfilerEntry*
getEntry(ProfilerObject *pObj, void *key)
{}

static ProfilerSubEntry *
getSubEntry(ProfilerObject *pObj, ProfilerEntry *caller, ProfilerEntry* entry)
{}

static ProfilerSubEntry *
newSubEntry(ProfilerObject *pObj,  ProfilerEntry *caller, ProfilerEntry* entry)
{}

static int freeSubEntry(rotating_node_t *header, void *arg)
{}

static int freeEntry(rotating_node_t *header, void *arg)
{}

static void clearEntries(ProfilerObject *pObj)
{}

static void
initContext(ProfilerObject *pObj, ProfilerContext *self, ProfilerEntry *entry)
{}

static void
Stop(ProfilerObject *pObj, ProfilerContext *self, ProfilerEntry *entry)
{}

static void
ptrace_enter_call(PyObject *self, void *key, PyObject *userObj)
{}

static void
ptrace_leave_call(PyObject *self, void *key)
{}

static int
pending_exception(ProfilerObject *pObj)
{}

/************************************************************/

static PyStructSequence_Field profiler_entry_fields[] =;

static PyStructSequence_Field profiler_subentry_fields[] =;

static PyStructSequence_Desc profiler_entry_desc =;

static PyStructSequence_Desc profiler_subentry_desc =;

statscollector_t;

static int statsForSubEntry(rotating_node_t *node, void *arg)
{}

static int statsForEntry(rotating_node_t *node, void *arg)
{}

/*[clinic input]
_lsprof.Profiler.getstats

    cls: defining_class

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, PyTypeObject *cls)
/*[clinic end generated code: output=1806ef720019ee03 input=445e193ef4522902]*/
{}

static int
setSubcalls(ProfilerObject *pObj, int nvalue)
{}

static int
setBuiltins(ProfilerObject *pObj, int nvalue)
{}

/*[clinic input]
_lsprof.Profiler._pystart_callback

    code: object
    instruction_offset: object
    /

[clinic start generated code]*/

static PyObject *
_lsprof_Profiler__pystart_callback_impl(ProfilerObject *self, PyObject *code,
                                        PyObject *instruction_offset)
/*[clinic end generated code: output=5fec8b7ad5ed25e8 input=b166e6953c579cda]*/
{}

/*[clinic input]
_lsprof.Profiler._pyreturn_callback

    code: object
    instruction_offset: object
    retval: object
    /

[clinic start generated code]*/

static PyObject *
_lsprof_Profiler__pyreturn_callback_impl(ProfilerObject *self,
                                         PyObject *code,
                                         PyObject *instruction_offset,
                                         PyObject *retval)
/*[clinic end generated code: output=9e2f6fc1b882c51e input=667ffaeb2fa6fd1f]*/
{}

PyObject* get_cfunc_from_callable(PyObject* callable, PyObject* self_arg, PyObject* missing)
{}

/*[clinic input]
_lsprof.Profiler._ccall_callback

    code: object
    instruction_offset: object
    callable: object
    self_arg: object
    /

[clinic start generated code]*/

static PyObject *
_lsprof_Profiler__ccall_callback_impl(ProfilerObject *self, PyObject *code,
                                      PyObject *instruction_offset,
                                      PyObject *callable, PyObject *self_arg)
/*[clinic end generated code: output=152db83cabd18cad input=0e66687cfb95c001]*/
{}

/*[clinic input]
_lsprof.Profiler._creturn_callback

    code: object
    instruction_offset: object
    callable: object
    self_arg: object
    /

[clinic start generated code]*/

static PyObject *
_lsprof_Profiler__creturn_callback_impl(ProfilerObject *self, PyObject *code,
                                        PyObject *instruction_offset,
                                        PyObject *callable,
                                        PyObject *self_arg)
/*[clinic end generated code: output=1e886dde8fed8fb0 input=b18afe023746923a]*/
{}

static const struct {} callback_table[] =;


/*[clinic input]
_lsprof.Profiler.enable

    subcalls: bool = True
        If True, also records for each function
        statistics separated according to its current caller.

    builtins: bool = True
        If True, records the time spent in
        built-in functions separately from their caller.

Start collecting profiling information.
[clinic start generated code]*/

static PyObject *
_lsprof_Profiler_enable_impl(ProfilerObject *self, int subcalls,
                             int builtins)
/*[clinic end generated code: output=1e747f9dc1edd571 input=9ab81405107ab7f1]*/
{}

static void
flush_unmatched(ProfilerObject *pObj)
{}


/*[clinic input]
_lsprof.Profiler.disable

Stop collecting profiling information.
[clinic start generated code]*/

static PyObject *
_lsprof_Profiler_disable_impl(ProfilerObject *self)
/*[clinic end generated code: output=838cffef7f651870 input=05700b3fc68d1f50]*/
{}

/*[clinic input]
_lsprof.Profiler.clear

Clear all profiling information collected so far.
[clinic start generated code]*/

static PyObject *
_lsprof_Profiler_clear_impl(ProfilerObject *self)
/*[clinic end generated code: output=dd1c668fb84b1335 input=fbe1f88c28be4f98]*/
{}

static int
profiler_traverse(ProfilerObject *op, visitproc visit, void *arg)
{}

static void
profiler_dealloc(ProfilerObject *op)
{}

/*[clinic input]
_lsprof.Profiler.__init__ as profiler_init

    timer: object(c_default='NULL') = None
    timeunit: double = 0.0
    subcalls: bool = True
    builtins: bool = True

Build a profiler object using the specified timer function.

The default timer is a fast built-in one based on real time.
For custom timer functions returning integers, 'timeunit' can
be a float specifying a scale (that is, how long each integer unit
is, in seconds).
[clinic start generated code]*/

static int
profiler_init_impl(ProfilerObject *self, PyObject *timer, double timeunit,
                   int subcalls, int builtins)
/*[clinic end generated code: output=ac523803ec9f9df2 input=8285ca746f96a414]*/
{}

static PyMethodDef profiler_methods[] =;

static PyType_Slot _lsprof_profiler_type_spec_slots[] =;

static PyType_Spec _lsprof_profiler_type_spec =;

static PyMethodDef moduleMethods[] =;

static int
_lsprof_traverse(PyObject *module, visitproc visit, void *arg)
{}

static int
_lsprof_clear(PyObject *module)
{}

static void
_lsprof_free(void *module)
{}

static int
_lsprof_exec(PyObject *module)
{}

static PyModuleDef_Slot _lsprofslots[] =;

static struct PyModuleDef _lsprofmodule =;

PyMODINIT_FUNC
PyInit__lsprof(void)
{}