def test_profiler_retains_multiple_calls(): profiler = Profiler() profiler.start() long_function_a() long_function_b() long_function_a() long_function_b() profiler.stop() print(profiler.output_text()) frame = profiler.first_interesting_frame() assert frame.function == 'test_profiler_retains_multiple_calls' assert len(frame.children) == 4
def test_two_functions(): profiler = Profiler() profiler.start() long_function_a() long_function_b() profiler.stop() print(profiler.output_text()) frame = profiler.first_interesting_frame() assert frame.function == 'test_two_functions' assert len(frame.children) == 2 frame_b, frame_a = sorted(frame.children, key=lambda f: f.time(), reverse=True) assert frame_a.function == 'long_function_a' assert frame_b.function == 'long_function_b' assert 0.2 < frame_a.time() < 0.3 assert 0.45 < frame_b.time() < 0.55