Skip to content

Commit 42df0a5

Browse files
authored
Rollup merge of rust-lang#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`
2 parents 045fc18 + 4e8faff commit 42df0a5

File tree

14 files changed

+56
-74
lines changed

14 files changed

+56
-74
lines changed

compiler/rustc_codegen_llvm/src/back/lto.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -573,7 +573,7 @@ pub(crate) fn run_pass_manager(
573573
module: &mut ModuleCodegen<ModuleLlvm>,
574574
thin: bool,
575575
) -> Result<(), FatalError> {
576-
let _timer = cgcx.prof.extra_verbose_generic_activity("LLVM_lto_optimize", &*module.name);
576+
let _timer = cgcx.prof.verbose_generic_activity_with_arg("LLVM_lto_optimize", &*module.name);
577577
let config = cgcx.config(module.kind);
578578

579579
// Now we have one massive module inside of llmod. Time to run the

compiler/rustc_codegen_ssa/src/back/write.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1637,7 +1637,7 @@ fn start_executing_work<B: ExtraBackendMethods>(
16371637
llvm_start_time: &mut Option<VerboseTimingGuard<'a>>,
16381638
) {
16391639
if config.time_module && llvm_start_time.is_none() {
1640-
*llvm_start_time = Some(prof.extra_verbose_generic_activity("LLVM_passes", "crate"));
1640+
*llvm_start_time = Some(prof.verbose_generic_activity("LLVM_passes"));
16411641
}
16421642
}
16431643
}

compiler/rustc_data_structures/src/profiling.rs

+27-37
Original file line numberDiff line numberDiff line change
@@ -158,30 +158,21 @@ pub struct SelfProfilerRef {
158158
// actually enabled.
159159
event_filter_mask: EventFilter,
160160

161-
// Print verbose generic activities to stdout
161+
// Print verbose generic activities to stderr?
162162
print_verbose_generic_activities: bool,
163-
164-
// Print extra verbose generic activities to stdout
165-
print_extra_verbose_generic_activities: bool,
166163
}
167164

