Author: Tobias Pape <tob...@netshed.de> Branch: traceviewer-common-merge-point-formats Changeset: r82896:00a68dd7adc9 Date: 2016-03-09 00:53 +0100 http://bitbucket.org/pypy/pypy/changeset/00a68dd7adc9/
Log: (traceviewer) try to parse most common debug_merge_point formarts out there Includes: - PyPy (clearly) - PyPy cffi callbacks - RSqueak - js - pycket - others (hippy, topaz) via fallback diff --git a/rpython/jit/tool/test/test_traceviewer.py b/rpython/jit/tool/test/test_traceviewer.py --- a/rpython/jit/tool/test/test_traceviewer.py +++ b/rpython/jit/tool/test/test_traceviewer.py @@ -1,7 +1,8 @@ import math import py from rpython.jit.tool.traceviewer import splitloops, FinalBlock, Block,\ - split_one_loop, postprocess, main, get_gradient_color, guard_number + split_one_loop, postprocess, main, get_gradient_color, guard_number,\ + find_name_key def test_gradient_color(): @@ -103,3 +104,46 @@ fname = py.path.local(__file__).join('..', 'f.pypylog.bz2') main(str(fname), False, view=False) # assert did not explode + +class TestMergPointStringExtraciton(object): + + def test_find_name_key(self): + def find(s): + return find_name_key(FinalBlock(s, None)) + assert find(r"debug_merge_point(0, 0, '<code object f5. file 'f.py'. line 34> #63 GET_ITER')") \ + == (r"f5. file 'f.py'. line 34 #63 GET_ITER", r"<code object f5. file 'f.py'. line 34> #63 GET_ITER") + assert find(r"debug_merge_point(0, 0, '<code object f5. file 'f.py'. line 34> <generator>')") \ + == (r"f5. file 'f.py'. line 34 <generator>", r"<code object f5. file 'f.py'. line 34> <generator>") + assert find(r"debug_merge_point(0, 0, 'cffi_callback <code object f5. file 'f.py'. line 34>')") \ + == (r"f5. file 'f.py'. line 34 (cffi_callback)", r"cffi_callback <code object f5. file 'f.py'. line 34>") + assert find(r"debug_merge_point(0, 0, 'cffi_callback <?>')") \ + == (r"? (cffi_callback)", r"cffi_callback <?>") + assert find(r"debug_merge_point(0, 0, 'cffi_call_python somestr')") \ + == (r"somestr (cffi_call_python)", r"cffi_call_python somestr") + assert find(r"debug_merge_point(0, 0, '(SequenceableCollection >> #replaceFrom:to:with:startingAt:) [8]: <0x14>pushTemporaryVariableBytecode(4)')") \ + == (r"SequenceableCollection>>#replaceFrom:to:with:startingAt: @ 8 <pushTemporaryVariableBytecode>", r"(SequenceableCollection >> #replaceFrom:to:with:startingAt:) [8]: <0x14>pushTemporaryVariableBytecode(4)") + assert find(r"debug_merge_point(1, 4, '(Magnitude >> #min:max:) [0]: <0x70>pushReceiverBytecode')") \ + == (r"Magnitude>>#min:max: @ 0 <pushReceiverBytecode>", r"(Magnitude >> #min:max:) [0]: <0x70>pushReceiverBytecode") + assert find(r"debug_merge_point(0, 0, '(#DoIt) [0]: <0x70>pushReceiverBytecode')") \ + == (r"#DoIt @ 0 <pushReceiverBytecode>", r"(#DoIt) [0]: <0x70>pushReceiverBytecode") + + assert find(r"debug_merge_point(0, 0, '54: LOAD LIST 4')") \ + == (r"? @ 54 <LOAD LIST 4>", r"54: LOAD LIST 4") + assert find(r"debug_merge_point(0, 0, '44: LOAD_MEMBER_DOT function: barfoo')") \ + == (r"barfoo @ 44 <LOAD_MEMBER_DOT>", r"44: LOAD_MEMBER_DOT function: barfoo") + assert find(r"debug_merge_point(0, 0, '87: end of opcodes')") \ + == (r"? @ 87 <end of opcodes>", r"87: end of opcodes") + assert find(r"debug_merge_point(0, 0, 'Green_Ast is None')") \ + == (r"Green_Ast is None", r"Green_Ast is None") + assert find(r"debug_merge_point(0, 0, 'Label(safe_return_multi_vals:pycket.interpreter:565)')") \ + == (r"Label(safe_return_multi_vals:pycket.interpreter:565)", r"Label(safe_return_multi_vals:pycket.interpreter:565)") + assert find(r"debug_merge_point(0, 0, '(*node2 item AppRand1_289 AppRand2_116)')") \ + == (r"(*node2 item AppRand1_289 AppRand2_116)", r"(*node2 item AppRand1_289 AppRand2_116)") + assert find(r"debug_merge_point(0, 0, '(let ([if_2417 (let ([AppRand0_2026 (* Zr Zr)][AppRand1_1531 (* Zi Zi)]) (let ([AppRand0_2027 (+ AppRand0_2026 AppRand1_1531)]) (> AppRand0_2027 LIMIT-SQR)))]) (if if_2417 0 (let ([if_2416 (= i ITERATIONS)]) (if if_2416 1 (let ([Zr199 (let ([AppRand0_2041 (* Zr Zr)][AppRand1_1540 (* Zi Zi)]) (let ([AppRand0_2042 (- AppRand0_2041 AppRand1_1540)]) (+ AppRand0_2042 Cr)))][Zi206 (let ([AppRand1_1541 (* Zr Zi)]) (let ([AppRand0_2043 (* 2.0 AppRand1_1541)]) (+ AppRand0_2043 Ci)))]) (let ([Zr211 (let ([AppRand0_2038 (* Zr199 Zr199)][AppRand1_1538 (* Zi206 Zi206)]) (let ([AppRand0_2039 (- AppRand0_2038 AppRand1_1538)]) (+ AppRand0_2039 Cr)))][Zi218 (let ([AppRand1_1539 (* Zr199 Zi206)]) (let ([AppRand0_2040 (* 2.0 AppRand1_1539)]) (+ AppRand0_2040 Ci)))]) (let ([Zr223 (let ([AppRand0_2035 (* Zr211 Zr211)][AppRand1_1536 (* Zi218 Zi218)]) (let ([AppRand0_2036 (- AppRand0_2035 AppRand1_1536)]) (+ AppRand0_2036 Cr)))][Zi230 (let ([AppRand1_1537 (* Zr211 Zi218)]) (let ([AppRand0_2037 (* 2.0 AppRand1_1537)]) (+ AppRand0_2037 Ci)))]) (let ([Zr235 (let ([AppRand0_2032 (* Zr223 Zr223)][AppRand1_1534 (* Zi230 Zi230)]) (let ([AppRand0_2033 (- AppRand0_2032 AppRand1_1534)]) (+ AppRand0_2033 Cr)))][Zi242 (let ([AppRand1_1535 (* Zr223 Zi230)]) (let ([AppRand0_2034 (* 2.0 AppRand1_1535)]) (+ AppRand0_2034 Ci)))]) (let ([Zr247 (let ([AppRand0_2029 (* Zr235 Zr235)][AppRand1_1532 (* Zi242 Zi242)]) (let ([AppRand0_2030 (- AppRand0_2029 AppRand1_1532)]) (+ AppRand0_2030 Cr)))][Zi254 (let ([AppRand1_1533 (* Zr235 Zi242)]) (let ([AppRand0_2031 (* 2.0 AppRand1_1533)]) (+ AppRand0_2031 Ci)))]) (let ([AppRand0_2028 (+ i 5)]) (loop AppRand0_2028 Zr247 Zi254))))))))))) from (loop AppRand0_2028 Zr247 Zi254)')") \ + == (r"(let ([if_2417 (let ([AppRand0_2026 (* Zr Zr)][AppRand1_1531 (* ...", r"(let ([if_2417 (let ([AppRand0_2026 (* Zr Zr)][AppRand1_1531 (* Zi Zi)]) (let ([AppRand0_2027 (+ AppRand0_2026 AppRand1_1531)]) (> AppRand0_2027 LIMIT-SQR)))]) (if if_2417 0 (let ([if_2416 (= i ITERATIONS)]) (if if_2416 1 (let ([Zr199 (let ([AppRand0_2041 (* Zr Zr)][AppRand1_1540 (* Zi Zi)]) (let ([AppRand0_2042 (- AppRand0_2041 AppRand1_1540)]) (+ AppRand0_2042 Cr)))][Zi206 (let ([AppRand1_1541 (* Zr Zi)]) (let ([AppRand0_2043 (* 2.0 AppRand1_1541)]) (+ AppRand0_2043 Ci)))]) (let ([Zr211 (let ([AppRand0_2038 (* Zr199 Zr199)][AppRand1_1538 (* Zi206 Zi206)]) (let ([AppRand0_2039 (- AppRand0_2038 AppRand1_1538)]) (+ AppRand0_2039 Cr)))][Zi218 (let ([AppRand1_1539 (* Zr199 Zi206)]) (let ([AppRand0_2040 (* 2.0 AppRand1_1539)]) (+ AppRand0_2040 Ci)))]) (let ([Zr223 (let ([AppRand0_2035 (* Zr211 Zr211)][AppRand1_1536 (* Zi218 Zi218)]) (let ([AppRand0_2036 (- AppRand0_2035 AppRand1_1536)]) (+ AppRand0 _2036 Cr)))][Zi230 (let ([AppRand1_1537 (* Zr211 Zi218)]) (let ([AppRand0_2037 (* 2.0 AppRand1_1537)]) (+ AppRand0_2037 Ci)))]) (let ([Zr235 (let ([AppRand0_2032 (* Zr223 Zr223)][AppRand1_1534 (* Zi230 Zi230)]) (let ([AppRand0_2033 (- AppRand0_2032 AppRand1_1534)]) (+ AppRand0_2033 Cr)))][Zi242 (let ([AppRand1_1535 (* Zr223 Zi230)]) (let ([AppRand0_2034 (* 2.0 AppRand1_1535)]) (+ AppRand0_2034 Ci)))]) (let ([Zr247 (let ([AppRand0_2029 (* Zr235 Zr235)][AppRand1_1532 (* Zi242 Zi242)]) (let ([AppRand0_2030 (- AppRand0_2029 AppRand1_1532)]) (+ AppRand0_2030 Cr)))][Zi254 (let ([AppRand1_1533 (* Zr235 Zi242)]) (let ([AppRand0_2031 (* 2.0 AppRand1_1533)]) (+ AppRand0_2031 Ci)))]) (let ([AppRand0_2028 (+ i 5)]) (loop AppRand0_2028 Zr247 Zi254))))))))))) from (loop AppRand0_2028 Zr247 Zi254)") + assert find(r"debug_merge_point(0, 0, 'times at LOAD_SELF')") \ + == (r"times at LOAD_SELF", r"times at LOAD_SELF") + assert find(r"debug_merge_point(1, 1, 'block in <main> at LOAD_DEREF')") \ + == (r"block in <main> at LOAD_DEREF", r"block in <main> at LOAD_DEREF") + assert find(r"debug_merge_point(0, 0, '<main> at SEND')") \ + == (r"<main> at SEND", r"<main> at SEND") diff --git a/rpython/jit/tool/traceviewer.py b/rpython/jit/tool/traceviewer.py --- a/rpython/jit/tool/traceviewer.py +++ b/rpython/jit/tool/traceviewer.py @@ -219,19 +219,78 @@ counter += loop.count("\n") + 2 return real_loops, allloops + +def find_name_key(l): + m = re.search("debug_merge_point\((?:\d+,\ )*'(.*)'(?:, \d+)*\)", l.content) + if m is None: + # default fallback + return '?', '?' + info = m.group(1) + + # PyPy (pypy/module/pypyjit/interp_jit.py, pypy/interpreter/generator.py) + # '<code object f5. file 'f.py'. line 34> #63 GET_ITER' + # '<code object f5. file 'f.py'. line 34> <generator>' + m = re.search("^(<code object (.*?)> (.*?))$", info) + if m: + return m.group(2) + " " + m.group(3), m.group(1) + + # PyPy cffi (pypy/module/_cffi_backend/ccallback.py) + # 'cffi_callback <code object f5. file 'f.py'. line 34>', 'cffi_callback <?>' + # 'cffi_call_python somestr' + m = re.search("^((cffi_callback) <code object (.*?)>)$", info) + if m: + return "%s (%s)" %(m.group(3), m.group(2)), m.group(1) + m = re.search("^((cffi_callback) <\?>)$", info) + if m: + return "? (%s)" %(m.group(2)), m.group(1) + m = re.search("^((cffi_call_python) (.*))$", info) + if m: + return "%s (%s)" %(m.group(3), m.group(2)), m.group(1) + + # RSqueak/lang-smalltalk (spyvm/interpreter.py) + # '(SequenceableCollection >> #replaceFrom:to:with:startingAt:) [8]: <0x14>pushTemporaryVariableBytecode(4)' + m = re.search("^(\(((.+?) >> )?(#.*)\) \[(\d+)\].+?>(.*?)(?:\(\d+\))?)$", info) + if m: + if m.group(3): + return "%s>>%s @ %s <%s>" % (m.group(3), m.group(4), m.group(5), m.group(6)), m.group(1) + else: + return "%s @ %s <%s>" % (m.group(4), m.group(5), m.group(6)), m.group(1) + + # lang-js (js/jscode.py) + # '54: LOAD LIST 4' + # '44: LOAD_MEMBER_DOT function: barfoo' + # '87: end of opcodes' + m = re.search("^((\d+): (.+?)(:? function: (.+?))?)$", info) + if m: + if m.group(5): + return "%s @ %s <%s>" % (m.group(5), m.group(2), m.group(3)), m.group(1) + else: + return "? @ %s <%s>" % (m.group(2), m.group(3)), m.group(1) + + # pycket (pycket/interpreter.py) [sorted down because the s-exp is very generic] + # 'Green_Ast is None' + # 'Label(safe_return_multi_vals:pycket.interpreter:565)' + # '(*node2 item AppRand1_289 AppRand2_116)' + if info[0] == '(' and info[-1] == ')': + if len(info) > 64: #s-exp can be quite long + return info[:64] +'...', info + + # info fallback (eg, rsre_jit, qoppy, but also + # pyhaskell (pyhaskell/interpreter/haskell.py) + # pyrolog (prolog/interpreter/continuation.py) + # RPySOM/RTruffleSom (src/som/interpreter/interpreter.py) + # Topaz (topaz/interpreter.py) + # hippyvm (hippy/interpreter.py) + return info, info + def postprocess_loop(loop, loops, memo, counts): + if loop in memo: return memo.add(loop) if loop is None: return - m = re.search("debug_merge_point\((?:\d+,\ )*'(<code object (.*?)> (.*?))'", loop.content) - if m is None: - name = '?' - loop.key = '?' - else: - name = m.group(2) + " " + m.group(3) - loop.key = m.group(1) + name, loop.key = find_name_key(loop) opsno = loop.content.count("\n") lastline = loop.content[loop.content.rfind("\n", 0, len(loop.content) - 2):] m = re.search('descr=<Loop(\d+)', lastline) _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit