Skip to content

Commit 4e8faff

Browse files
committed
Be consistent about deciding whether to print pass data.
`print_time_passes_entry` unconditionally prints data about a pass. The most commonly used call site, in `VerboseTimingGuard::drop`, guards it with a `should_print_passes` test. But there are a couple of other call sites that don't do that test. This commit moves the `should_print_passes` test within `print_time_passes_entry` so that all passes are treated equally.
1 parent 9110d92 commit 4e8faff

File tree

1 file changed

+21
-19
lines changed

1 file changed

+21
-19
lines changed

compiler/rustc_data_structures/src/profiling.rs

+21-19
Original file line numberDiff line numberDiff line change
@@ -733,27 +733,9 @@ impl Drop for VerboseTimingGuard<'_> {
733733
if let Some((start_time, start_rss, ref message)) = self.start_and_message {
734734
let end_rss = get_resident_set_size();
735735
let dur = start_time.elapsed();
736-
737-
if should_print_passes(dur, start_rss, end_rss) {
738-
print_time_passes_entry(&message, dur, start_rss, end_rss);
739-
}
740-
}
741-
}
742-
}
743-
744-
fn should_print_passes(dur: Duration, start_rss: Option<usize>, end_rss: Option<usize>) -> bool {
745-
if dur.as_millis() > 5 {
746-
return true;
747-
}
748-
749-
if let (Some(start_rss), Some(end_rss)) = (start_rss, end_rss) {
750-
let change_rss = end_rss.abs_diff(start_rss);
751-
if change_rss > 0 {
752-
return true;
736+
print_time_passes_entry(&message, dur, start_rss, end_rss);
753737
}
754738
}
755-
756-
false
757739
}
758740

759741
pub fn print_time_passes_entry(
@@ -762,6 +744,26 @@ pub fn print_time_passes_entry(
762744
start_rss: Option<usize>,
763745
end_rss: Option<usize>,
764746
) {
747+
// Print the pass if its duration is greater than 5 ms, or it changed the
748+
// measured RSS.
749+
let is_notable = || {
750+
if dur.as_millis() > 5 {
751+
return true;
752+
}
753+
754+
if let (Some(start_rss), Some(end_rss)) = (start_rss, end_rss) {
755+
let change_rss = end_rss.abs_diff(start_rss);
756+
if change_rss > 0 {
757+
return true;
758+
}
759+
}
760+
761+
false
762+
};
763+
if !is_notable() {
764+
return;
765+
}
766+
765767
let rss_to_mb = |rss| (rss as f64 / 1_000_000.0).round() as usize;
766768
let rss_change_to_mb = |rss| (rss as f64 / 1_000_000.0).round() as i128;
767769

0 commit comments

Comments
 (0)