@@ -767,7 +767,7 @@ fn main_result() -> anyhow::Result<i32> {
767767 CargoIsolationMode :: Isolated
768768 } ;
769769
770- let mut rt = build_async_runtime ( ) ;
770+ let rt = build_async_runtime ( ) ;
771771 let mut conn = rt. block_on ( pool. connection ( ) ) ;
772772 let artifact_id = ArtifactId :: Commit ( Commit {
773773 sha : toolchain. id . clone ( ) ,
@@ -795,7 +795,7 @@ fn main_result() -> anyhow::Result<i32> {
795795 RuntimeBenchmarkFilter :: new ( local. exclude , local. include ) ,
796796 iterations,
797797 ) ;
798- run_benchmarks ( & mut rt , conn, shared, None , Some ( config) ) ?;
798+ rt . block_on ( run_benchmarks ( conn, shared, None , Some ( config) ) ) ?;
799799 Ok ( 0 )
800800 }
801801 Commands :: ProfileRuntime {
@@ -924,7 +924,7 @@ fn main_result() -> anyhow::Result<i32> {
924924 r#type : CommitType :: Master ,
925925 } ) ;
926926
927- let mut rt = build_async_runtime ( ) ;
927+ let rt = build_async_runtime ( ) ;
928928 let mut conn = rt. block_on ( pool. connection ( ) ) ;
929929 rt. block_on ( purge_old_data ( conn. as_mut ( ) , & artifact_id, purge. purge ) ) ;
930930
@@ -943,7 +943,7 @@ fn main_result() -> anyhow::Result<i32> {
943943 targets : vec ! [ Target :: default ( ) ] ,
944944 } ;
945945
946- run_benchmarks ( & mut rt , conn, shared, Some ( config) , None ) ?;
946+ rt . block_on ( run_benchmarks ( conn, shared, Some ( config) , None ) ) ?;
947947 Ok ( 0 )
948948 }
949949
@@ -976,18 +976,14 @@ fn main_result() -> anyhow::Result<i32> {
976976
977977 let res = std:: panic:: catch_unwind ( || {
978978 let pool = database:: Pool :: open ( & db. db ) ;
979- let mut rt = build_async_runtime ( ) ;
979+ let rt = build_async_runtime ( ) ;
980980
981981 match next {
982982 NextArtifact :: Release ( tag) => {
983983 let toolchain =
984984 create_toolchain_from_published_version ( & tag, & target_triple) ?;
985- bench_published_artifact (
986- rt. block_on ( pool. connection ( ) ) ,
987- & mut rt,
988- toolchain,
989- & benchmark_dirs,
990- )
985+ let conn = rt. block_on ( pool. connection ( ) ) ;
986+ rt. block_on ( bench_published_artifact ( conn, toolchain, & benchmark_dirs) )
991987 }
992988 NextArtifact :: Commit {
993989 commit,
@@ -1078,13 +1074,12 @@ fn main_result() -> anyhow::Result<i32> {
10781074 toolchain,
10791075 } ;
10801076
1081- run_benchmarks (
1082- & mut rt,
1077+ rt. block_on ( run_benchmarks (
10831078 conn,
10841079 shared,
10851080 Some ( compile_config) ,
10861081 Some ( runtime_config) ,
1087- )
1082+ ) )
10881083 }
10891084 }
10901085 } ) ;
@@ -1103,10 +1098,10 @@ fn main_result() -> anyhow::Result<i32> {
11031098 Commands :: BenchPublished { toolchain, db } => {
11041099 log_db ( & db) ;
11051100 let pool = database:: Pool :: open ( & db. db ) ;
1106- let mut rt = build_async_runtime ( ) ;
1101+ let rt = build_async_runtime ( ) ;
11071102 let conn = rt. block_on ( pool. connection ( ) ) ;
11081103 let toolchain = create_toolchain_from_published_version ( & toolchain, & target_triple) ?;
1109- bench_published_artifact ( conn, & mut rt , toolchain, & benchmark_dirs) ?;
1104+ rt . block_on ( bench_published_artifact ( conn, toolchain, & benchmark_dirs) ) ?;
11101105 Ok ( 0 )
11111106 }
11121107
@@ -1658,31 +1653,27 @@ async fn init_collection(
16581653}
16591654
16601655/// Execute all benchmarks specified by the given configurations.
1661- fn run_benchmarks (
1662- rt : & mut Runtime ,
1656+ async fn run_benchmarks (
16631657 mut connection : Box < dyn Connection > ,
16641658 shared : SharedBenchmarkConfig ,
16651659 compile : Option < CompileBenchmarkConfig > ,
16661660 runtime : Option < RuntimeBenchmarkConfig > ,
16671661) -> anyhow:: Result < ( ) > {
1668- rt. block_on ( record_toolchain_sizes (
1669- connection. as_mut ( ) ,
1670- & shared. artifact_id ,
1671- & shared. toolchain ,
1672- ) ) ;
1662+ record_toolchain_sizes ( connection. as_mut ( ) , & shared. artifact_id , & shared. toolchain ) . await ;
16731663
1674- let collector = rt . block_on ( init_collection (
1664+ let collector = init_collection (
16751665 connection. as_mut ( ) ,
16761666 & shared,
16771667 compile. as_ref ( ) ,
16781668 runtime. as_ref ( ) ,
1679- ) ) ;
1669+ )
1670+ . await ;
16801671
16811672 let start = Instant :: now ( ) ;
16821673
16831674 // Compile benchmarks
16841675 let compile_result = if let Some ( compile) = compile {
1685- let errors = bench_compile ( rt , connection. as_mut ( ) , & shared, compile, & collector) ;
1676+ let errors = bench_compile ( connection. as_mut ( ) , & shared, compile, & collector) . await ;
16861677 errors
16871678 . fail_if_nonzero ( )
16881679 . context ( "Compile benchmarks failed" )
@@ -1692,30 +1683,32 @@ fn run_benchmarks(
16921683
16931684 // Runtime benchmarks
16941685 let runtime_result = if let Some ( runtime) = runtime {
1695- rt . block_on ( bench_runtime (
1686+ bench_runtime (
16961687 connection. as_mut ( ) ,
16971688 runtime. runtime_suite ,
16981689 & collector,
16991690 runtime. filter ,
17001691 runtime. iterations ,
1701- ) )
1692+ )
1693+ . await
17021694 . context ( "Runtime benchmarks failed" )
17031695 } else {
17041696 Ok ( ( ) )
17051697 } ;
17061698
17071699 let end = start. elapsed ( ) ;
1708- rt. block_on ( connection. record_duration ( collector. artifact_row_id , end) ) ;
1700+ connection
1701+ . record_duration ( collector. artifact_row_id , end)
1702+ . await ;
17091703
17101704 compile_result. and ( runtime_result)
17111705}
17121706
17131707/// Perform benchmarks on a published artifact.
1714- fn bench_published_artifact (
1708+ async fn bench_published_artifact (
17151709 mut connection : Box < dyn Connection > ,
1716- rt : & mut Runtime ,
17171710 toolchain : Toolchain ,
1718- dirs : & BenchmarkDirs ,
1711+ dirs : & BenchmarkDirs < ' _ > ,
17191712) -> anyhow:: Result < ( ) > {
17201713 let artifact_id = ArtifactId :: Tag ( toolchain. id . clone ( ) ) ;
17211714
@@ -1734,21 +1727,21 @@ fn bench_published_artifact(
17341727 let mut compile_benchmarks = get_compile_benchmarks ( dirs. compile , CompileBenchmarkFilter :: All ) ?;
17351728 compile_benchmarks. retain ( |b| b. category ( ) . is_stable ( ) ) ;
17361729
1737- let runtime_suite = rt . block_on ( load_runtime_benchmarks (
1730+ let runtime_suite = load_runtime_benchmarks (
17381731 connection. as_mut ( ) ,
17391732 dirs. runtime ,
17401733 CargoIsolationMode :: Isolated ,
17411734 None ,
17421735 & toolchain,
17431736 & artifact_id,
1744- ) ) ?;
1737+ )
1738+ . await ?;
17451739
17461740 let shared = SharedBenchmarkConfig {
17471741 artifact_id,
17481742 toolchain,
17491743 } ;
17501744 run_benchmarks (
1751- rt,
17521745 connection,
17531746 shared,
17541747 Some ( CompileBenchmarkConfig {
@@ -1767,6 +1760,7 @@ fn bench_published_artifact(
17671760 DEFAULT_RUNTIME_ITERATIONS ,
17681761 ) ) ,
17691762 )
1763+ . await
17701764}
17711765
17721766const COMPILE_BENCHMARK_TIMEOUT : Duration = Duration :: from_secs ( 60 * 30 ) ;
@@ -1782,8 +1776,7 @@ async fn with_timeout<F: Future<Output = anyhow::Result<()>>>(fut: F) -> anyhow:
17821776}
17831777
17841778/// Perform compile benchmarks.
1785- fn bench_compile (
1786- rt : & mut Runtime ,
1779+ async fn bench_compile (
17871780 conn : & mut dyn Connection ,
17881781 shared : & SharedBenchmarkConfig ,
17891782 config : CompileBenchmarkConfig ,
@@ -1799,51 +1792,63 @@ fn bench_compile(
17991792
18001793 let start = Instant :: now ( ) ;
18011794
1802- let mut measure_and_record =
1803- |benchmark_name : & BenchmarkName ,
1804- category : Category ,
1805- print_intro : & dyn Fn ( ) ,
1806- measure : & dyn Fn ( & mut BenchProcessor ) -> anyhow:: Result < ( ) > | {
1807- let is_fresh = rt. block_on ( collector. start_compile_step ( conn, benchmark_name) ) ;
1808- if !is_fresh {
1809- eprintln ! ( "skipping {} -- already benchmarked" , benchmark_name) ;
1810- return ;
1811- }
1812- let mut tx = rt. block_on ( conn. transaction ( ) ) ;
1813- let ( supports_stable, category) = category. db_representation ( ) ;
1814- rt. block_on ( tx. conn ( ) . record_compile_benchmark (
1815- & benchmark_name. 0 ,
1816- Some ( supports_stable) ,
1817- category,
1818- ) ) ;
1819- print_intro ( ) ;
1820- let mut processor = BenchProcessor :: new (
1821- tx. conn ( ) ,
1822- benchmark_name,
1823- & shared. artifact_id ,
1824- collector. artifact_row_id ,
1825- config. is_self_profile ,
1795+ #[ allow( clippy:: too_many_arguments) ]
1796+ async fn measure_and_record < F : AsyncFn ( & mut BenchProcessor ) -> anyhow:: Result < ( ) > > (
1797+ collector : & CollectorCtx ,
1798+ shared : & SharedBenchmarkConfig ,
1799+ config : & CompileBenchmarkConfig ,
1800+ errors : & mut BenchmarkErrors ,
1801+ conn : & mut dyn Connection ,
1802+ benchmark_name : & BenchmarkName ,
1803+ category : Category ,
1804+ print_intro : & dyn Fn ( ) ,
1805+ measure : F ,
1806+ ) {
1807+ let is_fresh = collector. start_compile_step ( conn, benchmark_name) . await ;
1808+ if !is_fresh {
1809+ eprintln ! ( "skipping {} -- already benchmarked" , benchmark_name) ;
1810+ return ;
1811+ }
1812+ let mut tx = conn. transaction ( ) . await ;
1813+ let ( supports_stable, category) = category. db_representation ( ) ;
1814+ tx. conn ( )
1815+ . record_compile_benchmark ( & benchmark_name. 0 , Some ( supports_stable) , category)
1816+ . await ;
1817+ print_intro ( ) ;
1818+ let mut processor = BenchProcessor :: new (
1819+ tx. conn ( ) ,
1820+ benchmark_name,
1821+ & shared. artifact_id ,
1822+ collector. artifact_row_id ,
1823+ config. is_self_profile ,
1824+ ) ;
1825+ let result = measure ( & mut processor) . await ;
1826+ if let Err ( s) = result {
1827+ eprintln ! (
1828+ "collector error: Failed to benchmark '{}', recorded: {:#}" ,
1829+ benchmark_name, s
18261830 ) ;
1827- let result = measure ( & mut processor) ;
1828- if let Err ( s) = result {
1829- eprintln ! (
1830- "collector error: Failed to benchmark '{}', recorded: {:#}" ,
1831- benchmark_name, s
1832- ) ;
1833- errors. incr ( ) ;
1834- rt. block_on ( tx. conn ( ) . record_error (
1831+ errors. incr ( ) ;
1832+ tx. conn ( )
1833+ . record_error (
18351834 collector. artifact_row_id ,
18361835 & benchmark_name. 0 ,
18371836 & format ! ( "{:?}" , s) ,
1838- ) ) ;
1839- } ;
1840- rt. block_on ( collector. end_compile_step ( tx. conn ( ) , benchmark_name) ) ;
1841- rt. block_on ( tx. commit ( ) ) . expect ( "committed" ) ;
1837+ )
1838+ . await ;
18421839 } ;
1840+ collector. end_compile_step ( tx. conn ( ) , benchmark_name) . await ;
1841+ tx. commit ( ) . await . expect ( "committed" ) ;
1842+ }
18431843
18441844 // Normal benchmarks.
18451845 for ( nth_benchmark, benchmark) in config. benchmarks . iter ( ) . enumerate ( ) {
18461846 measure_and_record (
1847+ collector,
1848+ shared,
1849+ & config,
1850+ & mut errors,
1851+ conn,
18471852 & benchmark. name ,
18481853 benchmark. category ( ) ,
18491854 & || {
@@ -1852,32 +1857,41 @@ fn bench_compile(
18521857 n_normal_benchmarks_remaining( config. benchmarks. len( ) - nth_benchmark)
18531858 )
18541859 } ,
1855- & |processor| {
1856- rt . block_on ( with_timeout ( benchmark. measure (
1860+ async |processor| {
1861+ with_timeout ( benchmark. measure (
18571862 processor,
18581863 & config. profiles ,
18591864 & config. scenarios ,
18601865 & config. backends ,
18611866 & shared. toolchain ,
18621867 config. iterations ,
18631868 & config. targets ,
1864- ) ) )
1869+ ) )
1870+ . await
18651871 . with_context ( || anyhow:: anyhow!( "Cannot compile {}" , benchmark. name) )
18661872 } ,
18671873 )
1874+ . await ;
18681875 }
18691876
18701877 // The special rustc benchmark, if requested.
18711878 if bench_rustc {
18721879 measure_and_record (
1880+ collector,
1881+ shared,
1882+ & config,
1883+ & mut errors,
1884+ conn,
18731885 & BenchmarkName ( "rustc" . to_string ( ) ) ,
18741886 Category :: Primary ,
18751887 & || eprintln ! ( "Special benchmark commencing (due to `--bench-rustc`)" ) ,
1876- & |processor| {
1877- rt. block_on ( with_timeout ( processor. measure_rustc ( & shared. toolchain ) ) )
1888+ async |processor| {
1889+ with_timeout ( processor. measure_rustc ( & shared. toolchain ) )
1890+ . await
18781891 . context ( "measure rustc" )
18791892 } ,
1880- ) ;
1893+ )
1894+ . await ;
18811895 }
18821896
18831897 let end = start. elapsed ( ) ;
@@ -1887,10 +1901,8 @@ fn bench_compile(
18871901 end, errors. 0
18881902 ) ;
18891903
1890- rt. block_on ( async move {
1891- // This ensures that we're good to go with the just updated data.
1892- conn. maybe_create_indices ( ) . await ;
1893- } ) ;
1904+ // This ensures that we're good to go with the just updated data.
1905+ conn. maybe_create_indices ( ) . await ;
18941906 errors
18951907}
18961908
@@ -1968,7 +1980,7 @@ fn get_downloaded_crate_target(benchmark_dir: &Path, cmd: &DownloadCommand) -> P
19681980 . trim_end_matches ( '/' )
19691981 . trim_end_matches ( ".git" )
19701982 . split ( '/' )
1971- . last ( )
1983+ . next_back ( )
19721984 . expect ( "Crate name could not be determined from git URL" )
19731985 . to_string ( ) ,
19741986 DownloadSubcommand :: Crate { krate, version } => format ! ( "{krate}-{version}" ) ,
0 commit comments