From ddc0c6e4b745022cb90400ae7408b722f8de03ed Mon Sep 17 00:00:00 2001 From: Antonio Cuni Date: Wed, 29 Nov 2017 16:17:32 +0100 Subject: add a test which checks that vmprof is actually enabled inside greenlets; it fails on default and passes on this branch --- extra_tests/test_vmprof_greenlet.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 extra_tests/test_vmprof_greenlet.py (limited to 'extra_tests/test_vmprof_greenlet.py') diff --git a/extra_tests/test_vmprof_greenlet.py b/extra_tests/test_vmprof_greenlet.py new file mode 100644 index 0000000000..7c43715ed5 --- /dev/null +++ b/extra_tests/test_vmprof_greenlet.py @@ -0,0 +1,28 @@ +import time +import pytest +import greenlet +import vmprof + +def count_samples(filename): + stats = vmprof.read_profile(filename) + return len(stats.profiles) + +def cpuburn(duration): + end = time.time() + duration + while time.time() < end: + pass + +def test_sampling_inside_callback(tmpdir): + # see also test_sampling_inside_callback inside + # pypy/module/_continuation/test/test_stacklet.py + # + G = greenlet.greenlet(cpuburn) + fname = tmpdir.join('log.vmprof') + with fname.open('w+b') as f: + vmprof.enable(f.fileno(), 1/250.0) + G.switch(0.1) + vmprof.disable() + + samples = count_samples(str(fname)) + # 0.1 seconds at 250Hz should be 25 samples + assert 23 < samples < 27 -- cgit v1.2.3-65-gdbad