Skip to content

Add entire perf command to find slow performance hooks etc.#652

Open
pfleidi wants to merge 14 commits intomainfrom
feat/entire-perf-command
Open

Add entire perf command to find slow performance hooks etc.#652
pfleidi wants to merge 14 commits intomainfrom
feat/entire-perf-command

Conversation

@pfleidi
Copy link
Contributor

@pfleidi pfleidi commented Mar 7, 2026

entire perf subcommand

Adds a new entire perf CLI command that displays hook performance traces, and extends the perf/span package with loop iteration tracking.

New command: entire perf

Parses structured perf log entries from .entire/logs/entire.log and renders them as formatted timing tables with hierarchical sub-step breakdowns.

  • entire perf — show the most recent hook trace
  • entire perf --last 5 — show the last 5 traces
  • entire perf --hook post-commit — filter by hook type

Perf traces require ENTIRE_LOG_LEVEL=DEBUG to be enabled.

Implementation (cmd/entire/cli/perf.go, perf_cmd.go):

  • JSONL log parser that extracts steps.*_ms and steps.*_err keys into a hierarchical step tree
  • Sub-step detection: keys like foo.0, foo.1 are nested under their parent foo when the parent exists
  • ASCII tree rendering (├─/└─) with manual padding to avoid UTF-8 multi-byte alignment issues
  • Input validation on --last flag (must be >= 1)

The result will look something like this:

❯ go run ./cmd/entire perf --hook post-commit --last 2
post-commit  123ms  2026-03-06T16:35:48-08:00

  STEP                        DURATION
  cleanup_shadow_branches         12ms
  find_sessions_for_worktree       0ms
  open_repository_and_head         0ms
  process_sessions               100ms
    ├─ process_sessions.0          3ms
    ├─ process_sessions.1          0ms
    ├─ process_sessions.2         95ms
    ├─ process_sessions.3          0ms
    ├─ process_sessions.4          0ms
    └─ process_sessions.5          0ms
  resolve_commit_trees             5ms

post-commit  595ms  2026-03-06T15:54:13-08:00

  STEP                        DURATION
  cleanup_shadow_branches         13ms
  find_sessions_for_worktree       0ms
  open_repository_and_head         0ms
  process_sessions               570ms
    ├─ process_sessions.0          3ms
    ├─ process_sessions.1        566ms
    ├─ process_sessions.2          0ms
    ├─ process_sessions.3          0ms
    └─ process_sessions.4          0ms
  resolve_commit_trees             6ms

perf/span: LoopSpan and child deduplication

Extends the span package to support tracking loop iterations as grouped sub-spans.

  • LoopSpan — new type that wraps a grouping span; Iteration() creates child spans, End() auto-ends unfinished iterations
  • childStepKey() — deduplicates child span names (.1, .2 suffixes) so repeated loop iterations don't overwrite each other in log output
  • Grandchild emission — group spans emit their children as steps.<name>.<index>_ms entries with 0-based indexing

Hook integration

PostCommit in manual_commit_hooks.go now wraps the session processing loop with StartLoop/Iteration/End to emit per-session timing in perf traces.

Other

  • .goreleaser.yaml: Removed installation link from Discord release announcement template
  • strategy/common_test.go: Whitespace formatting cleanup

pfleidi and others added 8 commits March 6, 2026 13:49
Entire-Checkpoint: 22415ab59f02
Add collectPerfEntries() to read JSONL log files and return the last N
perf entries in newest-first order, with optional hook type filtering.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Entire-Checkpoint: eaf01bcc91eb
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Entire-Checkpoint: c3b7ec761aa8
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Entire-Checkpoint: e5bf775d5e75
Entire-Checkpoint: c75be2c5408c
Entire-Checkpoint: 2bc23d89214f
Entire-Checkpoint: 7d7c4e94c454
Copilot AI review requested due to automatic review settings March 7, 2026 00:40
@cursor
Copy link

cursor bot commented Mar 7, 2026

PR Summary

Medium Risk
Changes perf trace serialization and adds new loop-based spans; incorrect keying or span lifecycles could make perf logs misleading or noisy, and the post-commit hook now does extra tracing work (though only emitted at DEBUG).

Overview
Adds a new entire perf subcommand that reads .entire/logs/entire.log, extracts msg="perf" JSONL entries (including steps.*_ms/*_err), and renders them as a readable timing table with optional --last and --hook filtering plus hierarchical sub-step display.

Extends perf/span logging to preserve duplicate child step names (suffixing .1, .2, …) and to emit grouped loop iteration timings as steps.<name>.<index>_*, then instruments the post-commit session-processing loop to record per-session iteration spans. Includes comprehensive unit tests for parsing/rendering, key de-duplication, and loop span behavior (plus minor test formatting cleanup).

Written by Cursor Bugbot for commit c1c901d. Configure here.

tree := buildCommittedTree(t, map[string]string{
"a3/b2c4d5e6f7/0/prompt.txt": "Real session prompt",
"a3/b2c4d5e6f7/1/metadata.json": `{"session_id":"test"}`,
"a3/b2c4d5e6f7/0/prompt.txt": "Real session prompt",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

These kept coming up for some reason. 🤷

Copy link
Member

Choose a reason for hiding this comment

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

We could add golangci-lint fmt in mise to ensure we keep it to a specific format.

continue
}
s.postCommitProcessSession(ctx, repo, state, &transitionCtx, checkpointID,
iterCtx, iterSpan := processSessionsLoop.Iteration(loopCtx)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Tracking cumulative timings for looped steps didn't really work with the existing package. This adds a new abstraction for loops and other code that calls the the same operation multiple times. It will group it hierarchically under the processSessionsLoop span and render it as a tree in the entire perf command.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds a new entire perf CLI command for viewing hook performance traces, extends the perf/span package with loop iteration tracking (LoopSpan), and integrates the new loop span into the PostCommit hook to emit per-session timing data.

Changes:

  • New entire perf command (perf.go, perf_cmd.go) that parses JSONL log entries and renders hierarchical timing tables with sub-step breakdowns
  • New LoopSpan type in perf/span.go with StartLoop/Iteration/End pattern, plus childStepKey deduplication for repeated child span names
  • Integration of LoopSpan in PostCommit hook to track per-session processing times

Reviewed changes

Copilot reviewed 7 out of 8 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
cmd/entire/cli/perf.go New file: JSONL log parser, sub-step detection, and ASCII table renderer
cmd/entire/cli/perf_cmd.go New file: Cobra command definition for entire perf
cmd/entire/cli/perf_test.go New file: Tests for parsing, collecting, rendering, and flag validation
perf/span.go Adds childStepKey dedup, grandchild emission, LoopSpan type
perf/span_test.go Tests for deduplication, loop span creation, auto-end, and errors
cmd/entire/cli/strategy/manual_commit_hooks.go Wraps session loop with StartLoop/Iteration/End
cmd/entire/cli/root.go Registers newPerfCmd()
cmd/entire/cli/strategy/common_test.go Whitespace formatting cleanup

pfleidi and others added 6 commits March 6, 2026 16:58
Entire-Checkpoint: e6ea5a3d3580
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@pfleidi
Copy link
Contributor Author

pfleidi commented Mar 7, 2026

Bugbot run

@pfleidi pfleidi marked this pull request as ready for review March 7, 2026 01:27
@pfleidi pfleidi requested a review from a team as a code owner March 7, 2026 01:27
Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 7 out of 8 changed files in this pull request and generated no new comments.

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

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants