Skip to content

Commit 1e741ee

Browse files
authored
refactor(timings): reuse timing metric collection logic between --timings and -Zbuild-analysis (#16497)
Close #16474. ## What this PR addresses As described in the issue above, `cargo build --timings` and `cargo report timings` each had its own metric collection logic. Because `cargo report timings` will supersede `cargo build --timings`, this PR try to remove redundant logics from `core/compiler/timings/mod.rs`. ## Review points - I'm not sure if it's appropriate to modify logger for refactoring. However, logs emitted inside `core/compiler/timings/mod.rs` alone is not enough for `prepare_context_from_iter()` to properly replay the build so I think this is an appropriate way.
2 parents 85eff7c + 08c97db commit 1e741ee

File tree

9 files changed

+183
-356
lines changed

9 files changed

+183
-356
lines changed

src/cargo/core/compiler/job_queue/mod.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ impl<'gctx> JobQueue<'gctx> {
391391
JobQueue {
392392
queue: DependencyQueue::new(),
393393
counts: HashMap::new(),
394-
timings: Timings::new(bcx, &bcx.roots),
394+
timings: Timings::new(bcx),
395395
}
396396
}
397397

@@ -974,13 +974,11 @@ impl<'gctx> DrainState<'gctx> {
974974

975975
match is_fresh {
976976
true => {
977-
self.timings.add_fresh();
978977
// Running a fresh job on the same thread is often much faster than spawning a new
979978
// thread to run the job.
980979
doit(Some(&self.diag_dedupe));
981980
}
982981
false => {
983-
self.timings.add_dirty();
984982
scope.spawn(move || doit(None));
985983
}
986984
}

src/cargo/core/compiler/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1173,8 +1173,8 @@ fn add_allow_features(build_runner: &BuildRunner<'_, '_>, cmd: &mut ProcessBuild
11731173
///
11741174
/// [`--error-format`]: https://doc.rust-lang.org/nightly/rustc/command-line-arguments.html#--error-format-control-how-errors-are-produced
11751175
fn add_error_format_and_color(build_runner: &BuildRunner<'_, '_>, cmd: &mut ProcessBuilder) {
1176-
let enable_timings = build_runner.bcx.gctx.cli_unstable().section_timings
1177-
&& (build_runner.bcx.build_config.timing_report || build_runner.bcx.logger.is_some());
1176+
let enable_timings =
1177+
build_runner.bcx.gctx.cli_unstable().section_timings && build_runner.bcx.logger.is_some();
11781178
if enable_timings {
11791179
cmd.arg("-Zunstable-options");
11801180
}

0 commit comments

Comments
 (0)