def profile(profiler): with profiling(profiler): c1 = spawn(light) c2 = spawn(heavy) for c in [c1, c2]: join(c) stat1 = find_stat(profiler.stats, 'light') stat2 = find_stat(profiler.stats, 'heavy') return (stat1, stat2)
def test_profile(): profiler = Profiler() frame = foo() profiler._profile(frame, 'call', None) profiler._profile(frame, 'return', None) assert len(profiler.stats) == 1 stat1 = find_stat(profiler.stats, 'foo') stat2 = find_stat(profiler.stats, 'bar') stat3 = find_stat(profiler.stats, 'baz') assert stat1.calls == 0 assert stat2.calls == 0 assert stat3.calls == 1
def test_profile(): profiler = Profiler() frame = mock_stacked_frame(map(mock_code, ['foo', 'bar', 'baz'])) profiler._profile(frame, 'call', None) profiler._profile(frame, 'return', None) assert len(profiler.stats) == 1 stat1 = find_stat(profiler.stats, 'baz') stat2 = find_stat(profiler.stats, 'bar') stat3 = find_stat(profiler.stats, 'foo') assert stat1.calls == 0 assert stat2.calls == 0 assert stat3.calls == 1
def test_profiler(): profiler = Profiler(top_frame=sys._getframe()) assert isinstance(profiler.stats, RecordingStatistics) assert isinstance(profiler.result(), FrozenStatistics) assert len(profiler.stats) == 0 with profiling(profiler): factorial(1000) factorial(10000) stat1 = find_stat(profiler.stats, 'factorial') stat2 = find_stat(profiler.stats, '__enter__') stat3 = find_stat(profiler.stats, '__exit__') assert stat1.total_time != 0 assert stat1.total_time == stat1.own_time assert stat1.own_time > stat2.own_time assert stat1.own_time > stat3.own_time assert stat1.calls == 2 assert stat2.calls == 0 # entering to __enter__() wasn't profiled. assert stat3.calls == 1