[pypy-svn] r68827 - pypy/branch/logging/pypy/rlib
arigo at codespeak.net
arigo at codespeak.net
Wed Oct 28 17:53:47 CET 2009
Author: arigo
Date: Wed Oct 28 17:53:47 2009
New Revision: 68827
Modified:
pypy/branch/logging/pypy/rlib/rlog.py
pypy/branch/logging/pypy/rlib/rlog_ll.py
Log:
Add syntax: 'PYPYLOG=+filename' means 'always force a flush'.
Obscure for now, will document it is proves useful.
Modified: pypy/branch/logging/pypy/rlib/rlog.py
==============================================================================
--- pypy/branch/logging/pypy/rlib/rlog.py (original)
+++ pypy/branch/logging/pypy/rlib/rlog.py Wed Oct 28 17:53:47 2009
@@ -185,7 +185,7 @@
self.logwriter = logwriter
types = unrolling_iterable(self.types)
#
- def call(*args):
+ def really_call(*args):
if NonConstant(False):
logwriter.add_subentry_d(NonConstant(-123))
logwriter.add_subentry_s(NonConstant('abc'))
@@ -196,8 +196,6 @@
logwriter.add_subentry_r(llstr('abc'))
logwriter.add_subentry_f(NonConstant(123.4))
# ^^^ annotation hacks
- if not logwriter.enabled:
- return
if not logwriter.add_entry(self):
return
i = 0
@@ -205,8 +203,16 @@
methname = 'add_subentry_' + typechar
getattr(logwriter, methname)(args[i])
i = i + 1
- call = func_with_new_name(call, 'debug_log_' + self.category)
+ if logwriter.always_flush:
+ logwriter._flush()
+ really_call = func_with_new_name(really_call,
+ 'debug_log_' + self.category)
+ #
+ def call(*args):
+ if logwriter.enabled:
+ really_call(*args)
call._always_inline_ = True
+ #
self.call = call
else:
assert self.logwriter is logwriter
@@ -215,6 +221,7 @@
class AbstractLogWriter(object):
get_time = time.time
+ always_flush = False
def __init__(self):
self.enabled = True
Modified: pypy/branch/logging/pypy/rlib/rlog_ll.py
==============================================================================
--- pypy/branch/logging/pypy/rlib/rlog_ll.py (original)
+++ pypy/branch/logging/pypy/rlib/rlog_ll.py Wed Oct 28 17:53:47 2009
@@ -31,6 +31,9 @@
def do_open_file(self):
l_result = self.ll_get_filename()
if l_result and l_result[0] != '\x00':
+ if l_result[0] == '+':
+ self.always_flush = True
+ l_result = rffi.ptradd(l_result, 1)
flags = rffi.cast(rffi.INT, os.O_WRONLY | os.O_CREAT | os.O_TRUNC)
mode = rffi.cast(rffi.MODE_T, 0666)
self.fd = rffi.cast(lltype.Signed, os_open(l_result, flags, mode))
More information about the Pypy-commit
mailing list