From c3e7ff4609ea14126077de16f2bd2dc4cc3e2cde Mon Sep 17 00:00:00 2001 From: Ben Kimock Date: Sun, 7 May 2023 19:33:58 -0400 Subject: [PATCH 1/3] Adopt the measureme output naming strategy from rustc --- src/tools/miri/src/machine.rs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/tools/miri/src/machine.rs b/src/tools/miri/src/machine.rs index 21c5a9c1b70..b91efae3bcb 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,17 @@ 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(); + 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)); From 9f1624a22d9d0243be11ffee0049ae06a48639da Mon Sep 17 00:00:00 2001 From: Ben Kimock Date: Tue, 9 May 2023 19:45:09 -0400 Subject: [PATCH 2/3] Amend the docs for -Zmiri-measureme --- src/tools/miri/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 From f9a42139682aff545e41b9ed3566fafbafdd09f1 Mon Sep 17 00:00:00 2001 From: Ben Kimock Date: Wed, 10 May 2023 13:27:31 -0400 Subject: [PATCH 3/3] Explain the padding --- src/tools/miri/src/machine.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/tools/miri/src/machine.rs b/src/tools/miri/src/machine.rs index b91efae3bcb..32717a0d28b 100644 --- a/src/tools/miri/src/machine.rs +++ b/src/tools/miri/src/machine.rs @@ -508,6 +508,10 @@ impl<'mir, 'tcx> MiriMachine<'mir, 'tcx> { .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")