Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions collector/src/bin/rustc-fake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::fs;
use std::path::Path;
use std::path::PathBuf;
use std::process::Command;
use std::time::{Duration, Instant};
use std::time::{Duration, Instant, SystemTime, UNIX_EPOCH};

fn determinism_env(cmd: &mut Command) {
// Since rust-lang/rust#89836, rustc stable crate IDs include a hash of the
Expand Down Expand Up @@ -37,6 +37,20 @@ fn run_with_determinism_env(mut cmd: Command) {
);
}

// We want each rustc execution to have a separate self-profile directory,
// to avoid overwriting the results. PID of this process and timestamp should
// hopefully be unique enough.
fn create_self_profile_dir() -> PathBuf {
let pid = std::process::id();
let timestamp = SystemTime::now()
.duration_since(UNIX_EPOCH)
.unwrap()
.as_millis();
let name = format!("self-profile-output-{pid}-{timestamp}");

std::env::current_dir().unwrap().join(name)
}

fn main() {
let mut args_os = env::args_os();
let name = args_os.next().unwrap().into_string().unwrap();
Expand Down Expand Up @@ -104,7 +118,7 @@ fn main() {
.arg(&tool)
.args(&args);

let prof_out_dir = std::env::current_dir().unwrap().join("self-profile-output");
let prof_out_dir = create_self_profile_dir();
if wrapper == "PerfStatSelfProfile" {
cmd.arg(&format!(
"-Zself-profile={}",
Expand Down Expand Up @@ -175,7 +189,7 @@ fn main() {
let mut tool = Command::new(tool);
tool.args(&args);

let prof_out_dir = std::env::current_dir().unwrap().join("self-profile-output");
let prof_out_dir = create_self_profile_dir();
if wrapper == "XperfStatSelfProfile" {
tool.arg(&format!(
"-Zself-profile={}",
Expand Down