feat(engine): log elapsed time for completed workunits#22992
feat(engine): log elapsed time for completed workunits#22992jasonwbarnett wants to merge 2 commits intopantsbuild:mainfrom
Conversation
When a workunit completes, the log message now includes how long it took. For example: "Completed: Generate lockfile for foo (12.34s)" For operations taking 60 seconds or more, the format shows minutes: "Completed: Build target (2m 30.0s)" Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
a16c307 to
0983a6a
Compare
benjyw
left a comment
There was a problem hiding this comment.
Thanks for the contribution! See comments.
src/rust/workunit_store/src/lib.rs
Outdated
| (WorkunitState::Completed { .. }, _) => "Completed:", | ||
| }; | ||
|
|
||
| // Format duration for completed workunits (not canceled ones) |
There was a problem hiding this comment.
This comment is superfluous (typical of LLM-generated code). It just restates what the code below it clearly does...
src/rust/workunit_store/src/lib.rs
Outdated
| let duration_str = if !canceled { | ||
| if let WorkunitState::Completed { time_span } = &self.state { | ||
| format_workunit_duration(std::time::Duration::from(time_span.duration)) | ||
| } else { |
There was a problem hiding this comment.
Why not show duration of incomplete workunits too?
src/rust/workunit_store/src/lib.rs
Outdated
| String::new() | ||
| } | ||
| } else { | ||
| String::new() |
There was a problem hiding this comment.
Seems weird to allocate a superfluous empty String for this. Better to use an Option and the format can use something like duration_str.as_ref().unwrap_or("")
|
@jasonwbarnett this partially implements this idea: #11965 |
0983a6a to
2248d22
Compare
Extract format_workunit_duration into a standalone function and add comprehensive unit tests covering: - Sub-second durations - Durations under 60 seconds - Boundary case at exactly 60 seconds - Durations with minutes and seconds - Zero duration Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2248d22 to
c58d943
Compare
| WorkunitState::Completed { time_span } => { | ||
| Some(format_workunit_duration(std::time::Duration::from(time_span.duration))) | ||
| } | ||
| WorkunitState::Started { start_time, .. } if canceled => { |
There was a problem hiding this comment.
So you only show the elapsed time if the work was canceled? Why? Wouldn't the opposite make more sense? Or just always show it?
|
Hi, just checking in on the status of this... |
Problem
When Pants completes a workunit (like generating a lockfile), the log message only shows that it completed, not how long it took:
This makes it difficult to identify slow operations or track performance over time.
Solution
Log the elapsed time alongside the completion message:
For longer operations (60+ seconds), show minutes:
Implementation
format_workunit_duration()helper function insrc/rust/workunit_store/src/lib.rslog_workunit_state()to include duration for completed (non-canceled) workunitsCloses #22991