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(),
|
start_rss.unwrap(),
|
||||||
end_rss,
|
end_rss,
|
||||||
tcx.sess.opts.unstable_opts.time_passes_format,
|
tcx.sess.opts.unstable_opts.time_passes_format,
|
||||||
true,
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -220,7 +220,7 @@ impl SelfProfilerRef {
|
|||||||
let message_and_format =
|
let message_and_format =
|
||||||
self.print_verbose_generic_activities.map(|format| (event_label.to_owned(), 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.
|
/// Like `verbose_generic_activity`, but with an extra arg.
|
||||||
@ -239,21 +239,9 @@ impl SelfProfilerRef {
|
|||||||
VerboseTimingGuard::start(
|
VerboseTimingGuard::start(
|
||||||
message_and_format,
|
message_and_format,
|
||||||
self.generic_activity_with_arg(event_label, event_arg),
|
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
|
/// Start profiling a generic activity. Profiling continues until the
|
||||||
/// TimingGuard returned from this call is dropped.
|
/// TimingGuard returned from this call is dropped.
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
@ -729,9 +717,16 @@ impl<'a> TimingGuard<'a> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct VerboseInfo {
|
||||||
|
start_time: Instant,
|
||||||
|
start_rss: Option<usize>,
|
||||||
|
message: String,
|
||||||
|
format: TimePassesFormat,
|
||||||
|
}
|
||||||
|
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub struct VerboseTimingGuard<'a> {
|
pub struct VerboseTimingGuard<'a> {
|
||||||
start_and_message: Option<(Instant, Option<usize>, String, TimePassesFormat, bool)>,
|
info: Option<VerboseInfo>,
|
||||||
_guard: TimingGuard<'a>,
|
_guard: TimingGuard<'a>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -739,12 +734,14 @@ impl<'a> VerboseTimingGuard<'a> {
|
|||||||
pub fn start(
|
pub fn start(
|
||||||
message_and_format: Option<(String, TimePassesFormat)>,
|
message_and_format: Option<(String, TimePassesFormat)>,
|
||||||
_guard: TimingGuard<'a>,
|
_guard: TimingGuard<'a>,
|
||||||
unique: bool,
|
|
||||||
) -> Self {
|
) -> Self {
|
||||||
VerboseTimingGuard {
|
VerboseTimingGuard {
|
||||||
_guard,
|
_guard,
|
||||||
start_and_message: message_and_format.map(|(msg, format)| {
|
info: message_and_format.map(|(message, format)| VerboseInfo {
|
||||||
(Instant::now(), get_resident_set_size(), msg, format, unique)
|
start_time: Instant::now(),
|
||||||
|
start_rss: get_resident_set_size(),
|
||||||
|
message,
|
||||||
|
format,
|
||||||
}),
|
}),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -758,10 +755,10 @@ impl<'a> VerboseTimingGuard<'a> {
|
|||||||
|
|
||||||
impl Drop for VerboseTimingGuard<'_> {
|
impl Drop for VerboseTimingGuard<'_> {
|
||||||
fn drop(&mut self) {
|
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 end_rss = get_resident_set_size();
|
||||||
let dur = start_time.elapsed();
|
let dur = info.start_time.elapsed();
|
||||||
print_time_passes_entry(message, dur, start_rss, end_rss, format, unique);
|
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>,
|
start_rss: Option<usize>,
|
||||||
end_rss: Option<usize>,
|
end_rss: Option<usize>,
|
||||||
format: TimePassesFormat,
|
format: TimePassesFormat,
|
||||||
unique: bool,
|
|
||||||
) {
|
) {
|
||||||
if format == TimePassesFormat::Json {
|
match format {
|
||||||
let json = json!({
|
TimePassesFormat::Json => {
|
||||||
"pass": what,
|
let json = json!({
|
||||||
"time": dur.as_secs_f64(),
|
"pass": what,
|
||||||
"rss_start": start_rss,
|
"time": dur.as_secs_f64(),
|
||||||
"rss_end": end_rss,
|
"rss_start": start_rss,
|
||||||
"unique": unique,
|
"rss_end": end_rss,
|
||||||
});
|
});
|
||||||
eprintln!("time: {}", json.to_string());
|
eprintln!("time: {}", json.to_string());
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
TimePassesFormat::Text => (),
|
||||||
}
|
}
|
||||||
|
|
||||||
// Print the pass if its duration is greater than 5 ms, or it changed the
|
// 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 {
|
if let Some(format) = callbacks.time_passes {
|
||||||
let end_rss = get_resident_set_size();
|
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)
|
process::exit(exit_code)
|
||||||
|
@ -4,10 +4,10 @@ use std::path::{Path, PathBuf};
|
|||||||
|
|
||||||
impl Session {
|
impl Session {
|
||||||
pub fn timer(&self, what: &'static str) -> VerboseTimingGuard<'_> {
|
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 {
|
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…
x
Reference in New Issue
Block a user