Skip to content

Commit d2ea42f

Browse files
committedMay 10, 2023
Auto merge of #2879 - saethlin:measureme, r=RalfJung
Include the current Crate name in the measureme output name See https://rust-lang.zulipchat.com/#narrow/stream/182449-t-compiler.2Fhelp/topic/measureme.20flamegraph.20panics/near/356367013 cc `@andjo403` Currently, attempting to use `MIRIFLAGS=-Zmiri-measureme=miri cargo miri test` on a crate with multiple test targets (which is very common) will produce a corrupted measureme output file, because the various interpreter processes will stomp each other's output. This change does not entirely prevent this, but the various test targets seem to always have different crate names, so if nothing else this will make the broken measureme files much harder to encounter by accident, while also making it clear what they are all for.
2 parents 7a41eac + f9a4213 commit d2ea42f

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed
 

Diff for: ‎src/tools/miri/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ to Miri failing to detect cases of undefined behavior in a program.
389389
Follow [the discussion on supporting other types](https://github.com/rust-lang/miri/issues/2365).
390390
* `-Zmiri-measureme=<name>` enables `measureme` profiling for the interpreted program.
391391
This can be used to find which parts of your program are executing slowly under Miri.
392-
The profile is written out to a file with the prefix `<name>`, and can be processed
392+
The profile is written out to a file inside a directory called `<name>`, and can be processed
393393
using the tools in the repository https://github.com/rust-lang/measureme.
394394
* `-Zmiri-mute-stdout-stderr` silently ignores all writes to stdout and stderr,
395395
but reports to the program that it did actually write. This is useful when you

Diff for: ‎src/tools/miri/src/machine.rs

+17-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
use std::borrow::Cow;
55
use std::cell::RefCell;
66
use std::fmt;
7+
use std::path::Path;
8+
use std::process;
79

810
use rand::rngs::StdRng;
911
use rand::SeedableRng;
@@ -498,7 +500,21 @@ impl<'mir, 'tcx> MiriMachine<'mir, 'tcx> {
498500
let layouts =
499501
PrimitiveLayouts::new(layout_cx).expect("Couldn't get layouts of primitive types");
500502
let profiler = config.measureme_out.as_ref().map(|out| {
501-
measureme::Profiler::new(out).expect("Couldn't create `measureme` profiler")
503+
let crate_name = layout_cx
504+
.tcx
505+
.sess
506+
.opts
507+
.crate_name
508+
.clone()
509+
.unwrap_or_else(|| "unknown-crate".to_string());
510+
let pid = process::id();
511+
// We adopt the same naming scheme for the profiler output that rustc uses. In rustc,
512+
// the PID is padded so that the nondeterministic value of the PID does not spread
513+
// nondeterminisim to the allocator. In Miri we are not aiming for such performance
514+
// control, we just pad for consistency with rustc.
515+
let filename = format!("{crate_name}-{pid:07}");
516+
let path = Path::new(out).join(filename);
517+
measureme::Profiler::new(path).expect("Couldn't create `measureme` profiler")
502518
});
503519
let rng = StdRng::seed_from_u64(config.seed.unwrap_or(0));
504520
let borrow_tracker = config.borrow_tracker.map(|bt| bt.instantiate_global_state(config));

0 commit comments

Comments
 (0)
Please sign in to comment.