Add 'window' support to mprof to plot a particular time range#105
Add 'window' support to mprof to plot a particular time range#105fabianp merged 2 commits intopythonprofilers:masterfrom pbowyer:xlim
Conversation
|
Hi! Thanks a lot for this! The code looks fine. It would be nice to have the possibility to only specify a start time or an end time, i.e. I would like to have that plots in the window 0.1 to end and that plots in the window from start to 1. . Do you think this is possible? |
|
Heh, I wanted to add that too, but I couldn't work out how to get the max time in the code to automatically set the final condition 😄 If you can point me to that, I'll add it. I'm not a fan of the syntax you propose as the first is open to interpretation (is it from 0 to the time, or from the time to the end?). I was thinking of the following, inspired by Python/numpy's list syntax: This way, it's explicit and can catch errors. |
There was a problem hiding this comment.
on my system I get an error because it doesn't find OptionValueError:
NameError: name 'OptionValueError' is not defined
There was a problem hiding this comment.
Thanks for the report, didn't realise Python wouldn't pick up missing imports until the line of code was run. Fixed with a modification to Line 12.
There was a problem hiding this comment.
Great. Now it just lacks support for open-ended windows (i.e. .1,:). Thanks!
|
I don't think you need to know the end time in advance. You can do
for a limit on the start and
for a limit on the end. So you just need to convert options.xlim[0] and options.xlim[1] to None if the limit is not present. I am OK with your syntax as long as it is documented. |
|
Adding open-ended window support is taking a bit longer to do, as while I have something working locally, but not happy with the code. You can view it at https://github.com/pbowyer/memory_profiler/compare/xlim...pbowyer:xlim--openwindow |
|
I think it would be cleaner in our case to not use The first step is finding the entries in the time array that fit within our window, and then extracting the same slice from the other arrays. This has extra benefits over I've tried and failed as my array knowledge is not yet there for Python/numpy, so I'm leaving open-ended windows for someone else to implement. This PR for windows works well and I've a few people using it. |
|
Great, thanks for your effort. I'm merging it as-is then, we can take care of the rest later. |
Add 'window' support to mprof to plot a particular time range
This is my contribution to address #103. It is my first time contributing to a Python project, so code review & feedback will be much appreciated.
My code lets one plot a particular time range out of the entire graph. This is really useful when bracketing functions in a long running, as it allows you to zoom in and see in detail which functions are being called.
To use, I added a new option called
--windowor-w, taking a comma-separated value of two numbers:One comment
optionsfromplot_actiontoplot_fileand thence toadd_bracketsis not a great. I couldn't think of a better way, short of putting the functions inside a class so a class variable can be accessed directly.