Author: Richard Plangger <[email protected]>
Branch: vmprof-native
Changeset: r90003:389b5116a6a3
Date: 2017-02-07 18:57 +0100
http://bitbucket.org/pypy/pypy/changeset/389b5116a6a3/
Log: force function name __vmprof_eval_vmprof for the "trampoline", add
native test
diff --git a/rpython/rlib/rvmprof/__init__.py b/rpython/rlib/rvmprof/__init__.py
--- a/rpython/rlib/rvmprof/__init__.py
+++ b/rpython/rlib/rvmprof/__init__.py
@@ -32,8 +32,8 @@
return code._vmprof_unique_id
return 0
-def enable(fileno, interval):
- _get_vmprof().enable(fileno, interval)
+def enable(fileno, interval, memory=0, native=0):
+ _get_vmprof().enable(fileno, interval, memory, native)
def disable():
_get_vmprof().disable()
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
@@ -214,6 +214,7 @@
return decorated_jitted_function(unique_id, *args)
decorated_function.__name__ = func.__name__ + '_rvmprof'
+ decorated_function.c_name = '__vmprof_eval_vmprof'
return decorated_function
return decorate
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
@@ -16,36 +16,6 @@
#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
-
void dump_native_symbols(int fileno)
{
// TODO PyObject * mod = NULL;
diff --git a/rpython/rlib/rvmprof/src/shared/_vmprof.c
b/rpython/rlib/rvmprof/src/shared/_vmprof.c
--- a/rpython/rlib/rvmprof/src/shared/_vmprof.c
+++ b/rpython/rlib/rvmprof/src/shared/_vmprof.c
@@ -14,6 +14,7 @@
static volatile int is_enabled = 0;
static destructor Original_code_dealloc = 0;
static PyObject* (*_default_eval_loop)(PyFrameObject *, int) = 0;
+void dump_native_symbols(int fileno);
#if VMPROF_UNIX
#include "trampoline.h"
diff --git a/rpython/rlib/rvmprof/src/shared/vmp_stack.c
b/rpython/rlib/rvmprof/src/shared/vmp_stack.c
--- a/rpython/rlib/rvmprof/src/shared/vmp_stack.c
+++ b/rpython/rlib/rvmprof/src/shared/vmp_stack.c
@@ -195,7 +195,7 @@
//}
- if ((void*)pip.start_ip == (void*)vmprof_eval) {
+ if ((void*)pip.start_ip == (void*)VMPROF_EVAL()) {
// yes we found one stack entry of the python frames!
unw_word_t rbx = 0;
if (unw_get_reg(&cursor, REG_RBX, &rbx) < 0) {
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
@@ -41,7 +41,9 @@
#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);
+typedef long Signed;
+RPY_EXTERN Signed __vmprof_eval_vmprof();
+#define VMPROF_EVAL() __vmprof_eval_vmprof
#else
#define RPY_EXTERN
// for cpython
@@ -54,6 +56,7 @@
#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);
+#define VMPROF_EVAL() vmprof_eval
#endif
diff --git a/rpython/rlib/rvmprof/test/test_rvmprof.py
b/rpython/rlib/rvmprof/test/test_rvmprof.py
--- a/rpython/rlib/rvmprof/test/test_rvmprof.py
+++ b/rpython/rlib/rvmprof/test/test_rvmprof.py
@@ -147,3 +147,78 @@
finally:
assert os.path.exists(tmpfilename)
os.unlink(tmpfilename)
+
+from rpython.translator.tool.cbuild import ExternalCompilationInfo
+from rpython.rtyper.lltypesystem import rffi, lltype
+def test_native():
+ eci = ExternalCompilationInfo(compile_extra=['-g','-O2'],
+ separate_module_sources=["""
+ RPY_EXTERN int native_func(void) {
+ return 42;
+ }
+ """])
+
+ native_func = rffi.llexternal("native_func", [], rffi.INT,
+ compilation_info=eci)
+
+ class MyCode:
+ pass
+ def get_name(code):
+ return 'py:code:52:x'
+
+ try:
+ rvmprof.register_code_object_class(MyCode, get_name)
+ except rvmprof.VMProfPlatformUnsupported as e:
+ py.test.skip(str(e))
+
+ @rvmprof.vmprof_execute_code("xcode1", lambda code, num: code)
+ def main(code, num):
+ if num > 0:
+ return main(code, num-1)
+ else:
+ for i in range(100):
+ native_func()
+ return native_func()
+
+ tmpfilename = str(udir.join('test_rvmprof'))
+
+ def f():
+ if NonConstant(False):
+ # Hack to give os.open() the correct annotation
+ os.open('foo', 1, 1)
+ code = MyCode()
+ rvmprof.register_code(code, get_name)
+ fd = os.open(tmpfilename, os.O_WRONLY | os.O_CREAT, 0666)
+ if we_are_translated():
+ num = 100000000
+ period = 0.0001
+ else:
+ num = 10000
+ period = 0.9
+ rvmprof.enable(fd, period, native=1)
+ res = main(code, num)
+ #assert res == 499999500000
+ rvmprof.disable()
+ os.close(fd)
+ return 0
+
+ def check_profile(filename):
+ from vmprof import read_profile
+
+ prof = read_profile(filename)
+ assert prof.get_tree().name.startswith("py:")
+ assert prof.get_tree().count
+
+ #assert f() == 0
+ #assert os.path.exists(tmpfilename)
+ fn = compile(f, [], gcpolicy="minimark")
+ assert fn() == 0
+ try:
+ import vmprof
+ except ImportError:
+ py.test.skip("vmprof unimportable")
+ else:
+ check_profile(tmpfilename)
+ finally:
+ assert os.path.exists(tmpfilename)
+ os.unlink(tmpfilename)
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit