Commits

Manuel Jacob committed 3f632ce

Back out changeset 89c0969caec9.

Comments (0)

Files changed (1)

rpython/translator/driver.py

 # TODO:
 # sanity-checks using states
 
+# set of translation steps to profile
+PROFILE = set([])
+
 class Instrument(Exception):
     pass
 
     def info(self, msg):
         log.info(msg)
 
+    def _profile(self, goal, func):
+        from cProfile import Profile
+        from rpython.tool.lsprofcalltree import KCacheGrind
+        d = {'func':func}
+        prof = Profile()
+        prof.runctx("res = func()", globals(), d)
+        KCacheGrind(prof).output(open(goal + ".out", "w"))
+        return d['res']
+
     def _do(self, goal, func, *args, **kwds):
         title = func.task_title
         if goal in self.done:
         try:
             instrument = False
             try:
-                res = func()
+                if goal in PROFILE:
+                    res = self._profile(goal, func)
+                else:
+                    res = func()
             except Instrument:
                 instrument = True
             if not func.task_idempotent: