~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/trace.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2008-09-27 00:11:40 UTC
  • mfrom: (3698.1.4 debug_memory)
  • Revision ID: pqm@pqm.ubuntu.com-20080927001140-kf9vnhradsc7ilmo
(jam) Add trace.debug_memory() as a simple way to dump mem info.

Show diffs side-by-side

added added

removed removed

Lines of Context:
388
388
    pass
389
389
 
390
390
 
 
391
_short_fields = ('VmPeak', 'VmSize', 'VmRSS')
 
392
 
 
393
def debug_memory(message='', short=True):
 
394
    """Write out a memory dump."""
 
395
    try:
 
396
        status_file = file('/proc/%s/status' % os.getpid(), 'rb')
 
397
    except IOError:
 
398
        return
 
399
    try:
 
400
        status = status_file.read()
 
401
    finally:
 
402
        status_file.close()
 
403
    if message:
 
404
        note(message)
 
405
    for line in status.splitlines():
 
406
        if not short:
 
407
            note(line)
 
408
        else:
 
409
            for field in _short_fields:
 
410
                if line.startswith(field):
 
411
                    note(line)
 
412
                    break
 
413
 
 
414
 
391
415
def report_exception(exc_info, err_file):
392
416
    """Report an exception to err_file (typically stderr) and to .bzr.log.
393
417