[pypy-svn] jitviewer default: kill the class Bytecode, use a subclass of jitlogparser.TraceForOpcode instead
antocuni
commits-noreply at bitbucket.org
Fri Feb 25 14:59:36 CET 2011
Author: Antonio Cuni <anto.cuni at gmail.com>
Branch:
Changeset: r92:c4c55bb7e810
Date: 2011-02-25 14:14 +0100
http://bitbucket.org/pypy/jitviewer/changeset/c4c55bb7e810/
Log: kill the class Bytecode, use a subclass of
jitlogparser.TraceForOpcode instead
diff --git a/_jitviewer/parser.py b/_jitviewer/parser.py
--- a/_jitviewer/parser.py
+++ b/_jitviewer/parser.py
@@ -107,60 +107,7 @@
Op = OpHtml
-class NonCodeError(Exception):
- pass
-
-class Bytecode(object):
- filename = None
- startlineno = 0
- name = None
- code = None
- bytecode_no = 0
- bytecode_name = None
- is_bytecode = True
- inline_level = None
-
- def __init__(self, operations, storage):
- if operations[0].name == 'debug_merge_point':
- self.inline_level = int(operations[0].args[1])
- m = re.search('<code object ([<>\w]+), file \'(.+?)\', line (\d+)> #(\d+) (\w+)',
- operations[0].getarg(0))
- if m is None:
- # a non-code loop, like StrLiteralSearch or something
- self.bytecode_name = operations[0].args[0].split(" ")[0][1:]
- else:
- self.name, self.filename, lineno, bytecode_no, self.bytecode_name = m.groups()
- self.startlineno = int(lineno)
- self.bytecode_no = int(bytecode_no)
- self.operations = operations
- self.storage = storage
-
- def repr(self):
- if self.filename is None:
- return "Unknown"
- return "%s, file '%s', line %d" % (self.name, self.filename,
- self.startlineno)
-
- def getcode(self):
- if self.code is None:
- self.code = dis(self.storage.load_code(self.filename)[self.startlineno])
- return self.code
-
- def getlineno(self):
- code = self.getcode()
- return code.map[self.bytecode_no].lineno
- lineno = property(getlineno)
-
- def getline_starts_here(self):
- code = self.getcode()
- return code.map[self.bytecode_no].line_starts_here
- line_starts_here = property(getline_starts_here)
-
- def __repr__(self):
- return "[%s]" % ", ".join([repr(op) for op in self.operations])
-
- def pretty_print(self, out):
- pass
+class TraceForOpcodeHtml(parser.TraceForOpcode):
def html_repr(self):
if self.filename is not None:
@@ -289,13 +236,13 @@
for op in operations:
if op.name == 'debug_merge_point':
if so_far:
- append_to_res(Bytecode(so_far, storage))
+ append_to_res(TraceForOpcodeHtml(so_far, storage))
if limit:
break
so_far = []
so_far.append(op)
if so_far:
- append_to_res(Bytecode(so_far, storage))
+ append_to_res(TraceForOpcodeHtml(so_far, storage))
# wrap stack back up
if not stack:
# no ops whatsoever
diff --git a/_jitviewer/test/test_parser.py b/_jitviewer/test/test_parser.py
--- a/_jitviewer/test/test_parser.py
+++ b/_jitviewer/test/test_parser.py
@@ -1,8 +1,7 @@
-
+from pypy.tool.jitlogparser.storage import LoopStorage
from pypy.jit.metainterp.resoperation import ResOperation, rop
from pypy.jit.metainterp.history import ConstInt, Const
-from pypy.tool.jitlogparser.storage import LoopStorage
-from _jitviewer.parser import parse, Bytecode, Function,\
+from _jitviewer.parser import parse, TraceForOpcodeHtml, Function,\
slice_debug_merge_points,\
adjust_bridges, parse_log_counts, cssclass
import py
@@ -36,10 +35,10 @@
def test_split():
ops = parse('''
[i0]
- debug_merge_point("<code object stuff, file '/tmp/x.py', line 200> #10 ADD", 0)
- debug_merge_point("<code object stuff, file '/tmp/x.py', line 200> #11 SUB", 0)
+ debug_merge_point("<code object stuff, file '/I/dont/exist.py', line 200> #10 ADD", 0)
+ debug_merge_point("<code object stuff, file '/I/dont/exist.py', line 200> #11 SUB", 0)
i1 = int_add(i0, 1)
- debug_merge_point("<code object stuff, file '/tmp/x.py', line 200> #11 SUB", 0)
+ debug_merge_point("<code object stuff, file '/I/dont/exist.py', line 200> #11 SUB", 0)
i2 = int_add(i1, 1)
''')
res = slice_debug_merge_points(ops.operations, LoopStorage())
@@ -61,36 +60,36 @@
""")
res = slice_debug_merge_points(ops.operations, LoopStorage())
assert len(res.chunks) == 3 # two chunks + inlined call
- assert isinstance(res.chunks[0], Bytecode)
+ assert isinstance(res.chunks[0], TraceForOpcodeHtml)
assert isinstance(res.chunks[1], Function)
- assert isinstance(res.chunks[2], Bytecode)
+ assert isinstance(res.chunks[2], TraceForOpcodeHtml)
assert res.chunks[1].path == "1"
assert len(res.chunks[1].chunks) == 3
def test_name():
ops = parse('''
[i0]
- debug_merge_point("<code object stuff, file '/tmp/x.py', line 200> #10 ADD", 0)
- debug_merge_point("<code object stuff, file '/tmp/x.py', line 201> #11 SUB", 0)
+ debug_merge_point("<code object stuff, file '/I/dont/exist.py', line 200> #10 ADD", 0)
+ debug_merge_point("<code object stuff, file '/I/dont/exist.py', line 201> #11 SUB", 0)
i1 = int_add(i0, 1)
- debug_merge_point("<code object stuff, file '/tmp/x.py', line 202> #11 SUB", 0)
+ debug_merge_point("<code object stuff, file '/I/dont/exist.py', line 202> #11 SUB", 0)
i2 = int_add(i1, 1)
''')
res = slice_debug_merge_points(ops.operations, LoopStorage())
assert res.repr() == res.chunks[0].repr()
- assert res.repr() == "stuff, file '/tmp/x.py', line 200"
+ assert res.repr() == "stuff, file '/I/dont/exist.py', line 200"
assert res.startlineno == 200
- assert res.filename == '/tmp/x.py'
+ assert res.filename == '/I/dont/exist.py'
assert res.name == 'stuff'
def test_name_no_first():
ops = parse('''
[i0]
i3 = int_add(i0, 1)
- debug_merge_point("<code object stuff, file '/tmp/x.py', line 200> #10 ADD", 0)
- debug_merge_point("<code object stuff, file '/tmp/x.py', line 201> #11 SUB", 0)
+ debug_merge_point("<code object stuff, file '/I/dont/exist.py', line 200> #10 ADD", 0)
+ debug_merge_point("<code object stuff, file '/I/dont/exist.py', line 201> #11 SUB", 0)
i1 = int_add(i0, 1)
- debug_merge_point("<code object stuff, file '/tmp/x.py', line 202> #11 SUB", 0)
+ debug_merge_point("<code object stuff, file '/I/dont/exist.py', line 202> #11 SUB", 0)
i2 = int_add(i1, 1)
''')
res = slice_debug_merge_points(ops.operations, LoopStorage())
More information about the Pypy-commit
mailing list