[pypy-svn] r68814 - in pypy/branch/logging/pypy/rlib: . test
arigo at codespeak.net
arigo at codespeak.net
Wed Oct 28 13:18:35 CET 2009
Author: arigo
Date: Wed Oct 28 13:18:34 2009
New Revision: 68814
Modified:
pypy/branch/logging/pypy/rlib/rlog.py
pypy/branch/logging/pypy/rlib/rlog_parsing.py
pypy/branch/logging/pypy/rlib/test/test_rlog.py
Log:
Small fixes and a new function, untested so far...
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 13:18:34 2009
@@ -1,6 +1,7 @@
import py, time, struct
from pypy.tool.ansi_print import ansi_log
from pypy.rlib.unroll import unrolling_iterable
+from pypy.rlib.nonconst import NonConstant
from pypy.tool.sourcetools import func_with_new_name
from pypy.rpython.extregistry import ExtRegistryEntry
from pypy.rpython.annlowlevel import hlstr
@@ -185,6 +186,12 @@
types = unrolling_iterable(self.types)
#
def call(*args):
+ if NonConstant(False):
+ logwriter.add_subentry_d(123)
+ logwriter.add_subentry_s('abc')
+ logwriter.add_subentry_r('abc')
+ logwriter.add_subentry_f(123.4)
+ # ^^^ annotation hacks
if not logwriter.enabled:
return
if not logwriter.add_entry(self):
Modified: pypy/branch/logging/pypy/rlib/rlog_parsing.py
==============================================================================
--- pypy/branch/logging/pypy/rlib/rlog_parsing.py (original)
+++ pypy/branch/logging/pypy/rlib/rlog_parsing.py Wed Oct 28 13:18:34 2009
@@ -1,11 +1,21 @@
import autopath
-import struct
+import struct, re, fnmatch
from pypy.rlib.rarithmetic import intmask
from pypy.rlib import rlog
SIZEOF_FLOAT = rlog.SIZEOF_FLOAT
+class LogCategory(object):
+
+ def __init__(self, category, message, index):
+ self.category = category
+ self.message = message
+ self.index = index
+ self.types = re.findall(r"%\(\w+\)(\w)", message)
+ self.messagestr = re.sub(r"%\(\w+\)", "%", message)
+
+
class LogParser(object):
def __init__(self, file, has_signature=True):
@@ -64,7 +74,7 @@
category = self.read_str()
message = self.read_str()
assert index not in categories
- categories[index] = rlog.LogCategory(category, message, index)
+ categories[index] = LogCategory(category, message, index)
else:
curtime += self.read_float()
cat = categories[c]
@@ -77,8 +87,6 @@
return logparser.enum_entries()
def dump_log(filename, limit='*', highlight=False):
- import re
- r_replace = re.compile(r"%\(\w+\)")
for curtime, cat, entries in parse_log(filename):
if not fnmatch.fnmatch(cat.category, limit):
continue
@@ -86,8 +94,7 @@
printcode = cat.printcode
except AttributeError:
code = '[%s] ' % cat.category
- message = cat.message.replace('\n', '\n' + ' '*len(code))
- message = r_replace.sub("%", message)
+ message = cat.messagestr.replace('\n', '\n' + ' '*len(code))
printcode = code + message
if highlight:
if cat.category.endswith('{'):
@@ -97,9 +104,24 @@
cat.printcode = printcode
print printcode % tuple(entries)
+def extract_sections(filename, limit):
+ """Extract sections between 'limit-{' and 'limit-}'.
+ Yields multiline strings, each a complete section.
+ Accept * and ? in 'limit'.
+ """
+ pieces = None
+ for curtime, cat, entries in parse_log(filename):
+ if fnmatch.fnmatch(cat.category, limit + '-{'):
+ pieces = []
+ if pieces is not None:
+ pieces.append(cat.messagestr % tuple(entries))
+ if fnmatch.fnmatch(cat.category, limit + '-}'):
+ yield '\n'.join(pieces)
+ pieces = None
+
if __name__ == '__main__':
- import sys, fnmatch
+ import sys
filename = sys.argv[1]
if len(sys.argv) > 2:
limit = sys.argv[2] + '*'
Modified: pypy/branch/logging/pypy/rlib/test/test_rlog.py
==============================================================================
--- pypy/branch/logging/pypy/rlib/test/test_rlog.py (original)
+++ pypy/branch/logging/pypy/rlib/test/test_rlog.py Wed Oct 28 13:18:34 2009
@@ -248,13 +248,16 @@
assert entries[5][1] is Ac
assert Aa.category == 'Aa'
assert Aa.message == 'hello %(foo)d %(bar)f'
- assert Aa.entries == [('foo', 'd'), ('bar', 'f')]
+ assert Aa.messagestr == 'hello %d %f'
+ assert Aa.types == ['d', 'f']
assert Ab.category == 'Ab'
assert Ab.message == '<<%(baz)s>>'
- assert Ab.entries == [('baz', 's')]
+ assert Ab.messagestr == '<<%s>>'
+ assert Ab.types == ['s']
assert Ac.category == 'Ac'
assert Ac.message == '[%(foo)r]'
- assert Ac.entries == [('foo', 'r')]
+ assert Ac.messagestr == '[%r]'
+ assert Ac.types == ['r']
#
assert entries[0][2] == [132, roughly(-7.3)]
assert entries[1][2] == [133, 132.5]
More information about the Pypy-commit
mailing list