@@ -383,6 +383,29 @@ def baz(n):
383383 self .assertNotIn (f"py::bar:{ script } " , stdout )
384384 self .assertNotIn (f"py::baz:{ script } " , stdout )
385385
386+ @unittest .skipUnless (perf_command_works (), "perf command doesn't work" )
387+ @unittest .skipUnless (
388+ is_unwinding_reliable_with_frame_pointers (),
389+ "Unwinding is unreliable with frame pointers" ,
390+ )
391+ class TestPerfProfiler (unittest .TestCase , TestPerfProfilerMixin ):
392+ def run_perf (self , script_dir , script , activate_trampoline = True ):
393+ if activate_trampoline :
394+ return run_perf (script_dir , sys .executable , "-Xperf" , script )
395+ return run_perf (script_dir , sys .executable , script )
396+
397+ def setUp (self ):
398+ super ().setUp ()
399+ self .perf_files = set (pathlib .Path ("/tmp/" ).glob ("perf-*.map" ))
400+
401+ def tearDown (self ) -> None :
402+ super ().tearDown ()
403+ files_to_delete = (
404+ set (pathlib .Path ("/tmp/" ).glob ("perf-*.map" )) - self .perf_files
405+ )
406+ for file in files_to_delete :
407+ file .unlink ()
408+
386409 def test_pre_fork_compile (self ):
387410 code = """if 1:
388411 import sys
@@ -400,7 +423,7 @@ def bar_fork():
400423 foo_fork()
401424
402425 def foo():
403- pass
426+ import time; time.sleep(1)
404427
405428 def bar():
406429 foo()
@@ -457,30 +480,6 @@ def compile_trampolines_for_all_functions():
457480 self .assertIn (line , child_perf_file_contents )
458481
459482
460- @unittest .skipUnless (perf_command_works (), "perf command doesn't work" )
461- @unittest .skipUnless (
462- is_unwinding_reliable_with_frame_pointers (),
463- "Unwinding is unreliable with frame pointers" ,
464- )
465- class TestPerfProfiler (unittest .TestCase , TestPerfProfilerMixin ):
466- def run_perf (self , script_dir , script , activate_trampoline = True ):
467- if activate_trampoline :
468- return run_perf (script_dir , sys .executable , "-Xperf" , script )
469- return run_perf (script_dir , sys .executable , script )
470-
471- def setUp (self ):
472- super ().setUp ()
473- self .perf_files = set (pathlib .Path ("/tmp/" ).glob ("perf-*.map" ))
474-
475- def tearDown (self ) -> None :
476- super ().tearDown ()
477- files_to_delete = (
478- set (pathlib .Path ("/tmp/" ).glob ("perf-*.map" )) - self .perf_files
479- )
480- for file in files_to_delete :
481- file .unlink ()
482-
483-
484483@unittest .skipUnless (perf_command_works (), "perf command doesn't work" )
485484class TestPerfProfilerWithDwarf (unittest .TestCase , TestPerfProfilerMixin ):
486485 def run_perf (self , script_dir , script , activate_trampoline = True ):
0 commit comments