-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Add tracing to step.rs and friends #144708
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
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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 |
---|---|---|
|
@@ -48,10 +48,24 @@ pub(crate) fn create_static_alloc<'tcx>( | |
|
||
/// A marker trait returned by [crate::interpret::Machine::enter_trace_span], identifying either a | ||
/// real [tracing::span::EnteredSpan] in case tracing is enabled, or the dummy type `()` when | ||
/// tracing is disabled. | ||
pub trait EnteredTraceSpan {} | ||
impl EnteredTraceSpan for () {} | ||
impl EnteredTraceSpan for tracing::span::EnteredSpan {} | ||
/// tracing is disabled. Also see [crate::enter_trace_span!] below. | ||
pub trait EnteredTraceSpan { | ||
/// Allows executing an alternative function when tracing is disabled. Useful for example if you | ||
/// want to open a trace span when tracing is enabled, and alternatively just log a line when | ||
/// tracing is disabled. | ||
fn or_if_tracing_disabled(self, f: impl FnOnce()) -> Self; | ||
} | ||
impl EnteredTraceSpan for () { | ||
fn or_if_tracing_disabled(self, f: impl FnOnce()) -> Self { | ||
f(); // tracing is disabled, execute the function | ||
self | ||
} | ||
} | ||
impl EnteredTraceSpan for tracing::span::EnteredSpan { | ||
fn or_if_tracing_disabled(self, _f: impl FnOnce()) -> Self { | ||
self // tracing is enabled, don't execute anything | ||
} | ||
} | ||
|
||
/// Shortand for calling [crate::interpret::Machine::enter_trace_span] on a [tracing::info_span!]. | ||
/// This is supposed to be compiled out when [crate::interpret::Machine::enter_trace_span] has the | ||
|
@@ -112,6 +126,19 @@ impl EnteredTraceSpan for tracing::span::EnteredSpan {} | |
/// # type M = rustc_const_eval::const_eval::CompileTimeMachine<'static>; | ||
/// let _span = enter_trace_span!(M, step::eval_statement, tracing_separate_thread = tracing::field::Empty); | ||
/// ``` | ||
/// | ||
/// ### Executing something else when tracing is disabled | ||
/// | ||
/// [crate::interpret::Machine::enter_trace_span] returns [EnteredTraceSpan], on which you can call | ||
/// [EnteredTraceSpan::or_if_tracing_disabled], to e.g. log a line as an alternative to the tracing | ||
/// span for when tracing is disabled. For example: | ||
/// ```rust | ||
/// # use rustc_const_eval::enter_trace_span; | ||
/// # use rustc_const_eval::interpret::EnteredTraceSpan; | ||
/// # type M = rustc_const_eval::const_eval::CompileTimeMachine<'static>; | ||
/// let _span = enter_trace_span!(M, step::eval_statement) | ||
/// .or_if_tracing_disabled(|| tracing::info!("eval_statement")); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's nice! |
||
/// ``` | ||
#[macro_export] | ||
macro_rules! enter_trace_span { | ||
($machine:ty, $name:ident :: $subname:ident $($tt:tt)*) => { | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
eval_statement and eval_terminator make a lot of sense -- I'm a bit surprised by the others, is that really helpful and worth the overhead?
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.
They do make it easier to understand what is happening at a particular point in my opinion, instead of having to look at the statement/terminator being executed and then guessing which path the execution followed. When I was looking for functions to trace, I found it quite helpful to notice "this init_fn_call took a lot of time, but most of it was outside init_stack_frame" or instead "this init_fn_call spent most of its time in init_stack_frame".
But yeah they do add quite some overhead (the number of spans is ~3x what it would be with only eval_statement and eval_terminator). If we want to prune some of the less useful ones, I'd remove
eval_place
andeval_place_to_op
(they are very short lived, see the table),eval_rvalue_into_place
(it's usually just a direct child ofeval_statement
with nothing else happening around it). This would leave us with just an 1.5x overhead over just eval_statement and eval_terminator. What do you think?Uh oh!
There was an error while loading. Please reload this page.
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 was referring to the ones in this file only, i.e. eval_rvalue_into_place, eval_fn_call_argument, eval_callee_and_args. My first inclination would be to remove them.
eval_place and eval_place_to_op and eval_operand form a nice group that makes sense together.
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.
Oh ok, I don't have strong opinions about those so we can as well remove them.