@@ -479,17 +479,23 @@ def compile_trampolines_for_all_functions():
479
479
if f"py::foo_fork:{ script } " in line or f"py::bar_fork:{ script } " in line :
480
480
self .assertIn (line , child_perf_file_contents )
481
481
482
- def _is_kernel_version_at_least (major , minor ):
482
+
483
+ def _is_perf_vesion_at_least (major , minor ):
484
+ # The output of perf --version looks like "perf version 6.7-3" but
485
+ # it can also be perf version "perf version 5.15.143"
483
486
try :
484
- with open ("/proc/version" ) as f :
485
- version = f .readline ().split ()[2 ]
486
- except FileNotFoundError :
487
+ output = subprocess .check_output (["perf" , "--version" ], text = True )
488
+ except (subprocess .CalledProcessError , FileNotFoundError ):
487
489
return False
490
+ version = output .split ()[2 ]
491
+ version = version .split ("-" )[0 ]
488
492
version = version .split ("." )
489
- return int (version [0 ]) > major or (int (version [0 ]) == major and int (version [1 ]) >= minor )
493
+ version = tuple (map (int , version ))
494
+ return version >= (major , minor )
495
+
490
496
491
497
@unittest .skipUnless (perf_command_works (), "perf command doesn't work" )
492
- @unittest .skipUnless (_is_kernel_version_at_least (6 , 6 ), "perf command may not work due to a perf bug" )
498
+ @unittest .skipUnless (_is_perf_vesion_at_least (6 , 6 ), "perf command may not work due to a perf bug" )
493
499
class TestPerfProfilerWithDwarf (unittest .TestCase , TestPerfProfilerMixin ):
494
500
def run_perf (self , script_dir , script , activate_trampoline = True ):
495
501
if activate_trampoline :
0 commit comments