diff options
author | Antonio Cuni <anto.cuni@gmail.com> | 2017-11-29 16:17:32 +0100 |
---|---|---|
committer | Antonio Cuni <anto.cuni@gmail.com> | 2017-11-29 16:17:32 +0100 |
commit | ddc0c6e4b745022cb90400ae7408b722f8de03ed (patch) | |
tree | 03d43a66027316c730e52311e199480248447815 /extra_tests/test_vmprof_greenlet.py | |
parent | simplify (diff) | |
download | pypy-ddc0c6e4b745022cb90400ae7408b722f8de03ed.tar.gz pypy-ddc0c6e4b745022cb90400ae7408b722f8de03ed.tar.bz2 pypy-ddc0c6e4b745022cb90400ae7408b722f8de03ed.zip |
add a test which checks that vmprof is actually enabled inside greenlets; it fails on default and passes on this branch
Diffstat (limited to 'extra_tests/test_vmprof_greenlet.py')
-rw-r--r-- | extra_tests/test_vmprof_greenlet.py | 28 |
1 files changed, 28 insertions, 0 deletions
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 |