[pypy-svn] r68126 - in pypy/trunk/pypy/jit/metainterp: . test

arigo at codespeak.net arigo at codespeak.net
Fri Oct 2 13:24:16 CEST 2009


Author: arigo
Date: Fri Oct  2 13:24:13 2009
New Revision: 68126

Modified:
   pypy/trunk/pypy/jit/metainterp/compile.py
   pypy/trunk/pypy/jit/metainterp/jitprof.py
   pypy/trunk/pypy/jit/metainterp/pyjitpl.py
   pypy/trunk/pypy/jit/metainterp/test/test_basic.py
   pypy/trunk/pypy/jit/metainterp/test/test_compile.py
   pypy/trunk/pypy/jit/metainterp/test/test_jitprof.py
   pypy/trunk/pypy/jit/metainterp/test/test_warmspot.py
   pypy/trunk/pypy/jit/metainterp/test/test_zrpy_basic.py
   pypy/trunk/pypy/jit/metainterp/warmspot.py
Log:
(pedronis, arigo)
Make debug_level and profiler interaction sane.
The profiler class is no longer selectable at run-time
(see issue #448), but we can turn on or off the final
printing.


Modified: pypy/trunk/pypy/jit/metainterp/compile.py
==============================================================================
--- pypy/trunk/pypy/jit/metainterp/compile.py	(original)
+++ pypy/trunk/pypy/jit/metainterp/compile.py	Fri Oct  2 13:24:13 2009
@@ -12,7 +12,6 @@
 from pypy.jit.metainterp.specnode import NotSpecNode, more_general_specnodes
 from pypy.jit.metainterp.typesystem import llhelper, oohelper
 from pypy.jit.metainterp.optimizeutil import InvalidLoop
-from pypy.rlib.debug import debug_print
 
 def show_loop(metainterp_sd, loop=None, error=None):
     # debugging
@@ -64,8 +63,7 @@
     except InvalidLoop:
         return None
     if old_loop_token is not None:
-        if metainterp.staticdata.state.debug > 1:
-            debug_print("reusing old loop")
+        metainterp.staticdata.log("reusing old loop")
         return old_loop_token
     send_loop_to_backend(metainterp_sd, loop, "loop")
     insert_loop_token(old_loop_tokens, loop_token)
@@ -86,40 +84,32 @@
 
 def send_loop_to_backend(metainterp_sd, loop, type):
     metainterp_sd.options.logger_ops.log_loop(loop.inputargs, loop.operations)
-    metainterp_sd.state.profiler.start_backend()
+    metainterp_sd.profiler.start_backend()
     if not we_are_translated():
         show_loop(metainterp_sd, loop)
         loop.check_consistency()
     metainterp_sd.cpu.compile_loop(loop.inputargs, loop.operations, loop.token)
-    metainterp_sd.state.profiler.end_backend()
+    metainterp_sd.profiler.end_backend()
     metainterp_sd.stats.add_new_loop(loop)
     if not we_are_translated():
         if type != "entry bridge":
             metainterp_sd.stats.compiled()
         else:
             loop._ignore_during_counting = True
-        if metainterp_sd.state.debug > 1:
-            log.info("compiled new " + type)
-    else:
-        if metainterp_sd.state.debug > 1:
-            debug_print("compiled new " + type)
+    metainterp_sd.log("compiled new " + type)
 
 def send_bridge_to_backend(metainterp_sd, faildescr, inputargs, operations):
     metainterp_sd.options.logger_ops.log_loop(inputargs, operations)
-    metainterp_sd.state.profiler.start_backend()
+    metainterp_sd.profiler.start_backend()
     if not we_are_translated():
         show_loop(metainterp_sd)
         TreeLoop.check_consistency_of(inputargs, operations)
         pass
     metainterp_sd.cpu.compile_bridge(faildescr, inputargs, operations)        
-    metainterp_sd.state.profiler.end_backend()
+    metainterp_sd.profiler.end_backend()
     if not we_are_translated():
-        if metainterp_sd.state.debug > 1:
-            metainterp_sd.stats.compiled()
-            log.info("compiled new bridge")
-    else:
-        if metainterp_sd.state.debug > 1:
-            debug_print("compiled new bridge")            
+        metainterp_sd.stats.compiled()
+    metainterp_sd.log("compiled new bridge")            
 
 # ____________________________________________________________
 

Modified: pypy/trunk/pypy/jit/metainterp/jitprof.py
==============================================================================
--- pypy/trunk/pypy/jit/metainterp/jitprof.py	(original)
+++ pypy/trunk/pypy/jit/metainterp/jitprof.py	Fri Oct  2 13:24:13 2009
@@ -36,6 +36,9 @@
     def finish(self):
         pass
 
+    def set_printing(self, printing):
+        pass
+
     def start_tracing(self):
         pass
 
@@ -75,6 +78,7 @@
     counters = None
     calls = None
     current = None
+    printing = True
 
     def start(self):
         self.starttime = self.timer()
@@ -86,7 +90,11 @@
 
     def finish(self):
         self.tk = self.timer()
-        self.print_stats()
+        if self.printing:
+            self.print_stats()
+
+    def set_printing(self, printing):
+        self.printing = printing
 
     def _start(self, event):
         t0 = self.t1

Modified: pypy/trunk/pypy/jit/metainterp/pyjitpl.py
==============================================================================
--- pypy/trunk/pypy/jit/metainterp/pyjitpl.py	(original)
+++ pypy/trunk/pypy/jit/metainterp/pyjitpl.py	Fri Oct  2 13:24:13 2009
@@ -10,7 +10,7 @@
 from pypy.jit.metainterp.resoperation import rop
 from pypy.jit.metainterp import codewriter, executor
 from pypy.jit.metainterp.logger import Logger
-from pypy.jit.metainterp.jitprof import BLACKHOLED_OPS
+from pypy.jit.metainterp.jitprof import BLACKHOLED_OPS, EmptyProfiler
 from pypy.jit.metainterp.jitprof import GUARDS, RECORDED_OPS
 from pypy.rlib.rarithmetic import intmask
 from pypy.rlib.objectmodel import specialize
@@ -796,8 +796,8 @@
     def opimpl_jit_merge_point(self, pc):
         if not self.metainterp.is_blackholing():
             self.generate_merge_point(pc, self.env)
-            if self.metainterp.staticdata.state.debug > DEBUG_PROFILE:
-                self.debug_merge_point()
+            # xxx we may disable the following line in some context later
+            self.debug_merge_point()
             if self.metainterp.seen_can_enter_jit:
                 self.metainterp.seen_can_enter_jit = False
                 try:
@@ -872,7 +872,7 @@
         self.pc = pc
         self.exception_target = exception_target
         self.env = env
-        if self.metainterp.staticdata.state.debug >= DEBUG_DETAILED:
+        if self.metainterp.staticdata.state.debug_level >= DEBUG_DETAILED:
             values = ' '.join([box.repr_rpython() for box in self.env])
             log = self.metainterp.staticdata.log
             log('setup_resume_at_op  %s:%d [%s] %d' % (self.jitcode.name,
@@ -916,7 +916,7 @@
             virtualizable_boxes = metainterp.virtualizable_boxes
         resume.capture_resumedata(metainterp.framestack, virtualizable_boxes,
                                   resumedescr)
-        self.metainterp.staticdata.state.profiler.count_ops(opnum, GUARDS)
+        self.metainterp.staticdata.profiler.count_ops(opnum, GUARDS)
         # count
         metainterp.attach_debug_info(guard_op)
         self.pc = saved_pc
@@ -960,7 +960,7 @@
     virtualizable_info = None
 
     def __init__(self, portal_graph, graphs, cpu, stats, options,
-                 profile=None, warmrunnerdesc=None,
+                 ProfilerClass=EmptyProfiler, warmrunnerdesc=None,
                  leave_graph=None):
         self.portal_graph = portal_graph
         self.cpu = cpu
@@ -976,6 +976,8 @@
         self.opcode_names = []
         self.opname_to_index = {}
 
+        self.profiler = ProfilerClass()
+
         self.indirectcall_keys = []
         self.indirectcall_values = []
 
@@ -1008,6 +1010,9 @@
             self._setup_class_sizes()
             self.cpu.setup_once()
             self.log(self.jit_starting_line)
+            if not self.profiler.initialized:
+                self.profiler.start()
+                self.profiler.initialized = True
             self.globaldata.initialized = True
             self.options.logger_noopt.create_log('.noopt')
             self.options.logger_ops.create_log('.ops')
@@ -1074,7 +1079,7 @@
     # ---------------- logging ------------------------
 
     def log(self, msg, event_kind='info'):
-        if self.state.debug > DEBUG_PROFILE:
+        if self.state.debug_level > DEBUG_PROFILE:
             if not we_are_translated():
                 getattr(history.log, event_kind)(msg)
             else:
@@ -1224,7 +1229,7 @@
         history.check_descr(descr)
         assert opnum != rop.CALL and opnum != rop.OOSEND
         # execute the operation
-        profiler = self.staticdata.state.profiler
+        profiler = self.staticdata.profiler
         profiler.count_ops(opnum)
         resbox = executor.execute(self.cpu, opnum, descr, *argboxes)
         if self.is_blackholing():
@@ -1246,7 +1251,7 @@
         if require_attention and not self.is_blackholing():
             self.before_residual_call()
         # execute the operation
-        profiler = self.staticdata.state.profiler
+        profiler = self.staticdata.profiler
         profiler.count_ops(opnum)
         resbox = executor.execute_varargs(self.cpu, opnum, argboxes, descr)
         if self.is_blackholing():
@@ -1285,7 +1290,7 @@
     def _record_helper_nonpure_varargs(self, opnum, resbox, descr, argboxes):
         assert resbox is None or isinstance(resbox, Box)
         # record the operation
-        profiler = self.staticdata.state.profiler
+        profiler = self.staticdata.profiler
         profiler.count_ops(opnum, RECORDED_OPS)        
         op = self.history.record(opnum, argboxes, resbox, descr)
         self.attach_debug_info(op)
@@ -1301,8 +1306,8 @@
         self.history = None   # start blackholing
         self.staticdata.stats.aborted()
         self.staticdata.log('~~~ ABORTING TRACING', event_kind='event')
-        self.staticdata.state.profiler.end_tracing()
-        self.staticdata.state.profiler.start_blackhole()
+        self.staticdata.profiler.end_tracing()
+        self.staticdata.profiler.start_blackhole()
 
     def switch_to_blackhole_if_trace_too_long(self):
         if not self.is_blackholing():
@@ -1324,9 +1329,9 @@
                     self.check_recursion_invariant()
         finally:
             if self.is_blackholing():
-                self.staticdata.state.profiler.end_blackhole()
+                self.staticdata.profiler.end_blackhole()
             else:
-                self.staticdata.state.profiler.end_tracing()
+                self.staticdata.profiler.end_tracing()
             self.staticdata.log('~~~ LEAVE' + self.blackholing_text(),
                                 event_kind='event')
 
@@ -1545,7 +1550,7 @@
     def initialize_state_from_start(self, *args):
         self.in_recursion = -1 # always one portal around
         self.staticdata._setup_once()
-        self.staticdata.state.profiler.start_tracing()
+        self.staticdata.profiler.start_tracing()
         self.create_empty_history()
         num_green_args = self.staticdata.num_green_args
         original_boxes = []
@@ -1567,9 +1572,9 @@
         if must_compile:
             self.history = history.History(self.cpu)
             self.history.inputargs = inputargs
-            self.staticdata.state.profiler.start_tracing()
+            self.staticdata.profiler.start_tracing()
         else:
-            self.staticdata.state.profiler.start_blackhole()
+            self.staticdata.profiler.start_blackhole()
             self.history = None   # this means that is_blackholing() is true
         self.rebuild_state_after_failure(resumedescr, inputargs)
         return resumedescr

Modified: pypy/trunk/pypy/jit/metainterp/test/test_basic.py
==============================================================================
--- pypy/trunk/pypy/jit/metainterp/test/test_basic.py	(original)
+++ pypy/trunk/pypy/jit/metainterp/test/test_basic.py	Fri Oct  2 13:24:13 2009
@@ -11,7 +11,6 @@
 from pypy.jit.metainterp.typesystem import LLTypeHelper, OOTypeHelper
 from pypy.rpython.lltypesystem import lltype
 from pypy.rpython.ootypesystem import ootype
-from pypy.jit.metainterp.jitprof import EmptyProfiler
 
 def get_metainterp(func, values, CPUClass, type_system, policy,
                    listops=False, optimizer=OPTIMIZER_FULL):
@@ -71,7 +70,7 @@
             def __init__(self, cpu, *args):
                 DoneWithThisFrame.__init__(self, *args)
         
-        class FakeWarmRunnerDesc:
+        class FakeWarmRunnerState:
             def attach_unoptimized_bridge_from_interp(self, greenkey, newloop):
                 pass
 
@@ -80,8 +79,7 @@
             optimize_bridge = staticmethod(simple_optimize.optimize_bridge)
 
             trace_limit = sys.maxint
-            profiler = EmptyProfiler()
-            debug = 2
+            debug_level = 2
         
         if policy is None:
             policy = JitPolicy()
@@ -96,7 +94,7 @@
         cw.finish_making_bytecodes()
         metainterp.staticdata.portal_code = maingraph
         metainterp.staticdata._class_sizes = cw.class_sizes
-        metainterp.staticdata.state = FakeWarmRunnerDesc()
+        metainterp.staticdata.state = FakeWarmRunnerState()
         metainterp.staticdata.DoneWithThisFrameInt = DoneWithThisFrame
         metainterp.staticdata.DoneWithThisFrameRef = DoneWithThisFrameRef
         metainterp.staticdata.DoneWithThisFrameFloat = DoneWithThisFrame

Modified: pypy/trunk/pypy/jit/metainterp/test/test_compile.py
==============================================================================
--- pypy/trunk/pypy/jit/metainterp/test/test_compile.py	(original)
+++ pypy/trunk/pypy/jit/metainterp/test/test_compile.py	Fri Oct  2 13:24:13 2009
@@ -41,13 +41,15 @@
 
 class FakeState:
     optimize_loop = staticmethod(optimize.optimize_loop)
-    profiler = jitprof.EmptyProfiler()
-    debug = 0
+    debug_level = 0
 
 class FakeMetaInterpStaticData:
     options = FakeOptions()
     state = FakeState()
     stats = Stats()
+    profiler = jitprof.EmptyProfiler()
+    def log(self, msg, event_kind=None):
+        pass
 
 class FakeMetaInterp:
     pass

Modified: pypy/trunk/pypy/jit/metainterp/test/test_jitprof.py
==============================================================================
--- pypy/trunk/pypy/jit/metainterp/test/test_jitprof.py	(original)
+++ pypy/trunk/pypy/jit/metainterp/test/test_jitprof.py	Fri Oct  2 13:24:13 2009
@@ -25,7 +25,7 @@
 class ProfilerMixin(LLJitMixin):
     def meta_interp(self, *args, **kwds):
         kwds = kwds.copy()
-        kwds['profile'] = FakeProfiler
+        kwds['ProfilerClass'] = FakeProfiler
         return LLJitMixin.meta_interp(self, *args, **kwds)
 
 class TestProfile(ProfilerMixin):
@@ -42,7 +42,7 @@
             return res * 2
         res = self.meta_interp(f, [6, 7])
         assert res == 84
-        profiler = pyjitpl._warmrunnerdesc.metainterp_sd.state.profiler
+        profiler = pyjitpl._warmrunnerdesc.metainterp_sd.profiler
         expected = [
             TRACING,
             BACKEND,
@@ -74,7 +74,7 @@
             return res * 2
         res = self.meta_interp(f, [6, 7])
         assert res == 84
-        profiler = pyjitpl._warmrunnerdesc.metainterp_sd.state.profiler
+        profiler = pyjitpl._warmrunnerdesc.metainterp_sd.profiler
         # calls = (executed, recorded, blackholed) x (inpure, pure)
         assert profiler.calls == [[1, 0], [1, 0], [0, 0]]
 
@@ -96,6 +96,6 @@
             return res * 2
         res = self.meta_interp(f, [6, 7, 2])
         assert res == 90
-        profiler = pyjitpl._warmrunnerdesc.metainterp_sd.state.profiler
+        profiler = pyjitpl._warmrunnerdesc.metainterp_sd.profiler
         # calls = (executed, recorded, blackholed) x (inpure, pure)
         assert profiler.calls == [[0, 1], [0, 0], [0, 1]]

Modified: pypy/trunk/pypy/jit/metainterp/test/test_warmspot.py
==============================================================================
--- pypy/trunk/pypy/jit/metainterp/test/test_warmspot.py	(original)
+++ pypy/trunk/pypy/jit/metainterp/test/test_warmspot.py	Fri Oct  2 13:24:13 2009
@@ -152,9 +152,55 @@
         assert warmrunnerdescr.state.optimize_loop is optimize.optimize_loop
         assert warmrunnerdescr.state.optimize_bridge is optimize.optimize_bridge
 
+    def test_static_debug_level(self):
+        from pypy.rlib.jit import DEBUG_PROFILE, DEBUG_OFF, DEBUG_STEPS
+        from pypy.jit.metainterp.jitprof import EmptyProfiler, Profiler
+        
+        myjitdriver = JitDriver(greens = [], reds = ['n'])
+        def f(n):
+            while n > 0:
+                myjitdriver.can_enter_jit(n=n)
+                myjitdriver.jit_merge_point(n=n)
+                n -= 1
+            return n
+
+        outerr = py.io.StdCaptureFD()
+        self.meta_interp(f, [10], debug_level=DEBUG_OFF,
+                                  ProfilerClass=Profiler)
+        out, errf = outerr.done()
+        err = errf.read()
+        assert not 'ENTER' in err
+        assert not 'LEAVE' in err
+        assert not "Running asm" in err
+        outerr = py.io.StdCaptureFD()
+        self.meta_interp(f, [10], debug_level=DEBUG_PROFILE,
+                                  ProfilerClass=Profiler)
+        out, errf = outerr.done()
+        err = errf.read()
+        assert not 'ENTER' in err
+        assert not 'LEAVE' in err
+        assert not 'compiled new' in err
+        assert "Running asm" in err
+        outerr = py.io.StdCaptureFD()
+        self.meta_interp(f, [10], debug_level=DEBUG_STEPS,
+                                  ProfilerClass=Profiler)
+        out, errf = outerr.done()
+        err = errf.read()
+        assert 'ENTER' in err
+        assert 'LEAVE' in err
+        assert "Running asm" in err
+        outerr = py.io.StdCaptureFD()
+        self.meta_interp(f, [10], debug_level=DEBUG_STEPS,
+                                  ProfilerClass=EmptyProfiler)
+        out, errf = outerr.done()
+        err = errf.read()
+        assert 'ENTER' in err
+        assert 'LEAVE' in err
+        assert not "Running asm" in err
+
     def test_set_param_debug(self):
-        from pypy.jit.metainterp.jitprof import Profiler, EmptyProfiler
         from pypy.rlib.jit import DEBUG_PROFILE, DEBUG_OFF, DEBUG_STEPS
+        from pypy.jit.metainterp.jitprof import EmptyProfiler, Profiler
         
         myjitdriver = JitDriver(greens = [], reds = ['n'])
         def f(n):
@@ -165,18 +211,20 @@
             return n
 
         def main(n, debug):
-            myjitdriver.set_param_debug(debug)
+            myjitdriver.set_param("debug", debug)
             print f(n)
 
         outerr = py.io.StdCaptureFD()
-        self.meta_interp(f, [10], debug=DEBUG_OFF)
+        self.meta_interp(main, [10, DEBUG_OFF], debug_level=DEBUG_STEPS,
+                                                ProfilerClass=Profiler)
         out, errf = outerr.done()
         err = errf.read()
         assert not 'ENTER' in err
         assert not 'LEAVE' in err
-        assert "Running asm" not in err
+        assert not "Running asm" in err
         outerr = py.io.StdCaptureFD()
-        self.meta_interp(f, [10], debug=DEBUG_PROFILE)
+        self.meta_interp(main, [10, DEBUG_PROFILE], debug_level=DEBUG_STEPS,
+                                                    ProfilerClass=Profiler)
         out, errf = outerr.done()
         err = errf.read()
         assert not 'ENTER' in err
@@ -184,7 +232,8 @@
         assert not 'compiled new' in err
         assert "Running asm" in err
         outerr = py.io.StdCaptureFD()
-        self.meta_interp(f, [10], debug=DEBUG_STEPS)
+        self.meta_interp(main, [10, DEBUG_STEPS], debug_level=DEBUG_OFF,
+                                                  ProfilerClass=Profiler)
         out, errf = outerr.done()
         err = errf.read()
         assert 'ENTER' in err

Modified: pypy/trunk/pypy/jit/metainterp/test/test_zrpy_basic.py
==============================================================================
--- pypy/trunk/pypy/jit/metainterp/test/test_zrpy_basic.py	(original)
+++ pypy/trunk/pypy/jit/metainterp/test/test_zrpy_basic.py	Fri Oct  2 13:24:13 2009
@@ -50,7 +50,7 @@
         res = rpython_ll_meta_interp(f, [17], loops=2, CPUClass=self.CPUClass,
                                      type_system=self.type_system,
                                      optimizer=OPTIMIZER_FULL,
-                                     profile=Profiler)
+                                     ProfilerClass=Profiler)
         assert res == (17+14+11+8+7+6+5+4) * 10
 
 

Modified: pypy/trunk/pypy/jit/metainterp/warmspot.py
==============================================================================
--- pypy/trunk/pypy/jit/metainterp/warmspot.py	(original)
+++ pypy/trunk/pypy/jit/metainterp/warmspot.py	Fri Oct  2 13:24:13 2009
@@ -33,10 +33,15 @@
     if 'CPUClass' not in kwds:
         from pypy.jit.backend.detect_cpu import getcpuclass
         kwds['CPUClass'] = getcpuclass(backend_name)
+    if debug_level > DEBUG_OFF:
+        ProfilerClass = Profiler
+    else:
+        ProfilerClass = EmptyProfiler
     warmrunnerdesc = WarmRunnerDesc(translator,
                                     translate_support_code=True,
                                     listops=True,
                                     no_stats = True,
+                                    ProfilerClass = ProfilerClass,
                                     **kwds)
     warmrunnerdesc.state.set_param_inlining(inline)
     warmrunnerdesc.state.set_param_debug(debug_level)
@@ -56,8 +61,9 @@
     clear_tcache()
     return jittify_and_run(interp, graph, args, backendopt=backendopt, **kwds)
 
-def jittify_and_run(interp, graph, args, repeat=1, hash_bits=None, backendopt=False, trace_limit=sys.maxint, debug=DEBUG_STEPS, profile=None,
-                    inline=False, **kwds):
+def jittify_and_run(interp, graph, args, repeat=1, hash_bits=None,
+                    backendopt=False, trace_limit=sys.maxint,
+                    debug_level=DEBUG_STEPS, inline=False, **kwds):
     translator = interp.typer.annotator.translator
     translator.config.translation.gc = "boehm"
     warmrunnerdesc = WarmRunnerDesc(translator, backendopt=backendopt, **kwds)
@@ -65,18 +71,14 @@
     warmrunnerdesc.state.set_param_trace_eagerness(2)    # for tests
     warmrunnerdesc.state.set_param_trace_limit(trace_limit)
     warmrunnerdesc.state.set_param_inlining(inline)
-    warmrunnerdesc.state.set_param_debug(debug)
-    if not we_are_translated() and profile is not None:
-        # for tests
-        warmrunnerdesc.state.profiler = profile()
-        warmrunnerdesc.state.profiler.start()
+    warmrunnerdesc.state.set_param_debug(debug_level)
     warmrunnerdesc.state.create_tables_now()             # for tests
     if hash_bits:
         warmrunnerdesc.state.set_param_hash_bits(hash_bits)
     warmrunnerdesc.finish()
     res = interp.eval_graph(graph, args)
     if not kwds.get('translate_support_code', False):
-        warmrunnerdesc.metainterp_sd.state.profiler.finish()
+        warmrunnerdesc.metainterp_sd.profiler.finish()
     print '~~~ return value:', res
     while repeat > 1:
         print '~' * 79
@@ -229,8 +231,8 @@
                               really_remove_asserts=True)
 
     def build_meta_interp(self, CPUClass, translate_support_code=False,
-                          view="auto", profile=None, no_stats=False,
-                          **kwds):
+                          view="auto", no_stats=False,
+                          ProfilerClass=EmptyProfiler, **kwds):
         assert CPUClass is not None
         opt = history.Options(**kwds)
         if no_stats:
@@ -249,6 +251,7 @@
         self.metainterp_sd = MetaInterpStaticData(self.portal_graph,
                                                   self.translator.graphs, cpu,
                                                   self.stats, opt,
+                                                  ProfilerClass=ProfilerClass,
                                                   warmrunnerdesc=self,
                                                   leave_graph=self.leave_graph)
 
@@ -530,8 +533,8 @@
 
     def add_profiler_finish(self):
         def finish_profiler():
-            if self.state.profiler.initialized:
-                self.state.profiler.finish()
+            if self.metainterp_sd.profiler.initialized:
+                self.metainterp_sd.profiler.finish()
         
         if self.cpu.translate_support_code:
             call_final_function(self.translator, finish_profiler,
@@ -797,14 +800,8 @@
                 raise ValueError("unknown optimizer")
 
         def set_param_debug(self, value):
-            if value >= DEBUG_PROFILE:
-                self.profiler = Profiler()
-            else:
-                self.profiler = EmptyProfiler()
-            if not self.profiler.initialized:
-                self.profiler.start()
-                self.profiler.initialized = True
-            self.debug = value
+            self.debug_level = value
+            metainterp_sd.profiler.set_printing(value >= DEBUG_PROFILE)
 
         def create_tables_now(self):
             count = 1 << self.hashbits
@@ -859,9 +856,9 @@
                     loop_token = cell.entry_loop_token
             # ---------- execute assembler ----------
             while True:     # until interrupted by an exception
-                metainterp_sd.state.profiler.start_running()
+                metainterp_sd.profiler.start_running()
                 fail_descr = metainterp_sd.cpu.execute_token(loop_token)
-                metainterp_sd.state.profiler.end_running()
+                metainterp_sd.profiler.end_running()
                 loop_token = fail_descr.handle_fail(metainterp_sd)
 
         maybe_compile_and_run._dont_inline_ = True



More information about the Pypy-commit mailing list