/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/trace.py

  • Committer: Benoît Pierre
  • Date: 2009-02-24 00:25:32 UTC
  • mfrom: (4035 +trunk)
  • mto: (4056.1.1 trunk2)
  • mto: This revision was merged to the branch mainline in revision 4058.
  • Revision ID: benoit.pierre@gmail.com-20090224002532-i2f64ou15pa7if2y
Merge with upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
131
131
error =     _bzr_logger.error
132
132
 
133
133
 
 
134
_last_mutter_flush_time = None
 
135
 
134
136
def mutter(fmt, *args):
 
137
    global _last_mutter_flush_time
135
138
    if _trace_file is None:
136
139
        return
137
140
    if (getattr(_trace_file, 'closed', None) is not None) and _trace_file.closed:
152
155
        out = fmt % tuple(real_args)
153
156
    else:
154
157
        out = fmt
155
 
    timestamp = '%0.3f  ' % (time.time() - _bzr_log_start_time,)
 
158
    now = time.time()
 
159
    timestamp = '%0.3f  ' % (now - _bzr_log_start_time,)
156
160
    out = timestamp + out + '\n'
157
161
    _trace_file.write(out)
158
 
    # no need to flush here, the trace file is now linebuffered when it's
159
 
    # opened.
 
162
    # We flush if we haven't flushed for a few seconds. We don't want to flush
 
163
    # on every mutter, but when a command takes a while, it can be nice to see
 
164
    # updates in the debug log.
 
165
    if (_last_mutter_flush_time is None
 
166
        or (now - _last_mutter_flush_time) > 2.0):
 
167
        flush = getattr(_trace_file, 'flush', None)
 
168
        if flush is not None:
 
169
            flush()
 
170
        _last_mutter_flush_time = now
160
171
 
161
172
 
162
173
def mutter_callsite(stacklevel, fmt, *args):
205
216
 
206
217
 
207
218
def _open_bzr_log():
208
 
    """Open the .bzr.log trace file.  
 
219
    """Open the .bzr.log trace file.
209
220
 
210
221
    If the log is more than a particular length, the old file is renamed to
211
222
    .bzr.log.old and a new file is started.  Otherwise, we append to the
270
281
 
271
282
    :param to_file: A file-like object to which messages will be sent.
272
283
 
273
 
    :returns: A memento that should be passed to _pop_log_file to restore the 
 
284
    :returns: A memento that should be passed to _pop_log_file to restore the
274
285
    previously active logging.
275
286
    """
276
287
    global _trace_file
305
316
    """Undo changes to logging/tracing done by _push_log_file.
306
317
 
307
318
    This flushes, but does not close the trace file.
308
 
    
 
319
 
309
320
    Takes the memento returned from _push_log_file."""
310
321
    global _trace_file
311
322
    _trace_file = old_trace_file
321
332
@symbol_versioning.deprecated_function(symbol_versioning.one_two)
322
333
def enable_test_log(to_file):
323
334
    """Redirect logging to a temporary file for a test
324
 
    
 
335
 
325
336
    :returns: an opaque reference that should be passed to disable_test_log
326
337
    after the test completes.
327
338
    """
336
347
def log_exception_quietly():
337
348
    """Log the last exception to the trace file only.
338
349
 
339
 
    Used for exceptions that occur internally and that may be 
340
 
    interesting to developers but not to users.  For example, 
 
350
    Used for exceptions that occur internally and that may be
 
351
    interesting to developers but not to users.  For example,
341
352
    errors loading plugins.
342
353
    """
343
354
    mutter(traceback.format_exc())
396
407
    pass
397
408
 
398
409
 
399
 
_short_fields = ('VmPeak', 'VmSize', 'VmRSS')
400
 
 
401
410
def debug_memory(message='', short=True):
402
411
    """Write out a memory dump."""
 
412
    if sys.platform == 'win32':
 
413
        from bzrlib import win32utils
 
414
        win32utils.debug_memory_win32api(message=message, short=short)
 
415
    else:
 
416
        _debug_memory_proc(message=message, short=short)
 
417
 
 
418
 
 
419
_short_fields = ('VmPeak', 'VmSize', 'VmRSS')
 
420
 
 
421
def _debug_memory_proc(message='', short=True):
403
422
    try:
404
423
        status_file = file('/proc/%s/status' % os.getpid(), 'rb')
405
424
    except IOError: