Author: Remi Meier <remi.me...@inf.ethz.ch>
Branch: stmgc-c8-gcc
Changeset: r78752:e61b8f6ff5db
Date: 2015-08-03 15:41 +0200
http://bitbucket.org/pypy/pypy/changeset/e61b8f6ff5db/

Log:    produce the perf-PID.map directly from pypy

        Produce the jitted code to trace name mapping for perf directly in
        PyPy. Should probably become a profagent in the future.

diff --git a/rpython/jit/backend/llsupport/assembler.py 
b/rpython/jit/backend/llsupport/assembler.py
--- a/rpython/jit/backend/llsupport/assembler.py
+++ b/rpython/jit/backend/llsupport/assembler.py
@@ -12,7 +12,7 @@
 from rpython.rlib.objectmodel import specialize, compute_unique_id
 from rpython.rtyper.annlowlevel import cast_instance_to_gcref, llhelper
 from rpython.rtyper.lltypesystem import rffi, lltype
-
+from rpython.jit.backend.x86 import perf_map
 
 DEBUG_COUNTER = lltype.Struct('DEBUG_COUNTER',
     # 'b'ridge, 'l'abel or # 'e'ntry point
@@ -407,8 +407,11 @@
         gcrootmap = self.cpu.gc_ll_descr.gcrootmap
         return bool(gcrootmap) and not gcrootmap.is_shadow_stack
 
+def debug_bridge(descr_number, rawstart, codeendpos):
+    perf_map.write_perf_map_entry(
+        "bridge out of Guard 0x%x" % r_uint(descr_number),
+        r_uint(rawstart), r_uint(rawstart + codeendpos))
 
-def debug_bridge(descr_number, rawstart, codeendpos):
     debug_start("jit-backend-addr")
     debug_print("bridge out of Guard 0x%x has address 0x%x to 0x%x" %
                 (r_uint(descr_number), r_uint(rawstart),
diff --git a/rpython/jit/backend/x86/assembler.py 
b/rpython/jit/backend/x86/assembler.py
--- a/rpython/jit/backend/x86/assembler.py
+++ b/rpython/jit/backend/x86/assembler.py
@@ -38,6 +38,7 @@
 from rpython.rlib.rarithmetic import intmask, r_uint
 from rpython.rlib.objectmodel import compute_unique_id
 from rpython.rlib import rstm, nonconst
+from rpython.jit.backend.x86 import perf_map
 
 
 class Assembler386(BaseAssembler):
@@ -629,9 +630,13 @@
         self.patch_stack_checks(frame_depth_no_fixed_size + 
JITFRAME_FIXED_SIZE,
                                 rawstart)
         looptoken._ll_loop_code = looppos + rawstart
+        #
+        name = "Loop %d (%s)" % (looptoken.number, loopname)
+        perf_map.write_perf_map_entry(
+            name, r_uint(rawstart), r_uint(rawstart + full_size))
         debug_start("jit-backend-addr")
-        debug_print("Loop %d (%s) has address 0x%x to 0x%x (bootstrap 0x%x)" % 
(
-            looptoken.number, loopname,
+        debug_print("%s has address 0x%x to 0x%x (bootstrap 0x%x)" % (
+            name,
             r_uint(rawstart + looppos),
             r_uint(rawstart + size_excluding_failure_stuff),
             r_uint(rawstart)))
diff --git a/rpython/jit/backend/x86/perf_map.py 
b/rpython/jit/backend/x86/perf_map.py
new file mode 100644
--- /dev/null
+++ b/rpython/jit/backend/x86/perf_map.py
@@ -0,0 +1,40 @@
+"""
+Support for generating a perf map in /tmp/perf-PID.map
+"""
+
+from rpython.rtyper.lltypesystem import lltype, llmemory, rffi
+from rpython.translator.tool.cbuild import ExternalCompilationInfo
+
+eci = ExternalCompilationInfo(separate_module_sources = [r"""
+#include <unistd.h>
+
+FILE *pypy_perf_map_file = NULL;
+
+RPY_EXPORTED void perf_map_write_entry(
+          const char *name,
+          size_t start_addr,
+          size_t end_addr) {
+
+    if (!pypy_perf_map_file) {
+        char pmap_filename[100];
+        snprintf(pmap_filename, 100, "/tmp/perf-%d.map", getpid());
+        pypy_perf_map_file = fopen(pmap_filename, "w");
+    }
+
+    fprintf(pypy_perf_map_file, "%lx %lx %s\n", start_addr,
+            end_addr - start_addr, name);
+}
+"""])
+
+_perf_map_write_entry = rffi.llexternal(
+    'perf_map_write_entry',
+    [rffi.CCHARP , lltype.Unsigned, lltype.Unsigned], lltype.Void,
+    compilation_info=eci,
+    _nowrapper=True, transactionsafe=True)
+
+# ____________________________________________________________
+
+def write_perf_map_entry(name, start_addr, end_addr):
+    # XXX: should be a profagent
+    with rffi.scoped_str2charp("JIT: " + name) as loopname:
+        _perf_map_write_entry(loopname, start_addr, end_addr)
diff --git a/rpython/translator/stm/test/targetjit1.py 
b/rpython/translator/stm/test/targetjit1.py
--- a/rpython/translator/stm/test/targetjit1.py
+++ b/rpython/translator/stm/test/targetjit1.py
@@ -125,9 +125,8 @@
 def start_thread(args):
     bootstrapper.acquire(args)
     try:
-        rthread.gc_thread_prepare()     # (this has no effect any more)
         ident = rthread.start_new_thread(bootstrapper.bootstrap, ())
-    except Exception, e:
+    except Exception:
         bootstrapper.release()     # normally called by the new thread
         raise
     return ident
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to