@@ -18,6 +18,16 @@ fn determinism_env(cmd: &mut Command) {
18
18
cmd. env ( "RUSTC_FORCE_RUSTC_VERSION" , "rustc-perf" ) ;
19
19
}
20
20
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
+
21
31
fn main ( ) {
22
32
let mut args_os = env:: args_os ( ) ;
23
33
let name = args_os. next ( ) . unwrap ( ) . into_string ( ) . unwrap ( ) ;
@@ -64,7 +74,6 @@ fn main() {
64
74
match wrapper {
65
75
"PerfStat" | "PerfStatSelfProfile" => {
66
76
let mut cmd = Command :: new ( "perf" ) ;
67
- determinism_env ( & mut cmd) ;
68
77
let has_perf = cmd. output ( ) . is_ok ( ) ;
69
78
assert ! ( has_perf) ;
70
79
cmd. arg ( "stat" )
@@ -94,9 +103,8 @@ fn main() {
94
103
}
95
104
96
105
let start = Instant :: now ( ) ;
97
- let status = cmd . status ( ) . expect ( "failed to spawn" ) ;
106
+ run_with_determinism_env ( cmd ) ;
98
107
let dur = start. elapsed ( ) ;
99
- assert ! ( status. success( ) ) ;
100
108
print_memory ( ) ;
101
109
print_time ( dur) ;
102
110
if wrapper == "PerfStatSelfProfile" {
@@ -147,7 +155,6 @@ fn main() {
147
155
assert ! ( status. success( ) , "tracelog did not complete successfully" ) ;
148
156
149
157
let mut tool = Command :: new ( tool) ;
150
- determinism_env ( & mut tool) ;
151
158
tool. args ( & args) ;
152
159
153
160
let prof_out_dir = std:: env:: current_dir ( ) . unwrap ( ) . join ( "self-profile-output" ) ;
@@ -161,18 +168,14 @@ fn main() {
161
168
}
162
169
163
170
let start = Instant :: now ( ) ;
164
- let status = tool . status ( ) . expect ( " tool failed to start" ) ;
171
+ run_with_determinism_env ( tool) ;
165
172
let dur = start. elapsed ( ) ;
166
- assert ! ( status. success( ) , "tool did not run successfully" ) ;
167
173
println ! ( "!wall-time:{}.{:09}" , dur. as_secs( ) , dur. subsec_nanos( ) ) ;
168
174
169
175
let xperf = |args : & [ & str ] | {
170
176
let mut cmd = Command :: new ( & xperf) ;
171
177
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( ) ) ;
176
179
} ;
177
180
178
181
xperf ( & [ "-stop" , "rustc-perf-counters" ] ) ;
@@ -189,27 +192,26 @@ fn main() {
189
192
190
193
"SelfProfile" => {
191
194
let mut cmd = Command :: new ( & tool) ;
192
- determinism_env ( & mut cmd) ;
193
- cmd . arg ( "-Zself-profile-events=all" ) ;
194
- cmd . arg ( "-Zself-profile=Zsp" ) . args ( & args) ;
195
+ cmd. arg ( "-Zself-profile-events=all" )
196
+ . arg ( "-Zself-profile=Zsp" )
197
+ . args ( & args) ;
195
198
196
- assert ! ( cmd. status ( ) . expect ( "failed to spawn" ) . success ( ) ) ;
199
+ run_with_determinism_env ( cmd) ;
197
200
}
198
201
199
202
"TimePasses" => {
200
- args. insert ( 0 , "-Ztime-passes" . into ( ) ) ;
201
-
202
203
let mut cmd = Command :: new ( & tool) ;
203
- determinism_env ( & mut cmd) ;
204
- cmd. args ( args) . stderr ( std:: process:: Stdio :: from (
205
- std:: fs:: File :: create ( "Ztp" ) . unwrap ( ) ,
206
- ) ) ;
207
- assert ! ( cmd. status( ) . expect( "failed to spawn" ) . success( ) ) ;
204
+ cmd. arg ( "-Ztime-passes" )
205
+ . args ( args)
206
+ . stderr ( std:: process:: Stdio :: from (
207
+ std:: fs:: File :: create ( "Ztp" ) . unwrap ( ) ,
208
+ ) ) ;
209
+
210
+ run_with_determinism_env ( cmd) ;
208
211
}
209
212
210
213
"PerfRecord" => {
211
214
let mut cmd = Command :: new ( "perf" ) ;
212
- determinism_env ( & mut cmd) ;
213
215
let has_perf = cmd. output ( ) . is_ok ( ) ;
214
216
assert ! ( has_perf) ;
215
217
cmd. arg ( "record" )
@@ -220,23 +222,21 @@ fn main() {
220
222
. arg ( & tool)
221
223
. args ( & args) ;
222
224
223
- assert ! ( cmd. status ( ) . expect ( "failed to spawn" ) . success ( ) ) ;
225
+ run_with_determinism_env ( cmd) ;
224
226
}
225
227
226
228
"Oprofile" => {
227
229
let mut cmd = Command :: new ( "operf" ) ;
228
- determinism_env ( & mut cmd) ;
229
230
let has_oprofile = cmd. output ( ) . is_ok ( ) ;
230
231
assert ! ( has_oprofile) ;
231
232
// Other possibly useful args: --callgraph, --separate-thread
232
233
cmd. arg ( "operf" ) . arg ( & tool) . args ( & args) ;
233
234
234
- assert ! ( cmd. status ( ) . expect ( "failed to spawn" ) . success ( ) ) ;
235
+ run_with_determinism_env ( cmd) ;
235
236
}
236
237
237
238
"Cachegrind" => {
238
239
let mut cmd = Command :: new ( "valgrind" ) ;
239
- determinism_env ( & mut cmd) ;
240
240
let has_valgrind = cmd. output ( ) . is_ok ( ) ;
241
241
assert ! ( has_valgrind) ;
242
242
@@ -256,12 +256,11 @@ fn main() {
256
256
. arg ( & tool)
257
257
. args ( & args) ;
258
258
259
- assert ! ( cmd. status ( ) . expect ( "failed to spawn" ) . success ( ) ) ;
259
+ run_with_determinism_env ( cmd) ;
260
260
}
261
261
262
262
"Callgrind" => {
263
263
let mut cmd = Command :: new ( "valgrind" ) ;
264
- determinism_env ( & mut cmd) ;
265
264
let has_valgrind = cmd. output ( ) . is_ok ( ) ;
266
265
assert ! ( has_valgrind) ;
267
266
@@ -274,12 +273,11 @@ fn main() {
274
273
. arg ( & tool)
275
274
. args ( & args) ;
276
275
277
- assert ! ( cmd. status ( ) . expect ( "failed to spawn" ) . success ( ) ) ;
276
+ run_with_determinism_env ( cmd) ;
278
277
}
279
278
280
279
"Dhat" => {
281
280
let mut cmd = Command :: new ( "valgrind" ) ;
282
- determinism_env ( & mut cmd) ;
283
281
let has_valgrind = cmd. output ( ) . is_ok ( ) ;
284
282
assert ! ( has_valgrind) ;
285
283
cmd. arg ( "--tool=dhat" )
@@ -288,12 +286,11 @@ fn main() {
288
286
. arg ( & tool)
289
287
. args ( & args) ;
290
288
291
- assert ! ( cmd. status ( ) . expect ( "failed to spawn" ) . success ( ) ) ;
289
+ run_with_determinism_env ( cmd) ;
292
290
}
293
291
294
292
"DhatCopy" => {
295
293
let mut cmd = Command :: new ( "valgrind" ) ;
296
- determinism_env ( & mut cmd) ;
297
294
let has_valgrind = cmd. output ( ) . is_ok ( ) ;
298
295
assert ! ( has_valgrind) ;
299
296
cmd. arg ( "--tool=dhat" )
@@ -303,12 +300,11 @@ fn main() {
303
300
. arg ( & tool)
304
301
. args ( & args) ;
305
302
306
- assert ! ( cmd. status ( ) . expect ( "failed to spawn" ) . success ( ) ) ;
303
+ run_with_determinism_env ( cmd) ;
307
304
}
308
305
309
306
"Massif" => {
310
307
let mut cmd = Command :: new ( "valgrind" ) ;
311
- determinism_env ( & mut cmd) ;
312
308
let has_valgrind = cmd. output ( ) . is_ok ( ) ;
313
309
assert ! ( has_valgrind) ;
314
310
cmd. arg ( "--tool=massif" )
@@ -320,14 +316,16 @@ fn main() {
320
316
. arg ( & tool)
321
317
. args ( & args) ;
322
318
323
- assert ! ( cmd. status ( ) . expect ( "failed to spawn" ) . success ( ) ) ;
319
+ run_with_determinism_env ( cmd) ;
324
320
}
325
321
326
322
"Eprintln" => {
327
- let mut cmd = bash_command ( tool, args, "2> eprintln" ) ;
328
- determinism_env ( & mut cmd) ;
323
+ let mut cmd = Command :: new ( tool) ;
324
+ cmd. args ( args) . stderr ( std:: process:: Stdio :: from (
325
+ std:: fs:: File :: create ( "eprintln" ) . unwrap ( ) ,
326
+ ) ) ;
329
327
330
- assert ! ( cmd. status ( ) . expect ( "failed to spawn" ) . success ( ) ) ;
328
+ run_with_determinism_env ( cmd) ;
331
329
}
332
330
333
331
"LlvmLines" => {
@@ -339,40 +337,41 @@ fn main() {
339
337
// `rustc` (which this file wraps) doesn't produce the output,
340
338
// this file can't redirect that output.
341
339
let mut cmd = Command :: new ( & tool) ;
342
- determinism_env ( & mut cmd) ;
343
340
cmd. args ( & args) ;
344
341
345
- assert ! ( cmd. status ( ) . expect ( "failed to spawn" ) . success ( ) ) ;
342
+ run_with_determinism_env ( cmd) ;
346
343
}
347
344
348
345
"LlvmIr" => {
349
- args. push ( "--emit=llvm-ir=./llvm-ir" . into ( ) ) ;
350
- args. push ( "-Cno-prepopulate-passes" . into ( ) ) ;
351
- args. push ( "-Cpasses=name-anon-globals" . into ( ) ) ;
352
346
let mut cmd = Command :: new ( tool) ;
353
- cmd. args ( args) ;
354
- determinism_env ( & mut cmd) ;
355
- assert ! ( cmd. status( ) . expect( "failed to spawn" ) . success( ) ) ;
347
+ cmd. arg ( "--emit=llvm-ir=./llvm-ir" )
348
+ . arg ( "-Cno-prepopulate-passes" )
349
+ . arg ( "-Cpasses=name-anon-globals" )
350
+ . args ( args) ;
351
+
352
+ run_with_determinism_env ( cmd) ;
356
353
}
357
354
358
355
"MonoItems" => {
359
356
// Lazy item collection is the default (i.e., without this
360
357
// option)
361
- args. push ( "-Zprint-mono-items=lazy" . into ( ) ) ;
362
- let mut cmd = bash_command ( tool, args, "1> mono-items" ) ;
363
- determinism_env ( & mut cmd) ;
358
+ let mut cmd = Command :: new ( tool) ;
359
+ cmd. arg ( "-Zprint-mono-items=lazy" )
360
+ . args ( args)
361
+ . stdout ( std:: process:: Stdio :: from (
362
+ std:: fs:: File :: create ( "mono-items" ) . unwrap ( ) ,
363
+ ) ) ;
364
364
365
- assert ! ( cmd. status ( ) . expect ( "failed to spawn" ) . success ( ) ) ;
365
+ run_with_determinism_env ( cmd) ;
366
366
}
367
367
368
368
"DepGraph" => {
369
- args. push ( "-Zdump-dep-graph" . into ( ) ) ;
370
- args. push ( "-Zquery-dep-graph" . into ( ) ) ;
371
369
let mut cmd = Command :: new ( tool) ;
372
- determinism_env ( & mut cmd) ;
373
- cmd. args ( & args) ;
370
+ cmd. arg ( "-Zdump-dep-graph" )
371
+ . arg ( "-Zquery-dep-graph" )
372
+ . args ( & args) ;
374
373
375
- assert ! ( cmd. status ( ) . expect ( "failed to spawn" ) . success ( ) ) ;
374
+ run_with_determinism_env ( cmd) ;
376
375
}
377
376
378
377
_ => {
@@ -459,24 +458,6 @@ fn process_self_profile_output(prof_out_dir: PathBuf, args: &[OsString]) {
459
458
}
460
459
}
461
460
462
- /// Run a command via bash, in order to redirect its output to a file.
463
- /// `redirect` should be something like "> out" or "2> out".
464
- fn bash_command ( tool : OsString , args : Vec < OsString > , redirect : & str ) -> Command {
465
- let mut bash_cmd = String :: new ( ) ;
466
- bash_cmd. push_str ( & format ! ( "{} " , tool. to_str( ) . unwrap( ) ) ) ;
467
- for arg in args {
468
- // Args with double quotes (e.g. `--cfg feature="foo"`)
469
- // will be munged by bash if we don't protect them. So we
470
- // wrap every arg in single quotes.
471
- bash_cmd. push_str ( & format ! ( "'{}' " , arg. to_str( ) . unwrap( ) ) ) ;
472
- }
473
- bash_cmd. push_str ( redirect) ;
474
-
475
- let mut cmd = Command :: new ( "bash" ) ;
476
- cmd. args ( & [ "-c" , & bash_cmd] ) ;
477
- cmd
478
- }
479
-
480
461
#[ cfg( windows) ]
481
462
fn exec ( cmd : & mut Command ) {
482
463
let cmd_d = format ! ( "{:?}" , cmd) ;
0 commit comments