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

fijal at codespeak.net fijal at codespeak.net
Fri May 1 03:30:18 CEST 2009


Author: fijal
Date: Fri May  1 03:30:12 2009
New Revision: 64906

Modified:
   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:
progress on profiler


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 03:30:12 2009
@@ -7,9 +7,10 @@
 TRACING = 0
 RUNNING = 1
 BLACKHOLE = 2
-END_TRACING = 4
-END_RUNNING = 5
-END_BLACKHOLE = 6
+LAST_START = 2
+END_TRACING = 3
+END_RUNNING = 4
+END_BLACKHOLE = 5
 
 class EmptyProfiler(object):
     initialized = False
@@ -46,32 +47,50 @@
 
 class Profiler(object):
     initialized = False
+    timer = time.clock
     
     def start(self):
-        self.t0 = time.clock()
+        self.t0 = self.timer()
         self.events = []
 
     def finish(self):
-        self.tk = time.clock()
+        self.tk = self.timer()
+        self.summarize()
         self.print_stats()
 
     def start_tracing(self, greenkey=None):
-        self.events.append((time.clock(), TRACING))
+        self.events.append((self.timer(), TRACING))
 
     def end_tracing(self):
-        self.events.append((time.clock(), END_TRACING))
+        self.events.append((self.timer(), END_TRACING))
 
     def start_running(self, greenkey=None):
-        self.events.append((time.clock(), RUNNING))
+        self.events.append((self.timer(), RUNNING))
 
     def end_running(self):
-        self.events.append((time.clock(), END_RUNNING))
+        self.events.append((self.timer(), END_RUNNING))
 
     def start_blackhole(self, greenkey=None):
-        self.events.append((time.clock(), BLACKHOLE))
+        self.events.append((self.timer(), BLACKHOLE))
 
     def end_blackhole(self):
-        self.events.append((time.clock(), END_BLACKHOLE))
+        self.events.append((self.timer(), END_BLACKHOLE))
+
+    def summarize(self):
+        current = []
+        t = 0
+        times = [0, 0, 0]
+        for t0, ev in self.events:
+            if ev <= LAST_START:
+                if current:
+                    times[current[-1]] += t0 - t
+                current.append(ev)
+            else:
+                times[current.pop()] += t0 - t
+            t = t0
+        self.trace_time = times[TRACING]
+        self.run_time = times[RUNNING]
+        self.blackhole_time = times[BLACKHOLE]
 
     def print_stats(self):
         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 03:30:12 2009
@@ -862,8 +862,8 @@
         else:
             self.ts = typesystem.llhelper
 
-        if profile:
-            self.profiler = Profiler()
+        if profile is not None:
+            self.profiler = profile()
         else:
             self.profiler = EmptyProfiler()
 

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 03:30:12 2009
@@ -5,10 +5,21 @@
 from pypy.jit.metainterp import pyjitpl
 from pypy.jit.metainterp.jitprof import *
 
+class FakeProfiler(Profiler):
+    def __init__(self):
+        self.counter = 0
+    
+    def timer(self):
+        self.counter += 1
+        return self.counter - 1
+
+    def print_stats(self):
+        pass
+
 class ProfilerMixin(LLJitMixin):
     def meta_interp(self, *args, **kwds):
         kwds = kwds.copy()
-        kwds['profile'] = True
+        kwds['profile'] = FakeProfiler
         return LLJitMixin.meta_interp(self, *args, **kwds)
 
 class TestProfile(ProfilerMixin):
@@ -36,4 +47,6 @@
             END_BLACKHOLE
             ]
         assert [i[1] for i in profiler.events] == expected
-        
+        assert profiler.trace_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 03:30:12 2009
@@ -54,6 +54,7 @@
         warmrunnerdesc.state.set_param_hash_bits(hash_bits)
     warmrunnerdesc.finish()
     res = interp.eval_graph(graph, args)
+    warmrunnerdesc.metainterp_sd.profiler.finish()
     print '~~~ return value:', res
     while repeat > 1:
         print '~' * 79



More information about the Pypy-commit mailing list