[pypy-svn] r71064 - in pypy/branch/oprofile-support/pypy/jit/backend/x86: . test

cfbolz at codespeak.net cfbolz at codespeak.net
Tue Feb 2 17:01:10 CET 2010


Author: cfbolz
Date: Tue Feb  2 17:01:10 2010
New Revision: 71064

Modified:
   pypy/branch/oprofile-support/pypy/jit/backend/x86/assembler.py
   pypy/branch/oprofile-support/pypy/jit/backend/x86/runner.py
   pypy/branch/oprofile-support/pypy/jit/backend/x86/test/test_assembler.py
Log:
Change the assembler to pass function name information on to the profiler. Right
now, the first debug_merge_point that is found is used as the name of the
function.


Modified: pypy/branch/oprofile-support/pypy/jit/backend/x86/assembler.py
==============================================================================
--- pypy/branch/oprofile-support/pypy/jit/backend/x86/assembler.py	(original)
+++ pypy/branch/oprofile-support/pypy/jit/backend/x86/assembler.py	Tue Feb  2 17:01:10 2010
@@ -156,7 +156,7 @@
             # done
             # we generate the loop body in 'mc'
             # 'mc2' is for guard recovery code
-            self.mc = MachineCodeBlockWrapper(self.mc_size)
+            self.mc = MachineCodeBlockWrapper(self.mc_size, self.cpu.profile_agent)
             self.mc2 = MachineCodeBlockWrapper(self.mc_size)
             self._build_failure_recovery(False)
             self._build_failure_recovery(True)
@@ -194,6 +194,8 @@
                _x86_param_depth
                _x86_arglocs
         """
+        funcname = self._find_debug_merge_point(operations)
+
         self.make_sure_mc_exists()
         regalloc = RegAlloc(self, self.cpu.translate_support_code)
         arglocs = regalloc.prepare_loop(inputargs, operations, looptoken)
@@ -201,6 +203,10 @@
         needed_mem = len(arglocs[0]) * 16 + 16
         if needed_mem >= self.mc.bytes_free():
             self.mc.make_new_mc()
+
+        # profile support
+        name = "Loop # %s: %s" % (looptoken.number, funcname)
+        self.mc.start_function(name)
         looptoken._x86_bootstrap_code = self.mc.tell()
         adr_stackadjust = self._assemble_bootstrap_code(inputargs, arglocs)
         curadr = self.mc.tell()
@@ -221,8 +227,12 @@
                                              frame_depth+param_depth)
         debug_print("Loop #", looptoken.number, "has address",
                     looptoken._x86_loop_code, "to", self.mc.tell())
+        self.mc.end_function()
+        
 
     def assemble_bridge(self, faildescr, inputargs, operations):
+        funcname = self._find_debug_merge_point(operations)
+
         self.make_sure_mc_exists()
         arglocs = self.rebuild_faillocs_from_descr(
             faildescr._x86_failure_recovery_bytecode)
@@ -233,6 +243,12 @@
         fail_depths = faildescr._x86_current_depths
         regalloc.prepare_bridge(fail_depths, inputargs, arglocs,
                                 operations)
+
+        # oprofile support
+        descr_number = self.cpu.get_fail_descr_number(faildescr)
+        name = "Bridge # %s: %s" % (descr_number, funcname)
+        self.mc.start_function(name)
+
         adr_bridge = self.mc.tell()
         adr_stackadjust = self._patchable_stackadjust()
         frame_depth, param_depth = self._assemble(regalloc, operations)
@@ -244,8 +260,16 @@
         # patch the jump from original guard
         self.patch_jump(faildescr, adr_bridge)
         debug_print("Bridge out of guard",
-                    self.cpu.get_fail_descr_number(faildescr),
+                    descr_number,
                     "has address", adr_bridge, "to", self.mc.tell())
+        self.mc.end_function()
+
+    def _find_debug_merge_point(self, operations):
+        for op in operations:
+            if op.opnum == rop.DEBUG_MERGE_POINT:
+                return op.args[0]._get_str()
+        return ""
+        
 
     def patch_jump(self, faildescr, adr_new_target):
         adr_jump_offset = faildescr._x86_adr_jump_offset

Modified: pypy/branch/oprofile-support/pypy/jit/backend/x86/runner.py
==============================================================================
--- pypy/branch/oprofile-support/pypy/jit/backend/x86/runner.py	(original)
+++ pypy/branch/oprofile-support/pypy/jit/backend/x86/runner.py	Tue Feb  2 17:01:10 2010
@@ -20,6 +20,13 @@
                  gcdescr=None):
         AbstractLLCPU.__init__(self, rtyper, stats, opts,
                                translate_support_code, gcdescr)
+        profile_agent = None
+        if rtyper is not None:
+            config = rtyper.annotator.translator.config
+            if config.translation.jit_profiler == "oprofile":
+                from pypy.jit.backend.x86 import oprofile
+                profile_agent = oprofile.OProfileAgent()
+        self._profile_agent = profile_agent
 
     def setup(self):
         if self.opts is not None:
@@ -33,7 +40,12 @@
         return self.assembler.leave_jitted_hook
 
     def setup_once(self):
-        pass
+        if self._profile_agent is not None:
+            self._profile_agent.setup()
+
+    def finish_once(self):
+        if self._profile_agent is not None:
+            self._profile_agent.shutdown()
 
     def compile_loop(self, inputargs, operations, looptoken):
         self.assembler.assemble_loop(inputargs, operations, looptoken)

Modified: pypy/branch/oprofile-support/pypy/jit/backend/x86/test/test_assembler.py
==============================================================================
--- pypy/branch/oprofile-support/pypy/jit/backend/x86/test/test_assembler.py	(original)
+++ pypy/branch/oprofile-support/pypy/jit/backend/x86/test/test_assembler.py	Tue Feb  2 17:01:10 2010
@@ -244,7 +244,7 @@
         # bits of the float were correctly saved and restored.
         assert assembler.fail_boxes_float.getitem(i) == expected_floats[i]
 
-class ProfileAgent(object):
+class FakeProfileAgent(object):
     def __init__(self):
         self.functions = []
 



More information about the Pypy-commit mailing list