@@ -10,7 +10,7 @@ use collector::compile::benchmark::scenario::Scenario;
1010use collector:: compile:: benchmark:: {
1111 compile_benchmark_dir, get_compile_benchmarks, ArtifactType , Benchmark , BenchmarkName ,
1212} ;
13- use collector:: { runtime , utils, CollectorCtx , CollectorStepBuilder } ;
13+ use collector:: { utils, CollectorCtx , CollectorStepBuilder } ;
1414use database:: { ArtifactId , ArtifactIdNumber , Commit , CommitType , Connection , Pool } ;
1515use rayon:: iter:: { IndexedParallelIterator , IntoParallelRefIterator , ParallelIterator } ;
1616use std:: cmp:: Ordering ;
@@ -31,9 +31,11 @@ use tokio::runtime::Runtime;
3131use collector:: compile:: execute:: bencher:: BenchProcessor ;
3232use collector:: compile:: execute:: profiler:: { ProfileProcessor , Profiler } ;
3333use collector:: runtime:: {
34- bench_runtime, runtime_benchmark_dir, BenchmarkFilter , BenchmarkSuite ,
35- BenchmarkSuiteCompilation , CargoIsolationMode , DEFAULT_RUNTIME_ITERATIONS ,
34+ bench_runtime, prepare_runtime_benchmark_suite, runtime_benchmark_dir, BenchmarkFilter ,
35+ BenchmarkSuite , BenchmarkSuiteCompilation , CargoIsolationMode , RuntimeProfiler ,
36+ DEFAULT_RUNTIME_ITERATIONS ,
3637} ;
38+ use collector:: runtime:: { profile_runtime, RuntimeCompilationOpts } ;
3739use collector:: toolchain:: {
3840 create_toolchain_from_published_version, get_local_toolchain, Sysroot , Toolchain ,
3941} ;
@@ -255,7 +257,7 @@ fn cg_annotate(cgout: &Path, path: &Path) -> anyhow::Result<()> {
255257}
256258
257259#[ allow( clippy:: too_many_arguments) ]
258- fn profile (
260+ fn profile_compile (
259261 toolchain : & Toolchain ,
260262 profiler : Profiler ,
261263 out_dir : & Path ,
@@ -502,6 +504,19 @@ enum Commands {
502504 #[ arg( long = "no-isolate" ) ]
503505 no_isolate : bool ,
504506 } ,
507+
508+ /// Profiles a runtime benchmark.
509+ ProfileRuntime {
510+ /// Profiler to use
511+ profiler : RuntimeProfiler ,
512+
513+ /// The path to the local rustc used to compile the runtime benchmark
514+ rustc : String ,
515+
516+ /// Name of the benchmark that should be profiled
517+ benchmark : String ,
518+ } ,
519+
505520 /// Benchmarks a local rustc
506521 BenchLocal {
507522 #[ command( flatten) ]
@@ -650,15 +665,7 @@ fn main_result() -> anyhow::Result<i32> {
650665 no_isolate,
651666 } => {
652667 log_db ( & db) ;
653- let toolchain = get_local_toolchain (
654- & [ Profile :: Opt ] ,
655- & local. rustc ,
656- None ,
657- local. cargo . as_deref ( ) ,
658- local. id . as_deref ( ) ,
659- "" ,
660- target_triple,
661- ) ?;
668+ let toolchain = get_local_toolchain_for_runtime_benchmarks ( & local, & target_triple) ?;
662669 let pool = Pool :: open ( & db. db ) ;
663670
664671 let isolation_mode = if no_isolate {
@@ -689,6 +696,25 @@ fn main_result() -> anyhow::Result<i32> {
689696 run_benchmarks ( & mut rt, conn, shared, None , Some ( config) ) ?;
690697 Ok ( 0 )
691698 }
699+ Commands :: ProfileRuntime {
700+ profiler,
701+ rustc,
702+ benchmark,
703+ } => {
704+ let toolchain =
705+ get_local_toolchain ( & [ Profile :: Opt ] , & rustc, None , None , None , "" , target_triple) ?;
706+ let suite = prepare_runtime_benchmark_suite (
707+ & toolchain,
708+ & runtime_benchmark_dir,
709+ CargoIsolationMode :: Cached ,
710+ // Compile with debuginfo to have filenames and line numbers available in the
711+ // generated profiles.
712+ RuntimeCompilationOpts :: default ( ) . debug_info ( "1" ) ,
713+ ) ?
714+ . suite ;
715+ profile_runtime ( profiler, suite, & benchmark) ?;
716+ Ok ( 0 )
717+ }
692718 Commands :: BenchLocal {
693719 local,
694720 opts,
@@ -904,7 +930,7 @@ fn main_result() -> anyhow::Result<i32> {
904930 target_triple. clone ( ) ,
905931 ) ?;
906932 let id = toolchain. id . clone ( ) ;
907- profile (
933+ profile_compile (
908934 & toolchain,
909935 profiler,
910936 & out_dir,
@@ -1005,6 +1031,21 @@ Make sure to modify `{dir}/perf-config.json` if the category/artifact don't matc
10051031 }
10061032}
10071033
1034+ fn get_local_toolchain_for_runtime_benchmarks (
1035+ local : & LocalOptions ,
1036+ target_triple : & str ,
1037+ ) -> anyhow:: Result < Toolchain > {
1038+ get_local_toolchain (
1039+ & [ Profile :: Opt ] ,
1040+ & local. rustc ,
1041+ None ,
1042+ local. cargo . as_deref ( ) ,
1043+ local. id . as_deref ( ) ,
1044+ "" ,
1045+ target_triple. to_string ( ) ,
1046+ )
1047+ }
1048+
10081049async fn load_runtime_benchmarks (
10091050 conn : & mut dyn Connection ,
10101051 benchmark_dir : & Path ,
@@ -1015,7 +1056,12 @@ async fn load_runtime_benchmarks(
10151056 let BenchmarkSuiteCompilation {
10161057 suite,
10171058 failed_to_compile,
1018- } = runtime:: prepare_runtime_benchmark_suite ( toolchain, benchmark_dir, isolation_mode) ?;
1059+ } = prepare_runtime_benchmark_suite (
1060+ toolchain,
1061+ benchmark_dir,
1062+ isolation_mode,
1063+ RuntimeCompilationOpts :: default ( ) ,
1064+ ) ?;
10191065
10201066 record_runtime_compilation_errors ( conn, artifact_id, failed_to_compile) . await ;
10211067 Ok ( suite)
0 commit comments