-
Notifications
You must be signed in to change notification settings - Fork 446
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
py-spy not showing child function calls in flame graph #87
Comments
Hmm - I'm guessing that the time.sleep call takes the most amount of time and is crowding out the actual work. There is some code in the the flame graph generation that limits traces to a minimum of 2px (https://github.com/benfred/py-spy/blob/v0.1.10/src/flamegraph.rs#L88). I'm wondering if the time.sleep call is hit so much more often that the other calls just don't show up since they would be less than 2px in the output. You could change the rate to something much higher (1000 or 5000 samples per second - py-spy will warn you if it can't keep up) and try again, but that might not change the relative proportion. Turning off showing line numbers might help in this case ( I think we really should have better idle detection: we should be able to filter out calls to time.sleep entirely from the output since no work is being done. Right now there are some heuristics to match common idle states, but it shouldn't be too crazy to actually get the thread status from the OS |
I was able to get the information I needed with pyflame using the Thanks again for your help. |
I created a new issue to track better idle detection #92 and I'm going to close this issue. The pyflame option you used is filtering down to stack frame that hold on to the GIL. This isn't perfect either (extensions can release the GIL while doing work etc), but I'm glad it helped you out here. Also, I pushed out a beta version with some UI changes that might help you out: |
Thanks for investigating this. I'll try to checkout the |
I was attempting to use
py-spy
to profile a monitoring tool that has a number of different threads that do things like read from external APIs, parse results and store them to a database, etc at some fixed interval. My hope was to identify hotspots and a recent performance regression. The experience of installing and usingpy-spy
was fantastically easy and I was able to get a flame graph for the program without issues. When I look at the flame graph though, I see the functions listed that are thetarget
for each thread, but in most cases, none of the child functions that they call are listed. For each of these cases the line number it points to is thetime.sleep()
call within the target function rather than any of the actual work that it does between sleeps.A given target function might look something like:
The line number points to the
time.sleep(diff)
, but then I don't see any of the sub-calls (e.g.self.update_mappings()
,self.calculate_stats()
, etc) belowaux_jobs
. I expect the work part of the function to take on the order of 50-200 milliseconds in total.It looks like threads that are just waiting on data from a
multiprocessing.queue
and don't have explicit calls totime.sleep()
show their calls all of the way down.I've tried extending the duration out to 5 minutes and increasing the sampling rate to 200 samples per second, but I don't see any difference.
Is this to be expected given how py-spy works, or am I missing something? I can post the flame graph if that would be useful.
The text was updated successfully, but these errors were encountered: