@@ -10,10 +10,11 @@ use crate::toolchain::Toolchain;
1010use crate :: utils:: git:: get_rustc_perf_commit;
1111use futures:: stream:: FuturesUnordered ;
1212use futures:: StreamExt ;
13+ use std:: future:: Future ;
1314use std:: path:: PathBuf ;
15+ use std:: pin:: Pin ;
1416use std:: process:: Command ;
1517use std:: { env, process} ;
16- use tokio:: runtime:: Runtime ;
1718
1819// Tools usable with the benchmarking subcommands.
1920#[ derive( Clone , Copy , Debug , PartialEq ) ]
@@ -25,7 +26,6 @@ pub enum Bencher {
2526}
2627
2728pub struct BenchProcessor < ' a > {
28- rt : & ' a mut Runtime ,
2929 benchmark : & ' a BenchmarkName ,
3030 conn : & ' a mut dyn database:: Connection ,
3131 artifact : & ' a database:: ArtifactId ,
@@ -38,7 +38,6 @@ pub struct BenchProcessor<'a> {
3838
3939impl < ' a > BenchProcessor < ' a > {
4040 pub fn new (
41- rt : & ' a mut Runtime ,
4241 conn : & ' a mut dyn database:: Connection ,
4342 benchmark : & ' a BenchmarkName ,
4443 artifact : & ' a database:: ArtifactId ,
@@ -63,7 +62,6 @@ impl<'a> BenchProcessor<'a> {
6362 }
6463
6564 BenchProcessor {
66- rt,
6765 upload : None ,
6866 conn,
6967 benchmark,
@@ -75,15 +73,15 @@ impl<'a> BenchProcessor<'a> {
7573 }
7674 }
7775
78- fn insert_stats (
76+ async fn insert_stats (
7977 & mut self ,
8078 scenario : database:: Scenario ,
8179 profile : Profile ,
8280 stats : ( Stats , Option < SelfProfile > , Option < SelfProfileFiles > ) ,
8381 ) {
8482 let version = get_rustc_perf_commit ( ) ;
8583
86- let collection = self . rt . block_on ( self . conn . collection_id ( & version) ) ;
84+ let collection = self . conn . collection_id ( & version) . await ;
8785 let profile = match profile {
8886 Profile :: Check => database:: Profile :: Check ,
8987 Profile :: Debug => database:: Profile :: Debug ,
@@ -110,13 +108,15 @@ impl<'a> BenchProcessor<'a> {
110108 . join ( profile. to_string ( ) )
111109 . join ( scenario. to_id ( ) ) ;
112110 self . upload = Some ( Upload :: new ( prefix, collection, files) ) ;
113- self . rt . block_on ( self . conn . record_raw_self_profile (
114- collection,
115- self . artifact_row_id ,
116- self . benchmark . 0 . as_str ( ) ,
117- profile,
118- scenario,
119- ) ) ;
111+ self . conn
112+ . record_raw_self_profile (
113+ collection,
114+ self . artifact_row_id ,
115+ self . benchmark . 0 . as_str ( ) ,
116+ profile,
117+ scenario,
118+ )
119+ . await ;
120120 }
121121 }
122122
@@ -156,18 +156,11 @@ impl<'a> BenchProcessor<'a> {
156156 }
157157 }
158158
159- self . rt
160- . block_on ( async move { while let Some ( ( ) ) = buf. next ( ) . await { } } ) ;
159+ while let Some ( ( ) ) = buf. next ( ) . await { }
161160 }
162161
163- pub fn measure_rustc ( & mut self , toolchain : & Toolchain ) -> anyhow:: Result < ( ) > {
164- rustc:: measure (
165- self . rt ,
166- self . conn ,
167- toolchain,
168- self . artifact ,
169- self . artifact_row_id ,
170- )
162+ pub async fn measure_rustc ( & mut self , toolchain : & Toolchain ) -> anyhow:: Result < ( ) > {
163+ rustc:: measure ( self . conn , toolchain, self . artifact , self . artifact_row_id ) . await
171164 }
172165}
173166
@@ -197,63 +190,70 @@ impl<'a> Processor for BenchProcessor<'a> {
197190 self . perf_tool ( ) != original
198191 }
199192
200- fn process_output (
201- & mut self ,
202- data : & ProcessOutputData < ' _ > ,
193+ fn process_output < ' b > (
194+ & ' b mut self ,
195+ data : & ' b ProcessOutputData < ' _ > ,
203196 output : process:: Output ,
204- ) -> anyhow:: Result < Retry > {
205- match execute:: process_stat_output ( output) {
206- Ok ( mut res) => {
207- if let Some ( ref profile) = res. 1 {
208- execute:: store_artifact_sizes_into_stats ( & mut res. 0 , profile) ;
209- }
210- if let Profile :: Doc = data. profile {
211- let doc_dir = data. cwd . join ( "target/doc" ) ;
212- if doc_dir. is_dir ( ) {
213- execute:: store_documentation_size_into_stats ( & mut res. 0 , & doc_dir) ;
214- }
215- }
216-
217- match data. scenario {
218- Scenario :: Full => {
219- self . insert_stats ( database:: Scenario :: Empty , data. profile , res) ;
197+ ) -> Pin < Box < dyn Future < Output = anyhow:: Result < Retry > > + ' b > > {
198+ Box :: pin ( async move {
199+ match execute:: process_stat_output ( output) {
200+ Ok ( mut res) => {
201+ if let Some ( ref profile) = res. 1 {
202+ execute:: store_artifact_sizes_into_stats ( & mut res. 0 , profile) ;
220203 }
221- Scenario :: IncrFull => {
222- self . insert_stats ( database:: Scenario :: IncrementalEmpty , data. profile , res) ;
204+ if let Profile :: Doc = data. profile {
205+ let doc_dir = data. cwd . join ( "target/doc" ) ;
206+ if doc_dir. is_dir ( ) {
207+ execute:: store_documentation_size_into_stats ( & mut res. 0 , & doc_dir) ;
208+ }
223209 }
224- Scenario :: IncrUnchanged => {
225- self . insert_stats ( database:: Scenario :: IncrementalFresh , data. profile , res) ;
226- }
227- Scenario :: IncrPatched => {
228- let patch = data. patch . unwrap ( ) ;
229- self . insert_stats (
230- database:: Scenario :: IncrementalPatch ( patch. name ) ,
210+
211+ let fut = match data. scenario {
212+ Scenario :: Full => {
213+ self . insert_stats ( database:: Scenario :: Empty , data. profile , res)
214+ }
215+ Scenario :: IncrFull => self . insert_stats (
216+ database:: Scenario :: IncrementalEmpty ,
217+ data. profile ,
218+ res,
219+ ) ,
220+ Scenario :: IncrUnchanged => self . insert_stats (
221+ database:: Scenario :: IncrementalFresh ,
231222 data. profile ,
232223 res,
224+ ) ,
225+ Scenario :: IncrPatched => {
226+ let patch = data. patch . unwrap ( ) ;
227+ self . insert_stats (
228+ database:: Scenario :: IncrementalPatch ( patch. name ) ,
229+ data. profile ,
230+ res,
231+ )
232+ }
233+ } ;
234+ fut. await ;
235+ Ok ( Retry :: No )
236+ }
237+ Err ( DeserializeStatError :: NoOutput ( output) ) => {
238+ if self . tries < 5 {
239+ log:: warn!(
240+ "failed to deserialize stats, retrying (try {}); output: {:?}" ,
241+ self . tries,
242+ output
233243 ) ;
244+ self . tries += 1 ;
245+ Ok ( Retry :: Yes )
246+ } else {
247+ panic ! ( "failed to collect statistics after 5 tries" ) ;
234248 }
235249 }
236- Ok ( Retry :: No )
237- }
238- Err ( DeserializeStatError :: NoOutput ( output) ) => {
239- if self . tries < 5 {
240- log:: warn!(
241- "failed to deserialize stats, retrying (try {}); output: {:?}" ,
242- self . tries,
243- output
244- ) ;
245- self . tries += 1 ;
246- Ok ( Retry :: Yes )
247- } else {
248- panic ! ( "failed to collect statistics after 5 tries" ) ;
250+ Err (
251+ e @ ( DeserializeStatError :: ParseError { .. }
252+ | DeserializeStatError :: XperfError ( ..) ) ,
253+ ) => {
254+ panic ! ( "process_perf_stat_output failed: {:?}" , e) ;
249255 }
250256 }
251- Err (
252- e
253- @ ( DeserializeStatError :: ParseError { .. } | DeserializeStatError :: XperfError ( ..) ) ,
254- ) => {
255- panic ! ( "process_perf_stat_output failed: {:?}" , e) ;
256- }
257- }
257+ } )
258258 }
259259}
0 commit comments