Skip to content

Commit 16f4692

Browse files
committed
Address review comments
1 parent 2166eae commit 16f4692

File tree

5 files changed

+29
-23
lines changed

5 files changed

+29
-23
lines changed

Cargo.lock

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ test = false # we have no unit tests
1818
doctest = false # and no doc tests
1919

2020
[dependencies]
21-
measureme = { git = "https://github.com/rust-lang/measureme", rev = "501d6a3c192beee5e633a6c5f79130bedfdadcb5" }
2221
getrandom = { version = "0.2", features = ["std"] }
2322
env_logger = "0.8"
2423
log = "0.4"
@@ -31,6 +30,7 @@ smallvec = "1.4.2"
3130
# See the `src/tools/rustc-workspace-hack/README.md` file in `rust-lang/rust`
3231
# for more information.
3332
rustc-workspace-hack = "1.0.0"
33+
measureme = "9.1.2"
3434

3535
# Enable some feature flags that dev-dependencies need but dependencies
3636
# do not. This makes `./miri install` after `./miri build` faster.

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,10 @@ environment variable:
222222
times to exclude several variables. On Windows, the `TERM` environment
223223
variable is excluded by default.
224224
* `-Zmiri-ignore-leaks` disables the memory leak checker.
225+
* `-Zmiri-measureme=<name>` enables `measureme` profiling for the interpreted program.
226+
This can be used to find which parts of your program are executing slowly under Miri.
227+
The profile is written out to a file with the prefix `<name>`, and can be processed
228+
using the tools in the repository https://github.com/rust-lang/measureme.
225229
* `-Zmiri-seed=<hex>` configures the seed of the RNG that Miri uses to resolve
226230
non-determinism. This RNG is used to pick base addresses for allocations.
227231
When isolation is enabled (the default), this is also used to emulate system
@@ -258,10 +262,6 @@ environment variable:
258262
this pointer. Note that it is not currently guaranteed that code that works
259263
with `-Zmiri-track-raw-pointers` also works without
260264
`-Zmiri-track-raw-pointers`, but for the vast majority of code, this will be the case.
261-
* `-Zmiri-measureme=<name>` enables `measureme` profiling for the interpreted program.
262-
This can be used to find which parts of your program are executing slowly under Miri.
263-
The profile is written out to a file with the prefix `<name>`, and can be processed
264-
using the tools in the repository https://github.com/rust-lang/measureme
265265

266266
Some native rustc `-Z` flags are also very relevant for Miri:
267267

src/eval.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ pub struct MiriConfig {
5454
/// Rate of spurious failures for compare_exchange_weak atomic operations,
5555
/// between 0.0 and 1.0, defaulting to 0.8 (80% chance of failure).
5656
pub cmpxchg_weak_failure_rate: f64,
57-
/// If `Some`, enable the `measureme` profiler, writing results to the specified
58-
/// directory.
57+
/// If `Some`, enable the `measureme` profiler, writing results to a file
58+
/// with the specified prefix.
5959
pub measureme_out: Option<String>,
6060
}
6161

src/machine.rs

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ use std::time::Instant;
1010
use log::trace;
1111
use rand::rngs::StdRng;
1212
use rand::SeedableRng;
13-
use std::collections::hash_map::Entry;
1413
use measureme::{Profiler, StringId, EventId, DetachedTiming};
1514

1615
use rustc_data_structures::fx::FxHashMap;
@@ -45,6 +44,9 @@ pub struct FrameData<'tcx> {
4544
/// we stop unwinding, use the `CatchUnwindData` to handle catching.
4645
pub catch_unwind: Option<CatchUnwindData<'tcx>>,
4746

47+
/// If `measureme` profiling is enabled, holds timing information
48+
/// for the start of this frame. When we finish executing this frame,
49+
/// we use this to register a completed event with `measureme`.
4850
pub timing: Option<DetachedTiming>,
4951
}
5052

@@ -274,7 +276,11 @@ pub struct Evaluator<'mir, 'tcx> {
274276
/// Allocations that are considered roots of static memory (that may leak).
275277
pub(crate) static_roots: Vec<AllocId>,
276278

279+
/// The `measureme` profiler used to record timing information about
280+
/// the emulated program.
277281
profiler: Option<Profiler>,
282+
/// Used with `profiler` to cache the `StringId`s for event names
283+
/// uesd with `measureme`.
278284
string_cache: FxHashMap<String, StringId>,
279285
}
280286

@@ -607,29 +613,28 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for Evaluator<'mir, 'tcx> {
607613
ecx: &mut InterpCx<'mir, 'tcx, Self>,
608614
frame: Frame<'mir, 'tcx, Tag>,
609615
) -> InterpResult<'tcx, Frame<'mir, 'tcx, Tag, FrameData<'tcx>>> {
610-
let stacked_borrows = ecx.memory.extra.stacked_borrows.as_ref();
611-
let call_id = stacked_borrows.map_or(NonZeroU64::new(1).unwrap(), |stacked_borrows| {
612-
stacked_borrows.borrow_mut().new_call()
613-
});
616+
// Start recording our event before doing anything else
614617
let timing = if let Some(profiler) = ecx.machine.profiler.as_ref() {
615618
let fn_name = frame.instance.to_string();
616619
let entry = ecx.machine.string_cache.entry(fn_name.clone());
617-
let name = match entry {
618-
Entry::Occupied(e) => *e.get(),
619-
Entry::Vacant(e) => {
620-
*e.insert(profiler.alloc_string(&*fn_name))
621-
}
622-
};
620+
let name = entry.or_insert_with(|| {
621+
profiler.alloc_string(&*fn_name)
622+
});
623623

624624
Some(profiler.start_recording_interval_event_detached(
625-
name,
626-
EventId::from_label(name),
627-
ecx.get_active_thread().to_u32()
625+
*name,
626+
EventId::from_label(*name),
627+
ecx.get_active_thread().to_u32(),
628628
))
629629
} else {
630630
None
631631
};
632632

633+
let stacked_borrows = ecx.memory.extra.stacked_borrows.as_ref();
634+
let call_id = stacked_borrows.map_or(NonZeroU64::new(1).unwrap(), |stacked_borrows| {
635+
stacked_borrows.borrow_mut().new_call()
636+
});
637+
633638
let extra = FrameData { call_id, catch_unwind: None, timing };
634639
Ok(frame.with_extra(extra))
635640
}

0 commit comments

Comments
 (0)