-
Notifications
You must be signed in to change notification settings - Fork 389
Add tracing_chrome under "tracing" feature #4406
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
base: master
Are you sure you want to change the base?
Conversation
16e2ce6
to
d432b6b
Compare
I am not sure why tests fail, when I tried locally they failed even on the latest commit on |
I am on May I know what os are you currently using? And is the failure the same as the one in the CI? |
@tiif On my PC the tests that fail run into errors like "error: unsupported operation: extern static
I am also on |
I suspect the CI failure might be triggered by the change in this PR, as there were successful CI runs after this one in https://github.com/rust-lang/miri/actions. (I haven't read the code closely, so this is just a guess :) About the unsupported error, I think maybe the toolchain is outdated. You can try to follow the steps here https://github.com/rust-lang/miri/blob/master/CONTRIBUTING.md#preparing-the-build-environment to update it if you haven't done so recently. If the problem persists, feel free to ask for help in zulip. |
The file was taken unmodified from the following link, except for file attributes at the top: https://github.com/thoren-d/tracing-chrome/blob/7e2625ab4aeeef2f0ef9bde9d6258dd181c04472/src/lib.rs Depending on the tracing-chrome crate from crates.io is unfortunately not possible since it depends on `tracing_core` which conflicts with rustc_private's `tracing_core` (meaning it would not be possible to use the [ChromeLayer] in a context that expects a [Layer] from from rustc_private's `tracing_core` version)
The tracing_chrome Layer has a connected Guard that needs to be dropped before exiting the process, or else data may not be flushed to the tracing file. This required making a few changes to main() to ensure std::process::exit() is not called without making sure to first drop the guard.
The tests pass locally. I rebased on master and force pushed to make the CI rerun, but it still fails. Both now and earlier, I think the cause for the CI failure was "memory allocation of 408 bytes failed" on windows-latest (see here and here). mac also fails due to "No space left on device (os error 28)" (see here). I don't understand why ubuntu fails with code 143 without printing any error. I don't understand how changes in this PR can cause the tests to use more memory (assuming that's the culprit). The behavior of the code in this PR should be the same as before when no |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The build was failing because the ci/ci.sh
script passed CARGO_EXTRA_FLAGS=--all-features
and thus enabled the tracing feature, which caused every test to collect and save tracing information to file which filled up the worker filesystem leading to the errors above. Now I changed ci/ci.sh
to only include the features relevant for tests, i.e. all but "tracing", i.e. genmc, stack-cache, stack-cache-consistency-check
.
|
||
# Determine configuration for installed build (used by test-cargo-miri and `./miri bench`). | ||
echo "Installing release version of Miri" | ||
time ./miri install | ||
time ./miri install "$FEATURES" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The change in this line changes the behavior of test-cargo-miri
and ./miri bench
down the line by enabling the genmc
and stack-cache-consistency-check
features which would otherwise be disabled by default. Since I couldn't find a comment explaining why those features are not being enabled here too, I made this change, but it's not really necessary. Is this ok or should I revert this change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
stack-cache-consistency-check
makes things quite slow so it was deliberately not enabled here.
//! Depending on the tracing-chrome crate from crates.io is unfortunately not possible, since it | ||
//! depends on `tracing_core` which conflicts with rustc_private's `tracing_core` (meaning it would | ||
//! not be possible to use the [ChromeLayer] in a context that expects a [Layer] from from | ||
//! rustc_private's `tracing_core` version). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please explain the licensing situation to ensure we got that covered, too.
@@ -63,6 +64,7 @@ struct MiriCompilerCalls { | |||
many_seeds: Option<ManySeedsConfig>, | |||
/// Settings for using GenMC with Miri. | |||
genmc_config: Option<GenmcConfig>, | |||
tracing_guard: Option<TracingGuard>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need a new field here and what does this do?
@@ -211,6 +219,10 @@ impl rustc_driver::Callbacks for MiriCompilerCalls { | |||
if return_code != rustc_driver::EXIT_SUCCESS { | |||
eprintln!("FAILING SEED: {seed}"); | |||
if !many_seeds.keep_going { | |||
// drop the tracing guard before exiting, so tracing calls are flushed correctly | |||
if let Ok(mut lock) = tracing_guard.try_lock() { | |||
let _guard_being_dropped = (*lock).take(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An explicit call to drop
seems more clear here.
But it's not great tha we apparently have to remember to do this in multiple places...
@@ -223,6 +235,9 @@ impl rustc_driver::Callbacks for MiriCompilerCalls { | |||
if num_failed > 0 { | |||
eprintln!("{num_failed}/{total} SEEDS FAILED", total = many_seeds.seeds.count()); | |||
} | |||
// drop the tracing guard before exiting, so tracing calls are flushed correctly | |||
#[allow(clippy::drop_non_drop)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can probably avoid the lint by adding impl Drop for TracingGuard
to make sure it is always a drop-type.
/// Does not call [std::process::exit] directly, but rather returns an [ExitCode], | ||
/// to allow the tracing guard to be dropped before exiting. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With those new semantics, the function name no longer makes sense.
guard = Some(TracingGuard { | ||
#[cfg(feature = "tracing")] | ||
_chrome: chrome_guard, | ||
_no_construct: (), | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why does this guard have toe be created here? This then causes all sorts of complexity since you can't know whether it gets created in early-init or late-init.
It seems better to just create the guard separately?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not convinced that this file should live here. That makes the responsibility sharing between the bin crate and the lib crate a lot more complicated.
Can this live as a separate file in the bin
folder?
use tracing_subscriber::Registry; | ||
|
||
#[must_use] | ||
pub struct TracingGuard { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a doc comment to this type.
@@ -0,0 +1,623 @@ | |||
//! This file is taken unmodified from the following link, except for file attributes at the top: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And except for the extern crate
I guess?
// this is here and not in src/lib.rs since it is a direct dependency of tracing_chrome.rs and | ||
// should not be included if the "tracing" feature is disabled | ||
extern crate tracing_core; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// this is here and not in src/lib.rs since it is a direct dependency of tracing_chrome.rs and | |
// should not be included if the "tracing" feature is disabled | |
extern crate tracing_core; | |
// This is here and not in src/lib.rs since it is a direct dependency of tracing_chrome.rs and | |
// should not be included if the "tracing" feature is disabled. | |
extern crate tracing_core; |
Machine::TRACING_ENABLED
totrue
tracing_chrome
crate by copy-pasting this ~600 line file.tracing_core
which conflicts with rustc_private'stracing_core
(meaning it would not be possible to use theChromeLayer
in a context that expects aLayer
from from rustc_private'stracing_core
version).[patch]
and[replace]
sections, but although they would work for normal libraries, they don't seem to behave as expected when the crate to replace comes fromrustc_private
, see this Zulip comment for a list of experimentsmiri.rs
so the file is less cluttered.trace/
(like done now) or should I rather move them underbin/
, since onlybin/miri.rs
uses those functions?ChromeLayer
internally starts a thread to write data to file, and thus relies on a guard to properly flush the file and terminate the thread when dropped. Sincestd::process::exit()
was being called in a few places, I had to restructure the code a bit to avoid exiting directly (which wouldn't calldrop()
on the guard).rustc_driver::catch_fatal_errors()
. After modifyingrun_compiler_then_exit
to not exit directly, I could confirm that the tracing file was being flushed correctly in case of a compiler error by runningRUSTC_LOG=1 ./miri run --features tracing FILE_WITH_SYNTAX_ERRORS
.init_early_loggers()
after argument parsing, is this ok? I did not see any log/trace call during argument parsing anyway. This avoids having to refactorshow_error!()
to not exit() directly