Commits

Konstantin Lopuhin  committed 7f27588

test parsed log - check that we find bridges and that counts are reasonable

  • Participants
  • Parent commits 84b2a0a
  • Branches bridge-logging

Comments (0)

Files changed (3)

File pypy/module/pypyjit/test_pypy_c/test_00_model.py

         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:

File pypy/module/pypyjit/test_pypy_c/test_jitlogparser.py

+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):
                     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
 
+

File pypy/tool/jitlogparser/parser.py

             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])