@@ -10,10 +10,11 @@ use crate::toolchain::Toolchain;
10
10
use crate :: utils:: git:: get_rustc_perf_commit;
11
11
use futures:: stream:: FuturesUnordered ;
12
12
use futures:: StreamExt ;
13
+ use std:: future:: Future ;
13
14
use std:: path:: PathBuf ;
15
+ use std:: pin:: Pin ;
14
16
use std:: process:: Command ;
15
17
use std:: { env, process} ;
16
- use tokio:: runtime:: Runtime ;
17
18
18
19
// Tools usable with the benchmarking subcommands.
19
20
#[ derive( Clone , Copy , Debug , PartialEq ) ]
@@ -25,7 +26,6 @@ pub enum Bencher {
25
26
}
26
27
27
28
pub struct BenchProcessor < ' a > {
28
- rt : & ' a mut Runtime ,
29
29
benchmark : & ' a BenchmarkName ,
30
30
conn : & ' a mut dyn database:: Connection ,
31
31
artifact : & ' a database:: ArtifactId ,
@@ -38,7 +38,6 @@ pub struct BenchProcessor<'a> {
38
38
39
39
impl < ' a > BenchProcessor < ' a > {
40
40
pub fn new (
41
- rt : & ' a mut Runtime ,
42
41
conn : & ' a mut dyn database:: Connection ,
43
42
benchmark : & ' a BenchmarkName ,
44
43
artifact : & ' a database:: ArtifactId ,
@@ -63,7 +62,6 @@ impl<'a> BenchProcessor<'a> {
63
62
}
64
63
65
64
BenchProcessor {
66
- rt,
67
65
upload : None ,
68
66
conn,
69
67
benchmark,
@@ -75,15 +73,15 @@ impl<'a> BenchProcessor<'a> {
75
73
}
76
74
}
77
75
78
- fn insert_stats (
76
+ async fn insert_stats (
79
77
& mut self ,
80
78
scenario : database:: Scenario ,
81
79
profile : Profile ,
82
80
stats : ( Stats , Option < SelfProfile > , Option < SelfProfileFiles > ) ,
83
81
) {
84
82
let version = get_rustc_perf_commit ( ) ;
85
83
86
- let collection = self . rt . block_on ( self . conn . collection_id ( & version) ) ;
84
+ let collection = self . conn . collection_id ( & version) . await ;
87
85
let profile = match profile {
88
86
Profile :: Check => database:: Profile :: Check ,
89
87
Profile :: Debug => database:: Profile :: Debug ,
@@ -110,13 +108,15 @@ impl<'a> BenchProcessor<'a> {
110
108
. join ( profile. to_string ( ) )
111
109
. join ( scenario. to_id ( ) ) ;
112
110
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 ;
120
120
}
121
121
}
122
122
@@ -156,18 +156,11 @@ impl<'a> BenchProcessor<'a> {
156
156
}
157
157
}
158
158
159
- self . rt
160
- . block_on ( async move { while let Some ( ( ) ) = buf. next ( ) . await { } } ) ;
159
+ while let Some ( ( ) ) = buf. next ( ) . await { }
161
160
}
162
161
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
171
164
}
172
165
}
173
166
@@ -197,63 +190,70 @@ impl<'a> Processor for BenchProcessor<'a> {
197
190
self . perf_tool ( ) != original
198
191
}
199
192
200
- fn process_output (
201
- & mut self ,
202
- data : & ProcessOutputData < ' _ > ,
193
+ fn process_output < ' b > (
194
+ & ' b mut self ,
195
+ data : & ' b ProcessOutputData < ' _ > ,
203
196
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) ;
220
203
}
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
+ }
223
209
}
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 ,
231
222
data. profile ,
232
223
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
233
243
) ;
244
+ self . tries += 1 ;
245
+ Ok ( Retry :: Yes )
246
+ } else {
247
+ panic ! ( "failed to collect statistics after 5 tries" ) ;
234
248
}
235
249
}
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) ;
249
255
}
250
256
}
251
- Err (
252
- e
253
- @ ( DeserializeStatError :: ParseError { .. } | DeserializeStatError :: XperfError ( ..) ) ,
254
- ) => {
255
- panic ! ( "process_perf_stat_output failed: {:?}" , e) ;
256
- }
257
- }
257
+ } )
258
258
}
259
259
}
0 commit comments