Exemple #1
0
 def profile(profiler):
     with profiler:
         c1 = spawn(light)
         c2 = spawn(heavy)
         for c in [c1, c2]:
             join(c)
     stat1 = find_stats(profiler.stats, 'light')
     stat2 = find_stats(profiler.stats, 'heavy')
     return (stat1, stat2)
Exemple #2
0
 def profile(profiler):
     with profiler:
         c1 = spawn(light)
         c2 = spawn(heavy)
         for c in [c1, c2]:
             join(c)
     stat1 = find_stats(profiler.stats, 'light')
     stat2 = find_stats(profiler.stats, 'heavy')
     return (stat1, stat2)
def _test_sampling_profiler(sampler):
    profiler = SamplingProfiler(top_frames=[sys._getframe()], sampler=sampler)
    with profiler:
        spin_100ms()
        spin_500ms()
    stat1 = find_stats(profiler.stats, 'spin_100ms')
    stat2 = find_stats(profiler.stats, 'spin_500ms')
    ratio = stat1.deep_hits / stat2.deep_hits
    # 1:5 expaected, but tolerate (0.8~1.2):5
    assert 0.8 <= ratio * 5 <= 1.2
def _test_sampling_profiler(sampler):
    profiler = SamplingProfiler(base_frame=sys._getframe(), sampler=sampler)
    with profiler:
        spin_100ms()
        spin_500ms()
    stat1 = find_stats(profiler.stats, 'spin_100ms')
    stat2 = find_stats(profiler.stats, 'spin_500ms')
    ratio = stat1.deep_hits / stat2.deep_hits
    # 1:5 expaected, but tolerate (0.8~1.2):5
    assert 0.8 <= ratio * 5 <= 1.2
Exemple #5
0
def test_profile():
    profiler = TracingProfiler()
    frame = foo()
    profiler._profile(frame, 'call', None)
    profiler._profile(frame, 'return', None)
    assert len(profiler.stats) == 1
    stats1 = find_stats(profiler.stats, 'foo')
    stats2 = find_stats(profiler.stats, 'bar')
    stats3 = find_stats(profiler.stats, 'baz')
    assert stats1.own_hits == 0
    assert stats2.own_hits == 0
    assert stats3.own_hits == 1
    assert stats1.deep_hits == 1
    assert stats2.deep_hits == 1
    assert stats3.deep_hits == 1
Exemple #6
0
def test_profiler():
    profiler = TracingProfiler(top_frames=[sys._getframe()])
    assert isinstance(profiler.stats, RecordingStatistics)
    stats, cpu_time, wall_time = profiler.result()
    assert len(stats) == 0
    with profiler:
        factorial(1000)
        factorial(10000)
    stats1 = find_stats(profiler.stats, 'factorial')
    stats2 = find_stats(profiler.stats, '__enter__')
    stats3 = find_stats(profiler.stats, '__exit__')
    assert stats1.deep_time != 0
    assert stats1.deep_time == stats1.own_time
    assert stats1.own_time > stats2.own_time
    assert stats1.own_time > stats3.own_time
    assert stats1.own_hits == 2
    assert stats2.own_hits == 0  # entering to __enter__() wasn't profiled.
    assert stats3.own_hits == 1