[pypy-svn] r64940 - in pypy/branch/pyjitpl5/pypy/jit/metainterp: . test

arigo at codespeak.net arigo at codespeak.net
Fri May 1 14:17:38 CEST 2009


Author: arigo
Date: Fri May  1 14:17:38 2009
New Revision: 64940

Modified:
   pypy/branch/pyjitpl5/pypy/jit/metainterp/compile.py
   pypy/branch/pyjitpl5/pypy/jit/metainterp/jitprof.py
   pypy/branch/pyjitpl5/pypy/jit/metainterp/pyjitpl.py
   pypy/branch/pyjitpl5/pypy/jit/metainterp/test/test_jitprof.py
   pypy/branch/pyjitpl5/pypy/jit/metainterp/warmspot.py
Log:
The most important change is a fix in the placement of
profiler.start_tracing() and end_tracing().

Also counts for how long the backend compiled the operations.


Modified: pypy/branch/pyjitpl5/pypy/jit/metainterp/compile.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/metainterp/compile.py	(original)
+++ pypy/branch/pyjitpl5/pypy/jit/metainterp/compile.py	Fri May  1 14:17:38 2009
@@ -113,7 +113,9 @@
     return loop
 
 def send_loop_to_backend(metainterp, loop, type):
+    metainterp.staticdata.profiler.start_backend()
     metainterp.cpu.compile_operations(loop)
+    metainterp.staticdata.profiler.end_backend()
     if not we_are_translated():
         if type != "entry bridge":
             metainterp.staticdata.stats.compiled_count += 1

Modified: pypy/branch/pyjitpl5/pypy/jit/metainterp/jitprof.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/metainterp/jitprof.py	(original)
+++ pypy/branch/pyjitpl5/pypy/jit/metainterp/jitprof.py	Fri May  1 14:17:38 2009
@@ -5,41 +5,44 @@
 import time
 
 TRACING = 0
-RUNNING = 1
-BLACKHOLE = 2
-LAST_START = 2
-END_TRACING = 3
-END_RUNNING = 4
-END_BLACKHOLE = 5
+BACKEND = 1
+RUNNING = 2
+BLACKHOLE = 3
+LAST_START = 3
+
+END_TRACING = 4
+END_BACKEND = 5
+END_RUNNING = 6
+END_BLACKHOLE = 7
 
 class EmptyProfiler(object):
-    initialized = False
+    initialized = True
     
     def start(self):
         pass
 
     def finish(self):
         pass
-    
-    def start_normal(self, greenkey=None):
+
+    def start_tracing(self):
         pass
 
-    def end_normal(self):
+    def end_tracing(self):
         pass
 
-    def start_tracing(self, greenkey=None):
+    def start_backend(self):
         pass
 
-    def end_tracing(self):
+    def end_backend(self):
         pass
 
-    def start_running(self, greenkey=None):
+    def start_running(self):
         pass
 
     def end_running(self):
         pass
 
-    def start_blackhole(self, greenkey=None):
+    def start_blackhole(self):
         pass
 
     def end_blackhole(self):
@@ -58,19 +61,25 @@
         self.summarize()
         self.print_stats()
 
-    def start_tracing(self, greenkey=None):
+    def start_tracing(self):
         self.events.append((self.timer(), TRACING))
 
     def end_tracing(self):
         self.events.append((self.timer(), END_TRACING))
 
-    def start_running(self, greenkey=None):
+    def start_backend(self):
+        self.events.append((self.timer(), BACKEND))
+
+    def end_backend(self):
+        self.events.append((self.timer(), END_BACKEND))
+
+    def start_running(self):
         self.events.append((self.timer(), RUNNING))
 
     def end_running(self):
         self.events.append((self.timer(), END_RUNNING))
 
-    def start_blackhole(self, greenkey=None):
+    def start_blackhole(self):
         self.events.append((self.timer(), BLACKHOLE))
 
     def end_blackhole(self):
@@ -79,7 +88,7 @@
     def summarize(self):
         current = []
         t = 0
-        times = [0, 0, 0]
+        times = [0, 0, 0, 0]
         for t0, ev in self.events:
             if ev <= LAST_START:
                 if current:
@@ -89,12 +98,13 @@
                 times[current.pop()] += t0 - t
             t = t0
         self.trace_time = times[TRACING]
+        self.backend_time = times[BACKEND]
         self.run_time = times[RUNNING]
         self.blackhole_time = times[BLACKHOLE]
 
     def print_stats(self):
-        print "Total: %f" % (self.tk - self.t0)
-        print "Tracing: %f" % self.trace_time
-        print "Running: %f" % self.run_time
-        print "Blackhole: %f" % self.blackhole_time
-
+        print "Tracing:     %f" % self.trace_time
+        print "Backend:     %f" % self.backend_time
+        print "Running asm: %f" % self.run_time
+        print "Blackhole:   %f" % self.blackhole_time
+        print "TOTAL:       %f" % (self.tk - self.t0)

