[MERGE/RFC] Flush .bzr.log periodically

John Arbash Meinel john at arbash-meinel.com
Wed Jan 7 23:03:42 GMT 2009


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

I wrote this a while back when running long conversions on windows.

It seems that when writing to a buffered file, the buffer is in user
space, and if you kill the process early, it never gets written.

Further, it only flushes after a number of bytes are written, and not
even line-based.

I believe I remembered us not wanting to call .flush() all the time,
because of its performance overhead, so this call only flushes if it
hasn't written anything for 2s.

I'm not settled that we need it, but it did make following the log file
on windows during a long running process nicer.

(I haven't broken it out into a mergable patch yet, but the change is
pretty small).

I know there is a comment that the tracefile is line buffered, but I can
guarantee that isn't the case on Windows.

John
=:->

=== modified file 'bzrlib/trace.py'
- --- bzrlib/trace.py	2008-11-01 14:44:47 +0000
+++ bzrlib/trace.py	2009-01-07 21:59:52 +0000
@@ -129,9 +129,11 @@
 info = note
 log_error = _bzr_logger.error
 error =     _bzr_logger.error
+_last_mutter_flush_time = None


 def mutter(fmt, *args):
+    global _last_mutter_flush_time
     if _trace_file is None:
         return
     if (getattr(_trace_file, 'closed', None) is not None) and
_trace_file.closed:
@@ -152,11 +154,16 @@
         out = fmt % tuple(real_args)
     else:
         out = fmt
- -    timestamp = '%0.3f  ' % (time.time() - _bzr_log_start_time,)
+    now = time.time()
+    timestamp = '%0.3f  ' % (now - _bzr_log_start_time,)
     out = timestamp + out + '\n'
     _trace_file.write(out)
     # no need to flush here, the trace file is now linebuffered when it's
     # opened.
+    if (_last_mutter_flush_time is None
+        or (now - _last_mutter_flush_time) > 2.0):
+        _trace_file.flush()
+        _last_mutter_flush_time = now


 def mutter_callsite(stacklevel, fmt, *args):

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (Cygwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkllNM4ACgkQJdeBCYSNAAM2CACgzmEgmH9yuYLSI3HpQItRY63d
5t4AoIseJDyhtrvrISWudjn/wUFaah6V
=j5pN
-----END PGP SIGNATURE-----



More information about the bazaar mailing list