forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rustc-dev-guide: document
BOOTSTRAP_TRACING
and bootstrap tracing
…
… setup
- Loading branch information
Showing
4 changed files
with
104 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
100 changes: 100 additions & 0 deletions
100
src/doc/rustc-dev-guide/src/building/bootstrapping/debugging-bootstrap.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
# Debugging bootstrap | ||
|
||
> FIXME: this page could be expanded | ||
## `tracing` in bootstrap | ||
|
||
Bootstrap has conditional [`tracing`][tracing] setup to provide structured logging. | ||
|
||
[tracing]: https://docs.rs/tracing/0.1.41/tracing/index.html | ||
|
||
### Enabling `tracing` output | ||
|
||
Bootstrap will conditionally enable `tracing` output if the `BOOTSTRAP_TRACING` env var is set. | ||
|
||
Example usage: | ||
|
||
```bash | ||
$ BOOTSTRAP_TRACING=TRACE ./x build library --stage 1 | ||
``` | ||
|
||
Example output[^experimental]: | ||
|
||
![Example bootstrap tracing output](./debugging-bootstrap/tracing-output-example.png) | ||
|
||
[^experimental]: This shows what's *possible* with the infra in an experimental implementation. | ||
|
||
The env var `BOOTSTRAP_TRACING` accepts a [`tracing` env-filter][tracing-env-filter]. The `TRACE` filter will enable *all* `trace` level or less verbose level tracing output. | ||
|
||
[tracing-env-filter]: https://docs.rs/tracing-subscriber/0.3.19/tracing_subscriber/filter/struct.EnvFilter.html | ||
|
||
### Using `tracing` in bootstrap | ||
|
||
Both `tracing::*` macros and the `tracing::instrument` proc-macro attribute need to be gated behind `tracing` feature. Examples: | ||
|
||
```rs | ||
#[cfg(feature = "tracing")] | ||
use tracing::{instrument, trace}; | ||
|
||
struct Foo; | ||
|
||
impl Step for Foo { | ||
type Output = (); | ||
|
||
#[cfg_attr(feature = "tracing", instrument(level = "trace", name = "Foo::should_run", skip_all))] | ||
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> { | ||
#[cfg(feature = "tracing")] | ||
trace!(?run, "entered Foo::should_run"); | ||
|
||
todo!() | ||
} | ||
|
||
#[cfg_attr( | ||
feature = "tracing", | ||
instrument( | ||
level = "trace", | ||
name = "Foo::run", | ||
skip_all, | ||
fields(compiler = ?builder.compiler), | ||
), | ||
)] | ||
fn run(self, builder: &Builder<'_>) -> Self::Output { | ||
#[cfg(feature = "tracing")] | ||
trace!(?run, "entered Foo::run"); | ||
|
||
todo!() | ||
} | ||
} | ||
``` | ||
|
||
For `#[instrument]`, it's recommended to: | ||
|
||
- Gate it behind `trace` level for fine-granularity, possibly `debug` level for core functions. | ||
- Explicitly pick an instrumentation name via `name = ".."` to distinguish between e.g. `run` of different steps. | ||
- Take care to not cause diverging behavior via tracing, e.g. building extra things only when tracing infra is enabled. | ||
|
||
### Enabling `tracing` bootstrap feature in rust-analyzer | ||
|
||
You can adjust your `settings.json`'s `rust-analyzer.check.overrideCommand` and `rust-analyzer.cargo.buildScripts.overrideCommand` if you want to also enable `logging` cargo feature by default in your editor. This is mostly useful if you want proper r-a completions and such when working on bootstrap itself. | ||
|
||
```json | ||
"rust-analyzer.check.overrideCommand": [ | ||
"BOOTSTRAP_TRACING=1", // <- BOOTSTRAP_TRACING=1 won't enable tracing filter, but it will activate bootstrap's `tracing` feature | ||
"python3", | ||
"x.py", | ||
"check", | ||
"--json-output", | ||
"--build-dir=build-rust-analyzer" | ||
], | ||
``` | ||
|
||
```json | ||
"rust-analyzer.cargo.buildScripts.overrideCommand": [ | ||
"BOOTSTRAP_TRACING=1", // <- note this | ||
"python3", | ||
"x.py", | ||
"check", | ||
"--json-output", | ||
"--build-dir=build-rust-analyzer" | ||
], | ||
``` |
Binary file added
BIN
+137 KB
...guide/src/building/bootstrapping/debugging-bootstrap/tracing-output-example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters