@@ -767,7 +767,7 @@ fn main_result() -> anyhow::Result<i32> {
767
767
CargoIsolationMode :: Isolated
768
768
} ;
769
769
770
- let mut rt = build_async_runtime ( ) ;
770
+ let rt = build_async_runtime ( ) ;
771
771
let mut conn = rt. block_on ( pool. connection ( ) ) ;
772
772
let artifact_id = ArtifactId :: Commit ( Commit {
773
773
sha : toolchain. id . clone ( ) ,
@@ -795,7 +795,7 @@ fn main_result() -> anyhow::Result<i32> {
795
795
RuntimeBenchmarkFilter :: new ( local. exclude , local. include ) ,
796
796
iterations,
797
797
) ;
798
- run_benchmarks ( & mut rt , conn, shared, None , Some ( config) ) ?;
798
+ rt . block_on ( run_benchmarks ( conn, shared, None , Some ( config) ) ) ?;
799
799
Ok ( 0 )
800
800
}
801
801
Commands :: ProfileRuntime {
@@ -924,7 +924,7 @@ fn main_result() -> anyhow::Result<i32> {
924
924
r#type : CommitType :: Master ,
925
925
} ) ;
926
926
927
- let mut rt = build_async_runtime ( ) ;
927
+ let rt = build_async_runtime ( ) ;
928
928
let mut conn = rt. block_on ( pool. connection ( ) ) ;
929
929
rt. block_on ( purge_old_data ( conn. as_mut ( ) , & artifact_id, purge. purge ) ) ;
930
930
@@ -943,7 +943,7 @@ fn main_result() -> anyhow::Result<i32> {
943
943
targets : vec ! [ Target :: default ( ) ] ,
944
944
} ;
945
945
946
- run_benchmarks ( & mut rt , conn, shared, Some ( config) , None ) ?;
946
+ rt . block_on ( run_benchmarks ( conn, shared, Some ( config) , None ) ) ?;
947
947
Ok ( 0 )
948
948
}
949
949
@@ -976,18 +976,14 @@ fn main_result() -> anyhow::Result<i32> {
976
976
977
977
let res = std:: panic:: catch_unwind ( || {
978
978
let pool = database:: Pool :: open ( & db. db ) ;
979
- let mut rt = build_async_runtime ( ) ;
979
+ let rt = build_async_runtime ( ) ;
980
980
981
981
match next {
982
982
NextArtifact :: Release ( tag) => {
983
983
let toolchain =
984
984
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) )
991
987
}
992
988
NextArtifact :: Commit {
993
989
commit,
@@ -1078,13 +1074,12 @@ fn main_result() -> anyhow::Result<i32> {
1078
1074
toolchain,
1079
1075
} ;
1080
1076
1081
- run_benchmarks (
1082
- & mut rt,
1077
+ rt. block_on ( run_benchmarks (
1083
1078
conn,
1084
1079
shared,
1085
1080
Some ( compile_config) ,
1086
1081
Some ( runtime_config) ,
1087
- )
1082
+ ) )
1088
1083
}
1089
1084
}
1090
1085
} ) ;
@@ -1103,10 +1098,10 @@ fn main_result() -> anyhow::Result<i32> {
1103
1098
Commands :: BenchPublished { toolchain, db } => {
1104
1099
log_db ( & db) ;
1105
1100
let pool = database:: Pool :: open ( & db. db ) ;
1106
- let mut rt = build_async_runtime ( ) ;
1101
+ let rt = build_async_runtime ( ) ;
1107
1102
let conn = rt. block_on ( pool. connection ( ) ) ;
1108
1103
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) ) ?;
1110
1105
Ok ( 0 )
1111
1106
}
1112
1107
@@ -1658,31 +1653,27 @@ async fn init_collection(
1658
1653
}
1659
1654
1660
1655
/// Execute all benchmarks specified by the given configurations.
1661
- fn run_benchmarks (
1662
- rt : & mut Runtime ,
1656
+ async fn run_benchmarks (
1663
1657
mut connection : Box < dyn Connection > ,
1664
1658
shared : SharedBenchmarkConfig ,
1665
1659
compile : Option < CompileBenchmarkConfig > ,
1666
1660
runtime : Option < RuntimeBenchmarkConfig > ,
1667
1661
) -> 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 ;
1673
1663
1674
- let collector = rt . block_on ( init_collection (
1664
+ let collector = init_collection (
1675
1665
connection. as_mut ( ) ,
1676
1666
& shared,
1677
1667
compile. as_ref ( ) ,
1678
1668
runtime. as_ref ( ) ,
1679
- ) ) ;
1669
+ )
1670
+ . await ;
1680
1671
1681
1672
let start = Instant :: now ( ) ;
1682
1673
1683
1674
// Compile benchmarks
1684
1675
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 ;
1686
1677
errors
1687
1678
. fail_if_nonzero ( )
1688
1679
. context ( "Compile benchmarks failed" )
@@ -1692,30 +1683,32 @@ fn run_benchmarks(
1692
1683
1693
1684
// Runtime benchmarks
1694
1685
let runtime_result = if let Some ( runtime) = runtime {
1695
- rt . block_on ( bench_runtime (
1686
+ bench_runtime (
1696
1687
connection. as_mut ( ) ,
1697
1688
runtime. runtime_suite ,
1698
1689
& collector,
1699
1690
runtime. filter ,
1700
1691
runtime. iterations ,
1701
- ) )
1692
+ )
1693
+ . await
1702
1694
. context ( "Runtime benchmarks failed" )
1703
1695
} else {
1704
1696
Ok ( ( ) )
1705
1697
} ;
1706
1698
1707
1699
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 ;
1709
1703
1710
1704
compile_result. and ( runtime_result)
1711
1705
}
1712
1706
1713
1707
/// Perform benchmarks on a published artifact.
1714
- fn bench_published_artifact (
1708
+ async fn bench_published_artifact (
1715
1709
mut connection : Box < dyn Connection > ,
1716
- rt : & mut Runtime ,
1717
1710
toolchain : Toolchain ,
1718
- dirs : & BenchmarkDirs ,
1711
+ dirs : & BenchmarkDirs < ' _ > ,
1719
1712
) -> anyhow:: Result < ( ) > {
1720
1713
let artifact_id = ArtifactId :: Tag ( toolchain. id . clone ( ) ) ;
1721
1714
@@ -1734,21 +1727,21 @@ fn bench_published_artifact(
1734
1727
let mut compile_benchmarks = get_compile_benchmarks ( dirs. compile , CompileBenchmarkFilter :: All ) ?;
1735
1728
compile_benchmarks. retain ( |b| b. category ( ) . is_stable ( ) ) ;
1736
1729
1737
- let runtime_suite = rt . block_on ( load_runtime_benchmarks (
1730
+ let runtime_suite = load_runtime_benchmarks (
1738
1731
connection. as_mut ( ) ,
1739
1732
dirs. runtime ,
1740
1733
CargoIsolationMode :: Isolated ,
1741
1734
None ,
1742
1735
& toolchain,
1743
1736
& artifact_id,
1744
- ) ) ?;
1737
+ )
1738
+ . await ?;
1745
1739
1746
1740
let shared = SharedBenchmarkConfig {
1747
1741
artifact_id,
1748
1742
toolchain,
1749
1743
} ;
1750
1744
run_benchmarks (
1751
- rt,
1752
1745
connection,
1753
1746
shared,
1754
1747
Some ( CompileBenchmarkConfig {
@@ -1767,6 +1760,7 @@ fn bench_published_artifact(
1767
1760
DEFAULT_RUNTIME_ITERATIONS ,
1768
1761
) ) ,
1769
1762
)
1763
+ . await
1770
1764
}
1771
1765
1772
1766
const 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:
1782
1776
}
1783
1777
1784
1778
/// Perform compile benchmarks.
1785
- fn bench_compile (
1786
- rt : & mut Runtime ,
1779
+ async fn bench_compile (
1787
1780
conn : & mut dyn Connection ,
1788
1781
shared : & SharedBenchmarkConfig ,
1789
1782
config : CompileBenchmarkConfig ,
@@ -1799,51 +1792,63 @@ fn bench_compile(
1799
1792
1800
1793
let start = Instant :: now ( ) ;
1801
1794
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
1826
1830
) ;
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 (
1835
1834
collector. artifact_row_id ,
1836
1835
& benchmark_name. 0 ,
1837
1836
& 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 ;
1842
1839
} ;
1840
+ collector. end_compile_step ( tx. conn ( ) , benchmark_name) . await ;
1841
+ tx. commit ( ) . await . expect ( "committed" ) ;
1842
+ }
1843
1843
1844
1844
// Normal benchmarks.
1845
1845
for ( nth_benchmark, benchmark) in config. benchmarks . iter ( ) . enumerate ( ) {
1846
1846
measure_and_record (
1847
+ collector,
1848
+ shared,
1849
+ & config,
1850
+ & mut errors,
1851
+ conn,
1847
1852
& benchmark. name ,
1848
1853
benchmark. category ( ) ,
1849
1854
& || {
@@ -1852,32 +1857,41 @@ fn bench_compile(
1852
1857
n_normal_benchmarks_remaining( config. benchmarks. len( ) - nth_benchmark)
1853
1858
)
1854
1859
} ,
1855
- & |processor| {
1856
- rt . block_on ( with_timeout ( benchmark. measure (
1860
+ async |processor| {
1861
+ with_timeout ( benchmark. measure (
1857
1862
processor,
1858
1863
& config. profiles ,
1859
1864
& config. scenarios ,
1860
1865
& config. backends ,
1861
1866
& shared. toolchain ,
1862
1867
config. iterations ,
1863
1868
& config. targets ,
1864
- ) ) )
1869
+ ) )
1870
+ . await
1865
1871
. with_context ( || anyhow:: anyhow!( "Cannot compile {}" , benchmark. name) )
1866
1872
} ,
1867
1873
)
1874
+ . await ;
1868
1875
}
1869
1876
1870
1877
// The special rustc benchmark, if requested.
1871
1878
if bench_rustc {
1872
1879
measure_and_record (
1880
+ collector,
1881
+ shared,
1882
+ & config,
1883
+ & mut errors,
1884
+ conn,
1873
1885
& BenchmarkName ( "rustc" . to_string ( ) ) ,
1874
1886
Category :: Primary ,
1875
1887
& || 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
1878
1891
. context ( "measure rustc" )
1879
1892
} ,
1880
- ) ;
1893
+ )
1894
+ . await ;
1881
1895
}
1882
1896
1883
1897
let end = start. elapsed ( ) ;
@@ -1887,10 +1901,8 @@ fn bench_compile(
1887
1901
end, errors. 0
1888
1902
) ;
1889
1903
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 ;
1894
1906
errors
1895
1907
}
1896
1908
@@ -1968,7 +1980,7 @@ fn get_downloaded_crate_target(benchmark_dir: &Path, cmd: &DownloadCommand) -> P
1968
1980
. trim_end_matches ( '/' )
1969
1981
. trim_end_matches ( ".git" )
1970
1982
. split ( '/' )
1971
- . last ( )
1983
+ . next_back ( )
1972
1984
. expect ( "Crate name could not be determined from git URL" )
1973
1985
. to_string ( ) ,
1974
1986
DownloadSubcommand :: Crate { krate, version } => format ! ( "{krate}-{version}" ) ,
0 commit comments