[pypy-commit] pypy default: * Be more careful and let stop_sampling()/start_sampling() be called in code
arigo
pypy.commits at gmail.com
Wed Nov 22 17:44:28 EST 2017
Author: Armin Rigo <arigo at tunes.org>
Branch:
Changeset: r93124:1cc101a9ee5a
Date: 2017-11-22 23:43 +0100
http://bitbucket.org/pypy/pypy/changeset/1cc101a9ee5a/
Log: * Be more careful and let stop_sampling()/start_sampling() be called
in code that is not compiled with rvmprof. This is needed from
rstacklet; previously, it would fail translation on any non-rvmprof-
supported platform as soon as rstacklet is used.
* We already call a function from vmprof in rstacklet.py. No point
in calling another one, when we can make the function have both
effects.
diff --git a/rpython/rlib/rstacklet.py b/rpython/rlib/rstacklet.py
--- a/rpython/rlib/rstacklet.py
+++ b/rpython/rlib/rstacklet.py
@@ -3,7 +3,6 @@
from rpython.rlib import jit
from rpython.rlib.objectmodel import fetch_translated_config
from rpython.rtyper.lltypesystem import lltype, llmemory
-from rpython.rlib import rvmprof
from rpython.rlib.rvmprof import cintf
DEBUG = False
@@ -26,14 +25,12 @@
def new(self, callback, arg=llmemory.NULL):
if DEBUG:
callback = _debug_wrapper(callback)
- rvmprof.stop_sampling()
x = cintf.save_rvmprof_stack()
try:
cintf.empty_rvmprof_stack()
h = self._gcrootfinder.new(self, callback, arg)
finally:
cintf.restore_rvmprof_stack(x)
- rvmprof.start_sampling()
if DEBUG:
debug.add(h)
return h
@@ -43,13 +40,11 @@
def switch(self, stacklet):
if DEBUG:
debug.remove(stacklet)
- rvmprof.stop_sampling()
x = cintf.save_rvmprof_stack()
try:
h = self._gcrootfinder.switch(stacklet)
finally:
cintf.restore_rvmprof_stack(x)
- rvmprof.start_sampling()
if DEBUG:
debug.add(h)
return h
diff --git a/rpython/rlib/rvmprof/__init__.py b/rpython/rlib/rvmprof/__init__.py
--- a/rpython/rlib/rvmprof/__init__.py
+++ b/rpython/rlib/rvmprof/__init__.py
@@ -56,8 +56,10 @@
return None
def stop_sampling():
- fd = _get_vmprof().cintf.vmprof_stop_sampling()
+ from rpython.rlib.rvmprof.cintf import vmprof_stop_sampling
+ fd = vmprof_stop_sampling()
return rffi.cast(lltype.Signed, fd)
def start_sampling():
- _get_vmprof().cintf.vmprof_start_sampling()
+ from rpython.rlib.rvmprof.cintf import vmprof_start_sampling
+ vmprof_start_sampling()
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
@@ -40,7 +40,7 @@
compile_extra += ['-DVMPROF_UNIX']
compile_extra += ['-DVMPROF_LINUX']
elif sys.platform == 'win32':
- compile_extra = ['-DRPYTHON_VMPROF', '-DVMPROF_WINDOWS']
+ compile_extra += ['-DVMPROF_WINDOWS']
separate_module_files = [SHARED.join('vmprof_win.c')]
_libs = []
else:
@@ -120,16 +120,26 @@
vmprof_get_profile_path = rffi.llexternal("vmprof_get_profile_path", [rffi.CCHARP, lltype.Signed],
lltype.Signed, compilation_info=eci,
_nowrapper=True)
- vmprof_stop_sampling = rffi.llexternal("vmprof_stop_sampling", [],
- rffi.INT, compilation_info=eci,
- _nowrapper=True)
- vmprof_start_sampling = rffi.llexternal("vmprof_start_sampling", [],
- lltype.Void, compilation_info=eci,
- _nowrapper=True)
return CInterface(locals())
+# this is always present, but compiles to no-op if RPYTHON_VMPROF is not
+# defined (i.e. if we don't actually use vmprof in the generated C)
+auto_eci = ExternalCompilationInfo(post_include_bits=["""
+#ifndef RPYTHON_VMPROF
+# define vmprof_stop_sampling() (-1)
+# define vmprof_start_sampling() ((void)0)
+#endif
+"""])
+
+vmprof_stop_sampling = rffi.llexternal("vmprof_stop_sampling", [],
+ rffi.INT, compilation_info=auto_eci,
+ _nowrapper=True)
+vmprof_start_sampling = rffi.llexternal("vmprof_start_sampling", [],
+ lltype.Void, compilation_info=auto_eci,
+ _nowrapper=True)
+
class CInterface(object):
def __init__(self, namespace):
@@ -218,6 +228,7 @@
# stacklet support
def save_rvmprof_stack():
+ vmprof_stop_sampling()
return vmprof_tl_stack.get_or_make_raw()
def empty_rvmprof_stack():
@@ -225,6 +236,7 @@
def restore_rvmprof_stack(x):
vmprof_tl_stack.setraw(x)
+ vmprof_start_sampling()
#
# traceback support
More information about the pypy-commit
mailing list