[pypy-svn] r68717 - in pypy/trunk/pypy/jit/tool: . test

fijal at codespeak.net fijal at codespeak.net
Fri Oct 23 10:31:48 CEST 2009


Author: fijal
Date: Fri Oct 23 10:31:43 2009
New Revision: 68717

Added:
   pypy/trunk/pypy/jit/tool/
   pypy/trunk/pypy/jit/tool/__init__.py   (contents, props changed)
   pypy/trunk/pypy/jit/tool/jitoutput.py   (contents, props changed)
   pypy/trunk/pypy/jit/tool/test/
   pypy/trunk/pypy/jit/tool/test/__init__.py   (contents, props changed)
   pypy/trunk/pypy/jit/tool/test/test_jitoutput.py   (contents, props changed)
Log:
Add a tool for parsing results of jit profiling


Added: pypy/trunk/pypy/jit/tool/__init__.py
==============================================================================

Added: pypy/trunk/pypy/jit/tool/jitoutput.py
==============================================================================
--- (empty file)
+++ pypy/trunk/pypy/jit/tool/jitoutput.py	Fri Oct 23 10:31:43 2009
@@ -0,0 +1,75 @@
+
+""" Helpers for parsing various outputs jit produces.
+Notably:
+1. Statistics of log.ops
+2. Parsing what jitprof produces
+"""
+
+import re
+
+REGEXES = [
+    (('tracing_no', 'tracing_time'), '^Tracing:\s+([\d.]+)\s+([\d.]+)$'),
+    (('backend_no', 'backend_time'), '^Backend:\s+([\d.]+)\s+([\d.]+)$'),
+    (('asm_no', 'asm_time'), '^Running asm:\s+([\d.]+)\s+([\d.]+)$'),
+    (('blackhole_no', 'blackhole_time'),
+         '^Blackhole:\s+([\d.]+)\s+([\d.]+)$'),
+    (None, '^TOTAL.*$'),
+    (('ops.total',), '^ops:\s+(\d+)$'),
+    (('ops.calls',), '^\s+calls:\s+(\d+)$'),
+    (('ops.pure_calls',), '^\s+pure calls:\s+(\d+)$'),
+    (('recorded_ops.total',), '^recorded ops:\s+(\d+)$'),
+    (('recorded_ops.calls',), '^\s+calls:\s+(\d+)$'),
+    (('recorded_ops.pure_calls',), '^\s+pure calls:\s+(\d+)$'),
+    (('guards',), '^guards:\s+(\d+)$'),
+    (('blackholed_ops.total',), '^blackholed ops:\s+(\d+)$'),
+    (('blackholed_ops.pure_calls',), '^\s+pure calls:\s+(\d+)$'),
+    (('opt_ops',), '^opt ops:\s+(\d+)$'),
+    (('opt_guards',), '^opt guards:\s+(\d+)$'),
+    (('forcings',), '^forcings:\s+(\d+)$'),
+    (('trace_too_long',), '^trace too long:\s+(\d+)$'),
+    (('bridge_abort',), '^bridge abort:\s+(\d+)$'),    
+    ]
+
+class Ops(object):
+    total = 0
+    calls = 0
+    pure_calls = 0
+
+class OutputInfo(object):
+    tracing_no = 0
+    tracing_time = 0.0
+    backend_no = 0
+    backend_time = 0.0
+    asm_no = 0
+    asm_time = 0.0
+    guards = 0
+    opt_ops = 0
+    opt_guards = 0
+    trace_too_long = 0
+    bridge_abort = 0
+
+    def __init__(self):
+        self.ops = Ops()
+        self.recorded_ops = Ops()
+        self.blackholed_ops = Ops()
+
+def parse_prof(output):
+    lines = output.splitlines()
+    # assert len(lines) == len(REGEXES)
+    info = OutputInfo()
+    for (attrs, regexp), line in zip(REGEXES, lines):
+        m = re.match(regexp, line)
+        assert m is not None, "Error parsing line: %s" % line
+        if attrs:
+            for i, a in enumerate(attrs):
+                v = m.group(i + 1)
+                if '.' in v:
+                    v = float(v)
+                else:
+                    v = int(v)
+                if '.' in a:
+                    before, after = a.split('.')
+                    setattr(getattr(info, before), after, v)
+                else:
+                    setattr(info, a, v)
+    return info

