Repository navigation
perf(sysstat): read the focused pane's process tree from /proc, not ps - #306
Merged
Merged
Conversation
The focused pane's process line called sysstat.Trees every 1.2 s, which forks ps twice and walks every process on the machine to report on the few under one pane. Tree walks /proc from the root on Linux, with ps's lifetime %cpu computed from each process's start time, and falls back to Trees elsewhere. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Tree read each process's resident pages from /proc/<pid>/stat. The kernel sums that count from per-CPU counters without folding them in, so on the small processes under a pane it ran about a tenth below what ps reported through Trees: the focused pane's line showed 11.6MB where ps saw 12.5MB. Tree now reads statm, which agrees with ps to the page, and the test that compares the two holds RSS to 2% instead of 2x. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
While a pane is focused, the board refreshes its process line (CPU, RAM, what the pane runs) every 1.2 s, and each refresh forks
pstwice. The first fork lists every process on the machine to report on the few under one pane. On a 1,636-process host that costs 159 ms per refresh, about 13% of a core spent onpsalone. A 60 sexecsnoopof a live board counted 80psforks a minute.Summary
sysstat.Tree(pid)walks the pane's tree from its root through/proc/<pid>/task/*/children, using the walker the poll pass'sTreeSampleralready relies on. It forks nothing.PCPUis computed the waypscomputes%cpu: each process's CPU time over its lifetime, usingstarttimefrom/proc/<pid>/statand/proc/uptime.ScaleToHostthen gets the same input it got fromps./procchild lists (macOS, or a kernel withoutCONFIG_PROC_CHILDREN),Treefalls back toTreesunchanged.Tree.Trees, and theTreeSamplerseeding scan that tests check againstps, stay as they are.pssites are left alone because no timer drives them. The child sweep's background-work check runs only for a finished child about to be retired, andSessionOfProcessruns once per caller, not on a clock.Numbers
BenchmarkFocusedPaneTree, 50 iterations on a host with 1,636 processes:psforksTrees(before)Tree(after)Test plan
TestTreeAgreesWithTreesWithoutForkingPs: on a fixture tree,TreematchesTreesexactly on process count and children, keeps RSS withinTreeSampler's 2× bound, and keepsPCPUwithin 0.5. Apsshim onPATHproves it never forks; passes 5/5go test ./internal/sysstat/andgo test -short ./internal/ui/pass, run withenv -u TMUX -u TMUX_PANEand a scratchTMUX_TMPDIR🤖 Generated with Claude Code