[pypy-svn] r20596 - pypy/dist/pypy/translator/tool

pedronis at codespeak.net pedronis at codespeak.net
Sat Dec 3 01:29:19 CET 2005


Author: pedronis
Date: Sat Dec  3 01:29:18 2005
New Revision: 20596

Modified:
   pypy/dist/pypy/translator/tool/graphpage.py
   pypy/dist/pypy/translator/tool/pdbplus.py
Log:
pass at fixining graph commands in pdbplus



Modified: pypy/dist/pypy/translator/tool/graphpage.py
==============================================================================
--- pypy/dist/pypy/translator/tool/graphpage.py	(original)
+++ pypy/dist/pypy/translator/tool/graphpage.py	Sat Dec  3 01:29:18 2005
@@ -308,7 +308,7 @@
     def followlink(self, name):
         if name.endswith('...'):
             obj = self.object_by_name[name]
-            return LocalizedCallGraphPage(self.translator, obj)
+            return LocalizedCallGraphPage(self.translator, [obj])
         obj = self.object_by_name[name]
         if isinstance(obj, ClassDef):
             return ClassDefPage(self.translator, obj)
@@ -331,7 +331,7 @@
 
         if len(graphs) > huge:
             assert graphs, "no graph to show!"
-            LocalizedCallGraphPage.do_compute.im_func(self, dotgen, graphs[0])
+            LocalizedCallGraphPage.do_compute.im_func(self, dotgen, [graphs[0]])
             return
 
         blocked_graphs = self.get_blocked_graphs(graphs)
@@ -361,16 +361,18 @@
     """A GraphPage showing the localized call graph for a function,
     that means just including direct callers and callees"""
 
-    def graph_name(self, graph0):
-        return 'LCG_%s' % nameof(graph0)
+    def graph_name(self, centers):
+        return 'LCG_%s' % nameof(centers[0])
+
+    def do_compute(self, dotgen, centers):
+        centers = dict.fromkeys(centers)
 
-    def do_compute(self, dotgen, graph0):
         translator = self.translator
 
         graphs = {}
 
         for g1, g2 in translator.callgraph.values():
-            if g1 is graph0 or g2 is graph0:
+            if g1 in centers  or g2 in centers:
                 dotgen.emit_edge(nameof(g1), nameof(g2))
                 graphs[g1] = True
                 graphs[g2] = True
@@ -391,7 +393,7 @@
                 kw = {}
             dotgen.emit_node(nameof(graph), label=data, shape="box", **kw)
 
-            if graph is not graph0:
+            if graph  not in centers:
                 lcg = 'LCG_%s' % nameof(graph)
                 label = graph.name+'...'
                 dotgen.emit_node(lcg, label=label)

Modified: pypy/dist/pypy/translator/tool/pdbplus.py
==============================================================================
--- pypy/dist/pypy/translator/tool/pdbplus.py	(original)
+++ pypy/dist/pypy/translator/tool/pdbplus.py	Sat Dec  3 01:29:18 2005
@@ -1,4 +1,6 @@
 import threading, pdb
+import types
+from pypy.objspace.flow.model import FunctionGraph
 
 class _EnableGraphic:
     def __init__(self, port=None):
@@ -176,8 +178,10 @@
             return
         if hasattr(obj, 'im_func'):
             obj = obj.im_func
-        if obj in translator.flowgraphs:
-            page = graphpage.LocalizedCallGraphPage(translator, obj)
+        if isinstance(obj, types.FunctionType):
+            page = graphpage.LocalizedCallGraphPage(translator, self._allgraphs(obj))
+        elif isinstance(obj, FunctionGraph):
+            page = graphpage.FlowGraphPage(translator, [obj])
         elif obj in getattr(translator.annotator, 'getuserclasses', lambda: {})():
             page = graphpage.ClassDefPage(translator, translator.annotator.getuserclasses()[obj])
         elif isinstance(obj, ClassDef):
@@ -194,7 +198,6 @@
         obj = self._getobj(arg)
         if obj is None:
             return
-        import types
         if isinstance(obj, (type, types.ClassType)):
             obj = [obj]
         else:
@@ -306,33 +309,50 @@
         """callg obj
 show flow graph for function obj, obj can be an expression or a dotted name
 (in which case prefixing with some packages in pypy is tried (see help pypyprefixes))"""            
-        import types
         from pypy.translator.tool import graphpage                        
         obj = self._getobj(arg)
         if obj is None:
             return
         if hasattr(obj, 'im_func'):
             obj = obj.im_func
-        if not isinstance(obj, types.FunctionType):
+        if isinstance(obj, types.FunctionType):
+            graphs = self._allgraphs(obj)
+        elif isinstance(obj, FunctionGraph):
+            graphs = [obj]
+        else:
             print "*** Not a function"
             return
-        self._show(graphpage.FlowGraphPage(self.translator, [obj]))
+        self._show(graphpage.FlowGraphPage(self.translator, graphs))
+
+    def _allgraphs(self, func):
+        graphs = {}
+        funcdesc = self.translator.annotator.bookkeeper.getdesc(func)
+        for graph in funcdesc._cache.itervalues():
+            graphs[graph] = True
+        for graph in self.translator.graphs:
+            if getattr(graph, 'func', None) is func:
+                graphs[graph] = True
+        return graphs.keys()
+
 
     def do_callg(self, arg):
         """callg obj
 show localized call-graph for function obj, obj can be an expression or a dotted name
 (in which case prefixing with some packages in pypy is tried (see help pypyprefixes))"""
-        import types
         from pypy.translator.tool import graphpage                        
         obj = self._getobj(arg)
         if obj is None:
             return
         if hasattr(obj, 'im_func'):
             obj = obj.im_func
-        if not isinstance(obj, types.FunctionType):
+        if isinstance(obj, types.FunctionType):
+            graphs = self._allgraphs(obj)
+        elif isinstance(obj, FunctionGraph):
+            graphs = [obj]
+        else:
             print "*** Not a function"
             return
-        self._show(graphpage.LocalizedCallGraphPage(self.translator, obj))
+        self._show(graphpage.LocalizedCallGraphPage(self.translator, graphs))
 
     def do_classhier(self, arg):
         """classhier



More information about the Pypy-commit mailing list