Added: pypy/trunk/pypy/jit/tool/test/__init__.py
==============================================================================

Added: pypy/trunk/pypy/jit/tool/test/test_jitoutput.py
==============================================================================
--- (empty file)
+++ pypy/trunk/pypy/jit/tool/test/test_jitoutput.py	Fri Oct 23 10:31:43 2009
@@ -0,0 +1,96 @@
+
+import py
+from pypy.jit.metainterp.warmspot import ll_meta_interp
+from pypy.rlib.jit import JitDriver, DEBUG_PROFILE
+from pypy.jit.backend.llgraph import runner
+from pypy.jit.metainterp.jitprof import Profiler, JITPROF_LINES
+from pypy.jit.tool.jitoutput import parse_prof
+
+def test_really_run():
+    """ This test checks whether output of jitprof did not change.
+    It'll explode when someone touches jitprof.py
+    """
+    mydriver = JitDriver(reds = ['i', 'n'], greens = [])
+    def f(n):
+        i = 0
+        while i < n:
+            mydriver.can_enter_jit(i=i, n=n)
+            mydriver.jit_merge_point(i=i, n=n)
+            i += 1
+
+    cap = py.io.StdCaptureFD()
+    try:
+        ll_meta_interp(f, [10], CPUClass=runner.LLtypeCPU, type_system='lltype',
+                       ProfilerClass=Profiler, debug_level=DEBUG_PROFILE)
+    finally:
+        out, err = cap.reset()
+    err = "\n".join(err.splitlines()[-JITPROF_LINES:])
+    print err
+    assert err.count("\n") == JITPROF_LINES - 1
+    info = parse_prof(err)
+    # assert did not crash
+    # asserts below are a bit delicate, possibly they might be deleted
+    assert info.tracing_no == 1
+    assert info.asm_no == 1
+    assert info.blackhole_no == 1
+    assert info.backend_no == 1
+    assert info.ops.total == 2
+    assert info.ops.calls == 0
+    assert info.ops.pure_calls == 0
+    assert info.recorded_ops.total == 2
+    assert info.recorded_ops.calls == 0
+    assert info.recorded_ops.pure_calls == 0
+    assert info.guards == 1
+    assert info.blackholed_ops.total == 0
+    assert info.blackholed_ops.pure_calls == 0
+    assert info.opt_ops == 6
+    assert info.opt_guards == 1
+    assert info.forcings == 0
+    assert info.trace_too_long == 0
+    assert info.bridge_abort == 0    
+
+DATA = '''Tracing:         1       0.006992
+Backend:        1       0.000525
+Running asm:    1       0.016957
+Blackhole:      1       0.000233
+TOTAL:                  0.025532
+ops:                    2
+  calls:                1
+  pure calls:           1
+recorded ops:           6
+  calls:                3
+  pure calls:           2
+guards:                 1
+blackholed ops:         5
+  pure calls:           3
+opt ops:                6
+opt guards:             1
+forcings:               1
+trace too long:         2
+bridge abort:           3
+'''
+
+def test_parse():
+    info = parse_prof(DATA)
+    assert info.tracing_no == 1
+    assert info.tracing_time == 0.006992
+    assert info.asm_no == 1
+    assert info.asm_time == 0.016957
+    assert info.blackhole_no == 1
+    assert info.blackhole_time == 0.000233
+    assert info.backend_no == 1
+    assert info.backend_time == 0.000525
+    assert info.ops.total == 2
+    assert info.ops.calls == 1
+    assert info.ops.pure_calls == 1
+    assert info.recorded_ops.total == 6
+    assert info.recorded_ops.calls == 3
+    assert info.recorded_ops.pure_calls == 2
+    assert info.guards == 1
+    assert info.blackholed_ops.total == 5
+    assert info.blackholed_ops.pure_calls == 3
+    assert info.opt_ops == 6
+    assert info.opt_guards == 1
+    assert info.forcings == 1
+    assert info.trace_too_long == 2
+    assert info.bridge_abort == 3  



More information about the Pypy-commit mailing list