[pypy-commit] pypy fix-vmprof-stacklet-switch-2: Switch to a saner way to handle vmprof on unsupported platforms:

antocuni pypy.commits at gmail.com
Tue Dec 19 10:12:28 EST 2017


Author: Antonio Cuni <anto.cuni at gmail.com>
Branch: fix-vmprof-stacklet-switch-2
Changeset: r93490:afe32451952d
Date: 2017-12-19 16:11 +0100
http://bitbucket.org/pypy/pypy/changeset/afe32451952d/

Log:	Switch to a saner way to handle vmprof on unsupported platforms:

	 - currently, we always compiled rvmprof.c & co. and hoped that the
	compilation worked well enough, even if rvmprof was not supposed to
	be used anyway

	 - with this commit, we compile rvmprof.c & co. ONLY if they are
	actually supported; moreover, we introduce a DummyVMProf to be unsed
	on unsupported platforms: this way, other modules can simply use
	rvmprof API without caring whether vmprof is supported or not (in
	the latter case, most calls are just no- ops).

	Hopefully, this should fix compilation on ARM and s390x

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,6 +14,9 @@
 class VMProfPlatformUnsupported(Exception):
     pass
 
+# vmprof works only on x86 for now
+IS_SUPPORTED = host_platform.machine() in ('x86', 'x86_64')
+
 ROOT = py.path.local(rpythonroot).join('rpython', 'rlib', 'rvmprof')
 SRC = ROOT.join('src')
 SHARED = SRC.join('shared')
@@ -57,7 +60,6 @@
         else:
             _libs = []
 
-
     eci_kwds = dict(
         include_dirs = [SRC, SHARED, BACKTRACE],
         includes = ['rvmprof.h','vmprof_stack.h'],
@@ -91,6 +93,9 @@
     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()
 
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


More information about the pypy-commit mailing list