@@ -1681,7 +1681,12 @@ fn run_benchmarks(
16811681
16821682 // Compile benchmarks
16831683 let compile_result = if let Some ( compile) = compile {
1684- let errors = bench_compile ( rt, connection. as_mut ( ) , & shared, compile, & collector) ;
1684+ let errors = rt. block_on ( bench_compile (
1685+ connection. as_mut ( ) ,
1686+ & shared,
1687+ compile,
1688+ & collector,
1689+ ) ) ;
16851690 errors
16861691 . fail_if_nonzero ( )
16871692 . context ( "Compile benchmarks failed" )
@@ -1781,8 +1786,7 @@ async fn with_timeout<F: Future<Output = anyhow::Result<()>>>(fut: F) -> anyhow:
17811786}
17821787
17831788/// Perform compile benchmarks.
1784- fn bench_compile (
1785- rt : & mut Runtime ,
1789+ async fn bench_compile (
17861790 conn : & mut dyn Connection ,
17871791 shared : & SharedBenchmarkConfig ,
17881792 config : CompileBenchmarkConfig ,
@@ -1798,51 +1802,62 @@ fn bench_compile(
17981802
17991803 let start = Instant :: now ( ) ;
18001804
1801- let mut measure_and_record =
1802- |benchmark_name : & BenchmarkName ,
1803- category : Category ,
1804- print_intro : & dyn Fn ( ) ,
1805- measure : & dyn Fn ( & mut BenchProcessor ) -> anyhow:: Result < ( ) > | {
1806- let is_fresh = rt. block_on ( collector. start_compile_step ( conn, benchmark_name) ) ;
1807- if !is_fresh {
1808- eprintln ! ( "skipping {} -- already benchmarked" , benchmark_name) ;
1809- return ;
1810- }
1811- let mut tx = rt. block_on ( conn. transaction ( ) ) ;
1812- let ( supports_stable, category) = category. db_representation ( ) ;
1813- rt. block_on ( tx. conn ( ) . record_compile_benchmark (
1814- & benchmark_name. 0 ,
1815- Some ( supports_stable) ,
1816- category,
1817- ) ) ;
1818- print_intro ( ) ;
1819- let mut processor = BenchProcessor :: new (
1820- tx. conn ( ) ,
1821- benchmark_name,
1822- & shared. artifact_id ,
1823- collector. artifact_row_id ,
1824- config. is_self_profile ,
1805+ async fn measure_and_record < F : AsyncFn ( & mut BenchProcessor ) -> anyhow:: Result < ( ) > > (
1806+ collector : & CollectorCtx ,
1807+ shared : & SharedBenchmarkConfig ,
1808+ config : & CompileBenchmarkConfig ,
1809+ errors : & mut BenchmarkErrors ,
1810+ conn : & mut dyn Connection ,
1811+ benchmark_name : & BenchmarkName ,
1812+ category : Category ,
1813+ print_intro : & dyn Fn ( ) ,
1814+ measure : F ,
1815+ ) {
1816+ let is_fresh = collector. start_compile_step ( conn, benchmark_name) . await ;
1817+ if !is_fresh {
1818+ eprintln ! ( "skipping {} -- already benchmarked" , benchmark_name) ;
1819+ return ;
1820+ }
1821+ let mut tx = conn. transaction ( ) . await ;
1822+ let ( supports_stable, category) = category. db_representation ( ) ;
1823+ tx. conn ( )
1824+ . record_compile_benchmark ( & benchmark_name. 0 , Some ( supports_stable) , category)
1825+ . await ;
1826+ print_intro ( ) ;
1827+ let mut processor = BenchProcessor :: new (
1828+ tx. conn ( ) ,
1829+ benchmark_name,
1830+ & shared. artifact_id ,
1831+ collector. artifact_row_id ,
1832+ config. is_self_profile ,
1833+ ) ;
1834+ let result = measure ( & mut processor) . await ;
1835+ if let Err ( s) = result {
1836+ eprintln ! (
1837+ "collector error: Failed to benchmark '{}', recorded: {:#}" ,
1838+ benchmark_name, s
18251839 ) ;
1826- let result = measure ( & mut processor) ;
1827- if let Err ( s) = result {
1828- eprintln ! (
1829- "collector error: Failed to benchmark '{}', recorded: {:#}" ,
1830- benchmark_name, s
1831- ) ;
1832- errors. incr ( ) ;
1833- rt. block_on ( tx. conn ( ) . record_error (
1840+ errors. incr ( ) ;
1841+ tx. conn ( )
1842+ . record_error (
18341843 collector. artifact_row_id ,
18351844 & benchmark_name. 0 ,
18361845 & format ! ( "{:?}" , s) ,
1837- ) ) ;
1838- } ;
1839- rt. block_on ( collector. end_compile_step ( tx. conn ( ) , benchmark_name) ) ;
1840- rt. block_on ( tx. commit ( ) ) . expect ( "committed" ) ;
1846+ )
1847+ . await ;
18411848 } ;
1849+ collector. end_compile_step ( tx. conn ( ) , benchmark_name) . await ;
1850+ tx. commit ( ) . await . expect ( "committed" ) ;
1851+ }
18421852
18431853 // Normal benchmarks.
18441854 for ( nth_benchmark, benchmark) in config. benchmarks . iter ( ) . enumerate ( ) {
18451855 measure_and_record (
1856+ collector,
1857+ shared,
1858+ & config,
1859+ & mut errors,
1860+ conn,
18461861 & benchmark. name ,
18471862 benchmark. category ( ) ,
18481863 & || {
@@ -1851,32 +1866,41 @@ fn bench_compile(
18511866 n_normal_benchmarks_remaining( config. benchmarks. len( ) - nth_benchmark)
18521867 )
18531868 } ,
1854- & |processor| {
1855- rt . block_on ( with_timeout ( benchmark. measure (
1869+ async |processor| {
1870+ with_timeout ( benchmark. measure (
18561871 processor,
18571872 & config. profiles ,
18581873 & config. scenarios ,
18591874 & config. backends ,
18601875 & shared. toolchain ,
18611876 config. iterations ,
18621877 & config. targets ,
1863- ) ) )
1878+ ) )
1879+ . await
18641880 . with_context ( || anyhow:: anyhow!( "Cannot compile {}" , benchmark. name) )
18651881 } ,
18661882 )
1883+ . await ;
18671884 }
18681885
18691886 // The special rustc benchmark, if requested.
18701887 if bench_rustc {
18711888 measure_and_record (
1889+ collector,
1890+ shared,
1891+ & config,
1892+ & mut errors,
1893+ conn,
18721894 & BenchmarkName ( "rustc" . to_string ( ) ) ,
18731895 Category :: Primary ,
18741896 & || eprintln ! ( "Special benchmark commencing (due to `--bench-rustc`)" ) ,
1875- & |processor| {
1876- rt. block_on ( with_timeout ( processor. measure_rustc ( & shared. toolchain ) ) )
1897+ async |processor| {
1898+ with_timeout ( processor. measure_rustc ( & shared. toolchain ) )
1899+ . await
18771900 . context ( "measure rustc" )
18781901 } ,
1879- ) ;
1902+ )
1903+ . await ;
18801904 }
18811905
18821906 let end = start. elapsed ( ) ;
@@ -1886,10 +1910,8 @@ fn bench_compile(
18861910 end, errors. 0
18871911 ) ;
18881912
1889- rt. block_on ( async move {
1890- // This ensures that we're good to go with the just updated data.
1891- conn. maybe_create_indices ( ) . await ;
1892- } ) ;
1913+ // This ensures that we're good to go with the just updated data.
1914+ conn. maybe_create_indices ( ) . await ;
18931915 errors
18941916}
18951917
0 commit comments