@@ -5,7 +5,7 @@ use std::fs;
5
5
use std:: path:: Path ;
6
6
use std:: path:: PathBuf ;
7
7
use std:: process:: Command ;
8
- use std:: time:: { Duration , Instant } ;
8
+ use std:: time:: { Duration , Instant , SystemTime , UNIX_EPOCH } ;
9
9
10
10
fn determinism_env ( cmd : & mut Command ) {
11
11
// Since rust-lang/rust#89836, rustc stable crate IDs include a hash of the
@@ -37,6 +37,20 @@ fn run_with_determinism_env(mut cmd: Command) {
37
37
) ;
38
38
}
39
39
40
+ // We want each rustc execution to have a separate self-profile directory,
41
+ // to avoid overwriting the results. PID of this process and timestamp should
42
+ // hopefully be unique enough.
43
+ fn create_self_profile_dir ( ) -> PathBuf {
44
+ let pid = std:: process:: id ( ) ;
45
+ let timestamp = SystemTime :: now ( )
46
+ . duration_since ( UNIX_EPOCH )
47
+ . unwrap ( )
48
+ . as_millis ( ) ;
49
+ let name = format ! ( "self-profile-output-{pid}-{timestamp}" ) ;
50
+
51
+ std:: env:: current_dir ( ) . unwrap ( ) . join ( name)
52
+ }
53
+
40
54
fn main ( ) {
41
55
let mut args_os = env:: args_os ( ) ;
42
56
let name = args_os. next ( ) . unwrap ( ) . into_string ( ) . unwrap ( ) ;
@@ -104,7 +118,7 @@ fn main() {
104
118
. arg ( & tool)
105
119
. args ( & args) ;
106
120
107
- let prof_out_dir = std :: env :: current_dir ( ) . unwrap ( ) . join ( "self-profile-output" ) ;
121
+ let prof_out_dir = create_self_profile_dir ( ) ;
108
122
if wrapper == "PerfStatSelfProfile" {
109
123
cmd. arg ( & format ! (
110
124
"-Zself-profile={}" ,
@@ -175,7 +189,7 @@ fn main() {
175
189
let mut tool = Command :: new ( tool) ;
176
190
tool. args ( & args) ;
177
191
178
- let prof_out_dir = std :: env :: current_dir ( ) . unwrap ( ) . join ( "self-profile-output" ) ;
192
+ let prof_out_dir = create_self_profile_dir ( ) ;
179
193
if wrapper == "XperfStatSelfProfile" {
180
194
tool. arg ( & format ! (
181
195
"-Zself-profile={}" ,
0 commit comments