Author: Tobias Pape <tob...@netshed.de>
Branch: 
Changeset: r65618:6842ab2403ae
Date: 2013-05-06 11:31 +0200
http://bitbucket.org/pypy/pypy/changeset/6842ab2403ae/

Log:    Teach traceviewer a newer syntax of pypylogs

diff --git a/rpython/jit/tool/test/f.pypylog.bz2 
b/rpython/jit/tool/test/f.pypylog.bz2
new file mode 100644
index 
0000000000000000000000000000000000000000..a982e459b1daa33547576733ccc0b560f99a3f79
GIT binary patch

[cut]

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,7 @@
 import math
 import py
 from rpython.jit.tool.traceviewer import splitloops, FinalBlock, Block,\
-     split_one_loop, postprocess, main, get_gradient_color
+     split_one_loop, postprocess, main, get_gradient_color, guard_number
 
 
 def test_gradient_color():
@@ -30,6 +30,20 @@
         loops = splitloops(data)
         assert len(loops) == 2
 
+    def test_no_of_loops_hexguards(self):
+        data = [preparse("""
+        # Loop 0 : loop with 39 ops
+        debug_merge_point('', 0)
+        guard_class(p4, 141310752, descr=<Guard0x10abcdef0>) [p0, p1]
+        p60 = getfield_gc(p4, descr=<GcPtrFieldDescr 16>)
+        guard_nonnull(p60, descr=<Guard0x10abcdef1>) [p0, p1]
+        """), preparse("""
+        # Loop 1 : loop with 46 ops
+        p21 = getfield_gc(p4, descr=<GcPtrFieldDescr 16>)
+        """)]
+        loops = splitloops(data)
+        assert len(loops) == 2
+
     def test_split_one_loop(self):
         real_loops = [FinalBlock(preparse("""
         p21 = getfield_gc(p4, descr=<GcPtrFieldDescr 16>)
@@ -50,12 +64,42 @@
         assert loop.left.content == ''
         assert loop.right.content == 'extra'
 
+    def test_split_one_loop_hexguards(self):
+        real_loops = [FinalBlock(preparse("""
+        p21 = getfield_gc(p4, descr=<GcPtrFieldDescr 16>)
+        guard_class(p4, 141310752, descr=<Guard0x10abcdef2>) [p0, p1]
+        """), None), FinalBlock(preparse("""
+        p60 = getfield_gc(p4, descr=<GcPtrFieldDescr 16>)
+        guard_nonnull(p60, descr=<Guard0x10abcdef0>) [p0, p1]
+        """), None)]
+        real_loops[0].loop_no = 0
+        real_loops[1].loop_no = 1
+        allloops = real_loops[:]
+        split_one_loop(real_loops, 'Guard0x10abcdef0', 'extra', 1, 
guard_number(("0x10abcdef0", "0x")), allloops)
+        loop = real_loops[1]
+        assert isinstance(loop, Block)
+        assert loop.content.endswith('p1]')
+        loop.left = allloops[loop.left]
+        loop.right = allloops[loop.right]
+        assert loop.left.content == ''
+        assert loop.right.content == 'extra'
+
     def test_postparse(self):
         real_loops = [FinalBlock("debug_merge_point('<code object 
_runCallbacks, file '/tmp/x/twisted-trunk/twisted/internet/defer.py', line 357> 
#40 POP_TOP', 0)", None)]
         postprocess(real_loops, real_loops[:], {})
         assert real_loops[0].header.startswith("_runCallbacks, file 
'/tmp/x/twisted-trunk/twisted/internet/defer.py', line 357")
 
+    def test_postparse_new(self):
+        real_loops = [FinalBlock("debug_merge_point(0, 0, '<code object 
_optimize_charset. file 
'/usr/local/Cellar/pypy/2.0-beta2/lib-python/2.7/sre_compile.py'. line 207> 
#351 LOAD_FAST')", None)]
+        postprocess(real_loops, real_loops[:], {})
+        assert real_loops[0].header.startswith("_optimize_charset. file 
'/usr/local/Cellar/pypy/2.0-beta2/lib-python/2.7/sre_compile.py'. line 207")
+
     def test_load_actual(self):
         fname = py.path.local(__file__).join('..', 'data.log.bz2')
         main(str(fname), False, view=False)
         # assert did not explode
+
+    def test_load_actual_f(self):
+        fname = py.path.local(__file__).join('..', 'f.pypylog.bz2')
+        main(str(fname), False, view=False)
+        # assert did not explode
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
@@ -56,6 +56,18 @@
 
 BOX_COLOR = (128, 0, 96)
 
+GUARDNO_RE = "((0x)?[\da-f]+)"
+def guard_number(guardno_match):
+    if (len(guardno_match) == 1 # ("12354",)
+        or guardno_match[1] != "0x" # ("12345", None)
+    ):
+        return int(guardno_match[0])
+    else: # ("0x12ef", "0x")
+        return int(guardno_match[0], 16)
+
+def guard_number_string(guardno_match):
+    return guardno_match[0] # its always the first group
+
 class BasicBlock(object):
     counter = 0
     startlineno = 0
@@ -85,13 +97,15 @@
 
     def set_content(self, content):
         self._content = content
-        groups = re.findall('Guard(\d+)', content)
+        groups = re.findall('Guard' + GUARDNO_RE, content)
         if not groups:
             self.first_guard = -1
             self.last_guard = -1
         else:
-            self.first_guard = int(groups[0])
-            self.last_guard = int(groups[-1])
+            # guards can be out of order nowadays
+            groups = sorted(groups)
+            self.first_guard = guard_number(groups[0])
+            self.last_guard = guard_number(groups[-1])
 
     content = property(get_content, set_content)
 
@@ -197,11 +211,11 @@
             _loop.loop_no = no
             allloops.append(_loop)
         else:
-            m = re.search("bridge out of Guard (\d+)", firstline)
+            m = re.search("bridge out of Guard " + GUARDNO_RE, firstline)
             assert m
-            guard_s = 'Guard' + m.group(1)
+            guard_s = 'Guard' + guard_number_string(m.groups())
             split_one_loop(real_loops, guard_s, loop, counter,
-                           int(m.group(1)), allloops)
+                           guard_number(m.groups()), allloops)
         counter += loop.count("\n") + 2
     return real_loops, allloops
 
@@ -211,7 +225,7 @@
     memo.add(loop)
     if loop is None:
         return
-    m = re.search("debug_merge_point\('(<code object (.*?)> (.*?))'", 
loop.content)
+    m = re.search("debug_merge_point\((?:\d+,\ )*'(<code object (.*?)> 
(.*?))'", loop.content)
     if m is None:
         name = '?'
         loop.key = '?'
@@ -236,7 +250,7 @@
     content = loop.content
     loop.content = "Logfile at %d\n" % loop.startlineno + content
     loop.postprocess(loops, memo, counts)
-    
+
 def postprocess(loops, allloops, counts):
     for loop in allloops:
         if isinstance(loop, Block):
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to