Skip to content

Commit 66faa28

Browse files
authored
Merge pull request #1797 from Kobzol/self-profile-unique-dir
Use a unique directory for self-profile output
2 parents cd37384 + 32f1c5c commit 66faa28

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

collector/src/bin/rustc-fake.rs

+17-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use std::fs;
55
use std::path::Path;
66
use std::path::PathBuf;
77
use std::process::Command;
8-
use std::time::{Duration, Instant};
8+
use std::time::{Duration, Instant, SystemTime, UNIX_EPOCH};
99

1010
fn 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+
4054
fn 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

Comments
 (0)