Author: Antonio Cuni <anto.c...@gmail.com> Branch: fix-vmprof-stacklet-switch-2 Changeset: r93191:2f204b1c432c Date: 2017-11-28 15:38 +0100 http://bitbucket.org/pypy/pypy/changeset/2f204b1c432c/
Log: move {start,stop}_sampling inside the VMProf API, and start to write a fake class to test the correct usage of them 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,10 +56,7 @@ return None def stop_sampling(): - from rpython.rlib.rvmprof.cintf import vmprof_stop_sampling - fd = vmprof_stop_sampling() - return rffi.cast(lltype.Signed, fd) + return _get_vmprof().stop_sampling() def start_sampling(): - from rpython.rlib.rvmprof.cintf import vmprof_start_sampling - vmprof_start_sampling() + return _get_vmprof().start_sampling() 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 @@ -168,6 +168,21 @@ if self.cintf.vmprof_register_virtual_function(name, uid, 500000) < 0: raise VMProfError("vmprof buffers full! disk full or too slow") + def stop_sampling(self): + """ + Temporarily stop the sampling of stack frames. Signals are still + delivered, but are ignored. + """ + fd = self.cintf.vmprof_stop_sampling() + return rffi.cast(lltype.Signed, fd) + + def start_sampling(self): + """ + Undo the effect of stop_sampling + """ + self.cintf.vmprof_start_sampling() + + def vmprof_execute_code(name, get_code_fn, result_class=None, _hack_update_stack_untranslated=False): """Decorator to be used on the function that interprets a code object. diff --git a/rpython/rlib/rvmprof/test/support.py b/rpython/rlib/rvmprof/test/support.py new file mode 100644 --- /dev/null +++ b/rpython/rlib/rvmprof/test/support.py @@ -0,0 +1,26 @@ + +class FakeVMProf(object): + + def __init__(self): + self._enabled = False + self._ignore_signals = 1 + + # --- VMProf official API --- + # add fake methods as needed by the tests + + def stop_sampling(self): + self._ignore_signals += 1 + + def start_sampling(self): + assert self._ignore_signals > 0, ('calling start_sampling() without ' + 'the corresponding stop_sampling()?') + self._ignore_signals -= 1 + + # --- FakeVMProf specific API --- + # this API is not part of rvmprof, but available only inside tests using + # fakervmprof + + @property + def is_sampling_enabled(self): + return self._ignore_signals == 0 + diff --git a/rpython/rlib/rvmprof/test/test_support.py b/rpython/rlib/rvmprof/test/test_support.py new file mode 100644 --- /dev/null +++ b/rpython/rlib/rvmprof/test/test_support.py @@ -0,0 +1,23 @@ +import pytest +from rpython.rlib.rvmprof.test.support import FakeVMProf + +class TestFakeVMProf(object): + + def test_sampling(self): + fake = FakeVMProf() + assert not fake.is_sampling_enabled + # + fake.start_sampling() + assert fake.is_sampling_enabled + # + fake.stop_sampling() + fake.stop_sampling() + assert not fake.is_sampling_enabled + # + fake.start_sampling() + assert not fake.is_sampling_enabled + fake.start_sampling() + assert fake.is_sampling_enabled + # + pytest.raises(AssertionError, "fake.start_sampling()") + _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit