48
48
49
49
LLVM_BOLT_CRATES = LLVM_PGO_CRATES
50
50
51
-
52
51
class Pipeline :
53
52
# Paths
54
53
def checkout_path (self ) -> Path :
@@ -451,6 +450,44 @@ def cmd(
451
450
)
452
451
return subprocess .run (args , env = environment , check = True )
453
452
453
+ class BenchmarkRunner :
454
+ def run_rustc (self , pipeline : Pipeline ):
455
+ raise NotImplementedError
456
+
457
+ def run_llvm (self , pipeline : Pipeline ):
458
+ raise NotImplementedError
459
+
460
+ def run_bolt (self , pipeline : Pipeline ):
461
+ raise NotImplementedError
462
+
463
+ class DefaultBenchmarkRunner (BenchmarkRunner ):
464
+ def run_rustc (self , pipeline : Pipeline ):
465
+ # Here we're profiling the `rustc` frontend, so we also include `Check`.
466
+ # The benchmark set includes various stress tests that put the frontend under pressure.
467
+ run_compiler_benchmarks (
468
+ pipeline ,
469
+ profiles = ["Check" , "Debug" , "Opt" ],
470
+ scenarios = ["All" ],
471
+ crates = RUSTC_PGO_CRATES ,
472
+ env = dict (
473
+ LLVM_PROFILE_FILE = str (pipeline .rustc_profile_template_path ())
474
+ )
475
+ )
476
+ def run_llvm (self , pipeline : Pipeline ):
477
+ run_compiler_benchmarks (
478
+ pipeline ,
479
+ profiles = ["Debug" , "Opt" ],
480
+ scenarios = ["Full" ],
481
+ crates = LLVM_PGO_CRATES
482
+ )
483
+
484
+ def run_bolt (self , pipeline : Pipeline ):
485
+ run_compiler_benchmarks (
486
+ pipeline ,
487
+ profiles = ["Check" , "Debug" , "Opt" ],
488
+ scenarios = ["Full" ],
489
+ crates = LLVM_BOLT_CRATES
490
+ )
454
491
455
492
def run_compiler_benchmarks (
456
493
pipeline : Pipeline ,
@@ -580,14 +617,10 @@ def create_pipeline() -> Pipeline:
580
617
raise Exception (f"Optimized build is not supported for platform { sys .platform } " )
581
618
582
619
583
- def gather_llvm_profiles (pipeline : Pipeline ):
620
+ def gather_llvm_profiles (pipeline : Pipeline , runner : BenchmarkRunner ):
584
621
LOGGER .info ("Running benchmarks with PGO instrumented LLVM" )
585
- run_compiler_benchmarks (
586
- pipeline ,
587
- profiles = ["Debug" , "Opt" ],
588
- scenarios = ["Full" ],
589
- crates = LLVM_PGO_CRATES
590
- )
622
+
623
+ runner .run_llvm (pipeline )
591
624
592
625
profile_path = pipeline .llvm_profile_merged_file ()
593
626
LOGGER .info (f"Merging LLVM PGO profiles to { profile_path } " )
@@ -609,20 +642,12 @@ def gather_llvm_profiles(pipeline: Pipeline):
609
642
delete_directory (pipeline .llvm_profile_dir_root ())
610
643
611
644
612
- def gather_rustc_profiles (pipeline : Pipeline ):
645
+ def gather_rustc_profiles (pipeline : Pipeline , runner : BenchmarkRunner ):
613
646
LOGGER .info ("Running benchmarks with PGO instrumented rustc" )
614
647
615
- # Here we're profiling the `rustc` frontend, so we also include `Check`.
616
- # The benchmark set includes various stress tests that put the frontend under pressure.
617
- run_compiler_benchmarks (
618
- pipeline ,
619
- profiles = ["Check" , "Debug" , "Opt" ],
620
- scenarios = ["All" ],
621
- crates = RUSTC_PGO_CRATES ,
622
- env = dict (
623
- LLVM_PROFILE_FILE = str (pipeline .rustc_profile_template_path ())
624
- )
625
- )
648
+
649
+ runner .run_rustc (pipeline )
650
+
626
651
627
652
profile_path = pipeline .rustc_profile_merged_file ()
628
653
LOGGER .info (f"Merging Rustc PGO profiles to { profile_path } " )
@@ -644,14 +669,10 @@ def gather_rustc_profiles(pipeline: Pipeline):
644
669
delete_directory (pipeline .rustc_profile_dir_root ())
645
670
646
671
647
- def gather_llvm_bolt_profiles (pipeline : Pipeline ):
672
+ def gather_llvm_bolt_profiles (pipeline : Pipeline , runner : BenchmarkRunner ):
648
673
LOGGER .info ("Running benchmarks with BOLT instrumented LLVM" )
649
- run_compiler_benchmarks (
650
- pipeline ,
651
- profiles = ["Check" , "Debug" , "Opt" ],
652
- scenarios = ["Full" ],
653
- crates = LLVM_BOLT_CRATES
654
- )
674
+
675
+ runner .run_bolt (pipeline )
655
676
656
677
merged_profile_path = pipeline .llvm_bolt_profile_merged_file ()
657
678
profile_files_path = Path ("/tmp/prof.fdata" )
@@ -744,7 +765,7 @@ def record_metrics(pipeline: Pipeline, timer: Timer):
744
765
log_metrics (metrics )
745
766
746
767
747
- def execute_build_pipeline (timer : Timer , pipeline : Pipeline , final_build_args : List [str ]):
768
+ def execute_build_pipeline (timer : Timer , pipeline : Pipeline , runner : BenchmarkRunner , final_build_args : List [str ]):
748
769
# Clear and prepare tmp directory
749
770
shutil .rmtree (pipeline .opt_artifacts (), ignore_errors = True )
750
771
os .makedirs (pipeline .opt_artifacts (), exist_ok = True )
@@ -762,7 +783,7 @@ def execute_build_pipeline(timer: Timer, pipeline: Pipeline, final_build_args: L
762
783
record_metrics (pipeline , rustc_build )
763
784
764
785
with stage1 .section ("Gather profiles" ):
765
- gather_llvm_profiles (pipeline )
786
+ gather_llvm_profiles (pipeline , runner )
766
787
print_free_disk_space (pipeline )
767
788
768
789
clear_llvm_files (pipeline )
@@ -781,7 +802,7 @@ def execute_build_pipeline(timer: Timer, pipeline: Pipeline, final_build_args: L
781
802
record_metrics (pipeline , rustc_build )
782
803
783
804
with stage2 .section ("Gather profiles" ):
784
- gather_rustc_profiles (pipeline )
805
+ gather_rustc_profiles (pipeline , runner )
785
806
print_free_disk_space (pipeline )
786
807
787
808
clear_llvm_files (pipeline )
@@ -804,7 +825,7 @@ def execute_build_pipeline(timer: Timer, pipeline: Pipeline, final_build_args: L
804
825
record_metrics (pipeline , rustc_build )
805
826
806
827
with stage3 .section ("Gather profiles" ):
807
- gather_llvm_bolt_profiles (pipeline )
828
+ gather_llvm_bolt_profiles (pipeline , runner )
808
829
809
830
# LLVM is not being cleared here, we want to reuse the previous build
810
831
print_free_disk_space (pipeline )
@@ -819,7 +840,7 @@ def execute_build_pipeline(timer: Timer, pipeline: Pipeline, final_build_args: L
819
840
record_metrics (pipeline , stage4 )
820
841
821
842
822
- if __name__ == "__main__" :
843
+ def run ( runner : BenchmarkRunner ) :
823
844
logging .basicConfig (
824
845
level = logging .DEBUG ,
825
846
format = "%(name)s %(levelname)-4s: %(message)s" ,
@@ -832,8 +853,9 @@ def execute_build_pipeline(timer: Timer, pipeline: Pipeline, final_build_args: L
832
853
833
854
timer = Timer ()
834
855
pipeline = create_pipeline ()
856
+
835
857
try :
836
- execute_build_pipeline (timer , pipeline , build_args )
858
+ execute_build_pipeline (timer , pipeline , runner , build_args )
837
859
except BaseException as e :
838
860
LOGGER .error ("The multi-stage build has failed" )
839
861
raise e
@@ -842,3 +864,7 @@ def execute_build_pipeline(timer: Timer, pipeline: Pipeline, final_build_args: L
842
864
print_free_disk_space (pipeline )
843
865
844
866
print_binary_sizes (pipeline )
867
+
868
+ if __name__ == "__main__" :
869
+ runner = DefaultBenchmarkRunner ()
870
+ run (runner )
0 commit comments