[New-bugs-announce] [issue28799] Drop CALL_PROFILE special build?

STINNER Victor report at bugs.python.org
Fri Nov 25 04:02:53 EST 2016


New submission from STINNER Victor:

Python/ceval.c contains conditional code to compute statistics on function calls when CALL_PROFILE is defined.

Extract of Misc/SpecialBuilds.txt:

    CALL_PROFILE
    ------------

    Count the number of function calls executed.

    When this symbol is defined, the ceval mainloop and
    helper functions count the number of function calls
    made.  It keeps detailed statistics about what kind of
    object was called and whether the call hit any of the
    special fast paths in the code.

Statistics can later be collected by sys.callstats().

I'm unable to find any unit test on this feature. The feature was added in Python 2.3.1 by the changeset 16856c9514e0 in 2003:
---
changeset:   27712:16856c9514e0
branch:      legacy-trunk
user:        Jeremy Hylton <jeremy at alum.mit.edu>
date:        Wed Feb 05 23:13:00 2003 +0000
files:       Include/ceval.h Include/compile.h Misc/SpecialBuilds.txt Python/ceval.c Python/compile.c Python/sysmodule.c
description:
Small function call optimization and special build option for call stats.

-DCALL_PROFILE: Count the number of function calls executed.

When this symbol is defined, the ceval mainloop and helper functions
count the number of function calls made.  It keeps detailed statistics
about what kind of object was called and whether the call hit any of
the special fast paths in the code.

Optimization:

When we take the fast_function() path, which seems to be taken for
most function calls, and there is minimal frame setup to do, avoid
call PyEval_EvalCodeEx().  The eval code ex function does a lot of
work to handle keywords args and star args, free variables,
generators, etc.  The inlined version simply allocates the frame and
copies the arguments values into the frame.

The optimization gets a little help from compile.c which adds a
CO_NOFREE flag to code objects that don't have free variables or cell
variables.  This change allows fast_function() to get into the fast
path with fewer tests.

I measure a couple of percent speedup in pystone with this change, but
there's surely more that can be done.
---

The changeset adds an optimization using CO_NOFREE and the CALL_PROFILE feature.

My problem is that with my work on FASTCALL, it became harder to track where the functions are called in practice. It maybe out of the Python/ceval.c file. I'm not sure that statistics are still computed correctly after my FASTCALL changes, and I don't know how to check it.

Python has already sys.setprofile(), cProfile and profile modules. There is also sys.settrace(). Do we still need CALL_PROFILE?

Attached patch removes the feature:

* Calling the the untested and undocumented sys.callstats() function now emits a DeprecationWarning warning
* Remove the PyEval_GetCallStats() function and its documentation

PyEval_GetCallStats() seems to be part of the stable API, but I don't expect that anyone uses it outside the CPython source code since it requires to rebuild CPython with a special build flag (-D CALL_PROFILE).

----------
messages: 281687
nosy: haypo
priority: normal
severity: normal
status: open
title: Drop CALL_PROFILE special build?
versions: Python 3.7

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue28799>
_______________________________________


More information about the New-bugs-announce mailing list