You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: crates/ty/docs/tracing.md
+27-15Lines changed: 27 additions & 15 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,7 @@
1
1
# Tracing
2
2
3
-
Traces are a useful tool to narrow down the location of a bug or, at least, to understand why the compiler is doing a particular thing.
3
+
Traces are a useful tool to narrow down the location of a bug or, at least, to understand why the compiler is doing a
4
+
particular thing.
4
5
Note, tracing messages with severity `debug` or greater are user-facing. They should be phrased accordingly.
5
6
Tracing spans are only shown when using `-vvv`.
6
7
@@ -9,20 +10,28 @@ Tracing spans are only shown when using `-vvv`.
9
10
The CLI supports different verbosity levels.
10
11
11
12
- default: Only show errors and warnings.
12
-
-`-v` activates `info!`: Show generally useful information such as paths of configuration files, detected platform, etc., but it's not a lot of messages, it's something you'll activate in CI by default. cargo build e.g. shows you which packages are fresh.
13
-
-`-vv` activates `debug!` and timestamps: This should be enough information to get to the bottom of bug reports. When you're processing many packages or files, you'll get pages and pages of output, but each line is link to a specific action or state change.
14
-
-`-vvv` activates `trace!` (only in debug builds) and shows tracing-spans: At this level, you're logging everything. Most of this is wasted, it's really slow, we dump e.g. the entire resolution graph. Only useful to developers, and you almost certainly want to use `TY_LOG` to filter it down to the area your investigating.
15
-
16
-
## Better logging with `TY_LOG` and `RAYON_NUM_THREADS`
13
+
-`-v` activates `info!`: Show generally useful information such as paths of configuration files, detected platform,
14
+
etc., but it's not a lot of messages, it's something you'll activate in CI by default. cargo build e.g. shows you
15
+
which packages are fresh.
16
+
-`-vv` activates `debug!` and timestamps: This should be enough information to get to the bottom of bug reports. When
17
+
you're processing many packages or files, you'll get pages and pages of output, but each line is link to a specific
18
+
action or state change.
19
+
-`-vvv` activates `trace!` (only in debug builds) and shows tracing-spans: At this level, you're logging everything.
20
+
Most of this is wasted, it's really slow, we dump e.g. the entire resolution graph. Only useful to developers, and you
21
+
almost certainly want to use `TY_LOG` to filter it down to the area your investigating.
22
+
23
+
## Better logging with `TY_LOG` and `TY_MAX_PARALLELISM`
17
24
18
25
By default, the CLI shows messages from the `ruff` and `ty` crates. Tracing messages from other crates are not shown.
19
26
The `TY_LOG` environment variable allows you to customize which messages are shown by specifying one
20
-
or more [filter directives](https://docs.rs/tracing-subscriber/latest/tracing_subscriber/filter/struct.EnvFilter.html#directives).
27
+
or
28
+
more [filter directives](https://docs.rs/tracing-subscriber/latest/tracing_subscriber/filter/struct.EnvFilter.html#directives).
21
29
22
-
The `RAYON_NUM_THREADS` environment variable, meanwhile, can be used to control the level of concurrency ty uses.
30
+
The `TY_MAX_PARALLELISM` environment variable, meanwhile, can be used to control the level of parallelism ty uses.
23
31
By default, ty will attempt to parallelize its work so that multiple files are checked simultaneously,
24
-
but this can result in a confused logging output where messages from different threads are intertwined.
25
-
To switch off concurrency entirely and have more readable logs, use `RAYON_NUM_THREADS=1`.
32
+
but this can result in a confused logging output where messages from different threads are intertwined and non
33
+
determinism.
34
+
To switch off parallelism entirely and have more readable logs, use `TY_MAX_PARALLELSIM=1` (or `RAYON_NUM_THREADS=1`).
26
35
27
36
### Examples
28
37
@@ -79,22 +88,24 @@ query to return the failure as part of the query's result or use a Salsa accumul
79
88
80
89
## Tracing in tests
81
90
82
-
You can use `ruff_db::testing::setup_logging` or `ruff_db::testing::setup_logging_with_filter` to set up logging in tests.
91
+
You can use `ruff_db::testing::setup_logging` or `ruff_db::testing::setup_logging_with_filter` to set up logging in
92
+
tests.
83
93
84
94
```rust
85
95
useruff_db::testing::setup_logging;
86
96
87
97
#[test]
88
98
fntest() {
89
-
let_logging=setup_logging();
99
+
let_logging=setup_logging();
90
100
91
-
tracing::info!("This message will be printed to stderr");
101
+
tracing::info!("This message will be printed to stderr");
92
102
}
93
103
```
94
104
95
105
Note: Most test runners capture stderr and only show its output when a test fails.
96
106
97
-
Note also that `setup_logging` only sets up logging for the current thread because [`set_global_default`](https://docs.rs/tracing/latest/tracing/subscriber/fn.set_global_default.html) can only be
107
+
Note also that `setup_logging` only sets up logging for the current thread because
108
+
[`set_global_default`](https://docs.rs/tracing/latest/tracing/subscriber/fn.set_global_default.html) can only be
98
109
called **once**.
99
110
100
111
## Release builds
@@ -103,7 +114,8 @@ called **once**.
103
114
104
115
## Profiling
105
116
106
-
ty generates a folded stack trace to the current directory named `tracing.folded` when setting the environment variable `TY_LOG_PROFILE` to `1` or `true`.
117
+
ty generates a folded stack trace to the current directory named `tracing.folded` when setting the environment variable
118
+
`TY_LOG_PROFILE` to `1` or `true`.
107
119
108
120
```bash
109
121
TY_LOG_PROFILE=1 ty -- --current-directory=../test -vvv
0 commit comments