Skip to content

Commit 3fc854d

Browse files
committed
WIP: Add initial support for running Miri flamegraph (no flamegraph options yet)
1 parent 5ff8417 commit 3fc854d

File tree

4 files changed

+34
-12
lines changed

4 files changed

+34
-12
lines changed

Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ name = "miri"
1717
test = false # we have no unit tests
1818
doctest = false # and no doc tests
1919

20+
[profile.bench]
21+
debug = true
22+
2023
[dependencies]
2124
getrandom = { version = "0.3", features = ["std"] }
2225
rand = "0.9"

miri-script/src/commands.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,8 @@ impl Command {
112112
Command::Check { features, flags } => Self::check(features, flags),
113113
Command::Test { bless, target, coverage, features, flags } =>
114114
Self::test(bless, target, coverage, features, flags),
115-
Command::Run { dep, verbose, target, edition, features, flags } =>
116-
Self::run(dep, verbose, target, edition, features, flags),
115+
Command::Run { dep, verbose, target, edition, features, flags, flamegraph } =>
116+
Self::run(dep, verbose, target, edition, features, flags, flamegraph),
117117
Command::Doc { features, flags } => Self::doc(features, flags),
118118
Command::Fmt { flags } => Self::fmt(flags),
119119
Command::Clippy { features, flags } => Self::clippy(features, flags),
@@ -463,6 +463,7 @@ impl Command {
463463
edition: Option<String>,
464464
features: Vec<String>,
465465
flags: Vec<String>,
466+
flamegraph: bool,
466467
) -> Result<()> {
467468
let mut e = MiriEnv::new()?;
468469

@@ -498,11 +499,14 @@ impl Command {
498499
// The basic command that executes the Miri driver.
499500
let mut cmd = if dep {
500501
// We invoke the test suite as that has all the logic for running with dependencies.
501-
e.cargo_cmd(".", "test", &features)
502-
.args(&["--test", "ui"])
503-
.args(quiet_flag)
504-
.arg("--")
505-
.args(&["--miri-run-dep-mode"])
502+
let cmd = e.cargo_cmd(".", "test", &features).args(&["--test", "ui"]).args(quiet_flag).arg("--");
503+
if flamegraph {
504+
cmd.args(&["--miri-run-dep-mode-flamegraph"])
505+
} else {
506+
cmd.args(&["--miri-run-dep-mode"])
507+
}
508+
} else if flamegraph {
509+
cmd!(e.sh, "flamegraph -- {miri_bin}")
506510
} else {
507511
cmd!(e.sh, "{miri_bin}")
508512
};

miri-script/src/main.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,9 @@ pub enum Command {
9696
/// The flags set in `MIRIFLAGS` are added in front of these flags.
9797
#[arg(trailing_var_arg = true, allow_hyphen_values = true)]
9898
flags: Vec<String>,
99+
/// Run with flamegraph (requires cargo-flamegraph to be installed)
100+
#[arg(long)]
101+
flamegraph: bool,
99102
},
100103
/// Build documentation.
101104
Doc {

tests/ui.rs

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -322,10 +322,12 @@ fn main() -> Result<()> {
322322
let mut args = std::env::args_os();
323323

324324
// Skip the program name and check whether this is a `./miri run-dep` invocation
325-
if let Some(first) = args.nth(1)
326-
&& first == "--miri-run-dep-mode"
327-
{
328-
return run_dep_mode(target, args);
325+
if let Some(first) = args.nth(1) {
326+
if first == "--miri-run-dep-mode" {
327+
return run_dep_mode(target, args, /* flamegraph */ false);
328+
} else if first == "--miri-run-dep-mode-flamegraph" {
329+
return run_dep_mode(target, args, /* flamegraph */ true);
330+
}
329331
}
330332

331333
ui(Mode::Pass, "tests/pass", &target, WithoutDependencies, tmpdir.path())?;
@@ -355,7 +357,11 @@ fn main() -> Result<()> {
355357
Ok(())
356358
}
357359

358-
fn run_dep_mode(target: String, args: impl Iterator<Item = OsString>) -> Result<()> {
360+
fn run_dep_mode(
361+
target: String,
362+
args: impl Iterator<Item = OsString>,
363+
flamegraph: bool,
364+
) -> Result<()> {
359365
let mut config =
360366
miri_config(&target, "", Mode::RunDep, Some(WithDependencies { bless: false }));
361367
config.comment_defaults.base().custom.remove("edition"); // `./miri` adds an `--edition` in `args`, so don't set it twice
@@ -370,5 +376,11 @@ fn run_dep_mode(target: String, args: impl Iterator<Item = OsString>) -> Result<
370376
// Build dependencies
371377
test_config.apply_custom(&mut cmd, &build_manager).unwrap();
372378

379+
if flamegraph {
380+
let mut flamegraph_cmd = Command::new("flamegraph");
381+
flamegraph_cmd.arg("--").arg(cmd.get_program()).args(cmd.get_args());
382+
cmd = flamegraph_cmd;
383+
}
384+
373385
if cmd.spawn()?.wait()?.success() { Ok(()) } else { std::process::exit(1) }
374386
}

0 commit comments

Comments
 (0)