[pypy-svn] r11968 - in pypy/dist: goal pypy/translator

arigo at codespeak.net arigo at codespeak.net
Thu May 5 17:32:57 CEST 2005


Author: arigo
Date: Thu May  5 17:32:57 2005
New Revision: 11968

Modified:
   pypy/dist/goal/translate_pypy.py
   pypy/dist/pypy/translator/annrpython.py
Log:
Display a Top Ten of the most often reflow blocks after translate_pypy.py.


Modified: pypy/dist/goal/translate_pypy.py
==============================================================================
--- pypy/dist/goal/translate_pypy.py	(original)
+++ pypy/dist/goal/translate_pypy.py	Thu May  5 17:32:57 2005
@@ -34,8 +34,7 @@
 from pypy.tool.cache import Cache
 from pypy.annotation.model import SomeObject
 from pypy.tool.udir import udir 
-
-
+from pypy.tool.ansi_print import ansi_print
 
 
 # XXX this tries to make compiling faster
@@ -56,7 +55,10 @@
     if listen_port:
         run_async_server()
     if not options['-no-a']:
-        a = t.annotate(inputtypes, overrides=pypy_overrides)
+        try:
+            a = t.annotate(inputtypes, overrides=pypy_overrides)
+        finally:
+            worstblocks_topten(t.annotator)
         if not options['-no-s']:
             a.simplify()
         if not options['-no-t']:
@@ -156,6 +158,22 @@
     graphserver.run_server(homepage, port=listen_port, background=True)
     options['-text'] = True
 
+def worstblocks_topten(ann, n=10):
+    import heapq
+    h = [(-count, block) for block, count in ann.reflowcounter.iteritems()]
+    heapq.heapify(h)
+    print
+    ansi_print(',-----------------------  Top %d Most Reflown Blocks  -----------------------.' % n, 36)
+    for i in range(n):
+        if not h:
+            break
+        count, block = heapq.heappop(h)
+        count = -count
+        ansi_print('                                                      #%3d: reflown %d times  |' % (i+1, count), 36)
+        about(block)
+    ansi_print("`----------------------------------------------------------------------------'", 36)
+    print
+
 
 if __name__ == '__main__':
 

Modified: pypy/dist/pypy/translator/annrpython.py
==============================================================================
--- pypy/dist/pypy/translator/annrpython.py	(original)
+++ pypy/dist/pypy/translator/annrpython.py	Thu May  5 17:32:57 2005
@@ -37,6 +37,7 @@
         self.binding_cause_history = {} # map Variables to lists of positions
                 # history of binding_caused_by, kept in sync with
                 # bindingshistory
+        self.reflowcounter = {}
         self.return_bindings = {} # map return Variables to functions
         # user-supplied annotation logic for functions we don't want to flow into
         self.overrides = overrides
@@ -293,6 +294,9 @@
         #      input variables).
 
         #print '* processblock', block, cells
+        if annmodel.DEBUG:
+            self.reflowcounter.setdefault(block, 0)
+            self.reflowcounter[block] += 1
         self.annotated[block] = fn or True
         try:
             self.flowin(fn, block)



More information about the Pypy-commit mailing list