Remove unique
and move VerboseTimingGuard
fields into a new struct
This commit is contained in:
parent
f60d2eb6c1
commit
6c57dda44d
@ -787,7 +787,6 @@ pub fn codegen_crate<B: ExtraBackendMethods>(
|
||||
start_rss.unwrap(),
|
||||
end_rss,
|
||||
tcx.sess.opts.unstable_opts.time_passes_format,
|
||||
true,
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -220,7 +220,7 @@ pub fn verbose_generic_activity(&self, event_label: &'static str) -> VerboseTimi
|
||||
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 @@ pub fn verbose_generic_activity_with_arg<A>(
|
||||
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 @@ pub fn run<R>(self, f: impl FnOnce() -> R) -> R {
|
||||
}
|
||||
}
|
||||
|
||||
struct VerboseInfo {
|
||||
start_time: Instant,
|
||||
start_rss: Option<usize>,
|
||||
message: String,
|
||||
format: TimePassesFormat,
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub struct VerboseTimingGuard<'a> {
|
||||
start_and_message: Option<(Instant, Option<usize>, String, TimePassesFormat, bool)>,
|
||||
info: Option<VerboseInfo>,
|
||||
_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 @@ pub fn run<R>(self, f: impl FnOnce() -> R) -> R {
|
||||
|
||||
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<usize>,
|
||||
end_rss: Option<usize>,
|
||||
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
|
||||
|
@ -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)
|
||||
|
@ -4,10 +4,10 @@
|
||||
|
||||
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<R>(&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)
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user