-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[rustdoc] Display total time and compilation time of merged doctests #144308
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?
[rustdoc] Display total time and compilation time of merged doctests #144308
Conversation
r? @notriddle rustbot has assigned @notriddle. Use |
This seems sufficient, in that it communicates the missing information, separately. However, there is a way in which I predict it will be frequently confusing: there is no spatial or textual association of "merged doctests compilation took…" with which tests are the merged ones. A user wanting to know which doctests this refers to has to reason about what 'merged doctests' means and then, using that fact, figure out they must be the first group since the second group has compile-fail tests. I strongly recommend that the report of compilation time should not be separated from the tests it refers to by unrelated tests. When I initially imagined quickly adding this feature, I imagined putting the doctest compilation time at the top, corresponding to when it actually happens, and thus also adjacent to the merged tests. Another option would be to label the group of merged tests as merged, somehow. |
You can have multiple merged doctests groups, so unless we show it for each group, I'm not sure it's really useful. It tells how much time it spent compiling merged doctests and the total time for all doctests. |
Ah, I see, I wasn't aware that there was a possibility of multiple groups. I don't have any further ideas. Thank you for working on this. |
src/librustdoc/doctest.rs
Outdated
struct MergedDoctestTimes { | ||
total_time: Instant, | ||
compilation_time: Duration, | ||
/// This field is used to keep track of how many merged doctests we (tried to) compile. | ||
added_compilation_times: usize, | ||
} |
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.
struct MergedDoctestTimes { | |
total_time: Instant, | |
compilation_time: Duration, | |
/// This field is used to keep track of how many merged doctests we (tried to) compile. | |
added_compilation_times: usize, | |
} | |
struct DoctestTimes { | |
compilation_start: Instant, | |
/// Total time spent compiling all merged doctests | |
merged_compilation_time: Duration, | |
/// This field is used to keep track of how many merged doctests we (tried to) compile. | |
merged_doctest_count: usize, | |
} |
Since this tracks time for standalone and merged doctests, I think these names would be more clear.
Also, is it possible for multiple merged doctest groups to get compiled in parallel? if so, that could cause some confusion due to the total time actually being shorter.
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.
Not currently at least and I don't think we're planning to. That could potentially use too much resources.
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 added the comments, however I didn't rename the type as it is only used for merged doctests and therefore didn't update the field name either.
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 total time is the total time for all doctests, though??
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.
Yes but it's only run in merged doctests context.
fn display_times(&self) { | ||
// If no merged doctest was compiled, then there is nothing to display. | ||
if self.added_compilation_times > 0 { | ||
println!("{self}"); | ||
} | ||
} | ||
} | ||
|
||
impl fmt::Display for MergedDoctestTimes { | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
write!( | ||
f, | ||
"all doctests ran in {:.2}s; merged doctests compilation took {:.2}s", | ||
self.total_time.elapsed().as_secs_f64(), | ||
self.compilation_time.as_secs_f64(), | ||
) | ||
} | ||
} |
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.
Shouldn't we still print the total compilation time, even if there are no merged doctests?
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.
No because in this case, the numbers displayed by libtest
are already accurate.
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.
Some extra info: for standalone tests, libtest
reports both compilation and run time as each doctest passed to libtest
will call the doctest_run_fn
which handles both.
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.
hm, that's odd, that's what i thought initially, but the numbers in the screenshot simply don't add up for that to be the case. not sure what's happening here.
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.
in any case, the comment explaining the rationale for ommitting all the output seems incomplete and mildly misleading.
@@ -501,11 +548,12 @@ fn run_test( | |||
rustdoc_options: &RustdocOptions, | |||
supports_color: bool, | |||
report_unused_externs: impl Fn(UnusedExterns), | |||
) -> Result<(), TestFailure> { | |||
) -> (Duration, Result<(), TestFailure>) { |
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.
There should be a comment explaining that this is the time taken for compilation, not the total time overall.
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.
Indeed, gonna add some comments.
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
write!( | ||
f, | ||
"all doctests ran in {:.2}s; merged doctests compilation took {:.2}s", |
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.
"all doctests ran in {:.2}s; merged doctests compilation took {:.2}s", | |
"all doctests compiled in {:.2}s; merged doctests compilation took {:.2}s", |
misleading string, this only measures compilation time
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.
Euh no. It measures the total time.
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 got confused by the inconsistencies of the times in the screenshot, i think.
@@ -1071,7 +1120,7 @@ fn doctest_run_fn( | |||
no_run: scraped_test.no_run(&rustdoc_options), | |||
merged_test_code: None, | |||
}; | |||
let res = | |||
let (_, res) = |
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.
Is there a reason we're not also tracking this, so we can report (time compiling standalone tests, time compiling merged tests)
?
I believe doctests are run with some level of parallelism, so currently we would be reporting the total absolute wall clock time for the total compilation time, but for merged doctests, we're reporting the sum of the amount of time each thread spent compiling. This inconsistency could over-report the impact of merged doctests.
Also, if parallelism is involved, then I think perhaps a more useful metric for minimizing compilation time would be how long the longest test took.
a3d520c
to
d0ec770
Compare
Fixes #144270.
Does it look good to you @kpreid?