-
Notifications
You must be signed in to change notification settings - Fork 384
Add 'window' support to mprof to plot a particular time range #105
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
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. |
newvalue = [float(x) for x in value.split(',')] | ||
except: | ||
raise OptionValueError("'%s' option must contain two numbers separated with a comma" % value) | ||
if len(newvalue) != 2: |
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm using Python 3.4
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
--window
or-w
, taking a comma-separated value of two numbers:One comment
options
fromplot_action
toplot_file
and thence toadd_brackets
is 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.