Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move from log to tracing #74726

Merged
merged 7 commits into from
Aug 1, 2020
Merged

Move from log to tracing #74726

merged 7 commits into from
Aug 1, 2020

Conversation

oli-obk
Copy link
Contributor

@oli-obk oli-obk commented Jul 24, 2020

The only visible change is that we now get timestamps in our logs:

Jul 24 18:41:01.065 TRACE rustc_mir::transform::const_prop: skipping replace of Rvalue::Use(const () because it is already a const
Jul 24 18:41:01.065 TRACE rustc_mir::transform::const_prop: propagated into _2
Jul 24 18:41:01.065 TRACE rustc_mir::transform::const_prop: visit_constant: const ()

This PR was explicitly designed to be as low-impact as possible. We can now move to using the name tracing insteads of log on a crate-by-crate basis and use any of the other tracing features where desirable.

As far as I can tell this will allow tools to seamlessly keep working (since they are using rustc_driver::init_log...).

This is the first half of step 1 of the accepted tracing MCP (rust-lang/compiler-team#331)

@rust-highfive
Copy link
Collaborator

r? @Mark-Simulacrum

(rust_highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jul 24, 2020
@@ -12,8 +12,8 @@ crate-type = ["dylib"]
[dependencies]
lazy_static = "1.0"
libc = "0.2"
log = "0.4"
env_logger = { version = "0.7", default-features = false }
log = { package = "tracing", version = "0.1" }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The replacements seem like they could be pretty confusing, so we should try to move off of them pretty quickly, but I agree that for now this is probably the right way to do things, presuming it doesn't cause problems with tracing's own macros expanding to ::tracing::foo and that not resolving.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, I'll open an E-easy issue with checkboxes for each of the renames

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tracing's macros should all use $crate::, so this should be fine.

@Mark-Simulacrum
Copy link
Member

Once CI is passing here, could you kick off a perf run? I want to make sure this isn't a performance regression (which would be unexpected, but we should check).

@jyn514
Copy link
Member

jyn514 commented Jul 24, 2020

Looks like rustdoc had a dependency on env_logger but didn't put it in cargo.toml 👀

     Checking rustdoc v0.0.0 (/checkout/src/librustdoc)
error[E0463]: can't find crate for `env_logger`
  --> src/librustdoc/lib.rs:17:1
   |
17 | extern crate env_logger;
   | ^^^^^^^^^^^^^^^^^^^^^^^^ can't find crate
```

@Mark-Simulacrum
Copy link
Member

(that is actually good - any tools that have shared dependencies with rustc should ideally not declare them to save time in CI as loading from the sysroot is free, compared to recompiling)

@oli-obk
Copy link
Contributor Author

oli-obk commented Jul 25, 2020

@bors try @rust-timer queue

@rust-timer
Copy link
Collaborator

Awaiting bors try build completion

@bors
Copy link
Contributor

bors commented Jul 25, 2020

⌛ Trying commit 2f7afb6d9058b3ebf7a059517ddc231da059ef0d with merge ec225facb960eff32c5290531b2dced3da219bdb...

@rust-log-analyzer
Copy link
Collaborator

The job dist-x86_64-linux of your PR failed (pretty log, raw log). Through arcane magic we have determined that the following fragments from the build log may contain information about the problem.

Click to expand the log.
Building stage1 tool error_index_generator (x86_64-unknown-linux-gnu)
   Compiling same-file v1.0.4
   Compiling walkdir v2.2.7
   Compiling error_index_generator v0.0.0 (/checkout/src/tools/error_index_generator)
error[E0463]: can't find crate for `env_logger`
  |
3 | extern crate env_logger;
  | ^^^^^^^^^^^^^^^^^^^^^^^^ can't find crate


error: aborting due to previous error

For more information about this error, try `rustc --explain E0463`.
error: could not compile `error_index_generator`.
To learn more, run the command again with --verbose.
command did not execute successfully: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/bin/cargo" "build" "--target" "x86_64-unknown-linux-gnu" "-Zbinary-dep-depinfo" "-j" "16" "--release" "--locked" "--color" "always" "--manifest-path" "/checkout/src/tools/error_index_generator/Cargo.toml" "--message-format" "json-render-diagnostics"
expected success, got: exit code: 101
failed to run: /checkout/obj/build/bootstrap/debug/bootstrap dist --host x86_64-unknown-linux-gnu --target x86_64-unknown-linux-gnu
failed to run: /checkout/obj/build/bootstrap/debug/bootstrap dist --host x86_64-unknown-linux-gnu --target x86_64-unknown-linux-gnu
Build completed unsuccessfully in 0:22:23
== clock drift check ==
  local time: Sat Jul 25 15:11:39 UTC 2020
  network time: Sat, 25 Jul 2020 15:11:40 GMT
== end clock drift check ==
##[error]Process completed with exit code 1.
Terminate orphan process: pid (3404) (python)

I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact @rust-lang/infra. (Feature Requests)

@bors
Copy link
Contributor

bors commented Jul 25, 2020

💔 Test failed - checks-actions

@bors bors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jul 25, 2020
@oli-obk
Copy link
Contributor Author

oli-obk commented Jul 25, 2020

@bors try @rust-timer queue

this time x.py test ran through cleanly locally and not just the few sub-tests I ran manually

@rust-timer
Copy link
Collaborator

Awaiting bors try build completion

@bors
Copy link
Contributor

bors commented Jul 25, 2020

⌛ Trying commit b9a3fd38bef4e62704cfefda80ccf67a815700d1 with merge 46c33324e985772632898d0f4c1b6d4c246496ec...

@bors
Copy link
Contributor

bors commented Jul 25, 2020

☀️ Try build successful - checks-actions, checks-azure
Build commit: 46c33324e985772632898d0f4c1b6d4c246496ec (46c33324e985772632898d0f4c1b6d4c246496ec)

@rust-timer
Copy link
Collaborator

Queued 46c33324e985772632898d0f4c1b6d4c246496ec with parent 037d8e7, future comparison URL.

@mark-i-m
Copy link
Member

Could you also make a PR to update the rustc-dev-guide, specifically with how to turn on and use logging? There is some existing content on how to enable the current logging system.

@rust-timer
Copy link
Collaborator

Finished benchmarking try commit (46c33324e985772632898d0f4c1b6d4c246496ec): comparison url.

Benchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. Please note that if the perf results are neutral, you should likely undo the rollup=never given below by specifying rollup- to bors.

Importantly, though, if the results of this run are non-neutral do not roll this PR up -- it will mask other regressions or improvements in the roll up.

@bors rollup=never

@oli-obk
Copy link
Contributor Author

oli-obk commented Jul 26, 2020

@hawkw any tips on debugging perf regressions due to migrating from log to tracing? I turned on release_max_level_info (we were using this before with log, so some crates enabling this feature should keep turning it on for all crates.

EDIT 1: I believe this is all working correctly, as looking at a const-eval heavy test's perf result (https://perf.rust-lang.org/detailed-query.html?commit=46c33324e985772632898d0f4c1b6d4c246496ec&base_commit=037d8e747de5056f0202f29aa2b0353bdbbf5cfe&benchmark=wf-projection-stress-65510-check&run_name=full) still has a significant number of info! invocations (3 per const eval stack frame, one per statement), which would then require runtime checks for whether they should get emitted. Could these slowdowns be due to the implementation of the env filter?

EDIT 2: I'm doing what you suggested originally now (I think?), and enabling the tracing-log feature of tracing-subscriber, which moves all the changes to just librustc_driver and we can port all the other crates one by one later.

EDIT 3: Oh, that doesn't work with log_enabled!, maybe the regression is due to my span_trace!("").is_none() checks?

EDIT 4: Maybe we're losing perf because we stay compatible to log?

@oli-obk
Copy link
Contributor Author

oli-obk commented Jul 26, 2020

@bors try @rust-timer queue

@rust-timer
Copy link
Collaborator

Awaiting bors try build completion

@bors
Copy link
Contributor

bors commented Jul 26, 2020

⌛ Trying commit e301587481705f5dd14df480a9f76c2432e3ad8e with merge 1b5adbdbb4a5be604061874ffc2dade72bf7ede0...

@bors
Copy link
Contributor

bors commented Jul 26, 2020

☀️ Try build successful - checks-actions, checks-azure
Build commit: 1b5adbdbb4a5be604061874ffc2dade72bf7ede0 (1b5adbdbb4a5be604061874ffc2dade72bf7ede0)

/// other than `RUSTC_LOG`.
pub fn init_env_logger(env: &str) {
// Don't register a dispatcher if there's no filter to print anything
match std::env::var(env) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be var_os?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what would be the difference in this case?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not checking utf8 validity.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm true, let's change it

@oli-obk oli-obk deleted the tracing branch August 2, 2020 06:17
@jyn514
Copy link
Member

jyn514 commented Aug 3, 2020

This broke my logging :( How do I get back the behavior of RUSTDOC_LOG=rustdoc::passes::collect? Right now it gives no output.

@jyn514
Copy link
Member

jyn514 commented Aug 3, 2020

RUSTDOC_LOG=rustdoc also doesn't work so I can't really use logging at all :/ RUSTDOC_LOG=debug has several million lines of output unfiltered.

@jyn514
Copy link
Member

jyn514 commented Aug 3, 2020

hmm, this works for RUSTDOC_LOG=rustc_metadata so maybe it's something specific to tools?

@jyn514
Copy link
Member

jyn514 commented Aug 3, 2020

This fixes it for me:

diff --git a/src/librustdoc/lib.rs b/src/librustdoc/lib.rs
index 002c5f96710..4f08452767a 100644
--- a/src/librustdoc/lib.rs
+++ b/src/librustdoc/lib.rs
@@ -43,7 +43,7 @@ extern crate rustc_trait_selection;
 extern crate rustc_typeck;
 extern crate test as testing;
 #[macro_use]
-extern crate log;
+extern crate tracing as log;
 
 use std::default::Default;
 use std::env;

Other tools might need a similar fix.

@jyn514 jyn514 mentioned this pull request Aug 3, 2020
@memoryruins
Copy link
Contributor

Other tools might need a similar fix.

@jyn514 ultimately the fix for rustdoc and any other tools may be similar to #74747,
where all mentions of log in the source are replaced by tracing.

@jyn514
Copy link
Member

jyn514 commented Aug 3, 2020

Sure, #74747 is the end goal and if tools want to do that first that's fine. But in the meantime logging is completely broken for rustdoc.

@memoryruins
Copy link
Contributor

👍 #75081 is a reasonable patch until rustdoc is ready for source renaming

Manishearth added a commit to Manishearth/rust that referenced this pull request Aug 3, 2020
Manishearth added a commit to Manishearth/rust that referenced this pull request Aug 3, 2020
Manishearth added a commit to Manishearth/rust that referenced this pull request Aug 3, 2020
@Mark-Simulacrum
Copy link
Member

This was a slight performance win, as expected. Huge thanks to @oli-obk and @hawkw for all the work put in here to get us an even faster logging framework. 🎉

JohnTitor added a commit to JohnTitor/rust that referenced this pull request Aug 3, 2020
@hawkw
Copy link
Contributor

hawkw commented Aug 3, 2020

Yay! I'm really glad we were able to get this merged, and the optimizations should benefit other tracing users, as well.

Please feel free to ping me if anyone has additional questions about migrating to tracing!

JohnTitor added a commit to JohnTitor/rust that referenced this pull request Aug 4, 2020
@hawkw
Copy link
Contributor

hawkw commented Aug 11, 2020

When we finish with optimizations, could we get another final try run in that checks the overhead of turning off the compile-time removal of most logging? In particular if we can afford it I'd love to have it on by default -- it's often a real pain to have to recompile with debug assertions on just to get debug logging. Plus, debug assertions are a 25% (just compiler) or 50% (std and compiler) performance hit; I wonder how much of that was from logging...

FWIW, it might be worth trying this again with the latest tracing and tracing-subscriber; we fixed a bug that caused the fast path to not be taken in some cases where it should have been. It might be worth a test.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.