[pypy-commit] pypy vecopt: using pygame viewer for the dependencies instead of writing it manually to the tmp folder (thx fijal for hint)

plan_rich noreply at buildbot.pypy.org
Mon Jul 27 12:48:27 CEST 2015


Author: Richard Plangger <rich at pasra.at>
Branch: vecopt
Changeset: r78682:d3b2ba395def
Date: 2015-07-27 12:48 +0200
http://bitbucket.org/pypy/pypy/changeset/d3b2ba395def/

Log:	using pygame viewer for the dependencies instead of writing it
	manually to the tmp folder (thx fijal for hint)

diff --git a/rpython/conftest.py b/rpython/conftest.py
--- a/rpython/conftest.py
+++ b/rpython/conftest.py
@@ -40,6 +40,9 @@
     group.addoption('--viewloops', action="store_true",
            default=False, dest="viewloops",
            help="show only the compiled loops")
+    group.addoption('--viewdeps', action="store_true",
+           default=False, dest="viewdeps",
+           help="show the dependencies that have been constructed from a trace")
 
 
 def pytest_pycollect_makeitem(__multicall__,collector, name, obj):
diff --git a/rpython/jit/metainterp/optimizeopt/test/test_dependency.py b/rpython/jit/metainterp/optimizeopt/test/test_dependency.py
--- a/rpython/jit/metainterp/optimizeopt/test/test_dependency.py
+++ b/rpython/jit/metainterp/optimizeopt/test/test_dependency.py
@@ -7,6 +7,7 @@
 from rpython.jit.metainterp.optimizeopt.dependency import (DependencyGraph, Dependency,
         IndexVar, MemoryRef)
 from rpython.jit.metainterp.resoperation import rop, ResOperation
+from rpython.conftest import option
 
 class DependencyBaseTest(BaseTest):
 
@@ -16,7 +17,7 @@
     def build_dependency(self, ops):
         loop = self.parse_loop(ops)
         self.last_graph = DependencyGraph(loop)
-        self._write_dot_and_convert_to_svg(self.last_graph, self.test_name)
+        self.show_dot_graph(self.last_graph, self.test_name)
         for node in self.last_graph.nodes:
             assert node.independent(node)
         return self.last_graph
@@ -45,7 +46,7 @@
                 node_b = graph.getnode(idx_b)
                 dependency = node_a.getedge_to(node_b)
                 if dependency is None and idx_b not in exceptions.setdefault(idx,[]):
-                    self._write_dot_and_convert_to_svg(graph, 'except')
+                    self.show_dot_graph(graph, self.test_name + '_except')
                     assert dependency is not None, \
                        " it is expected that instruction at index" + \
                        " %s depends on instr on index %s but it does not.\n%s" \
@@ -92,13 +93,13 @@
         b = self.last_graph.getnode(b)
         assert not a.independent(b), "{a} and {b} are independent!".format(a=a,b=b)
 
-    def _write_dot_and_convert_to_svg(self, graph, filename):
-        dot = graph.as_dot()
-        with open('/tmp/_'+filename+'.dot', 'w') as fd:
-            fd.write(dot)
-        with open('/tmp/'+filename+'.svg', 'w') as fd:
-            import subprocess
-            subprocess.Popen(['dot', '-Tsvg', '/tmp/_'+filename+'.dot'], stdout=fd).communicate()
+    def show_dot_graph(self, graph, name):
+        if option and option.viewdeps:
+            from rpython.translator.tool.graphpage import GraphPage
+            page = GraphPage()
+            page.source = graph.as_dot()
+            page.links = []
+            page.display()
 
     def debug_print_operations(self, loop):
         print('--- loop instr numbered ---')
diff --git a/rpython/jit/metainterp/optimizeopt/test/test_vectorize.py b/rpython/jit/metainterp/optimizeopt/test/test_vectorize.py
--- a/rpython/jit/metainterp/optimizeopt/test/test_vectorize.py
+++ b/rpython/jit/metainterp/optimizeopt/test/test_vectorize.py
@@ -76,7 +76,7 @@
             loop.operations.insert(idx+1, guard)
         opt.analyse_index_calculations()
         if opt.dependency_graph is not None:
-            self._write_dot_and_convert_to_svg(opt.dependency_graph, "ee" + self.test_name)
+            self.show_dot_graph(opt.dependency_graph, "early_exit_" + self.test_name)
             opt.schedule(False)
         opt.unroll_loop_iterations(loop, unroll_factor)
         opt.loop.operations = opt.get_newoperations()
@@ -84,7 +84,7 @@
         opt.clear_newoperations()
         opt.build_dependency_graph()
         self.last_graph = opt.dependency_graph
-        self._write_dot_and_convert_to_svg(self.last_graph, self.test_name)
+        self.show_dot_graph(self.last_graph, self.test_name)
         return opt
 
     def init_packset(self, loop, unroll_factor = -1):
diff --git a/rpython/translator/tool/graphpage.py b/rpython/translator/tool/graphpage.py
--- a/rpython/translator/tool/graphpage.py
+++ b/rpython/translator/tool/graphpage.py
@@ -12,7 +12,6 @@
 class GraphPage(BaseGraphPage):
     save_tmp_file = str(udir.join('graph.dot'))
 
-
 class VariableHistoryGraphPage(GraphPage):
     """ A GraphPage showing the history of variable bindings. """
 


More information about the pypy-commit mailing list