Rev 3699: Move the memory debugging into a helper function. in http://bzr.arbash-meinel.com/branches/bzr/1.8-dev/debug_memory
John Arbash Meinel
john at arbash-meinel.com
Wed Sep 10 19:18:01 BST 2008
At http://bzr.arbash-meinel.com/branches/bzr/1.8-dev/debug_memory
------------------------------------------------------------
revno: 3699
revision-id: john at arbash-meinel.com-20080910181759-3f30at7qak0k6syx
parent: pqm at pqm.ubuntu.com-20080910053334-fy7gihd6da2nyhy2
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: debug_memory
timestamp: Wed 2008-09-10 13:17:59 -0500
message:
Move the memory debugging into a helper function.
-------------- next part --------------
=== modified file 'NEWS'
--- a/NEWS 2008-09-10 04:54:57 +0000
+++ b/NEWS 2008-09-10 18:17:59 +0000
@@ -23,6 +23,11 @@
INTERNALS:
+ * ``bzrlib.trace.debug_memory`` can be used to get a quick memory dump
+ in the middle of processing. It only reports memory if
+ ``/proc/PID/status`` is available, and only if ``-Dmemory`` is being
+ run. (John Arbash Meinel)
+
bzr 1.7rc1 2008-09-09
---------------------
=== modified file 'bzrlib/commands.py'
--- a/bzrlib/commands.py 2008-08-31 19:39:01 +0000
+++ b/bzrlib/commands.py 2008-09-10 18:17:59 +0000
@@ -795,17 +795,7 @@
ret = apply_coveraged(opt_coverage_dir, run, *run_argv)
else:
ret = run(*run_argv)
- if 'memory' in debug.debug_flags:
- try:
- status_file = file('/proc/%s/status' % os.getpid(), 'rb')
- except IOError:
- pass
- else:
- status = status_file.read()
- status_file.close()
- trace.note("Process status after command:")
- for line in status.splitlines():
- trace.note(line)
+ trace.debug_memory('Process status after command:', short=False)
return ret or 0
finally:
# reset, in case we may do other commands later within the same process
=== modified file 'bzrlib/trace.py'
--- a/bzrlib/trace.py 2008-06-18 07:21:15 +0000
+++ b/bzrlib/trace.py 2008-09-10 18:17:59 +0000
@@ -388,6 +388,31 @@
pass
+_short_fields = ('VmPeak', 'VmSize', 'VmRSS')
+
+def debug_memory(message, short=True):
+ """Write out a memory dump."""
+ if 'memory' not in debug.debug_flags:
+ return
+ try:
+ status_file = file('/proc/%s/status' % os.getpid(), 'rb')
+ except IOError:
+ return
+ try:
+ status = status_file.read()
+ finally:
+ status_file.close()
+ note(message)
+ for line in status.splitlines():
+ if not short:
+ note(line)
+ else:
+ for field in _short_fields:
+ if line.startswith(field):
+ note(line)
+ break
+
+
def report_exception(exc_info, err_file):
"""Report an exception to err_file (typically stderr) and to .bzr.log.
More information about the bazaar-commits
mailing list