Skip to content

Conversation

@jasonwbarnett
Copy link
Contributor

@jasonwbarnett jasonwbarnett commented Jan 9, 2026

Problem

When Pants completes a workunit (like generating a lockfile), the log message only shows that it completed, not how long it took:

23:17:29.42 [INFO] Completed: Generate lockfile for my-resolve

This makes it difficult to identify slow operations or track performance over time.

Solution

Log the elapsed time alongside the completion message:

23:17:29.42 [INFO] Completed: Generate lockfile for my-resolve (45.23s)

For longer operations (60+ seconds), show minutes:

23:17:29.42 [INFO] Completed: Generate lockfile for my-resolve (2m 30.0s)

Implementation

  • Added format_workunit_duration() helper function in src/rust/workunit_store/src/lib.rs
  • Modified log_workunit_state() to include duration for completed (non-canceled) workunits
  • Added 7 unit tests covering various duration formats (sub-second, seconds, minutes boundary, multiple minutes, zero)

Closes #22991

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 <[email protected]>
@jasonwbarnett jasonwbarnett force-pushed the jwb/log-workunit-duration branch 2 times, most recently from a16c307 to 0983a6a Compare January 9, 2026 00:31
Copy link
Contributor

@benjyw benjyw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution! See comments.

(WorkunitState::Completed { .. }, _) => "Completed:",
};

// Format duration for completed workunits (not canceled ones)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment is superfluous (typical of LLM-generated code). It just restates what the code below it clearly does...

let duration_str = if !canceled {
if let WorkunitState::Completed { time_span } = &self.state {
format_workunit_duration(std::time::Duration::from(time_span.duration))
} else {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not show duration of incomplete workunits too?

String::new()
}
} else {
String::new()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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("")

@jsirois
Copy link
Contributor

jsirois commented Jan 9, 2026

@jasonwbarnett this partially implements this idea: #11965

@jasonwbarnett jasonwbarnett force-pushed the jwb/log-workunit-duration branch from 0983a6a to 2248d22 Compare January 9, 2026 15:53
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 <[email protected]>
@jasonwbarnett jasonwbarnett force-pushed the jwb/log-workunit-duration branch from 2248d22 to c58d943 Compare January 9, 2026 15:56
@jasonwbarnett jasonwbarnett requested a review from benjyw January 12, 2026 16:51
WorkunitState::Completed { time_span } => {
Some(format_workunit_duration(std::time::Duration::from(time_span.duration)))
}
WorkunitState::Started { start_time, .. } if canceled => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

@benjyw
Copy link
Contributor

benjyw commented Jan 25, 2026

Hi, just checking in on the status of this...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: Log elapsed time for completed workunits

3 participants