Skip to content

Commit 6c57dda

Browse files
committed
Remove unique and move VerboseTimingGuard fields into a new struct
1 parent f60d2eb commit 6c57dda

File tree

4 files changed

+32
-35
lines changed

4 files changed

+32
-35
lines changed

compiler/rustc_codegen_ssa/src/base.rs

-1
Original file line numberDiff line numberDiff line change
@@ -787,7 +787,6 @@ pub fn codegen_crate<B: ExtraBackendMethods>(
787787
start_rss.unwrap(),
788788
end_rss,
789789
tcx.sess.opts.unstable_opts.time_passes_format,
790-
true,
791790
);
792791
}
793792

compiler/rustc_data_structures/src/profiling.rs

+29-31
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ impl SelfProfilerRef {
220220
let message_and_format =
221221
self.print_verbose_generic_activities.map(|format| (event_label.to_owned(), format));
222222

223-
VerboseTimingGuard::start(message_and_format, self.generic_activity(event_label), false)
223+
VerboseTimingGuard::start(message_and_format, self.generic_activity(event_label))
224224
}
225225

226226
/// Like `verbose_generic_activity`, but with an extra arg.
@@ -239,21 +239,9 @@ impl SelfProfilerRef {
239239
VerboseTimingGuard::start(
240240
message_and_format,
241241
self.generic_activity_with_arg(event_label, event_arg),
242-
false,
243242
)
244243
}
245244

246-
/// Like `verbose_generic_activity`, but `event_label` must be unique for a rustc session.
247-
pub fn unique_verbose_generic_activity(
248-
&self,
249-
event_label: &'static str,
250-
) -> VerboseTimingGuard<'_> {
251-
let message_and_format =
252-
self.print_verbose_generic_activities.map(|format| (event_label.to_owned(), format));
253-
254-
VerboseTimingGuard::start(message_and_format, self.generic_activity(event_label), true)
255-
}
256-
257245
/// Start profiling a generic activity. Profiling continues until the
258246
/// TimingGuard returned from this call is dropped.
259247
#[inline(always)]
@@ -729,22 +717,31 @@ impl<'a> TimingGuard<'a> {
729717
}
730718
}
731719

720+
struct VerboseInfo {
721+
start_time: Instant,
722+
start_rss: Option<usize>,
723+
message: String,
724+
format: TimePassesFormat,
725+
}
726+
732727
#[must_use]
733728
pub struct VerboseTimingGuard<'a> {
734-
start_and_message: Option<(Instant, Option<usize>, String, TimePassesFormat, bool)>,
729+
info: Option<VerboseInfo>,
735730
_guard: TimingGuard<'a>,
736731
}
737732

738733
impl<'a> VerboseTimingGuard<'a> {
739734
pub fn start(
740735
message_and_format: Option<(String, TimePassesFormat)>,
741736
_guard: TimingGuard<'a>,
742-
unique: bool,
743737
) -> Self {
744738
VerboseTimingGuard {
745739
_guard,
746-
start_and_message: message_and_format.map(|(msg, format)| {
747-
(Instant::now(), get_resident_set_size(), msg, format, unique)
740+
info: message_and_format.map(|(message, format)| VerboseInfo {
741+
start_time: Instant::now(),
742+
start_rss: get_resident_set_size(),
743+
message,
744+
format,
748745
}),
749746
}
750747
}
@@ -758,10 +755,10 @@ impl<'a> VerboseTimingGuard<'a> {
758755

759756
impl Drop for VerboseTimingGuard<'_> {
760757
fn drop(&mut self) {
761-
if let Some((start_time, start_rss, ref message, format, unique)) = self.start_and_message {
758+
if let Some(info) = &self.info {
762759
let end_rss = get_resident_set_size();
763-
let dur = start_time.elapsed();
764-
print_time_passes_entry(message, dur, start_rss, end_rss, format, unique);
760+
let dur = info.start_time.elapsed();
761+
print_time_passes_entry(&info.message, dur, info.start_rss, end_rss, info.format);
765762
}
766763
}
767764
}
@@ -772,18 +769,19 @@ pub fn print_time_passes_entry(
772769
start_rss: Option<usize>,
773770
end_rss: Option<usize>,
774771
format: TimePassesFormat,
775-
unique: bool,
776772
) {
777-
if format == TimePassesFormat::Json {
778-
let json = json!({
779-
"pass": what,
780-
"time": dur.as_secs_f64(),
781-
"rss_start": start_rss,
782-
"rss_end": end_rss,
783-
"unique": unique,
784-
});
785-
eprintln!("time: {}", json.to_string());
786-
return;
773+
match format {
774+
TimePassesFormat::Json => {
775+
let json = json!({
776+
"pass": what,
777+
"time": dur.as_secs_f64(),
778+
"rss_start": start_rss,
779+
"rss_end": end_rss,
780+
});
781+
eprintln!("time: {}", json.to_string());
782+
return;
783+
}
784+
TimePassesFormat::Text => (),
787785
}
788786

789787
// Print the pass if its duration is greater than 5 ms, or it changed the

compiler/rustc_driver_impl/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1359,7 +1359,7 @@ pub fn main() -> ! {
13591359

13601360
if let Some(format) = callbacks.time_passes {
13611361
let end_rss = get_resident_set_size();
1362-
print_time_passes_entry("total", start_time.elapsed(), start_rss, end_rss, format, true);
1362+
print_time_passes_entry("total", start_time.elapsed(), start_rss, end_rss, format);
13631363
}
13641364

13651365
process::exit(exit_code)

compiler/rustc_session/src/utils.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ use std::path::{Path, PathBuf};
44

55
impl Session {
66
pub fn timer(&self, what: &'static str) -> VerboseTimingGuard<'_> {
7-
self.prof.unique_verbose_generic_activity(what)
7+
self.prof.verbose_generic_activity(what)
88
}
99
pub fn time<R>(&self, what: &'static str, f: impl FnOnce() -> R) -> R {
10-
self.prof.unique_verbose_generic_activity(what).run(f)
10+
self.prof.verbose_generic_activity(what).run(f)
1111
}
1212
}
1313

0 commit comments

Comments
 (0)