@@ -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,28 +192,26 @@ fn main() {
189
192
190
193
"SelfProfile" => {
191
194
let mut cmd = Command :: new ( & tool) ;
192
- determinism_env ( & mut cmd) ;
193
195
cmd. arg ( "-Zself-profile-events=all" )
194
196
. arg ( "-Zself-profile=Zsp" )
195
197
. args ( & args) ;
196
198
197
- assert ! ( cmd. status ( ) . expect ( "failed to spawn" ) . success ( ) ) ;
199
+ run_with_determinism_env ( cmd) ;
198
200
}
199
201
200
202
"TimePasses" => {
201
203
let mut cmd = Command :: new ( & tool) ;
202
- determinism_env ( & mut cmd) ;
203
204
cmd. arg ( "-Ztime-passes" )
204
205
. args ( args)
205
206
. stderr ( std:: process:: Stdio :: from (
206
207
std:: fs:: File :: create ( "Ztp" ) . unwrap ( ) ,
207
208
) ) ;
208
- assert ! ( cmd. status( ) . expect( "failed to spawn" ) . success( ) ) ;
209
+
210
+ run_with_determinism_env ( cmd) ;
209
211
}
210
212
211
213
"PerfRecord" => {
212
214
let mut cmd = Command :: new ( "perf" ) ;
213
- determinism_env ( & mut cmd) ;
214
215
let has_perf = cmd. output ( ) . is_ok ( ) ;
215
216
assert ! ( has_perf) ;
216
217
cmd. arg ( "record" )
@@ -221,23 +222,21 @@ fn main() {
221
222
. arg ( & tool)
222
223
. args ( & args) ;
223
224
224
- assert ! ( cmd. status ( ) . expect ( "failed to spawn" ) . success ( ) ) ;
225
+ run_with_determinism_env ( cmd) ;
225
226
}
226
227
227
228
"Oprofile" => {
228
229
let mut cmd = Command :: new ( "operf" ) ;
229
- determinism_env ( & mut cmd) ;
230
230
let has_oprofile = cmd. output ( ) . is_ok ( ) ;
231
231
assert ! ( has_oprofile) ;
232
232
// Other possibly useful args: --callgraph, --separate-thread
233
233
cmd. arg ( "operf" ) . arg ( & tool) . args ( & args) ;
234
234
235
- assert ! ( cmd. status ( ) . expect ( "failed to spawn" ) . success ( ) ) ;
235
+ run_with_determinism_env ( cmd) ;
236
236
}
237
237
238
238
"Cachegrind" => {
239
239
let mut cmd = Command :: new ( "valgrind" ) ;
240
- determinism_env ( & mut cmd) ;
241
240
let has_valgrind = cmd. output ( ) . is_ok ( ) ;
242
241
assert ! ( has_valgrind) ;
243
242
@@ -257,12 +256,11 @@ fn main() {
257
256
. arg ( & tool)
258
257
. args ( & args) ;
259
258
260
- assert ! ( cmd. status ( ) . expect ( "failed to spawn" ) . success ( ) ) ;
259
+ run_with_determinism_env ( cmd) ;
261
260
}
262
261
263
262
"Callgrind" => {
264
263
let mut cmd = Command :: new ( "valgrind" ) ;
265
- determinism_env ( & mut cmd) ;
266
264
let has_valgrind = cmd. output ( ) . is_ok ( ) ;
267
265
assert ! ( has_valgrind) ;
268
266
@@ -275,12 +273,11 @@ fn main() {
275
273
. arg ( & tool)
276
274
. args ( & args) ;
277
275
278
- assert ! ( cmd. status ( ) . expect ( "failed to spawn" ) . success ( ) ) ;
276
+ run_with_determinism_env ( cmd) ;
279
277
}
280
278
281
279
"Dhat" => {
282
280
let mut cmd = Command :: new ( "valgrind" ) ;
283
- determinism_env ( & mut cmd) ;
284
281
let has_valgrind = cmd. output ( ) . is_ok ( ) ;
285
282
assert ! ( has_valgrind) ;
286
283
cmd. arg ( "--tool=dhat" )
@@ -289,12 +286,11 @@ fn main() {
289
286
. arg ( & tool)
290
287
. args ( & args) ;
291
288
292
- assert ! ( cmd. status ( ) . expect ( "failed to spawn" ) . success ( ) ) ;
289
+ run_with_determinism_env ( cmd) ;
293
290
}
294
291
295
292
"DhatCopy" => {
296
293
let mut cmd = Command :: new ( "valgrind" ) ;
297
- determinism_env ( & mut cmd) ;
298
294
let has_valgrind = cmd. output ( ) . is_ok ( ) ;
299
295
assert ! ( has_valgrind) ;
300
296
cmd. arg ( "--tool=dhat" )
@@ -304,12 +300,11 @@ fn main() {
304
300
. arg ( & tool)
305
301
. args ( & args) ;
306
302
307
- assert ! ( cmd. status ( ) . expect ( "failed to spawn" ) . success ( ) ) ;
303
+ run_with_determinism_env ( cmd) ;
308
304
}
309
305
310
306
"Massif" => {
311
307
let mut cmd = Command :: new ( "valgrind" ) ;
312
- determinism_env ( & mut cmd) ;
313
308
let has_valgrind = cmd. output ( ) . is_ok ( ) ;
314
309
assert ! ( has_valgrind) ;
315
310
cmd. arg ( "--tool=massif" )
@@ -321,17 +316,16 @@ fn main() {
321
316
. arg ( & tool)
322
317
. args ( & args) ;
323
318
324
- assert ! ( cmd. status ( ) . expect ( "failed to spawn" ) . success ( ) ) ;
319
+ run_with_determinism_env ( cmd) ;
325
320
}
326
321
327
322
"Eprintln" => {
328
323
let mut cmd = Command :: new ( tool) ;
329
- determinism_env ( & mut cmd) ;
330
324
cmd. args ( args) . stderr ( std:: process:: Stdio :: from (
331
325
std:: fs:: File :: create ( "eprintln" ) . unwrap ( ) ,
332
326
) ) ;
333
327
334
- assert ! ( cmd. status ( ) . expect ( "failed to spawn" ) . success ( ) ) ;
328
+ run_with_determinism_env ( cmd) ;
335
329
}
336
330
337
331
"LlvmLines" => {
@@ -343,10 +337,9 @@ fn main() {
343
337
// `rustc` (which this file wraps) doesn't produce the output,
344
338
// this file can't redirect that output.
345
339
let mut cmd = Command :: new ( & tool) ;
346
- determinism_env ( & mut cmd) ;
347
340
cmd. args ( & args) ;
348
341
349
- assert ! ( cmd. status ( ) . expect ( "failed to spawn" ) . success ( ) ) ;
342
+ run_with_determinism_env ( cmd) ;
350
343
}
351
344
352
345
"LlvmIr" => {
@@ -355,32 +348,30 @@ fn main() {
355
348
. arg ( "-Cno-prepopulate-passes" )
356
349
. arg ( "-Cpasses=name-anon-globals" )
357
350
. args ( args) ;
358
- determinism_env ( & mut cmd ) ;
359
- assert ! ( cmd. status ( ) . expect ( "failed to spawn" ) . success ( ) ) ;
351
+
352
+ run_with_determinism_env ( cmd) ;
360
353
}
361
354
362
355
"MonoItems" => {
363
356
// Lazy item collection is the default (i.e., without this
364
357
// option)
365
358
let mut cmd = Command :: new ( tool) ;
366
- determinism_env ( & mut cmd) ;
367
359
cmd. arg ( "-Zprint-mono-items=lazy" )
368
360
. args ( args)
369
361
. stdout ( std:: process:: Stdio :: from (
370
362
std:: fs:: File :: create ( "mono-items" ) . unwrap ( ) ,
371
363
) ) ;
372
364
373
- assert ! ( cmd. status ( ) . expect ( "failed to spawn" ) . success ( ) ) ;
365
+ run_with_determinism_env ( cmd) ;
374
366
}
375
367
376
368
"DepGraph" => {
377
369
let mut cmd = Command :: new ( tool) ;
378
- determinism_env ( & mut cmd) ;
379
370
cmd. arg ( "-Zdump-dep-graph" )
380
371
. arg ( "-Zquery-dep-graph" )
381
372
. args ( & args) ;
382
373
383
- assert ! ( cmd. status ( ) . expect ( "failed to spawn" ) . success ( ) ) ;
374
+ run_with_determinism_env ( cmd) ;
384
375
}
385
376
386
377
_ => {
0 commit comments