python / python/cpython

Sampling profiler fails to display user-defined function in IDLE when started with the run command

Open
#142,325 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

3.15 stdlib topic-profiling type-bug
Dominant language
Python
Stars
77.2k
Forks
35.9k
PR merge metrics
PR metrics pending

Description

Bug report

Bug description:

This is my simple test running IDLE at profiler startup (sudo as I'm running on a Mac, YMMV):

sudo -E ./python.exe -m profiling.sampling run -a --realtime-stats -d 99999 --live -m idlelib

As expected, I can also attach to a running IDLE session:

sudo -E ./python.exe -m profiling.sampling attach -a --realtime-stats -d 99999 --live <PID>

The two versions display things differently. If I attach to a running IDLE, define fib(), then call it with a large n (say, 200), it will run for a while before returning a result. I can see the recursive calls to fib in the display.

Image

If I use the run command instead, I never see fib show in the display. Instead, I see something like this:

Image

It appears all the samples in fib are credited to Misc.mainloop. I know the function is executing, given that small-n calls return quickly with the correct result, but shouldn't fib show up in the display when called with a large value for n if I use the run command to start IDLE?

CPython versions tested on:

CPython main branch

Operating systems tested on:

macOS

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the difference between the profiling.sampling run and attach commands against idlelib, using a recursive fib() call as described. Start by tracing how profiling.sampling handles the run path and compare its displayed samples with attach; done means user-defined functions such as fib appear in the run display instead of being credited to Misc.mainloop.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
devtools, performance
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.