diff --git a/src/tools/miri/README.md b/src/tools/miri/README.md index 640a953dac9..79b0daf9e82 100644 --- a/src/tools/miri/README.md +++ b/src/tools/miri/README.md @@ -389,7 +389,7 @@ to Miri failing to detect cases of undefined behavior in a program. Follow [the discussion on supporting other types](https://github.com/rust-lang/miri/issues/2365). * `-Zmiri-measureme=` enables `measureme` profiling for the interpreted program. This can be used to find which parts of your program are executing slowly under Miri. - The profile is written out to a file with the prefix ``, and can be processed + The profile is written out to a file inside a directory called ``, and can be processed using the tools in the repository https://github.com/rust-lang/measureme. * `-Zmiri-mute-stdout-stderr` silently ignores all writes to stdout and stderr, but reports to the program that it did actually write. This is useful when you diff --git a/src/tools/miri/src/machine.rs b/src/tools/miri/src/machine.rs index 21c5a9c1b70..32717a0d28b 100644 --- a/src/tools/miri/src/machine.rs +++ b/src/tools/miri/src/machine.rs @@ -4,6 +4,8 @@ use std::borrow::Cow; use std::cell::RefCell; use std::fmt; +use std::path::Path; +use std::process; use rand::rngs::StdRng; use rand::SeedableRng; @@ -498,7 +500,21 @@ impl<'mir, 'tcx> MiriMachine<'mir, 'tcx> { let layouts = PrimitiveLayouts::new(layout_cx).expect("Couldn't get layouts of primitive types"); let profiler = config.measureme_out.as_ref().map(|out| { - measureme::Profiler::new(out).expect("Couldn't create `measureme` profiler") + let crate_name = layout_cx + .tcx + .sess + .opts + .crate_name + .clone() + .unwrap_or_else(|| "unknown-crate".to_string()); + let pid = process::id(); + // We adopt the same naming scheme for the profiler output that rustc uses. In rustc, + // the PID is padded so that the nondeterministic value of the PID does not spread + // nondeterminisim to the allocator. In Miri we are not aiming for such performance + // control, we just pad for consistency with rustc. + let filename = format!("{crate_name}-{pid:07}"); + let path = Path::new(out).join(filename); + measureme::Profiler::new(path).expect("Couldn't create `measureme` profiler") }); let rng = StdRng::seed_from_u64(config.seed.unwrap_or(0)); let borrow_tracker = config.borrow_tracker.map(|bt| bt.instantiate_global_state(config));