[pypy-commit] pypy default: (fijal, arigo) try to make vmprof C interface init a bit more lazy
fijal
noreply at buildbot.pypy.org
Wed Aug 12 19:34:15 CEST 2015
Author: Maciej Fijalkowski <fijall at gmail.com>
Branch:
Changeset: r78953:6bfa818c8cce
Date: 2015-08-12 19:34 +0200
http://bitbucket.org/pypy/pypy/changeset/6bfa818c8cce/
Log: (fijal, arigo) try to make vmprof C interface init a bit more lazy
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
@@ -6,54 +6,69 @@
from rpython.rtyper.tool import rffi_platform as platform
from rpython.jit.backend import detect_cpu
-if not detect_cpu.autodetect().startswith(detect_cpu.MODEL_X86_64):
- py.test.skip("rvmprof only supports x86-64 CPUs for now")
+class VMProfPlatformUnsupported(Exception):
+ pass
-ROOT = py.path.local(__file__).join('..')
-SRC = ROOT.join('src')
+def setup():
+ if not detect_cpu.autodetect().startswith(detect_cpu.MODEL_X86_64):
+ raise VMProfPlatformUnsupported("rvmprof only supports"
+ " x86-64 CPUs for now")
-if sys.platform.startswith('linux'):
- libs = ['dl']
-else:
- libs = []
+ ROOT = py.path.local(__file__).join('..')
+ SRC = ROOT.join('src')
-eci_kwds = dict(
- include_dirs = [SRC],
- includes = ['rvmprof.h'],
- libraries = libs,
- separate_module_files = [SRC.join('rvmprof.c')],
- post_include_bits=['#define RPYTHON_VMPROF\n'],
- )
-eci = ExternalCompilationInfo(**eci_kwds)
-platform.verify_eci(ExternalCompilationInfo(
- compile_extra=['-DRPYTHON_LL2CTYPES'],
- **eci_kwds))
+ 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')],
+ post_include_bits=['#define RPYTHON_VMPROF\n'],
+ )
+ eci = ExternalCompilationInfo(**eci_kwds)
-vmprof_init = rffi.llexternal("rpython_vmprof_init", [rffi.INT], rffi.CCHARP,
- compilation_info=eci)
-vmprof_enable = rffi.llexternal("rpython_vmprof_enable", [rffi.LONG], rffi.INT,
- compilation_info=eci,
- save_err=rffi.RFFI_SAVE_ERRNO)
-vmprof_disable = rffi.llexternal("rpython_vmprof_disable", [], rffi.INT,
- compilation_info=eci,
- save_err=rffi.RFFI_SAVE_ERRNO)
-vmprof_write_buf = rffi.llexternal("rpython_vmprof_write_buf",
- [rffi.CCHARP, rffi.LONG],
- lltype.Void, compilation_info=eci)
+ platform.verify_eci(ExternalCompilationInfo(
+ compile_extra=['-DRPYTHON_LL2CTYPES'],
+ **eci_kwds))
-## vmprof_register_virtual_function = rffi.llexternal(
-## "vmprof_register_virtual_function",
-## [rffi.CCHARP, rffi.VOIDP, rffi.VOIDP], lltype.Void,
-## compilation_info=eci, _nowrapper=True)
-vmprof_ignore_signals = rffi.llexternal("rpython_vmprof_ignore_signals",
- [rffi.INT], lltype.Void,
- compilation_info=eci)
+ vmprof_init = rffi.llexternal("rpython_vmprof_init", [rffi.INT], rffi.CCHARP,
+ compilation_info=eci)
+ vmprof_enable = rffi.llexternal("rpython_vmprof_enable", [rffi.LONG], rffi.INT,
+ compilation_info=eci,
+ save_err=rffi.RFFI_SAVE_ERRNO)
+ vmprof_disable = rffi.llexternal("rpython_vmprof_disable", [], rffi.INT,
+ compilation_info=eci,
+ save_err=rffi.RFFI_SAVE_ERRNO)
+ vmprof_write_buf = rffi.llexternal("rpython_vmprof_write_buf",
+ [rffi.CCHARP, rffi.LONG],
+ lltype.Void, compilation_info=eci)
+ ## vmprof_register_virtual_function = rffi.llexternal(
+ ## "vmprof_register_virtual_function",
+ ## [rffi.CCHARP, rffi.VOIDP, rffi.VOIDP], lltype.Void,
+ ## compilation_info=eci, _nowrapper=True)
+
+ vmprof_ignore_signals = rffi.llexternal("rpython_vmprof_ignore_signals",
+ [rffi.INT], lltype.Void,
+ compilation_info=eci)
+ return CInterface(locals())
+
+
+class CInterface(object):
+ def __init__(self, namespace):
+ for k, v in namespace.iteritems():
+ setattr(self, k, v)
+
+ def _freeze_(self):
+ return True
def token2lltype(tok):
if tok == 'i':
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
@@ -19,7 +19,6 @@
def __str__(self):
return self.msg
-
class VMProf(object):
def __init__(self):
@@ -31,6 +30,7 @@
self._code_unique_id = 0 # XXX this is wrong, it won't work on 32bit
else:
self._code_unique_id = 0x7000000000000000
+ self.cintf = cintf.setup()
def _cleanup_(self):
self.is_enabled = False
@@ -106,14 +106,14 @@
raise VMProfError("bad value for 'interval'")
interval_usec = int(interval * 1000000.0)
- p_error = cintf.vmprof_init(fileno)
+ p_error = self.cintf.vmprof_init(fileno)
if p_error:
raise VMProfError(rffi.charp2str(p_error))
self.fileno = fileno
self._write_header(interval_usec)
self._gather_all_code_objs()
- res = cintf.vmprof_enable(interval_usec)
+ res = self.cintf.vmprof_enable(interval_usec)
if res < 0:
raise VMProfError(os.strerror(rposix.get_saved_errno()))
self.is_enabled = True
@@ -128,7 +128,7 @@
if self._current_codes is not None:
self._flush_codes()
self.fileno = -1
- res = cintf.vmprof_disable()
+ res = self.cintf.vmprof_disable()
if res < 0:
raise VMProfError(os.strerror(rposix.get_saved_errno()))
@@ -149,7 +149,7 @@
def _flush_codes(self):
buf = self._current_codes.build()
self._current_codes = None
- cintf.vmprof_write_buf(buf, len(buf))
+ self.cintf.vmprof_write_buf(buf, len(buf))
# NOTE: keep in mind that vmprof_write_buf() can only write
# a maximum of 8184 bytes. This should be guaranteed here because:
assert MAX_CODES + 17 + MAX_FUNC_NAME <= 8184
@@ -165,7 +165,7 @@
b.append(chr(len('pypy')))
b.append('pypy')
buf = b.build()
- cintf.vmprof_write_buf(buf, len(buf))
+ self.cintf.vmprof_write_buf(buf, len(buf))
def _write_long_to_string_builder(l, b):
More information about the pypy-commit
mailing list