Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork33.3k
Closed
Description
Bug report
In 3.12, cProfile can count 0 primitive calls and miscalculate cumulative time in the following scenario.
For this layout:
script.pyproject/ typing.pyAnd the file contents:
script.py
importproject.typing
project/typing.py
fromtypingimportProtocolclassA(Protocol): ...
I observe this behavior difference withpython3 -m cProfile script.py:
3.11.2
697 function calls (693 primitive calls) in 0.001 seconds Ordered by: cumulative time ncalls tottime percall cumtime percall filename:lineno(function) 2/1 0.000 0.000 0.001 0.001 {built-in method builtins.exec} 1 0.000 0.000 0.001 0.001 script.py:1(<module>)3.12.0b3
635 function calls (630 primitive calls) in 0.001 seconds Ordered by: cumulative time ncalls tottime percall cumtime percall filename:lineno(function) 1 0.000 0.000 0.001 0.001 script.py:1(<module>)... 1/0 0.000 0.000 0.000 {built-in method builtins.exec}Notice the division by zero causing a missingpercall stat for exec.
This means that in more substantial examples, the profiler will omit a significant portion of the relevant cumulative time. See this output for a 14.286 second script, I only have access to a cumtime for 0.800:
45856453 function calls (31647888 primitive calls) in 14.286 seconds Ordered by: cumulative time ncalls tottime percall cumtime percall filename:lineno(function) 4054 0.005 0.000 0.800 0.000 modutils.py:620(_spec_from_modpath) ...Your environment
- CPython versions tested on: Python 3.12.0b3
- Operating system and architecture: MacOS 13.4.1