1
Fork 0

Rollup merge of #102725 - nnethercote:rm-Z-time, r=davidtwco

Remove `-Ztime`

Because it has a lot of overlap with `-Ztime-passes` but is generally less useful. Plus some related cleanups.

Best reviewed one commit at a time.

r? `@davidtwco`
This commit is contained in:
Matthias Krüger 2022-10-06 16:29:45 +02:00 committed by GitHub
commit 42df0a580f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 56 additions and 74 deletions

View file

@ -158,30 +158,21 @@ pub struct SelfProfilerRef {
// actually enabled.
event_filter_mask: EventFilter,
// Print verbose generic activities to stdout
// Print verbose generic activities to stderr?
print_verbose_generic_activities: bool,
// Print extra verbose generic activities to stdout
print_extra_verbose_generic_activities: bool,
}
impl SelfProfilerRef {
pub fn new(
profiler: Option<Arc<SelfProfiler>>,
print_verbose_generic_activities: bool,
print_extra_verbose_generic_activities: bool,
) -> SelfProfilerRef {
// If there is no SelfProfiler then the filter mask is set to NONE,
// ensuring that nothing ever tries to actually access it.
let event_filter_mask =
profiler.as_ref().map_or(EventFilter::empty(), |p| p.event_filter_mask);
SelfProfilerRef {
profiler,
event_filter_mask,
print_verbose_generic_activities,
print_extra_verbose_generic_activities,
}
SelfProfilerRef { profiler, event_filter_mask, print_verbose_generic_activities }
}
/// This shim makes sure that calls only get executed if the filter mask
@ -214,7 +205,7 @@ impl SelfProfilerRef {
/// Start profiling a verbose generic activity. Profiling continues until the
/// VerboseTimingGuard returned from this call is dropped. In addition to recording
/// a measureme event, "verbose" generic activities also print a timing entry to
/// stdout if the compiler is invoked with -Ztime or -Ztime-passes.
/// stderr if the compiler is invoked with -Ztime-passes.
pub fn verbose_generic_activity<'a>(
&'a self,
event_label: &'static str,
@ -225,11 +216,8 @@ impl SelfProfilerRef {
VerboseTimingGuard::start(message, self.generic_activity(event_label))
}
/// Start profiling an extra verbose generic activity. Profiling continues until the
/// VerboseTimingGuard returned from this call is dropped. In addition to recording
/// a measureme event, "extra verbose" generic activities also print a timing entry to
/// stdout if the compiler is invoked with -Ztime-passes.
pub fn extra_verbose_generic_activity<'a, A>(
/// Like `verbose_generic_activity`, but with an extra arg.
pub fn verbose_generic_activity_with_arg<'a, A>(
&'a self,
event_label: &'static str,
event_arg: A,
@ -237,7 +225,7 @@ impl SelfProfilerRef {
where
A: Borrow<str> + Into<String>,
{
let message = if self.print_extra_verbose_generic_activities {
let message = if self.print_verbose_generic_activities {
Some(format!("{}({})", event_label, event_arg.borrow()))
} else {
None
@ -745,35 +733,37 @@ impl Drop for VerboseTimingGuard<'_> {
if let Some((start_time, start_rss, ref message)) = self.start_and_message {
let end_rss = get_resident_set_size();
let dur = start_time.elapsed();
if should_print_passes(dur, start_rss, end_rss) {
print_time_passes_entry(&message, dur, start_rss, end_rss);
}
print_time_passes_entry(&message, dur, start_rss, end_rss);
}
}
}
fn should_print_passes(dur: Duration, start_rss: Option<usize>, end_rss: Option<usize>) -> bool {
if dur.as_millis() > 5 {
return true;
}
if let (Some(start_rss), Some(end_rss)) = (start_rss, end_rss) {
let change_rss = end_rss.abs_diff(start_rss);
if change_rss > 0 {
return true;
}
}
false
}
pub fn print_time_passes_entry(
what: &str,
dur: Duration,
start_rss: Option<usize>,
end_rss: Option<usize>,
) {
// Print the pass if its duration is greater than 5 ms, or it changed the
// measured RSS.
let is_notable = || {
if dur.as_millis() > 5 {
return true;
}
if let (Some(start_rss), Some(end_rss)) = (start_rss, end_rss) {
let change_rss = end_rss.abs_diff(start_rss);
if change_rss > 0 {
return true;
}
}
false
};
if !is_notable() {
return;
}
let rss_to_mb = |rss| (rss as f64 / 1_000_000.0).round() as usize;
let rss_change_to_mb = |rss| (rss as f64 / 1_000_000.0).round() as i128;