@@ -5,7 +5,7 @@ use std::fs;
55use std:: path:: Path ;
66use std:: path:: PathBuf ;
77use std:: process:: Command ;
8- use std:: time:: { Duration , Instant } ;
8+ use std:: time:: { Duration , Instant , SystemTime , UNIX_EPOCH } ;
99
1010fn determinism_env ( cmd : & mut Command ) {
1111 // 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) {
3737 ) ;
3838}
3939
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+
4054fn main ( ) {
4155 let mut args_os = env:: args_os ( ) ;
4256 let name = args_os. next ( ) . unwrap ( ) . into_string ( ) . unwrap ( ) ;
@@ -104,7 +118,7 @@ fn main() {
104118 . arg ( & tool)
105119 . args ( & args) ;
106120
107- let prof_out_dir = std :: env :: current_dir ( ) . unwrap ( ) . join ( "self-profile-output" ) ;
121+ let prof_out_dir = create_self_profile_dir ( ) ;
108122 if wrapper == "PerfStatSelfProfile" {
109123 cmd. arg ( & format ! (
110124 "-Zself-profile={}" ,
@@ -175,7 +189,7 @@ fn main() {
175189 let mut tool = Command :: new ( tool) ;
176190 tool. args ( & args) ;
177191
178- let prof_out_dir = std :: env :: current_dir ( ) . unwrap ( ) . join ( "self-profile-output" ) ;
192+ let prof_out_dir = create_self_profile_dir ( ) ;
179193 if wrapper == "XperfStatSelfProfile" {
180194 tool. arg ( & format ! (
181195 "-Zself-profile={}" ,
0 commit comments