Commit 3fb3da6
authored
Rollup merge of rust-lang#157190 - khyperia:nonrecursive-tracing-json, r=jieyouxu
Silence recursive RUSTC_LOG_FORMAT_JSON messages
We print a *lot* of debug messages while formatting the arguments of another, outer, debug message. For example, these two `debug!` lines are responsible for **75%** of all log messages when running with `RUSTC_LOG=trace RUSTC_LOG_FORMAT_JSON=1`, because we format paths to string a *lot* when debug logging:
https://github.com/rust-lang/rust/blob/c315891193c35827c2d789adce686f8a5481778f/compiler/rustc_hir/src/definitions.rs#L153-L156
The default rustc log formatter, `tracing_tree::HierarchicalLayer`, blocks all "recursive" tracing messages, dropping them:
https://github.com/davidbarsky/tracing-tree/blob/79627fc72ae7dcf95af16e047797e60494679678/src/lib.rs#L410-L412
However, `RUSTC_LOG_FORMAT_JSON` does not. This is mildly annoying, since once logged, it's impossible to tell that a message is "recursive", so which means that [my lil rustc log viewer](https://github.com/khyperia/khys-rustc-log-viewer), as [well as Jana's](https://git.donsz.nl/jana/logviewer), can only fully filter these messages out, rather than only showing them when they are top-level logs.
This change implements a very criminal, primitive recursion check, in a very hacky way, in rustc_log - I am not proud of this code, and wish there was a better way of doing this. As far as I can tell, though, this is the easiest/most effective way of implementing this - `tracing` doesn't provide nice tools for this kind of thing.
Before this change:
```
khyperia@argon /d/rust (main)> RUSTC_LOG_FORMAT_JSON=1 RUSTC_LOG=trace rustc +stage1 -Znext-solver=globally tests/ui/const-generics/gca/non-type-equality-ok.rs &| wc -l
1443792 lines
khyperia@argon /d/rust (main)> RUSTC_LOG_FORMAT_JSON=1 RUSTC_LOG=trace rustc +stage1 -Znext-solver=globally tests/ui/const-generics/gca/non-type-equality-ok.rs &| wc -c
3513565523 = 3.5 gigabytes
```
After this change:
```
khyperia@argon /d/rust (main)> RUSTC_LOG_FORMAT_JSON=1 RUSTC_LOG=trace rustc +stage1 -Znext-solver=globally tests/ui/const-generics/gca/non-type-equality-ok.rs &| wc -l
84104 lines = 5.8% of the number of lines
khyperia@argon /d/rust (main)> RUSTC_LOG_FORMAT_JSON=1 RUSTC_LOG=trace rustc +stage1 -Znext-solver=globally tests/ui/const-generics/gca/non-type-equality-ok.rs &| wc -c
257480205 = 257 megabytes = 7.3% the amount of data
```
FYI @jdonszelmann
r? @jieyouxu1 file changed
Lines changed: 106 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
| 36 | + | |
36 | 37 | | |
37 | 38 | | |
38 | 39 | | |
39 | 40 | | |
40 | 41 | | |
41 | 42 | | |
42 | 43 | | |
43 | | - | |
| 44 | + | |
44 | 45 | | |
45 | 46 | | |
46 | 47 | | |
47 | 48 | | |
48 | | - | |
| 49 | + | |
49 | 50 | | |
50 | 51 | | |
51 | 52 | | |
| |||
175 | 176 | | |
176 | 177 | | |
177 | 178 | | |
| 179 | + | |
178 | 180 | | |
179 | 181 | | |
180 | 182 | | |
| |||
286 | 288 | | |
287 | 289 | | |
288 | 290 | | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
0 commit comments