Author: Maciej Fijalkowski <[email protected]>
Branch: 
Changeset: r62874:10c464811795
Date: 2013-03-29 07:02 +0200
http://bitbucket.org/pypy/pypy/changeset/10c464811795/

Log:    Merged in kostialopuhin/pypy/bridge-logging (pull request #147)

        Add test for parsing jit log produced from actual pypy

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
new file mode 100644
--- /dev/null
+++ b/pypy/module/pypyjit/test_pypy_c/test_jitlogparser.py
@@ -0,0 +1,76 @@
+import re
+
+from rpython.tool.logparser import extract_category
+
+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):
+            def is_prime(x):
+                for y in xrange(2, x):
+                    if x % y == 0:
+                        return False
+                return True
+            result = 0
+            for x in xrange(N):
+                if x % 3 == 0:
+                    result += 5
+                elif x % 5 == 0:
+                    result += 3
+                elif is_prime(x):
+                    result += x
+                elif x == 99:
+                    result *= 2
+            return result
+        #
+        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:
+            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:
+                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])
     
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to