168165
impl SelfProfilerRef {
169166
pub fn new(
170167
profiler: Option<Arc<SelfProfiler>>,
171168
print_verbose_generic_activities: bool,
172-
print_extra_verbose_generic_activities: bool,
173169
) -> SelfProfilerRef {
174170
// If there is no SelfProfiler then the filter mask is set to NONE,
175171
// ensuring that nothing ever tries to actually access it.
176172
let event_filter_mask =
177173
profiler.as_ref().map_or(EventFilter::empty(), |p| p.event_filter_mask);
178174

179-
SelfProfilerRef {
180-
profiler,
181-
event_filter_mask,
182-
print_verbose_generic_activities,
183-
print_extra_verbose_generic_activities,
184-
}
175+
SelfProfilerRef { profiler, event_filter_mask, print_verbose_generic_activities }
185176
}
186177

187178
/// This shim makes sure that calls only get executed if the filter mask
@@ -214,7 +205,7 @@ impl SelfProfilerRef {
214205
/// Start profiling a verbose generic activity. Profiling continues until the
215206
/// VerboseTimingGuard returned from this call is dropped. In addition to recording
216207
/// a measureme event, "verbose" generic activities also print a timing entry to
217-
/// stdout if the compiler is invoked with -Ztime or -Ztime-passes.
208+
/// stderr if the compiler is invoked with -Ztime-passes.
218209
pub fn verbose_generic_activity<'a>(
219210
&'a self,
220211
event_label: &'static str,
@@ -225,19 +216,16 @@ impl SelfProfilerRef {
225216
VerboseTimingGuard::start(message, self.generic_activity(event_label))
226217
}
227218

228-
/// Start profiling an extra verbose generic activity. Profiling continues until the
229-
/// VerboseTimingGuard returned from this call is dropped. In addition to recording
230-
/// a measureme event, "extra verbose" generic activities also print a timing entry to
231-
/// stdout if the compiler is invoked with -Ztime-passes.
232-
pub fn extra_verbose_generic_activity<'a, A>(
219+
/// Like `verbose_generic_activity`, but with an extra arg.
220+
pub fn verbose_generic_activity_with_arg<'a, A>(
233221
&'a self,
234222
event_label: &'static str,
235223
event_arg: A,
236224
) -> VerboseTimingGuard<'a>
237225
where
238226
A: Borrow<str> + Into<String>,
239227
{
240-
let message = if self.print_extra_verbose_generic_activities {
228+
let message = if self.print_verbose_generic_activities {
241229
Some(format!("{}({})", event_label, event_arg.borrow()))
242230
} else {
243231
None
@@ -745,27 +733,9 @@ impl Drop for VerboseTimingGuard<'_> {
745733
if let Some((start_time, start_rss, ref message)) = self.start_and_message {
746734
let end_rss = get_resident_set_size();
747735
let dur = start_time.elapsed();
748-
749-
if should_print_passes(dur, start_rss, end_rss) {
750-
print_time_passes_entry(&message, dur, start_rss, end_rss);
751-
}
752-
}
753-
}
754-
}
755-
756-
fn should_print_passes(dur: Duration, start_rss: Option<usize>, end_rss: Option<usize>) -> bool {
757-
if dur.as_millis() > 5 {
758-
return true;
759-
}
760-
761-
if let (Some(start_rss), Some(end_rss)) = (start_rss, end_rss) {
762-
let change_rss = end_rss.abs_diff(start_rss);
763-
if change_rss > 0 {
764-
return true;
736+
print_time_passes_entry(&message, dur, start_rss, end_rss);
765737
}
766738
}
767-
768-
false
769739
}
770740

771741
pub fn print_time_passes_entry(
@@ -774,6 +744,26 @@ pub fn print_time_passes_entry(
774744
start_rss: Option<usize>,
775745
end_rss: Option<usize>,
776746
) {
747+
// Print the pass if its duration is greater than 5 ms, or it changed the
748+
// measured RSS.
749+
let is_notable = || {
750+
if dur.as_millis() > 5 {
751+
return true;
752+
}
753+
754+
if let (Some(start_rss), Some(end_rss)) = (start_rss, end_rss) {
755+
let change_rss = end_rss.abs_diff(start_rss);
756+
if change_rss > 0 {
757+
return true;
758+
}
759+
}
760+
761+
false
762+
};
763+
if !is_notable() {
764+
return;
765+
}
766+
777767
let rss_to_mb = |rss| (rss as f64 / 1_000_000.0).round() as usize;
778768
let rss_change_to_mb = |rss| (rss as f64 / 1_000_000.0).round() as i128;
779769

compiler/rustc_driver/src/lib.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,13 @@ pub struct TimePassesCallbacks {
127127
}
128128

129129
impl Callbacks for TimePassesCallbacks {
130+
// JUSTIFICATION: the session doesn't exist at this point.
131+
#[allow(rustc::bad_opt_access)]
130132
fn config(&mut self, config: &mut interface::Config) {
131-
// If a --prints=... option has been given, we don't print the "total"
132-
// time because it will mess up the --prints output. See #64339.
133-
self.time_passes = config.opts.prints.is_empty() && config.opts.time_passes();
133+
// If a --print=... option has been given, we don't print the "total"
134+
// time because it will mess up the --print output. See #64339.
135+
//
136+
self.time_passes = config.opts.prints.is_empty() && config.opts.unstable_opts.time_passes;
134137
config.opts.trimmed_def_paths = TrimmedDefPaths::GoodPath;
135138
}
136139
}

compiler/rustc_interface/src/tests.rs

-1
Original file line numberDiff line numberDiff line change
@@ -692,7 +692,6 @@ fn test_unstable_options_tracking_hash() {
692692
untracked!(span_free_formats, true);
693693
untracked!(temps_dir, Some(String::from("abc")));
694694
untracked!(threads, 99);
695-
untracked!(time, true);
696695
untracked!(time_llvm_passes, true);
697696
untracked!(time_passes, true);
698697
untracked!(trace_macros, true);

compiler/rustc_lint/src/early.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ pub fn check_ast_node<'a>(
409409
if sess.opts.unstable_opts.no_interleave_lints {
410410
for (i, pass) in passes.iter_mut().enumerate() {
411411
buffered =
412-
sess.prof.extra_verbose_generic_activity("run_lint", pass.name()).run(|| {
412+
sess.prof.verbose_generic_activity_with_arg("run_lint", pass.name()).run(|| {
413413
early_lint_node(
414414
sess,
415415
!pre_expansion && i == 0,

compiler/rustc_lint/src/late.rs

+10-7
Original file line numberDiff line numberDiff line change
@@ -425,20 +425,23 @@ fn late_lint_crate<'tcx, T: LateLintPass<'tcx>>(tcx: TyCtxt<'tcx>, builtin_lints
425425
late_lint_pass_crate(tcx, builtin_lints);
426426
} else {
427427
for pass in &mut passes {
428-
tcx.sess.prof.extra_verbose_generic_activity("run_late_lint", pass.name()).run(|| {
429-
late_lint_pass_crate(tcx, LateLintPassObjects { lints: slice::from_mut(pass) });
430-
});
428+
tcx.sess.prof.verbose_generic_activity_with_arg("run_late_lint", pass.name()).run(
429+
|| {
430+
late_lint_pass_crate(tcx, LateLintPassObjects { lints: slice::from_mut(pass) });
431+
},
432+
);
431433
}
432434

433435
let mut passes: Vec<_> =
434436
unerased_lint_store(tcx).late_module_passes.iter().map(|pass| (pass)(tcx)).collect();
435437

436438
for pass in &mut passes {
437-
tcx.sess.prof.extra_verbose_generic_activity("run_late_module_lint", pass.name()).run(
438-
|| {
439+
tcx.sess
440+
.prof
441+
.verbose_generic_activity_with_arg("run_late_module_lint", pass.name())
442+
.run(|| {
439443
late_lint_pass_crate(tcx, LateLintPassObjects { lints: slice::from_mut(pass) });
440-
},
441-
);
444+
});
442445
}
443446
}
444447
}

compiler/rustc_query_impl/src/on_disk_cache.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1067,7 +1067,7 @@ pub fn encode_query_results<'a, 'tcx, CTX, Q>(
10671067
let _timer = tcx
10681068
.dep_context()
10691069
.profiler()
1070-
.extra_verbose_generic_activity("encode_query_results_for", std::any::type_name::<Q>());
1070+
.verbose_generic_activity_with_arg("encode_query_results_for", std::any::type_name::<Q>());
10711071

10721072
assert!(Q::query_state(tcx).all_inactive());
10731073
let cache = Q::query_cache(tcx);

compiler/rustc_session/src/options.rs

-11
Original file line numberDiff line numberDiff line change
@@ -280,14 +280,6 @@ macro_rules! options {
280280

281281
) }
282282

283-
impl Options {
284-
// JUSTIFICATION: defn of the suggested wrapper fn
285-
#[allow(rustc::bad_opt_access)]
286-
pub fn time_passes(&self) -> bool {
287-
self.unstable_opts.time_passes || self.unstable_opts.time
288-
}
289-
}
290-
291283
impl CodegenOptions {
292284
// JUSTIFICATION: defn of the suggested wrapper fn
293285
#[allow(rustc::bad_opt_access)]
@@ -1596,9 +1588,6 @@ options! {
15961588
#[rustc_lint_opt_deny_field_access("use `Session::threads` instead of this field")]
15971589
threads: usize = (1, parse_threads, [UNTRACKED],
15981590
"use a thread pool with N threads"),
1599-
#[rustc_lint_opt_deny_field_access("use `Session::time_passes` instead of this field")]
1600-
time: bool = (false, parse_bool, [UNTRACKED],
1601-
"measure time of rustc processes (default: no)"),
16021591
#[rustc_lint_opt_deny_field_access("use `Session::time_llvm_passes` instead of this field")]
16031592
time_llvm_passes: bool = (false, parse_bool, [UNTRACKED],
16041593
"measure time of each LLVM pass (default: no)"),

compiler/rustc_session/src/session.rs

+5-6
Original file line numberDiff line numberDiff line change
@@ -606,10 +606,6 @@ impl Session {
606606
self.parse_sess.source_map()
607607
}
608608

609-
pub fn time_passes(&self) -> bool {
610-
self.opts.time_passes()
611-
}
612-
613609
/// Returns `true` if internal lints should be added to the lint store - i.e. if
614610
/// `-Zunstable-options` is provided and this isn't rustdoc (internal lints can trigger errors
615611
/// to be emitted under rustdoc).
@@ -927,6 +923,10 @@ impl Session {
927923
self.opts.unstable_opts.instrument_mcount
928924
}
929925

926+
pub fn time_passes(&self) -> bool {
927+
self.opts.unstable_opts.time_passes
928+
}
929+
930930
pub fn time_llvm_passes(&self) -> bool {
931931
self.opts.unstable_opts.time_llvm_passes
932932
}
@@ -1403,8 +1403,7 @@ pub fn build_session(
14031403
CguReuseTracker::new_disabled()
14041404
};
14051405

1406-
let prof =
1407-
SelfProfilerRef::new(self_profiler, sopts.time_passes(), sopts.unstable_opts.time_passes);
1406+
let prof = SelfProfilerRef::new(self_profiler, sopts.unstable_opts.time_passes);
14081407

14091408
let ctfe_backtrace = Lock::new(match env::var("RUSTC_CTFE_BACKTRACE") {
14101409
Ok(ref val) if val == "immediate" => CtfeBacktrace::Immediate,

src/bootstrap/bin/rustc.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ fn main() {
6767
if target == "all"
6868
|| target.into_string().unwrap().split(',').any(|c| c.trim() == crate_name)
6969
{
70-
cmd.arg("-Ztime");
70+
cmd.arg("-Ztime-passes");
7171
}
7272
}
7373
}

src/doc/rustc/src/command-line-arguments.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ _Note:_ The order of these lint level arguments is taken into account, see [lint
300300
## `-Z`: set unstable options
301301

302302
This flag will allow you to set unstable options of rustc. In order to set multiple options,
303-
the -Z flag can be used multiple times. For example: `rustc -Z verbose -Z time`.
303+
the -Z flag can be used multiple times. For example: `rustc -Z verbose -Z time-passes`.
304304
Specifying options with -Z is only available on nightly. To view all available options
305305
run: `rustc -Z help`.
306306

src/librustdoc/formats/renderer.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ pub(crate) fn run_format<'tcx, T: FormatRenderer<'tcx>>(
5858

5959
let emit_crate = options.should_emit_crate();
6060
let (mut format_renderer, krate) = prof
61-
.extra_verbose_generic_activity("create_renderer", T::descr())
61+
.verbose_generic_activity_with_arg("create_renderer", T::descr())
6262
.run(|| T::init(krate, options, cache, tcx))?;
6363

6464
if !emit_crate {
@@ -92,6 +92,6 @@ pub(crate) fn run_format<'tcx, T: FormatRenderer<'tcx>>(
9292
.run(|| cx.item(item))?;
9393
}
9494
}
95-
prof.extra_verbose_generic_activity("renderer_after_krate", T::descr())
95+
prof.verbose_generic_activity_with_arg("renderer_after_krate", T::descr())
9696
.run(|| format_renderer.after_krate())
9797
}

src/test/rustdoc-ui/z-help.stdout

-1
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,6 @@
170170
-Z thinlto=val -- enable ThinLTO when possible
171171
-Z thir-unsafeck=val -- use the THIR unsafety checker (default: no)
172172
-Z threads=val -- use a thread pool with N threads
173-
-Z time=val -- measure time of rustc processes (default: no)
174173
-Z time-llvm-passes=val -- measure time of each LLVM pass (default: no)
175174
-Z time-passes=val -- measure time of each rustc pass (default: no)
176175
-Z tls-model=val -- choose the TLS model to use (`rustc --print tls-models` for details)

0 commit comments

Comments
 (0)