Skip to content

Commit 78582e7

Browse files
committed
feat(log): add unit-started event
1 parent ea5850f commit 78582e7

File tree

4 files changed

+52
-3
lines changed

4 files changed

+52
-3
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -606,7 +606,8 @@ impl<'gctx> DrainState<'gctx> {
606606
.gctx
607607
.shell()
608608
.verbose(|c| c.status("Running", &cmd))?;
609-
self.timings.unit_start(id, self.active[&id].clone());
609+
self.timings
610+
.unit_start(build_runner, id, self.active[&id].clone());
610611
}
611612
Message::Stdout(out) => {
612613
writeln!(build_runner.bcx.gctx.shell().out(), "{}", out)?;

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ impl<'gctx> Timings<'gctx> {
189189
}
190190

191191
/// Mark that a unit has started running.
192-
pub fn unit_start(&mut self, id: JobId, unit: Unit) {
192+
pub fn unit_start(&mut self, build_runner: &BuildRunner<'_, '_>, id: JobId, unit: Unit) {
193193
if !self.enabled {
194194
return;
195195
}
@@ -210,16 +210,25 @@ impl<'gctx> Timings<'gctx> {
210210
CompileMode::Docscrape => target.push_str(" (doc scrape)"),
211211
CompileMode::RunCustomBuild => target.push_str(" (run)"),
212212
}
213+
let start = self.start.elapsed().as_secs_f64();
213214
let unit_time = UnitTime {
214215
unit,
215216
target,
216-
start: self.start.elapsed().as_secs_f64(),
217+
start,
217218
duration: 0.0,
218219
rmeta_time: None,
219220
unblocked_units: Vec::new(),
220221
unblocked_rmeta_units: Vec::new(),
221222
sections: Default::default(),
222223
};
224+
if let Some(logger) = build_runner.bcx.logger {
225+
logger.log(LogMessage::UnitStarted {
226+
package_id: unit_time.unit.pkg.package_id().to_spec(),
227+
target: (&unit_time.unit.target).into(),
228+
mode: unit_time.unit.mode,
229+
elapsed: start,
230+
});
231+
}
223232
assert!(self.active.insert(id, unit_time).is_none());
224233
}
225234

src/cargo/util/log_message.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,13 @@ pub enum LogMessage {
2828
target_dir: PathBuf,
2929
workspace_root: PathBuf,
3030
},
31+
/// Emitted when a compilation unit starts.
32+
UnitStarted {
33+
package_id: PackageIdSpec,
34+
target: Target,
35+
mode: CompileMode,
36+
elapsed: f64,
37+
},
3138
/// Emitted when a compilation unit finishes.
3239
UnitFinished {
3340
package_id: PackageIdSpec,

tests/testsuite/build_analysis.rs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,18 @@ fn log_msg_timing_info() {
130130
"...": "{...}",
131131
"reason": "build-started"
132132
},
133+
{
134+
"elapsed": "{...}",
135+
"mode": "check",
136+
"package_id": "path+[ROOTURL]/foo/bar#0.0.0",
137+
"reason": "unit-started",
138+
"run_id": "[..]T[..]Z-[..]",
139+
"target": {
140+
"kind": "lib",
141+
"name": "bar"
142+
},
143+
"timestamp": "[..]T[..]Z"
144+
},
133145
{
134146
"duration": "{...}",
135147
"mode": "check",
@@ -143,6 +155,18 @@ fn log_msg_timing_info() {
143155
},
144156
"timestamp": "[..]T[..]Z"
145157
},
158+
{
159+
"elapsed": "{...}",
160+
"mode": "check",
161+
"package_id": "path+[ROOTURL]/foo#0.0.0",
162+
"reason": "unit-started",
163+
"run_id": "[..]T[..]Z-[..]",
164+
"target": {
165+
"kind": "lib",
166+
"name": "foo"
167+
},
168+
"timestamp": "[..]T[..]Z"
169+
},
146170
{
147171
"duration": "{...}",
148172
"mode": "check",
@@ -190,6 +214,10 @@ fn log_rebuild_reason_fresh_build() {
190214
"...": "{...}",
191215
"reason": "build-started"
192216
},
217+
{
218+
"...": "{...}",
219+
"reason": "unit-started"
220+
},
193221
{
194222
"...": "{...}",
195223
"reason": "unit-finished"
@@ -253,6 +281,10 @@ fn log_rebuild_reason_file_changed() {
253281
},
254282
"timestamp": "[..]T[..]Z"
255283
},
284+
{
285+
"...": "{...}",
286+
"reason": "unit-started"
287+
},
256288
{
257289
"...": "{...}",
258290
"reason": "unit-finished"

0 commit comments

Comments
 (0)