[pypy-commit] pypy bridge-logging: test parsed log - check that we find bridges and that counts are reasonable
kostialopuhin
noreply at buildbot.pypy.org
Fri Mar 29 06:02:23 CET 2013
Author: Konstantin Lopuhin <kostia.lopuhin at gmail.com>
Branch: bridge-logging
Changeset: r62871:7f27588d5fb0
Date: 2013-03-28 21:23 +0100
http://bitbucket.org/pypy/pypy/changeset/7f27588d5fb0/
Log: test parsed log - check that we find bridges and that counts are
reasonable
diff --git a/pypy/module/pypyjit/test_pypy_c/test_00_model.py b/pypy/module/pypyjit/test_pypy_c/test_00_model.py
--- a/pypy/module/pypyjit/test_pypy_c/test_00_model.py
+++ b/pypy/module/pypyjit/test_pypy_c/test_00_model.py
@@ -75,6 +75,7 @@
rawtraces = logparser.extract_category(rawlog, 'jit-log-opt-')
log = Log(rawtraces)
log.result = eval(stdout)
+ log.logfile = str(logfile)
#
summaries = logparser.extract_category(rawlog, 'jit-summary')
if len(summaries) > 0:
diff --git a/pypy/module/pypyjit/test_pypy_c/test_jitlogparser.py b/pypy/module/pypyjit/test_pypy_c/test_jitlogparser.py
--- a/pypy/module/pypyjit/test_pypy_c/test_jitlogparser.py
+++ b/pypy/module/pypyjit/test_pypy_c/test_jitlogparser.py
@@ -1,10 +1,14 @@
+import re
+
from rpython.tool.logparser import extract_category
-from pypy.tool.jitlogparser.parser import import_log, parse_log_counts
+from pypy.tool.jitlogparser.parser import (import_log, parse_log_counts,
+ mangle_descr)
from pypy.module.pypyjit.test_pypy_c.test_00_model import BaseTestPyPyC
class TestLogParser(BaseTestPyPyC):
+ log_string = 'jit-log-opt,jit-backend'
def test(self):
def fn_with_bridges(N):
@@ -25,20 +29,48 @@
result *= 2
return result
#
- log = self.run(fn_with_bridges, [10000])
- print log
- import pdb; pdb.set_trace()
- # TODO
- log, loops = import_log(log_filename)
+ N = 10000
+ _log = self.run(fn_with_bridges, [N])
+ log, loops = import_log(_log.logfile)
parse_log_counts(extract_category(log, 'jit-backend-count'), loops)
+
+ is_prime_loops = []
+ fn_with_bridges_loops = []
+ bridges = {}
+
lib_re = re.compile("file '.*lib-python.*'")
for loop in loops:
- loop.force_asm()
+ if hasattr(loop, 'force_asm'):
+ loop.force_asm()
if lib_re.search(loop.comment) or \
lib_re.search(loop.operations[0].repr()):
# do not care for _optimize_charset or _mk_bitmap
continue
+ assert loop.count > 0
+ if ' is_prime, ' in loop.comment:
+ is_prime_loops.append(loop)
+ elif ' fn_with_bridges, ' in loop.comment:
+ fn_with_bridges_loops.append(loop)
else:
- import pdb; pdb.set_trace()
+ assert ' bridge ' in loop.comment
+ key = mangle_descr(loop.descr)
+ assert key not in bridges
+ bridges[key] = loop
+ by_count = lambda l: -l.count
+ is_prime_loops.sort(key=by_count)
+ fn_with_bridges_loops.sort(key=by_count)
+
+ # check that we can find bridges corresponding to " % 3" and " % 5"
+ mod_bridges = []
+ for op in fn_with_bridges_loops[0].operations:
+ if op.descr is not None:
+ bridge = bridges.get(mangle_descr(op.descr))
+ if bridge is not None:
+ mod_bridges.append(bridge)
+ assert len(mod_bridges) == 2
+
+ # check that counts are reasonable (precise # may change in the future)
+ assert N - 2000 < sum(l.count for l in fn_with_bridges_loops) < N
+
diff --git a/pypy/tool/jitlogparser/parser.py b/pypy/tool/jitlogparser/parser.py
--- a/pypy/tool/jitlogparser/parser.py
+++ b/pypy/tool/jitlogparser/parser.py
@@ -447,6 +447,17 @@
num, count = line.split(':', 2)
mapping[num].count = int(count)
+
+def mangle_descr(descr):
+ if descr.startswith('TargetToken('):
+ return descr[len('TargetToken('):-1]
+ if descr.startswith('<Guard'):
+ return 'bridge-' + str(int(descr[len('<Guard0x'):-1], 16))
+ if descr.startswith('<Loop'):
+ return 'entry-' + descr[len('<Loop'):-1]
+ return descr.replace(" ", '-')
+
+
if __name__ == '__main__':
import_log(sys.argv[1])
More information about the pypy-commit
mailing list