[pypy-commit] pypy vmprof-review: in-progress

arigo noreply at buildbot.pypy.org
Sun Aug 2 16:27:06 CEST 2015


Author: Armin Rigo <arigo at tunes.org>
Branch: vmprof-review
Changeset: r78741:fcf2c4f1208a
Date: 2015-08-02 16:27 +0200
http://bitbucket.org/pypy/pypy/changeset/fcf2c4f1208a/

Log:	in-progress

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
@@ -1,6 +1,46 @@
+import py
+import sys
 from rpython.tool.udir import udir
 from rpython.rtyper.lltypesystem import lltype, llmemory, rffi
 from rpython.translator.tool.cbuild import ExternalCompilationInfo
+from rpython.rtyper.tool import rffi_platform as platform
+
+
+ROOT = py.path.local(__file__).join('..')
+SRC = ROOT.join('src')
+
+
+if sys.platform.startswith('linux'):
+    libs = ['dl']
+else:
+    libs = []
+
+eci_kwds = dict(
+    include_dirs = [SRC],
+    includes = ['rvmprof.h'],
+    libraries = libs,
+    separate_module_files = [SRC.join('rvmprof.c')],
+    )
+eci = ExternalCompilationInfo(**eci_kwds)
+
+platform.verify_eci(eci)
+
+
+vmprof_init = rffi.llexternal("rpython_vmprof_init", [], rffi.CCHARP,
+                              compilation_info=eci)
+## vmprof_enable = rffi.llexternal("vmprof_enable",
+##                                 [rffi.INT, rffi.LONG, rffi.INT,
+##                                  rffi.CCHARP, rffi.INT],
+##                                 rffi.INT, compilation_info=eci,
+##                                 save_err=rffi.RFFI_SAVE_ERRNO)
+## vmprof_disable = rffi.llexternal("vmprof_disable", [], rffi.INT,
+##                                  compilation_info=eci,
+##                                 save_err=rffi.RFFI_SAVE_ERRNO)
+
+## vmprof_register_virtual_function = rffi.llexternal(
+##     "vmprof_register_virtual_function",
+##     [rffi.CCHARP, rffi.VOIDP, rffi.VOIDP], lltype.Void,
+##     compilation_info=eci, _nowrapper=True)
 
 
 def vmprof_init(): pass
@@ -36,7 +76,11 @@
            4: '%r8',
            5: '%r9',
            }
-    reg = reg[len(token)]
+    try:
+        reg = reg[len(token)]
+    except KeyError:
+        raise NotImplementedError(
+            "not supported: %r takes more than 5 arguments" % (func,))
 
     target = udir.join('module_cache')
     target.ensure(dir=1)
@@ -69,6 +113,19 @@
         tramp_name,
         ', '.join([tok2cname(tok) for tok in token] + ['long']))
 
+    header += """\
+static int cmp_%s(void *addr) {
+    if (addr == %s) return 1;
+#ifdef VMPROF_ADDR_OF_TRAMPOLINE
+    return VMPROF_ADDR_OF_TRAMPOLINE(addr);
+#undef VMPROF_ADDR_OF_TRAMPOLINE
+#else
+    return 0;
+#endif
+#define VMPROF_ADDR_OF_TRAMPOLINE cmp_%s
+}
+""" % (tramp_name, tramp_name, tramp_name)
+
     eci = ExternalCompilationInfo(
         post_include_bits = [header],
         separate_module_files = [str(target)],
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
@@ -194,8 +194,6 @@
 
         @specialize.memo()
         def get_ll_trampoline(token):
-            assert len(token) <= 5, (
-                "not supported: %r takes more than 5 arguments" % (func,))
             if result_class is None:
                 restok = "i"
             else:
diff --git a/rpython/rlib/rvmprof/src/rvmprof.c b/rpython/rlib/rvmprof/src/rvmprof.c
new file mode 100644
--- /dev/null
+++ b/rpython/rlib/rvmprof/src/rvmprof.c
@@ -0,0 +1,11 @@
+
+
+#ifndef VMPROF_ADDR_OF_TRAMPOLINE
+#  error "RPython program using rvmprof, but not calling vmprof_execute_code()"
+#endif
+
+
+char *rpython_vmprof_init(void)
+{
+    xxxx;
+}
diff --git a/rpython/rlib/rvmprof/src/rvmprof.h b/rpython/rlib/rvmprof/src/rvmprof.h
new file mode 100644
--- /dev/null
+++ b/rpython/rlib/rvmprof/src/rvmprof.h
@@ -0,0 +1,2 @@
+
+char *rpython_vmprof_init(void);
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
@@ -50,3 +50,26 @@
     assert f() == 0
     fn = compile(f, [])
     assert fn() == 0
+
+
+def test_register_code():
+
+    class MyCode:
+        pass
+    get_vmprof().register_code_object_class(MyCode, lambda code: 'some code')
+
+    @vmprof_execute_code("xcode1", lambda code, num: code)
+    def main(code, num):
+        print num
+        return 42
+
+    def f():
+        code = MyCode()
+        get_vmprof().register_code(code, 'some code')
+        res = main(code, 5)
+        assert res == 42
+        return 0
+
+    assert f() == 0
+    fn = compile(f, [])
+    assert fn() == 0


More information about the pypy-commit mailing list