Modified: pypy/branch/pyjitpl5/pypy/jit/metainterp/pyjitpl.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/metainterp/pyjitpl.py	(original)
+++ pypy/branch/pyjitpl5/pypy/jit/metainterp/pyjitpl.py	Fri May  1 14:17:38 2009
@@ -1022,6 +1022,8 @@
         finally:
             if isinstance(self.history, history.BlackHole):
                 self.staticdata.profiler.end_blackhole()
+            else:
+                self.staticdata.profiler.end_tracing()
             if not we_are_translated():
                 history.log.event('LEAVE' + self.history.extratext)
             elif DEBUG:
@@ -1242,6 +1244,7 @@
                                         *args[1:])
 
     def initialize_state_from_start(self, *args):
+        self.staticdata.profiler.start_tracing()
         self.staticdata._recompute_class_sizes()
         self.create_empty_history()
         num_green_args = self.staticdata.num_green_args
@@ -1273,7 +1276,9 @@
                 for i in range(extra):
                     self.history.operations.append(suboperations[i])
                 self.extra_rebuild_operations = extra
-        if not must_compile:
+        if must_compile:
+            self.staticdata.profiler.start_tracing()
+        else:
             self.staticdata.profiler.start_blackhole()
             self.history = history.BlackHole(self.cpu)
             # the BlackHole is invalid because it doesn't start with

Modified: pypy/branch/pyjitpl5/pypy/jit/metainterp/test/test_jitprof.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/metainterp/test/test_jitprof.py	(original)
+++ pypy/branch/pyjitpl5/pypy/jit/metainterp/test/test_jitprof.py	Fri May  1 14:17:38 2009
@@ -13,8 +13,8 @@
         self.counter += 1
         return self.counter - 1
 
-    def print_stats(self):
-        pass
+##    def print_stats(self):
+##        pass
 
 class ProfilerMixin(LLJitMixin):
     def meta_interp(self, *args, **kwds):
@@ -37,9 +37,11 @@
         res = self.meta_interp(f, [6, 7])
         assert res == 84
         profiler = pyjitpl._warmrunnerdesc.metainterp_sd.profiler
-        assert len(profiler.events) == 6
+        assert len(profiler.events) == 8
         expected = [
             TRACING,
+            BACKEND,
+            END_BACKEND,
             END_TRACING,
             RUNNING,
             END_RUNNING,
@@ -47,6 +49,7 @@
             END_BLACKHOLE
             ]
         assert [i[1] for i in profiler.events] == expected
-        assert profiler.trace_time == 1
+        assert profiler.trace_time == 2
+        assert profiler.backend_time == 1
         assert profiler.run_time == 1        
         assert profiler.blackhole_time == 1

Modified: pypy/branch/pyjitpl5/pypy/jit/metainterp/warmspot.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/metainterp/warmspot.py	(original)
+++ pypy/branch/pyjitpl5/pypy/jit/metainterp/warmspot.py	Fri May  1 14:17:38 2009
@@ -578,10 +578,6 @@
             # not too bad.
 
         def maybe_compile_and_run(self, *args):
-            metainterp_sd = warmrunnerdesc.metainterp_sd
-            if not metainterp_sd.profiler.initialized:
-                metainterp_sd.profiler.start()
-                metainterp_sd.profiler.initialized = True
             # get the greenargs and look for the cell corresponding to the hash
             greenargs = args[:num_green_args]
             argshash = self.getkeyhash(*greenargs)
@@ -595,10 +591,12 @@
                     self.cells[argshash] = Counter(n)
                     return
                 #interp.debug_trace("jit_compile", *greenargs)
+                metainterp_sd = warmrunnerdesc.metainterp_sd
+                if not metainterp_sd.profiler.initialized:
+                    metainterp_sd.profiler.start()
+                    metainterp_sd.profiler.initialized = True
                 metainterp = MetaInterp(metainterp_sd)
-                metainterp_sd.profiler.start_tracing()
                 loop = metainterp.compile_and_run_once(*args)
-                metainterp_sd.profiler.end_tracing()
             else:
                 # machine code was already compiled for these greenargs
                 # (or we have a hash collision)
@@ -644,10 +642,7 @@
                 return None
             metainterp_sd = warmrunnerdesc.metainterp_sd
             metainterp = MetaInterp(metainterp_sd)
-            warmrunnerdesc.metainterp_sd.profiler.start_tracing()
-            res = metainterp.compile_and_run_once(*args)
-            warmrunnerdesc.metainterp_sd.profiler.end_tracing()
-            return res
+            return metainterp.compile_and_run_once(*args)
         handle_hash_collision._dont_inline_ = True
 
         def getkeyhash(self, *greenargs):



More information about the Pypy-commit mailing list