Author: Antonio Cuni <anto.c...@gmail.com>
Branch: 
Changeset: r93500:e742e3594267
Date: 2017-12-19 19:04 +0100
http://bitbucket.org/pypy/pypy/changeset/e742e3594267/

Log:    merge again fix-vmprof-stacklet-switch-2: this should fix
        translation on platforms where vmprof is not supported, and it also
        refactor rvmprof.cintf to be slightly saner

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
@@ -14,67 +14,75 @@
 class VMProfPlatformUnsupported(Exception):
     pass
 
+# vmprof works only on x86 for now
+IS_SUPPORTED = host_platform.machine() in ('i686', 'x86_64')
+
 ROOT = py.path.local(rpythonroot).join('rpython', 'rlib', 'rvmprof')
 SRC = ROOT.join('src')
 SHARED = SRC.join('shared')
 BACKTRACE = SHARED.join('libbacktrace')
 
-compile_extra = ['-DRPYTHON_VMPROF']
-separate_module_files = [
-    SHARED.join('symboltable.c'),
-    SHARED.join('vmprof_unix.c')
-]
-if sys.platform.startswith('linux'):
-    separate_module_files += [
-       BACKTRACE.join('atomic.c'),
-       BACKTRACE.join('backtrace.c'),
-       BACKTRACE.join('state.c'),
-       BACKTRACE.join('elf.c'),
-       BACKTRACE.join('dwarf.c'),
-       BACKTRACE.join('fileline.c'),
-       BACKTRACE.join('mmap.c'),
-       BACKTRACE.join('mmapio.c'),
-       BACKTRACE.join('posix.c'),
-       BACKTRACE.join('sort.c'),
+def make_eci():
+    if make_eci.called:
+        raise ValueError("make_eci() should be called at most once")
+    #
+    compile_extra = ['-DRPYTHON_VMPROF']
+    separate_module_files = [
+        SHARED.join('symboltable.c'),
+        SHARED.join('vmprof_unix.c')
     ]
-    _libs = ['dl']
-    compile_extra += ['-DVMPROF_UNIX']
-    compile_extra += ['-DVMPROF_LINUX']
-elif sys.platform == 'win32':
-    compile_extra += ['-DVMPROF_WINDOWS']
-    separate_module_files = [SHARED.join('vmprof_win.c')]
-    _libs = []
-else:
-    # Guessing a BSD-like Unix platform
-    compile_extra += ['-DVMPROF_UNIX']
-    compile_extra += ['-DVMPROF_MAC']
-    if sys.platform.startswith('freebsd'):
-        _libs = ['unwind']
+    if sys.platform.startswith('linux'):
+        separate_module_files += [
+           BACKTRACE.join('atomic.c'),
+           BACKTRACE.join('backtrace.c'),
+           BACKTRACE.join('state.c'),
+           BACKTRACE.join('elf.c'),
+           BACKTRACE.join('dwarf.c'),
+           BACKTRACE.join('fileline.c'),
+           BACKTRACE.join('mmap.c'),
+           BACKTRACE.join('mmapio.c'),
+           BACKTRACE.join('posix.c'),
+           BACKTRACE.join('sort.c'),
+        ]
+        _libs = ['dl']
+        compile_extra += ['-DVMPROF_UNIX']
+        compile_extra += ['-DVMPROF_LINUX']
+    elif sys.platform == 'win32':
+        compile_extra += ['-DVMPROF_WINDOWS']
+        separate_module_files = [SHARED.join('vmprof_win.c')]
+        _libs = []
     else:
-        _libs = []
+        # Guessing a BSD-like Unix platform
+        compile_extra += ['-DVMPROF_UNIX']
+        compile_extra += ['-DVMPROF_MAC']
+        if sys.platform.startswith('freebsd'):
+            _libs = ['unwind']
+        else:
+            _libs = []
 
-
-eci_kwds = dict(
-    include_dirs = [SRC, SHARED, BACKTRACE],
-    includes = ['rvmprof.h','vmprof_stack.h'],
-    libraries = _libs,
-    separate_module_files = [
-        SRC.join('rvmprof.c'),
-        SHARED.join('compat.c'),
-        SHARED.join('machine.c'),
-        SHARED.join('vmp_stack.c'),
-        SHARED.join('vmprof_memory.c'),
-        SHARED.join('vmprof_common.c'),
-        # symbol table already in separate_module_files
-    ] + separate_module_files,
-    post_include_bits=[],
-    compile_extra=compile_extra
-    )
-if sys.platform != 'win32':
-    eci_kwds['separate_module_files'].append(
-        SHARED.join('vmprof_mt.c'),
-    )
-global_eci = ExternalCompilationInfo(**eci_kwds)
+    eci_kwds = dict(
+        include_dirs = [SRC, SHARED, BACKTRACE],
+        includes = ['rvmprof.h','vmprof_stack.h'],
+        libraries = _libs,
+        separate_module_files = [
+            SRC.join('rvmprof.c'),
+            SHARED.join('compat.c'),
+            SHARED.join('machine.c'),
+            SHARED.join('vmp_stack.c'),
+            SHARED.join('vmprof_memory.c'),
+            SHARED.join('vmprof_common.c'),
+            # symbol table already in separate_module_files
+        ] + separate_module_files,
+        post_include_bits=[],
+        compile_extra=compile_extra
+        )
+    if sys.platform != 'win32':
+        eci_kwds['separate_module_files'].append(
+            SHARED.join('vmprof_mt.c'),
+        )
+    make_eci.called = True
+    return ExternalCompilationInfo(**eci_kwds), eci_kwds
+make_eci.called = False
 
 def configure_libbacktrace_linux():
     bits = 32 if sys.maxsize == 2**31-1 else 64
@@ -85,14 +93,17 @@
     shutil.copy(str(BACKTRACE.join(specific_config)), str(config))
 
 def setup():
+    if not IS_SUPPORTED:
+        raise VMProfPlatformUnsupported
+    
     if sys.platform.startswith('linux'):
         configure_libbacktrace_linux()
 
+    eci, eci_kwds = make_eci()
     eci_kwds['compile_extra'].append('-DRPYTHON_LL2CTYPES')
     platform.verify_eci(ExternalCompilationInfo(
                         **eci_kwds))
 
-    eci = global_eci
     vmprof_init = rffi.llexternal("vmprof_init",
                                   [rffi.INT, rffi.DOUBLE, rffi.INT, rffi.INT,
                                    rffi.CCHARP, rffi.INT, rffi.INT],
diff --git a/rpython/rlib/rvmprof/dummy.py b/rpython/rlib/rvmprof/dummy.py
new file mode 100644
--- /dev/null
+++ b/rpython/rlib/rvmprof/dummy.py
@@ -0,0 +1,26 @@
+from rpython.rlib.objectmodel import specialize
+
+class DummyVMProf(object):
+
+    def __init__(self):
+        self._unique_id = 0
+
+    def register_code_object_class(self, CodeClass, full_name_func):
+        CodeClass._vmprof_unique_id = self._unique_id
+        self._unique_id += 1
+
+    @specialize.argtype(1)
+    def register_code(self, code, full_name_func):
+        pass
+
+    def enable(self, fileno, interval, memory=0, native=0, real_time=0):
+        pass
+
+    def disable(self):
+        pass
+
+    def start_sampling(self):
+        pass
+
+    def stop_sampling(self):
+        pass
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
@@ -2,6 +2,7 @@
 from rpython.rlib.objectmodel import specialize, we_are_translated, not_rpython
 from rpython.rlib import jit, rposix, rgc
 from rpython.rlib.rvmprof import cintf
+from rpython.rlib.rvmprof.dummy import DummyVMProf
 from rpython.rtyper.annlowlevel import cast_instance_to_gcref
 from rpython.rtyper.annlowlevel import cast_base_ptr_to_instance
 from rpython.rtyper.lltypesystem import lltype, llmemory, rffi
@@ -34,6 +35,9 @@
         return []
 
 class VMProf(object):
+    """
+    NOTE: the API of this class should be kept in sync with dummy.DummyVMProf
+    """
 
     _immutable_fields_ = ['is_enabled?']
 
@@ -255,5 +259,8 @@
 def _get_vmprof():
     global _vmprof_instance
     if _vmprof_instance is None:
-        _vmprof_instance = VMProf()
+        try:
+            _vmprof_instance = VMProf()
+        except cintf.VMProfPlatformUnsupported:
+            _vmprof_instance = DummyVMProf()
     return _vmprof_instance
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to