[pypy-commit] pypy vmprof-native: test_ztranslation translates now

plan_rich pypy.commits at gmail.com
Tue Feb 7 03:23:43 EST 2017


Author: Richard Plangger <planrichi at gmail.com>
Branch: vmprof-native
Changeset: r89990:ad7e7ef86e35
Date: 2017-02-07 09:23 +0100
http://bitbucket.org/pypy/pypy/changeset/ad7e7ef86e35/

Log:	test_ztranslation translates now

diff --git a/rpython/rlib/rvmprof/cintf.py b/rpython/rlib/rvmprof/cintf.py
--- a/rpython/rlib/rvmprof/cintf.py
+++ b/rpython/rlib/rvmprof/cintf.py
@@ -15,8 +15,8 @@
 ROOT = py.path.local(rpythonroot).join('rpython', 'rlib', 'rvmprof')
 SRC = ROOT.join('src')
 SHARED = SRC.join('shared')
-UDIS86 = ROOT.join('libudis86')
-BACKTRACE = ROOT.join('libbacktrace')
+UDIS86 = SHARED.join('libudis86')
+BACKTRACE = SHARED.join('libbacktrace')
 
 compile_extra = ['-DRPYTHON_LL2CTYPES','-DRPYTHON_VMPROF']
 if sys.platform.startswith('linux'):
@@ -31,7 +31,7 @@
        BACKTRACE.join('posix.c'),
        BACKTRACE.join('sort.c'),
     ]
-    _libs = ['dl']
+    _libs = ['dl', 'unwind']
     compile_extra += ['-DVMPROF_UNIX']
     compile_extra += ['-DVMPROF_LINUX']
 elif sys.platform == 'darwin':
diff --git a/rpython/rlib/rvmprof/rvmprof.py b/rpython/rlib/rvmprof/rvmprof.py
--- a/rpython/rlib/rvmprof/rvmprof.py
+++ b/rpython/rlib/rvmprof/rvmprof.py
@@ -122,7 +122,7 @@
         self._gather_all_code_objs = gather_all_code_objs
 
     @jit.dont_look_inside
