diff --git a/compiler/rustc_codegen_ssa/src/base.rs b/compiler/rustc_codegen_ssa/src/base.rs index a109633520ab9..24a83ac546f77 100644 --- a/compiler/rustc_codegen_ssa/src/base.rs +++ b/compiler/rustc_codegen_ssa/src/base.rs @@ -787,7 +787,6 @@ pub fn codegen_crate( start_rss.unwrap(), end_rss, tcx.sess.opts.unstable_opts.time_passes_format, - true, ); } diff --git a/compiler/rustc_data_structures/src/profiling.rs b/compiler/rustc_data_structures/src/profiling.rs index 87b74903d5125..58a0609e29655 100644 --- a/compiler/rustc_data_structures/src/profiling.rs +++ b/compiler/rustc_data_structures/src/profiling.rs @@ -220,7 +220,7 @@ impl SelfProfilerRef { let message_and_format = self.print_verbose_generic_activities.map(|format| (event_label.to_owned(), format)); - VerboseTimingGuard::start(message_and_format, self.generic_activity(event_label), false) + VerboseTimingGuard::start(message_and_format, self.generic_activity(event_label)) } /// Like `verbose_generic_activity`, but with an extra arg. @@ -239,21 +239,9 @@ impl SelfProfilerRef { VerboseTimingGuard::start( message_and_format, self.generic_activity_with_arg(event_label, event_arg), - false, ) } - /// Like `verbose_generic_activity`, but `event_label` must be unique for a rustc session. - pub fn unique_verbose_generic_activity( - &self, - event_label: &'static str, - ) -> VerboseTimingGuard<'_> { - let message_and_format = - self.print_verbose_generic_activities.map(|format| (event_label.to_owned(), format)); - - VerboseTimingGuard::start(message_and_format, self.generic_activity(event_label), true) - } - /// Start profiling a generic activity. Profiling continues until the /// TimingGuard returned from this call is dropped. #[inline(always)] @@ -729,9 +717,16 @@ impl<'a> TimingGuard<'a> { } } +struct VerboseInfo { + start_time: Instant, + start_rss: Option, + message: String, + format: TimePassesFormat, +} + #[must_use] pub struct VerboseTimingGuard<'a> { - start_and_message: Option<(Instant, Option, String, TimePassesFormat, bool)>, + info: Option, _guard: TimingGuard<'a>, } @@ -739,12 +734,14 @@ impl<'a> VerboseTimingGuard<'a> { pub fn start( message_and_format: Option<(String, TimePassesFormat)>, _guard: TimingGuard<'a>, - unique: bool, ) -> Self { VerboseTimingGuard { _guard, - start_and_message: message_and_format.map(|(msg, format)| { - (Instant::now(), get_resident_set_size(), msg, format, unique) + info: message_and_format.map(|(message, format)| VerboseInfo { + start_time: Instant::now(), + start_rss: get_resident_set_size(), + message, + format, }), } } @@ -758,10 +755,10 @@ impl<'a> VerboseTimingGuard<'a> { impl Drop for VerboseTimingGuard<'_> { fn drop(&mut self) { - if let Some((start_time, start_rss, ref message, format, unique)) = self.start_and_message { + if let Some(info) = &self.info { let end_rss = get_resident_set_size(); - let dur = start_time.elapsed(); - print_time_passes_entry(message, dur, start_rss, end_rss, format, unique); + let dur = info.start_time.elapsed(); + print_time_passes_entry(&info.message, dur, info.start_rss, end_rss, info.format); } } } @@ -772,18 +769,19 @@ pub fn print_time_passes_entry( start_rss: Option, end_rss: Option, format: TimePassesFormat, - unique: bool, ) { - if format == TimePassesFormat::Json { - let json = json!({ - "pass": what, - "time": dur.as_secs_f64(), - "rss_start": start_rss, - "rss_end": end_rss, - "unique": unique, - }); - eprintln!("time: {}", json.to_string()); - return; + match format { + TimePassesFormat::Json => { + let json = json!({ + "pass": what, + "time": dur.as_secs_f64(), + "rss_start": start_rss, + "rss_end": end_rss, + }); + eprintln!("time: {}", json.to_string()); + return; + } + TimePassesFormat::Text => (), } // Print the pass if its duration is greater than 5 ms, or it changed the diff --git a/compiler/rustc_driver_impl/src/lib.rs b/compiler/rustc_driver_impl/src/lib.rs index d44bd7fdb1851..ad2c2b13fed57 100644 --- a/compiler/rustc_driver_impl/src/lib.rs +++ b/compiler/rustc_driver_impl/src/lib.rs @@ -1359,7 +1359,7 @@ pub fn main() -> ! { if let Some(format) = callbacks.time_passes { let end_rss = get_resident_set_size(); - print_time_passes_entry("total", start_time.elapsed(), start_rss, end_rss, format, true); + print_time_passes_entry("total", start_time.elapsed(), start_rss, end_rss, format); } process::exit(exit_code) diff --git a/compiler/rustc_session/src/utils.rs b/compiler/rustc_session/src/utils.rs index a7feb2794c4f6..3b3d4ca5d6b21 100644 --- a/compiler/rustc_session/src/utils.rs +++ b/compiler/rustc_session/src/utils.rs @@ -4,10 +4,10 @@ use std::path::{Path, PathBuf}; impl Session { pub fn timer(&self, what: &'static str) -> VerboseTimingGuard<'_> { - self.prof.unique_verbose_generic_activity(what) + self.prof.verbose_generic_activity(what) } pub fn time(&self, what: &'static str, f: impl FnOnce() -> R) -> R { - self.prof.unique_verbose_generic_activity(what).run(f) + self.prof.verbose_generic_activity(what).run(f) } }