Skip to content

Commit 985fe4c

Browse files
committed
Only enable tracing when MIRI_TRACING is set
Also remove --features from ci.sh as now tracing won't be enabled anymore.
1 parent 238189c commit 985fe4c

File tree

5 files changed

+49
-26
lines changed

5 files changed

+49
-26
lines changed

CONTRIBUTING.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,15 @@ compiler that has `debug=true` set in `bootstrap.toml`.
158158
You can set `MIRI_BACKTRACE=1` to get a backtrace of where an
159159
evaluation error was originally raised.
160160

161+
#### Tracing
162+
163+
You can generate a Chrome trace file from a Miri execution by passing `--features=tracing` during
164+
build and then setting `MIRI_TRACING=1` when running Miri. This will generate a `.json` file that
165+
you can visualize in [Perfetto](https://ui.perfetto.dev/). For example:
166+
167+
```sh
168+
MIRI_TRACING=1 ./miri run --features=tracing tests/pass/hello.rs
169+
```
161170

162171
### UI testing
163172

Cargo.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,6 @@ harness = false
6565

6666
[features]
6767
default = ["stack-cache"]
68-
# When adding a new feature that is relevant for some tests,
69-
# make sure to add it to the FEATURES variable in `ci/ci.sh`.
7068
genmc = []
7169
stack-cache = []
7270
stack-cache-consistency-check = ["stack-cache"]

ci/ci.sh

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,16 @@ begingroup "Building Miri"
2828
export RUSTFLAGS="-D warnings"
2929
export CARGO_INCREMENTAL=0
3030
export CARGO_EXTRA_FLAGS="--locked"
31-
# We enable all features (except tracing) to make sure the Stacked Borrows consistency check runs.
32-
export FEATURES="--features=genmc,stack-cache,stack-cache-consistency-check"
3331

3432
# Determine configuration for installed build (used by test-cargo-miri and `./miri bench`).
35-
# $FEATURES is not passed here as "stack-cache-consistency-check" makes things quite slow.
3633
echo "Installing release version of Miri"
3734
time ./miri install
3835

3936
# Prepare debug build for direct `./miri` invocations.
37+
# We enable all features to make sure the Stacked Borrows consistency check runs.
4038
echo "Building debug version of Miri"
41-
time ./miri build "$FEATURES" # the build that all the `./miri test` below will use
39+
export CARGO_EXTRA_FLAGS="$CARGO_EXTRA_FLAGS --all-features"
40+
time ./miri build # the build that all the `./miri test` below will use
4241

4342
endgroup
4443

@@ -62,9 +61,9 @@ function run_tests {
6261

6362
## ui test suite
6463
if [ -n "${GC_STRESS-}" ]; then
65-
time MIRIFLAGS="${MIRIFLAGS-} -Zmiri-provenance-gc=1" ./miri test "$FEATURES" $TARGET_FLAG
64+
time MIRIFLAGS="${MIRIFLAGS-} -Zmiri-provenance-gc=1" ./miri test $TARGET_FLAG
6665
else
67-
time ./miri test "$FEATURES" $TARGET_FLAG
66+
time ./miri test $TARGET_FLAG
6867
fi
6968

7069
## advanced tests
@@ -75,20 +74,20 @@ function run_tests {
7574
# them. Also error locations change so we don't run the failing tests.
7675
# We explicitly enable debug-assertions here, they are disabled by -O but we have tests
7776
# which exist to check that we panic on debug assertion failures.
78-
time MIRIFLAGS="${MIRIFLAGS-} -O -Zmir-opt-level=4 -Cdebug-assertions=yes" MIRI_SKIP_UI_CHECKS=1 ./miri test "$FEATURES" $TARGET_FLAG tests/{pass,panic}
77+
time MIRIFLAGS="${MIRIFLAGS-} -O -Zmir-opt-level=4 -Cdebug-assertions=yes" MIRI_SKIP_UI_CHECKS=1 ./miri test $TARGET_FLAG tests/{pass,panic}
7978
fi
8079
if [ -n "${MANY_SEEDS-}" ]; then
8180
# Run many-seeds tests. (Also tests `./miri run`.)
8281
time for FILE in tests/many-seeds/*.rs; do
83-
./miri run "$FEATURES" $TARGET_FLAG "-Zmiri-many-seeds=0..$MANY_SEEDS" "$FILE"
82+
./miri run "-Zmiri-many-seeds=0..$MANY_SEEDS" $TARGET_FLAG "$FILE"
8483
done
8584
fi
8685
if [ -n "${TEST_BENCH-}" ]; then
8786
# Check that the benchmarks build and run, but only once.
8887
time HYPERFINE="hyperfine -w0 -r1 --show-output" ./miri bench $TARGET_FLAG --no-install
8988
fi
9089
# Smoke-test `./miri run --dep`.
91-
./miri run "$FEATURES" $TARGET_FLAG --dep tests/pass-dep/getrandom.rs
90+
./miri run $TARGET_FLAG --dep tests/pass-dep/getrandom.rs
9291

9392
## test-cargo-miri
9493
# On Windows, there is always "python", not "python3" or "python2".
@@ -126,7 +125,7 @@ function run_tests_minimal {
126125
exit 1
127126
fi
128127

129-
time ./miri test "$FEATURES" $TARGET_FLAG "$@"
128+
time ./miri test $TARGET_FLAG "$@"
130129

131130
# Ensure that a small smoke test of cargo-miri works.
132131
time cargo miri run --manifest-path test-cargo-miri/no-std-smoke/Cargo.toml $TARGET_FLAG

src/bin/log/setup.rs

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use std::sync::{Mutex, OnceLock};
44

55
use rustc_middle::ty::TyCtxt;
66
use rustc_session::{CtfeBacktrace, EarlyDiagCtxt};
7-
use tracing_subscriber::Registry;
87

98
/// The tracing layer from `tracing-chrome` starts a thread in the background that saves data to
109
/// file and closes the file when stopped. If the thread is not stopped properly, the file will be
@@ -57,21 +56,38 @@ static LOGGER_INITED: OnceLock<Mutex<Option<TracingGuard>>> = OnceLock::new();
5756
fn init_logger_once(early_dcx: &EarlyDiagCtxt) {
5857
// If the logger is not yet initialized, initialize it.
5958
LOGGER_INITED.get_or_init(|| {
60-
#[cfg(feature = "tracing")]
61-
let (chrome_layer, chrome_guard) =
62-
super::tracing_chrome::ChromeLayerBuilder::new().include_args(true).build();
63-
rustc_driver::init_logger_with_additional_layer(early_dcx, rustc_logger_config(), || {
64-
let registry = Registry::default();
65-
#[cfg(feature = "tracing")]
66-
let registry = tracing_subscriber::layer::SubscriberExt::with(registry, chrome_layer);
67-
registry
68-
});
59+
let guard = if env::var_os("MIRI_TRACING").is_some() {
60+
#[cfg(not(feature = "tracing"))]
61+
{
62+
eprintln!(
63+
"fatal error: cannot enable MIRI_TRACING since Miri was not built with the \"tracing\" feature"
64+
);
65+
std::process::exit(1)
66+
}
6967

70-
Mutex::new(Some(TracingGuard {
7168
#[cfg(feature = "tracing")]
72-
_chrome: chrome_guard,
73-
_no_construct: (),
74-
}))
69+
{
70+
let (chrome_layer, chrome_guard) =
71+
super::tracing_chrome::ChromeLayerBuilder::new().include_args(true).build();
72+
rustc_driver::init_logger_with_additional_layer(
73+
early_dcx,
74+
rustc_logger_config(),
75+
|| {
76+
tracing_subscriber::layer::SubscriberExt::with(
77+
tracing_subscriber::Registry::default(),
78+
chrome_layer,
79+
)
80+
},
81+
);
82+
83+
Some(TracingGuard { _chrome: chrome_guard, _no_construct: () })
84+
}
85+
} else {
86+
// initialize the logger without any tracing enabled
87+
rustc_driver::init_logger(early_dcx, rustc_logger_config());
88+
None
89+
};
90+
Mutex::new(guard)
7591
});
7692
}
7793

src/bin/miri.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
// Some "regular" crates we want to share with rustc
1212
extern crate tracing;
13+
#[cfg(feature = "tracing")]
1314
extern crate tracing_subscriber;
1415

1516
// The rustc crates we need

0 commit comments

Comments
 (0)