Exemple #1
0
def test_result(profiler):
    __, cpu_time, wall_time = profiler.result()
    assert cpu_time == wall_time == 0.0
    with profiler:
        spin(0.1)
    __, cpu_time, wall_time = profiler.result()
    assert cpu_time > 0.0
    assert wall_time >= 0.1
Exemple #2
0
def test_result(profiler):
    __, cpu_time, wall_time = profiler.result()
    assert cpu_time == wall_time == 0.0
    with profiler:
        spin(0.1)
    __, cpu_time, wall_time = profiler.result()
    assert cpu_time > 0.0
    assert wall_time >= 0.1
Exemple #3
0
def test_tracing_sampler_does_not_sample_too_often():
    # pytest-cov cannot detect a callback function registered by
    # :func:`sys.setprofile`.
    class fake_profiler(object):
        samples = []
        @classmethod
        def sample(cls, frame):
            cls.samples.append(frame)
        @classmethod
        def count_and_clear_samples(cls):
            count = len(cls.samples)
            del cls.samples[:]
            return count
    sampler = TracingSampler(0.1)
    sampler._profile(fake_profiler, None, None, None)
    assert fake_profiler.count_and_clear_samples() == 1
    sampler._profile(fake_profiler, None, None, None)
    assert fake_profiler.count_and_clear_samples() == 0
    spin(0.5)
    sampler._profile(fake_profiler, None, None, None)
    assert fake_profiler.count_and_clear_samples() == 1
Exemple #4
0
def test_tracing_sampler_does_not_sample_too_often():
    # pytest-cov cannot detect a callback function registered by
    # :func:`sys.setprofile`.
    class fake_profiler(object):
        samples = []

        @classmethod
        def sample(cls, frame):
            cls.samples.append(frame)

        @classmethod
        def count_and_clear_samples(cls):
            count = len(cls.samples)
            del cls.samples[:]
            return count

    sampler = TracingSampler(0.1)
    sampler._profile(fake_profiler, None, None, None)
    assert fake_profiler.count_and_clear_samples() == 1
    sampler._profile(fake_profiler, None, None, None)
    assert fake_profiler.count_and_clear_samples() == 0
    spin(0.5)
    sampler._profile(fake_profiler, None, None, None)
    assert fake_profiler.count_and_clear_samples() == 1
Exemple #5
0
def spin_500ms():
    spin(0.5)
Exemple #6
0
def spin_100ms():
    spin(0.1)
Exemple #7
0
def spin_500ms():
    spin(0.5)
Exemple #8
0
def spin_100ms():
    spin(0.1)