-    def enable(self, fileno, interval):
+    def enable(self, fileno, interval, memory=0):
         """Enable vmprof.  Writes go to the given 'fileno'.
         The sampling interval is given by 'interval' as a number of
         seconds, as a float which must be smaller than 1.0.
@@ -132,12 +132,15 @@
         if self.is_enabled:
             raise VMProfError("vmprof is already enabled")
 
-        p_error = self.cintf.vmprof_init(fileno, interval, "pypy")
+        lines = 0
+        native = 0
+
+        p_error = self.cintf.vmprof_init(fileno, interval, lines, memory, "pypy", native)
         if p_error:
             raise VMProfError(rffi.charp2str(p_error))
 
         self._gather_all_code_objs()
-        res = self.cintf.vmprof_enable()
+        res = self.cintf.vmprof_enable(memory)
         if res < 0:
             raise VMProfError(os.strerror(rposix.get_saved_errno()))
         self.is_enabled = True
diff --git a/rpython/rlib/rvmprof/src/rvmprof.c b/rpython/rlib/rvmprof/src/rvmprof.c
--- a/rpython/rlib/rvmprof/src/rvmprof.c
+++ b/rpython/rlib/rvmprof/src/rvmprof.c
@@ -17,3 +17,33 @@
 #else
 #include "shared/vmprof_main_win32.h"
 #endif
+
+#ifdef VMPROF_UNIX
+#ifdef __clang__
+__attribute__((disable_tail_calls))
+#elif defined(__GNUC__)
+__attribute__((optimize("O1")))
+#endif
+PY_EVAL_RETURN_T * vmprof_eval(PY_STACK_FRAME_T *f, int throwflag)
+{
+#ifdef X86_64
+    register PY_STACK_FRAME_T * callee_saved asm("rbx");
+#elif defined(X86_32)
+    register PY_STACK_FRAME_T * callee_saved asm("edi");
+#else
+#    error "platform not supported"
+#endif
+
+    asm volatile(
+#ifdef X86_64
+        "movq %1, %0\t\n"
+#elif defined(X86_32)
+        "mov %1, %0\t\n"
+#else
+#    error "platform not supported"
+#endif
+        : "=r" (callee_saved)
+        : "r" (f) );
+    return NULL; // TODO _default_eval_loop(f, throwflag);
+}
+#endif
diff --git a/rpython/rlib/rvmprof/src/shared/_vmprof.h b/rpython/rlib/rvmprof/src/shared/_vmprof.h
--- a/rpython/rlib/rvmprof/src/shared/_vmprof.h
+++ b/rpython/rlib/rvmprof/src/shared/_vmprof.h
@@ -42,6 +42,4 @@
 
 #define CPYTHON_HAS_FRAME_EVALUATION PY_VERSION_HEX >= 0x30600B0
 
-PyObject* vmprof_eval(PyFrameObject *f, int throwflag);
-
 int vmp_write_all(const char *buf, size_t bufsize);
diff --git a/rpython/rlib/rvmprof/src/shared/stack.c b/rpython/rlib/rvmprof/src/shared/stack.c
--- a/rpython/rlib/rvmprof/src/shared/stack.c
+++ b/rpython/rlib/rvmprof/src/shared/stack.c
@@ -6,8 +6,10 @@
 
 #include <string.h>
 #include <stdio.h>
+#include <stdlib.h>
 #include <sys/types.h>
 #include <stddef.h>
+#include <assert.h>
 
 #include "vmprof.h"
 #include "compat.h"
@@ -59,7 +61,6 @@
     int j;
     long line;
     char *lnotab;
-    intptr_t addr;
 
 #ifndef RPYTHON_VMPROF // pypy does not support line profiling
     if (vmp_profiles_python_lines()) {
@@ -99,26 +100,20 @@
 #else
     //result[*depth] = (void*)CODE_ADDR_TO_UID(FRAME_CODE(frame));
     //*depth = *depth + 1;
+
+    if (frame->kind == VMPROF_CODE_TAG) {
+        int n = *depth;
+        result[n++] = (void*)frame->kind;
+        result[n++] = (void*)frame->value;
+        *depth = n;
+    }
 #ifdef PYPY_JIT_CODEMAP
-    if (pypy_find_codemap_at_addr((intptr_t)pc, &addr)) {
-        // the bottom part is jitted, means we can fill up the first part
-        // from the JIT
-        *depth = vmprof_write_header_for_jit_addr(result, *depth, pc, max_depth);
-        stack = stack->next; // skip the first item as it contains garbage
+    else if (frame->kind == VMPROF_JITTED_TAG) {
+        intptr_t pc = ((intptr_t*)(frame->value - sizeof(intptr_t)))[0];
+        n = vmprof_write_header_for_jit_addr(result, n, pc, max_depth);
     }
 #endif
-    while (n < max_depth - 1 && stack) {
-        if (stack->kind == VMPROF_CODE_TAG) {
-            result[n] = stack->kind;
-            result[n + 1] = stack->value;
-            n += 2;
-        }
-#ifdef PYPY_JIT_CODEMAP
-        else if (stack->kind == VMPROF_JITTED_TAG) {
-            pc = ((intptr_t*)(stack->value - sizeof(intptr_t)))[0];
-            n = vmprof_write_header_for_jit_addr(result, n, pc, max_depth);
-        }
-#endif
+
 #endif
 
     return FRAME_STEP(frame);
@@ -128,7 +123,7 @@
                                      int max_depth, int depth, intptr_t pc)
 {
     while (depth < max_depth && frame) {
-        frame = _write_python_stack_entry(frame, result, &depth, pc);
+        frame = _write_python_stack_entry(frame, result, &depth);
     }
     return depth;
 }
@@ -147,6 +142,17 @@
 
 int vmp_walk_and_record_stack(PY_STACK_FRAME_T *frame, void ** result,
                               int max_depth, int native_skip, intptr_t pc) {
+
+//#ifdef PYPY_JIT_CODEMAP
+//    intptr_t codemap_addr;
+//    if (pypy_find_codemap_at_addr((intptr_t)pc, &codemap_addr)) {
+//        // the bottom part is jitted, means we can fill up the first part
+//        // from the JIT
+//        depth = vmprof_write_header_for_jit_addr(result, depth, pc, max_depth);
+//        frame = FRAME_STEP(frame); // skip the first item as it contains garbage
+//    }
+//#endif
+
     // called in signal handler
 #ifdef VMP_SUPPORTS_NATIVE_PROFILING
     intptr_t func_addr;
@@ -173,8 +179,8 @@
         native_skip--;
     }
 
+    int depth = 0;
     PY_STACK_FRAME_T * top_most_frame = frame;
-    int depth = 0;
     while (depth < max_depth) {
         unw_get_proc_info(&cursor, &pip);
 
@@ -205,7 +211,7 @@
                 if (top_most_frame == NULL) {
                     break;
                 }
-                top_most_frame = _write_python_stack_entry(top_most_frame, result, &depth, pc);
+                top_most_frame = _write_python_stack_entry(top_most_frame, result, &depth);
             }
         } else if (vmp_ignore_ip((intptr_t)func_addr)) {
             // this is an instruction pointer that should be ignored,
diff --git a/rpython/rlib/rvmprof/src/shared/vmprof.h b/rpython/rlib/rvmprof/src/shared/vmprof.h
--- a/rpython/rlib/rvmprof/src/shared/vmprof.h
+++ b/rpython/rlib/rvmprof/src/shared/vmprof.h
@@ -40,6 +40,8 @@
 #define PY_EVAL_RETURN_T void
 #define PY_THREAD_STATE_T void
 #define FRAME_STEP(f) f->next
+#define FRAME_CODE(f) f->
+PY_EVAL_RETURN_T * vmprof_eval(PY_STACK_FRAME_T *f, int throwflag);
 #else
 // for cpython
 #include "_vmprof.h"
@@ -49,4 +51,8 @@
 #define PY_EVAL_RETURN_T PyObject
 #define PY_THREAD_STATE_T PyThreadState
 #define FRAME_STEP(f) f->f_back
+#define FRAME_CODE(f) f->f_code
+PY_EVAL_RETURN_T * vmprof_eval(PY_STACK_FRAME_T *f, int throwflag);
 #endif
+
+


More information about the pypy-commit mailing list