[pypy-commit] pypy vmprof-multiple-eval-funcs: pass the function name and resolve the symbol by dlsym
plan_rich
pypy.commits at gmail.com
Tue Apr 4 18:03:50 EDT 2017
Author: Richard Plangger <planrichi at gmail.com>
Branch: vmprof-multiple-eval-funcs
Changeset: r90957:a7e4613fa118
Date: 2017-04-04 17:50 -0400
http://bitbucket.org/pypy/pypy/changeset/a7e4613fa118/
Log: pass the function name and resolve the symbol by dlsym
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
@@ -13,7 +13,7 @@
PLAT_WINDOWS = sys.platform == 'win32'
-EVAL_FUNCS = []
+EVAL_FUNC_NAMES = []
EVAL_FUNC_TYPE = lltype.FuncType([rffi.VOIDP], rffi.INT)
EVAL_FUNC_TYPE_P = lltype.Ptr(EVAL_FUNC_TYPE)
@@ -148,9 +148,9 @@
self.cintf.vmprof_register_eval(rffi.NULL)
from rpython.rtyper.annlowlevel import llhelper
# pass all known function at translation down to the c implementation
- for eval_func in unrolling_iterable(EVAL_FUNCS):
- addr = llhelper(EVAL_FUNC_TYPE_P, eval_func)
- self.cintf.vmprof_register_eval(rffi.cast(rffi.VOIDP, addr))
+ for c_func_name in unrolling_iterable(EVAL_FUNC_NAMES):
+ with rffi.scoped_str2charp(c_func_name) as cstr:
+ self.cintf.vmprof_register_eval(cstr)
p_error = self.cintf.vmprof_init(fileno, interval, lines, memory, "pypy", native)
if p_error:
@@ -238,8 +238,9 @@
else:
return decorated_jitted_function(unique_id, *args)
- decorated_function.__name__ = func.__name__ + '_rvmprof'
- EVAL_FUNCS.append(decorated_function)
+ fname = func.__name__ + '_rvmprof'
+ decorated_function.__name__ = fname
+ EVAL_FUNC_NAMES.append(fname)
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
@@ -1,5 +1,9 @@
#define _GNU_SOURCE 1
+#ifdef VMPROF_UNIX
+#include <dlfcn.h>
+#endif
+
#ifdef RPYTHON_LL2CTYPES
/* only for testing: ll2ctypes sets RPY_EXTERN from the command-line */
@@ -23,19 +27,27 @@
int _vmprof_eval_count = 0;
void * _vmprof_eval_funcs[5];
-int vmprof_register_eval(void * function)
+int vmprof_register_eval(const char * name)
{
+#ifdef VMPROF_UNIX
+ void * func = NULL;
+
if (_vmprof_eval_count >= 5) {
fprintf(stderr, "WARNING: cannot register more than 5 rpython interpreter " \
"evaluation functions (you can increase the amount in rvmprof.c)\n");
return -1;
}
- if (function == NULL) {
+ if (name == NULL) {
_vmprof_eval_count = 0;
} else {
- _vmprof_eval_funcs[_vmprof_eval_count++] = function;
+ func = dlsym(RTLD_DEFAULT, name);
+ if (func == NULL) {
+ fprintf(stderr, "WARNING: could not lookup addr of '%s', dlsym returned NULL\n", name);
+ return -1;
+ }
+ _vmprof_eval_funcs[_vmprof_eval_count++] = func;
}
-
+#endif
return 0;
}
diff --git a/rpython/rlib/rvmprof/src/rvmprof.h b/rpython/rlib/rvmprof/src/rvmprof.h
--- a/rpython/rlib/rvmprof/src/rvmprof.h
+++ b/rpython/rlib/rvmprof/src/rvmprof.h
@@ -36,14 +36,15 @@
RPY_EXTERN void vmprof_stack_free(void*);
RPY_EXTERN intptr_t vmprof_get_traceback(void *, void *, intptr_t*, intptr_t);
/**
- * Registers the first argument as a evaluation function. If NULL is provided,
- * it resets the registers eval functions.
+ * Registers the first argument as an evaluation function. The zero terminated
+ * name is provided as argument. If NULL is provided,
+ * it resets the eval functions.
*
* Note that a maximum of 5 evaluation functions is supported.
*
* Return 0 on success, any other value on failure.
*/
-RPY_EXTERN int vmprof_register_eval(void *);
+RPY_EXTERN int vmprof_register_eval(const char *);
long vmprof_write_header_for_jit_addr(intptr_t *result, long n,
intptr_t addr, int max_depth);
More information about the pypy-commit
mailing list