@@ -18,6 +18,16 @@ fn determinism_env(cmd: &mut Command) {
1818 cmd. env ( "RUSTC_FORCE_RUSTC_VERSION" , "rustc-perf" ) ;
1919}
2020
21+ fn run_with_determinism_env ( mut cmd : Command ) {
22+ determinism_env ( & mut cmd) ;
23+ let status = cmd. status ( ) . expect ( "failed to spawn" ) ;
24+ assert ! (
25+ status. success( ) ,
26+ "command did not complete successfully: {:?}" ,
27+ cmd
28+ ) ;
29+ }
30+
2131fn main ( ) {
2232 let mut args_os = env:: args_os ( ) ;
2333 let name = args_os. next ( ) . unwrap ( ) . into_string ( ) . unwrap ( ) ;
@@ -64,7 +74,6 @@ fn main() {
6474 match wrapper {
6575 "PerfStat" | "PerfStatSelfProfile" => {
6676 let mut cmd = Command :: new ( "perf" ) ;
67- determinism_env ( & mut cmd) ;
6877 let has_perf = cmd. output ( ) . is_ok ( ) ;
6978 assert ! ( has_perf) ;
7079 cmd. arg ( "stat" )
@@ -94,9 +103,8 @@ fn main() {
94103 }
95104
96105 let start = Instant :: now ( ) ;
97- let status = cmd . status ( ) . expect ( "failed to spawn" ) ;
106+ run_with_determinism_env ( cmd ) ;
98107 let dur = start. elapsed ( ) ;
99- assert ! ( status. success( ) ) ;
100108 print_memory ( ) ;
101109 print_time ( dur) ;
102110 if wrapper == "PerfStatSelfProfile" {
@@ -147,7 +155,6 @@ fn main() {
147155 assert ! ( status. success( ) , "tracelog did not complete successfully" ) ;
148156
149157 let mut tool = Command :: new ( tool) ;
150- determinism_env ( & mut tool) ;
151158 tool. args ( & args) ;
152159
153160 let prof_out_dir = std:: env:: current_dir ( ) . unwrap ( ) . join ( "self-profile-output" ) ;
@@ -161,18 +168,14 @@ fn main() {
161168 }
162169
163170 let start = Instant :: now ( ) ;
164- let status = tool . status ( ) . expect ( " tool failed to start" ) ;
171+ run_with_determinism_env ( tool) ;
165172 let dur = start. elapsed ( ) ;
166- assert ! ( status. success( ) , "tool did not run successfully" ) ;
167173 println ! ( "!wall-time:{}.{:09}" , dur. as_secs( ) , dur. subsec_nanos( ) ) ;
168174
169175 let xperf = |args : & [ & str ] | {
170176 let mut cmd = Command :: new ( & xperf) ;
171177 cmd. args ( args) ;
172- assert ! (
173- cmd. status( ) . expect( "failed to spawn xperf" ) . success( ) ,
174- "xperf did not complete successfully"
175- ) ;
178+ assert ! ( cmd. status( ) . expect( "failed to spawn xperf" ) . success( ) ) ;
176179 } ;
177180
178181 xperf ( & [ "-stop" , "rustc-perf-counters" ] ) ;
@@ -189,28 +192,26 @@ fn main() {
189192
190193 "SelfProfile" => {
191194 let mut cmd = Command :: new ( & tool) ;
192- determinism_env ( & mut cmd) ;
193195 cmd. arg ( "-Zself-profile-events=all" )
194196 . arg ( "-Zself-profile=Zsp" )
195197 . args ( & args) ;
196198
197- assert ! ( cmd. status ( ) . expect ( "failed to spawn" ) . success ( ) ) ;
199+ run_with_determinism_env ( cmd) ;
198200 }
199201
200202 "TimePasses" => {
201203 let mut cmd = Command :: new ( & tool) ;
202- determinism_env ( & mut cmd) ;
203204 cmd. arg ( "-Ztime-passes" )
204205 . args ( args)
205206 . stderr ( std:: process:: Stdio :: from (
206207 std:: fs:: File :: create ( "Ztp" ) . unwrap ( ) ,
207208 ) ) ;
208- assert ! ( cmd. status( ) . expect( "failed to spawn" ) . success( ) ) ;
209+
210+ run_with_determinism_env ( cmd) ;
209211 }
210212
211213 "PerfRecord" => {
212214 let mut cmd = Command :: new ( "perf" ) ;
213- determinism_env ( & mut cmd) ;
214215 let has_perf = cmd. output ( ) . is_ok ( ) ;
215216 assert ! ( has_perf) ;
216217 cmd. arg ( "record" )
@@ -221,23 +222,21 @@ fn main() {
221222 . arg ( & tool)
222223 . args ( & args) ;
223224
224- assert ! ( cmd. status ( ) . expect ( "failed to spawn" ) . success ( ) ) ;
225+ run_with_determinism_env ( cmd) ;
225226 }
226227
227228 "Oprofile" => {
228229 let mut cmd = Command :: new ( "operf" ) ;
229- determinism_env ( & mut cmd) ;
230230 let has_oprofile = cmd. output ( ) . is_ok ( ) ;
231231 assert ! ( has_oprofile) ;
232232 // Other possibly useful args: --callgraph, --separate-thread
233233 cmd. arg ( "operf" ) . arg ( & tool) . args ( & args) ;
234234
235- assert ! ( cmd. status ( ) . expect ( "failed to spawn" ) . success ( ) ) ;
235+ run_with_determinism_env ( cmd) ;
236236 }
237237
238238 "Cachegrind" => {
239239 let mut cmd = Command :: new ( "valgrind" ) ;
240- determinism_env ( & mut cmd) ;
241240 let has_valgrind = cmd. output ( ) . is_ok ( ) ;
242241 assert ! ( has_valgrind) ;
243242
@@ -257,12 +256,11 @@ fn main() {
257256 . arg ( & tool)
258257 . args ( & args) ;
259258
260- assert ! ( cmd. status ( ) . expect ( "failed to spawn" ) . success ( ) ) ;
259+ run_with_determinism_env ( cmd) ;
261260 }
262261
263262 "Callgrind" => {
264263 let mut cmd = Command :: new ( "valgrind" ) ;
265- determinism_env ( & mut cmd) ;
266264 let has_valgrind = cmd. output ( ) . is_ok ( ) ;
267265 assert ! ( has_valgrind) ;
268266
@@ -275,12 +273,11 @@ fn main() {
275273 . arg ( & tool)
276274 . args ( & args) ;
277275
278- assert ! ( cmd. status ( ) . expect ( "failed to spawn" ) . success ( ) ) ;
276+ run_with_determinism_env ( cmd) ;
279277 }
280278
281279 "Dhat" => {
282280 let mut cmd = Command :: new ( "valgrind" ) ;
283- determinism_env ( & mut cmd) ;
284281 let has_valgrind = cmd. output ( ) . is_ok ( ) ;
285282 assert ! ( has_valgrind) ;
286283 cmd. arg ( "--tool=dhat" )
@@ -289,12 +286,11 @@ fn main() {
289286 . arg ( & tool)
290287 . args ( & args) ;
291288
292- assert ! ( cmd. status ( ) . expect ( "failed to spawn" ) . success ( ) ) ;
289+ run_with_determinism_env ( cmd) ;
293290 }
294291
295292 "DhatCopy" => {
296293 let mut cmd = Command :: new ( "valgrind" ) ;
297- determinism_env ( & mut cmd) ;
298294 let has_valgrind = cmd. output ( ) . is_ok ( ) ;
299295 assert ! ( has_valgrind) ;
300296 cmd. arg ( "--tool=dhat" )
@@ -304,12 +300,11 @@ fn main() {
304300 . arg ( & tool)
305301 . args ( & args) ;
306302
307- assert ! ( cmd. status ( ) . expect ( "failed to spawn" ) . success ( ) ) ;
303+ run_with_determinism_env ( cmd) ;
308304 }
309305
310306 "Massif" => {
311307 let mut cmd = Command :: new ( "valgrind" ) ;
312- determinism_env ( & mut cmd) ;
313308 let has_valgrind = cmd. output ( ) . is_ok ( ) ;
314309 assert ! ( has_valgrind) ;
315310 cmd. arg ( "--tool=massif" )
@@ -321,17 +316,16 @@ fn main() {
321316 . arg ( & tool)
322317 . args ( & args) ;
323318
324- assert ! ( cmd. status ( ) . expect ( "failed to spawn" ) . success ( ) ) ;
319+ run_with_determinism_env ( cmd) ;
325320 }
326321
327322 "Eprintln" => {
328323 let mut cmd = Command :: new ( tool) ;
329- determinism_env ( & mut cmd) ;
330324 cmd. args ( args) . stderr ( std:: process:: Stdio :: from (
331325 std:: fs:: File :: create ( "eprintln" ) . unwrap ( ) ,
332326 ) ) ;
333327
334- assert ! ( cmd. status ( ) . expect ( "failed to spawn" ) . success ( ) ) ;
328+ run_with_determinism_env ( cmd) ;
335329 }
336330
337331 "LlvmLines" => {
@@ -343,10 +337,9 @@ fn main() {
343337 // `rustc` (which this file wraps) doesn't produce the output,
344338 // this file can't redirect that output.
345339 let mut cmd = Command :: new ( & tool) ;
346- determinism_env ( & mut cmd) ;
347340 cmd. args ( & args) ;
348341
349- assert ! ( cmd. status ( ) . expect ( "failed to spawn" ) . success ( ) ) ;
342+ run_with_determinism_env ( cmd) ;
350343 }
351344
352345 "LlvmIr" => {
@@ -355,32 +348,30 @@ fn main() {
355348 . arg ( "-Cno-prepopulate-passes" )
356349 . arg ( "-Cpasses=name-anon-globals" )
357350 . args ( args) ;
358- determinism_env ( & mut cmd ) ;
359- assert ! ( cmd. status ( ) . expect ( "failed to spawn" ) . success ( ) ) ;
351+
352+ run_with_determinism_env ( cmd) ;
360353 }
361354
362355 "MonoItems" => {
363356 // Lazy item collection is the default (i.e., without this
364357 // option)
365358 let mut cmd = Command :: new ( tool) ;
366- determinism_env ( & mut cmd) ;
367359 cmd. arg ( "-Zprint-mono-items=lazy" )
368360 . args ( args)
369361 . stdout ( std:: process:: Stdio :: from (
370362 std:: fs:: File :: create ( "mono-items" ) . unwrap ( ) ,
371363 ) ) ;
372364
373- assert ! ( cmd. status ( ) . expect ( "failed to spawn" ) . success ( ) ) ;
365+ run_with_determinism_env ( cmd) ;
374366 }
375367
376368 "DepGraph" => {
377369 let mut cmd = Command :: new ( tool) ;
378- determinism_env ( & mut cmd) ;
379370 cmd. arg ( "-Zdump-dep-graph" )
380371 . arg ( "-Zquery-dep-graph" )
381372 . args ( & args) ;
382373
383- assert ! ( cmd. status ( ) . expect ( "failed to spawn" ) . success ( ) ) ;
374+ run_with_determinism_env ( cmd) ;
384375 }
385376
386377 _ => {
0 commit comments