Merge lp:~mbp/bzr/integration into lp:bzr

Proposed by Martin Pool
Status: Merged
Approved by: Martin Pool
Approved revision: no longer in the revision history of the source branch.
Merged at revision: 5484
Proposed branch: lp:~mbp/bzr/integration
Merge into: lp:bzr
Diff against target: 127 lines (+45/-2)
5 files modified
NEWS (+4/-0)
bzrlib/help_topics/en/debug-flags.txt (+1/-0)
bzrlib/tests/features.py (+3/-1)
bzrlib/tests/test_trace.py (+13/-1)
bzrlib/trace.py (+24/-0)
To merge this branch: bzr merge lp:~mbp/bzr/integration
Reviewer Review Type Date Requested Status
bzr-core Pending
Review via email: mp+38166@code.launchpad.net

Commit message

add -Dmem_dump

Description of the change

Integrate vila and Karl's work on -Dmem_dump.

To post a comment you must log in.
Revision history for this message
Martin Pool (mbp) wrote :

sent to pqm by email

lp:~mbp/bzr/integration updated
5484. By Canonical.com Patch Queue Manager <email address hidden>

(mbp) add -Dmem_dump (Martin Pool)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'NEWS'
--- NEWS 2010-10-11 23:21:22 +0000
+++ NEWS 2010-10-11 23:57:06 +0000
@@ -70,6 +70,10 @@
70* Add ``annotate`` revision specifier, which selects the revision that70* Add ``annotate`` revision specifier, which selects the revision that
71 introduced a specified line of a file. (Aaron Bentley)71 introduced a specified line of a file. (Aaron Bentley)
7272
73* Add ``-Dmem_dump`` debug flag, which uses meliae to dump memory to
74 a file upon an out of memory error.
75 (Karl Bielefeldt, #551391)
76
73* ``bzr status`` now displays a summary of existing shelves after77* ``bzr status`` now displays a summary of existing shelves after
74 the other status information. This is done using a ``post_status``78 the other status information. This is done using a ``post_status``
75 hook.79 hook.
7680
=== modified file 'bzrlib/help_topics/en/debug-flags.txt'
--- bzrlib/help_topics/en/debug-flags.txt 2010-01-05 04:30:07 +0000
+++ bzrlib/help_topics/en/debug-flags.txt 2010-10-11 23:57:06 +0000
@@ -25,6 +25,7 @@
25-Dknit Trace knit operations.25-Dknit Trace knit operations.
26-Dlock Trace when lockdir locks are taken or released.26-Dlock Trace when lockdir locks are taken or released.
27-Dprogress Trace progress bar operations.27-Dprogress Trace progress bar operations.
28-Dmem_dump Dump memory to a file upon an out of memory error.
28-Dmerge Emit information for debugging merges.29-Dmerge Emit information for debugging merges.
29-Dno_apport Don't use apport to report crashes.30-Dno_apport Don't use apport to report crashes.
30-Dno_activity Don't show transport activity indicator in progress bar.31-Dno_activity Don't show transport activity indicator in progress bar.
3132
=== modified file 'bzrlib/tests/features.py'
--- bzrlib/tests/features.py 2010-09-27 19:31:45 +0000
+++ bzrlib/tests/features.py 2010-10-11 23:57:06 +0000
@@ -38,12 +38,14 @@
3838
3939
40not_running_as_root = _NotRunningAsRoot()40not_running_as_root = _NotRunningAsRoot()
41
41apport = tests.ModuleAvailableFeature('apport')42apport = tests.ModuleAvailableFeature('apport')
43meliae = tests.ModuleAvailableFeature('meliae')
42paramiko = tests.ModuleAvailableFeature('paramiko')44paramiko = tests.ModuleAvailableFeature('paramiko')
43pycurl = tests.ModuleAvailableFeature('pycurl')45pycurl = tests.ModuleAvailableFeature('pycurl')
44pywintypes = tests.ModuleAvailableFeature('pywintypes')46pywintypes = tests.ModuleAvailableFeature('pywintypes')
47sphinx = tests.ModuleAvailableFeature('sphinx')
45subunit = tests.ModuleAvailableFeature('subunit')48subunit = tests.ModuleAvailableFeature('subunit')
46sphinx = tests.ModuleAvailableFeature('sphinx')
4749
4850
49class _BackslashDirSeparatorFeature(tests.Feature):51class _BackslashDirSeparatorFeature(tests.Feature):
5052
=== modified file 'bzrlib/tests/test_trace.py'
--- bzrlib/tests/test_trace.py 2010-06-26 01:07:16 +0000
+++ bzrlib/tests/test_trace.py 2010-10-11 23:57:06 +0000
@@ -26,6 +26,7 @@
26import tempfile26import tempfile
2727
28from bzrlib import (28from bzrlib import (
29 debug,
29 errors,30 errors,
30 trace,31 trace,
31 )32 )
@@ -81,7 +82,18 @@
81 pass82 pass
82 msg = _format_exception()83 msg = _format_exception()
83 self.assertEquals(msg,84 self.assertEquals(msg,
84 "bzr: out of memory\n")85 "bzr: out of memory\nUse -Dmem_dump to dump memory to a file.\n")
86
87 def test_format_mem_dump(self):
88 self.requireFeature(features.meliae)
89 debug.debug_flags.add('mem_dump')
90 try:
91 raise MemoryError()
92 except MemoryError:
93 pass
94 msg = _format_exception()
95 self.assertStartsWith(msg,
96 "bzr: out of memory\nMemory dumped to ")
8597
86 def test_format_os_error(self):98 def test_format_os_error(self):
87 try:99 try:
88100
=== modified file 'bzrlib/trace.py'
--- bzrlib/trace.py 2010-06-28 02:41:22 +0000
+++ bzrlib/trace.py 2010-10-11 23:57:06 +0000
@@ -59,6 +59,7 @@
59import os59import os
60import sys60import sys
61import time61import time
62import tempfile
6263
63from bzrlib.lazy_import import lazy_import64from bzrlib.lazy_import import lazy_import
64lazy_import(globals(), """65lazy_import(globals(), """
@@ -469,6 +470,25 @@
469 note(line)470 note(line)
470 break471 break
471472
473def _dump_memory_usage(err_file):
474 try:
475 try:
476 fd, name = tempfile.mkstemp(prefix="bzr_memdump", suffix=".json")
477 dump_file = os.fdopen(fd, 'w')
478 from meliae import scanner
479 scanner.dump_gc_objects(dump_file)
480 err_file.write("Memory dumped to %s\n" % name)
481 except ImportError:
482 err_file.write("Dumping memory requires meliae module.\n")
483 log_exception_quietly()
484 except:
485 err_file.write("Exception while dumping memory.\n")
486 log_exception_quietly()
487 finally:
488 if dump_file is not None:
489 dump_file.close()
490 elif fd is not None:
491 os.close(fd)
472492
473def report_exception(exc_info, err_file):493def report_exception(exc_info, err_file):
474 """Report an exception to err_file (typically stderr) and to .bzr.log.494 """Report an exception to err_file (typically stderr) and to .bzr.log.
@@ -492,6 +512,10 @@
492 return errors.EXIT_ERROR512 return errors.EXIT_ERROR
493 elif isinstance(exc_object, MemoryError):513 elif isinstance(exc_object, MemoryError):
494 err_file.write("bzr: out of memory\n")514 err_file.write("bzr: out of memory\n")
515 if 'mem_dump' in debug.debug_flags:
516 _dump_memory_usage(err_file)
517 else:
518 err_file.write("Use -Dmem_dump to dump memory to a file.\n")
495 return errors.EXIT_ERROR519 return errors.EXIT_ERROR
496 elif isinstance(exc_object, ImportError) \520 elif isinstance(exc_object, ImportError) \
497 and str(exc_object).startswith("No module named "):521 and str(exc_object).startswith("No module named "):