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
ENH: add a renderer to save python-profile prof files #236
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey Matti! Thanks for this, it looks good. Would it be possible to add just a test that checks that pstats.Stats
doesn't crash when loading the output of a simple script?
I responded to the review and added a test |
I think this is ready for another round of review. Perhaps enabling the CI run would give some confidence that the tests are correct? |
Thanks and apologies for the delay! I'll try to look in the next few days |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is complicated by the fact that the prof renderer outputs bytes, not strs. I'll have a think how we can resolve this neatly.
I've pushed some fixes to this, if you get a sec could you check this is still working for you @mattip? There were a couple issues with the prof rendering as well as some internal issues (like total_self_time always returning zero), but I think I got them all. |
I think this looks good on a toy script I tried. Is there any end-to-end testing you do offline to verify that the renderers all give similar results? |
Normally I just play with some of the examples scripts in /examples. I checked these with snakeviz. But it would be good to double check the callers dict somehow, maybe there's some way to visualise the call graph? I seem to remember some tool that had blobs that represent functions and lines representing calls...The other thing we could do is assert more deeply in a unit test, but I'm not sure I'm confident enough how the data should look...! I suppose one could compare a toy script with cProfile to verify.
|
nice, thank you! well the "-1" is because the number of calls is -1, due to statistical profiling we don't know that. but the 50% below the branches is odd, and looks wrong. Perhaps it is getting confused with the numcalls being -1? we could try 1 to see if that helps. Otherwise it's probably something to do with the callers dict |
Ah, yeah it must be the callers dict - I made the same mistake as we had with the stats dict - the code overwrites rather than adding to the caller entry. I can try a fix now |
I thiiiink that might fix it. Are you able to try the viz again? |
yeah that looks good to me. I'd rather the numcalls said -1 rather than 1 or 0 as it's clear that there is no data. I think i'd like some more detailed unit tests on the things we've discovered during this PR about the pstats file format. mostly, just basic stuff around frames, timings, and asserting that the fix we made above still holds. If you have time, that would be great, otherwise I'll get around to it at some point. Something else I'd wondering - is |
yes, I am horrible at naming things. I will take a look at adding tests. Since the |
Added some tests and renamed the renderer. |
These test errors can be circumvented using fake time. I can look at that now |
Any idea why the readthedocs build failed? |
I fixed that in #239, should be resolved by merging |
Rebased off main, and CI is passing. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking over the diff, still a few instances of the renderer referred to as 'prof' and not pstats
Good catch. I changed the file extension for this renderer to |
Looks good! Thanks @mattip ! |
Thanks for shepherding this through to the end. |
Is there a plan for a new release? |
Sorry for the wait, gonna get #240 in and then cut a new release |
Cool, thanks |
Closes #64. Now running
python -m pyinstrument -r prof -o <filename> <script>
will create a file compatible withpython -m profile -o <filename> <script>
. It can be loaded into tools likegprof2dot
andsnakeviz
for visualization.Of course the
ncall
number is bogus. I used -1. Since we only know total time, thepercall
time is also not available. Ideas for further tests or correcting the statistics are welcome.