Merge lp:~kbielefe/bzr/551391-log-memory-usage into lp:bzr
| Status: | Merged |
|---|---|
| Approved by: | Vincent Ladeuil on 2010-10-11 |
| Approved revision: | 5456 |
| Merged at revision: | 5484 |
| Proposed branch: | lp:~kbielefe/bzr/551391-log-memory-usage |
| Merge into: | lp:bzr |
| Diff against target: |
106 lines (+41/-1) 4 files modified
NEWS (+4/-0) bzrlib/help_topics/en/debug-flags.txt (+1/-0) bzrlib/tests/test_trace.py (+12/-1) bzrlib/trace.py (+24/-0) |
| To merge this branch: | bzr merge lp:~kbielefe/bzr/551391-log-memory-usage |
| Related bugs: |
| Reviewer | Review Type | Date Requested | Status |
|---|---|---|---|
| Vincent Ladeuil | Needs Information on 2010-10-11 | ||
| Martin Pool | Needs Fixing on 2010-10-06 | ||
| John A Meinel | 2010-09-29 | Needs Fixing on 2010-10-02 | |
|
Review via email:
|
|||
Commit Message
Dump memory profile to log if -Dmem_dump is set.
Description of the Change
Implements bug 551391 by using meliae to dump all memory to a file in the current directory when there is a MemoryError exception. Gracefully exits if meliae is not installed or if there isn't enough memory to perform the dump or other exceptions occur during the dump. Logs whether it succeeded or not to ~/.bzr.log.
Test using ulimit -m and ulimit -v to set memory relatively low and run something that can potentially use a lot of memory such as bzr check.
| Martin Pool (mbp) wrote : | # |
Thanks very much for that.
Beyond John's comments I'd say:
* probably the dump should go into /tmp (ie use tempfile.mkstemp), so
that it doesn't clutter up or cause trouble in people's working
directory; then print the name
* if you get an ImportError or other error, please log the exception
so we have a chance of debugging it
* I would print the filename, not just logging it - or return it, and
let the higher-level code print it
--
Martin
| Karl Bielefeldt (kbielefe) wrote : | # |
Okay, I incorporated both of your suggestions. I'm not sure what the process is from this point.
| Martin Pool (mbp) wrote : | # |
That looks good to me. I might let John have a look again, but we can merge it from here.
| John A Meinel (jameinel) wrote : | # |
One thought... dump_all_objects builds a big set to make sure it gets everything, but only once.
If we just ran out of memory, maybe meliae.
If we really-really wanted to be evil, we could set the high bit on all refcount values, to indicate this has been dumped, and then walk it again to remove it. But I don't really like mutating important state like that.
| John A Meinel (jameinel) wrote : | # |
sent to pqm by email
| John A Meinel (jameinel) wrote : | # |
I failed to catch this, but PQM did.
try:
except:
finally:
Doesn't work in python 2.4, (I think it is python 2.5).
Also, if something early raises an exception, there is no 'dump_file' for finally use.
So it should be:
fd, name = ...
dump_file = ...
try:
try:
except:
return
finally:
dump_file.close()
16 +def _dump_memory_
17 + try:
18 + fd, name = tempfile.
19 + dump_file = os.fdopen(fd, 'w')
20 + from meliae import scanner
21 + scanner.
22 + err_file.
23 + except ImportError:
24 + err_file.
25 + log_exception_
26 + except:
27 + err_file.
28 + log_exception_
29 + finally:
30 + dump_file.close()
| Karl Bielefeldt (kbielefe) wrote : | # |
> If we just ran out of memory, maybe meliae.
> appropriate?
You're probably right. The way I tested it, it failed allocating one last big chunk, so it still had enough memory to build the set. However, I think the allocation that caused it to fail wouldn't show up in the dump anyway because it never existed. The stack trace would be more useful in that case.
Where a memory dump on MemoryError is really useful is when you have a slower accumulation of too many smaller objects, and an approximation is probably good enough for those purposes. Maybe a fallback from dump_all_objects to dump_gc_objects would be useful?
When you want the precision is while doing memory profiling for development, and then developers can use whichever method works best for their scenario.
It just occurred to me that since I'm fixing the PQM bugs anyway, if it would be useful to add a hidden command like "bzr decode-memdump /tmp/dumpfile.json" for printing the summary information. That would make it a lot easier for an end user to file a bug report.
| Karl Bielefeldt (kbielefe) wrote : | # |
Fixed PQM errors and ready for resubmit.
| Martin Pool (mbp) wrote : | # |
That looks good, thanks very much. We should also mention this in news, and in 'help debug-flags', which comes from bzrlib/
| Karl Bielefeldt (kbielefe) wrote : | # |
Okay, updated help and news. Thanks for your patience in walking me through this.
| Martin Pool (mbp) wrote : | # |
sent to pqm by email
| Martin Pool (mbp) wrote : | # |
This actually causes one correct test failure:
=======
FAIL: bzrlib.
-------
_StringException: Text attachment: log
------------
1966.897 Traceback (most recent call last):
File "/home/
raise MemoryError()
MemoryError
------------
Text attachment: traceback
------------
Traceback (most recent call last):
File "/usr/lib/
return fn(*args)
File "/usr/lib/
testMethod()
File "/home/
"bzr: out of memory\n")
AssertionError: not equal:
a = 'bzr: out of memory\nUse -Dmem_dump to dump memory to a file.\n'
b = 'bzr: out of memory\n'
------------
That's nice because we can check it is actually being printed.
| Karl Bielefeldt (kbielefe) wrote : | # |
Okay, I fixed that test and added another test for if -Dmem_dump is specified. On the latter, I'm getting the following output, which I'm not sure is a problem or not. Also I'm not sure if the test should assume the meliae module is present.
Output of bzr selftest --verbose test_format_
test_trace.
Most uses of dbus_bindings are applications catching the exception
dbus.dbus_
instead (this is compatible with all dbus-python versions since 0.40.2).
If you need additional public API, please contact the maintainers via
<email address hidden>.
import dbus.dbus_bindings as m
/usr/lib/
recurse_
OK 3602ms
-------
Ran 1 test in 3.684s
OK
| Martin Pool (mbp) wrote : | # |
The dbus warnings are probably caused by bzr-gtk; running with
--no-plugins should let your tests pass.
You can use ModuleAvailable
is written if meliae is installed and that it does not crash if it's
not.
--
Martin
| Vincent Ladeuil (vila) wrote : | # |
@Karl: I went ahead and created https:/
| Karl Bielefeldt (kbielefe) wrote : | # |
> @Karl: I went ahead and created
> https:/
> so we can land this patch (see there for details).
Thanks for that. My time for open source work comes in bursts. For future reference, should I make it a practice to give bzr-core or someone access to my branch, so you wouldn't need to create a new one?
| Vincent Ladeuil (vila) wrote : | # |
>>>>> Karl Bielefeldt <email address hidden> writes:
>> @Karl: I went ahead and created
>> https:/
>> so we can land this patch (see there for details).
> Thanks for that. My time for open source work comes in bursts.
> For future reference, should I make it a practice to give bzr-core
> or someone access to my branch, so you wouldn't need to create a
> new one?
Hmm, not really.
I was reviewing your submission in a local branch, all I had to do was:
bzr push lp:~vila/bzr/`bzr nick`
bzr lp-open
and add your branch as a pre-requisite when proposing mine for merge.
If I had made a controversial change and thought you may agree or not
with it, I would also have 'bzr push' my branch and told you: 'If these
changes suit you, you could:
bzr pull lp:~vila/bzr/551391-log-memory-usage
From there, you would have continue working on your branch, then 'bzr
push' again and add a comment in the ongoing merge proposal explaining
the new status.
There are a lot of variations around this theme, but in practive we
rarely use shared branches (in the ~bzr namespace).
| Vincent Ladeuil (vila) wrote : | # |
Meh, I was sure you signed the contributor agreement but you're not part of https:/
Did I miss something ?
| Karl Bielefeldt (kbielefe) wrote : | # |
> Meh, I was sure you signed the contributor agreement but you're not part of
> https:/
>
> Did I miss something ?
Taken care of. I thought I had signed it as well, but it turns out I was thinking of the Code of Conduct.

We should probably have a flag to enable/disable this. "-Ddump_memory" comes to mind. I don't know which should be the default, sort of like core-dumping. I think the default for most people is to have it off, so I would probably go with that. So we could change the error message to mention "use -Dmemory_dump to get a memory dump" (or whatever).
I like the idea, the code seems fine otherwise.