Sum CPU/memory of a collapsed subtree in tree view (#920)#2023
Conversation
New themeable color element used to tint values that represent the total of a collapsed tree node's subtree. Defaults to the existing PROCESS_SHADOW (dim) style in every bundled color scheme. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Signed-off-by: Max Morel <maxmorel@pisanvs.cl>
Introduce the collapsedSubtreeSum setting (htoprc key tree_sum_collapsed_subtree, off by default) and expose it as a checkbox in the tree-view section of the Display Options screen. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Signed-off-by: Max Morel <maxmorel@pisanvs.cl>
Add the aggregateClear/aggregateAdd class methods (with no-op fallbacks) and an 'aggregated' row flag, providing the generic scaffolding the table builder uses to accumulate subtree totals. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Signed-off-by: Max Morel <maxmorel@pisanvs.cl>
Store per-subtree totals of the additive fields shared by all platforms (CPU%, normalized CPU%, MEM%, VIRT, RES, page faults, CPU time) and render them, tinted, when a collapsed tree node displays its subtree summary. Closes htop-dev#920. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Signed-off-by: Max Morel <maxmorel@pisanvs.cl>
Extend subtree summation to the Linux additive columns: memory sizes (PRIV/PSS/SWAP/PSSWP/SHARE/TRS/DRS/LRS), self CPU times, IO bytes, counts and rates, context switches, delay-accounting percentages and GPU usage. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Signed-off-by: Max Morel <maxmorel@pisanvs.cl>
Point each platform's process class at the shared aggregate hooks so collapsed-subtree summation of the common fields works on every platform, not just Linux. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Signed-off-by: Max Morel <maxmorel@pisanvs.cl>
When the setting is enabled in tree view, clear each node's aggregate and fold in its children's totals during the existing bottom-up tree walk, marking collapsed non-empty nodes so they render the subtree summary. This activates the feature. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Signed-off-by: Max Morel <maxmorel@pisanvs.cl>
📝 WalkthroughWalkthroughThis PR adds an optional "Sum CPU/memory usage of collapsed subtrees" feature to htop's tree view. A new Poem
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
Table.c (1)
223-237:⚠️ Potential issue | 🟠 MajorClear
aggregatedflags when transitioning from tree to non-tree mode.The non-tree branch of
Table_updateDisplayList(lines 229-237) does not resetrow->aggregatedflags. When switching from tree to non-tree view, rows retainaggregated=truefrom the previous tree state, causingProcess_writeFieldto render aggregate values (e.g., PERCENT_CPU, M_RESIDENT) instead of individual row values. TogglingtreeViewcorrectly setsneedsSort=true, but the non-tree path never clears these flags because it skipsTable_buildTreewhich would reset them.Add a loop in the non-tree branch to clear all
row->aggregatedflags before rebuilding the display list, similar to howTable_buildTreedoes at line 182.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: ccc4555a-68ce-41b0-8b71-713b23bb8faf
📒 Files selected for processing (20)
CRT.cCRT.hDisplayOptionsPanel.cProcess.cProcess.hRow.cRow.hSettings.cSettings.hTable.cdarwin/DarwinProcess.cdragonflybsd/DragonFlyBSDProcess.cfreebsd/FreeBSDProcess.clinux/LinuxProcess.clinux/LinuxProcess.hnetbsd/NetBSDProcess.copenbsd/OpenBSDProcess.cpcp/PCPProcess.csolaris/SolarisProcess.cunsupported/UnsupportedProcess.c
| case MAJFLT: { | ||
| size_t start = RichString_size(str); | ||
| Row_printCount(str, useAgg ? this->aggregate.majflt : this->majflt, coloring); | ||
| if (useAgg) Process_aggregateRecolor(str, start); | ||
| return; | ||
| } | ||
| case MINFLT: { | ||
| size_t start = RichString_size(str); | ||
| Row_printCount(str, useAgg ? this->aggregate.minflt : this->minflt, coloring); | ||
| if (useAgg) Process_aggregateRecolor(str, start); | ||
| return; | ||
| } | ||
| case M_RESIDENT: { | ||
| size_t start = RichString_size(str); | ||
| Row_printKBytes(str, useAgg ? (unsigned long long)this->aggregate.m_resident : (unsigned long long)this->m_resident, coloring); | ||
| if (useAgg) Process_aggregateRecolor(str, start); | ||
| return; | ||
| } | ||
| case M_VIRT: { | ||
| size_t start = RichString_size(str); | ||
| Row_printKBytes(str, useAgg ? (unsigned long long)this->aggregate.m_virt : (unsigned long long)this->m_virt, coloring); | ||
| if (useAgg) Process_aggregateRecolor(str, start); | ||
| return; | ||
| } |
There was a problem hiding this comment.
Move single-statement if bodies to the next line.
Several newly added branches keep the body on the same line as the condition (e.g., if (useAgg) ...). This violates the C style rule used in this repo.
Suggested style-only patch
- if (useAgg) Process_aggregateRecolor(str, start);
+ if (useAgg)
+ Process_aggregateRecolor(str, start);
- if (useAgg) attr = CRT_colors[PROCESS_SUM];
+ if (useAgg)
+ attr = CRT_colors[PROCESS_SUM];Also applies to: 743-756, 808-813
Source: Coding guidelines
|
Thank you. Please clean up the color handling stuff (No re-coloring) and make logical commits. Add a hotkey to switch the aggregate function on/off. |
Implements #920. In tree view, when a node is collapsed, optionally display the sum of its subtree's additive values instead of only the node's own.
htoprckeytree_sum_collapsed_subtree).PROCESS_SUM, defaults to the shadow style per theme); the CPU% column auto-widens so large sums don't overflow.Verified on Linux: collapsing a parent of three ~95 MB / ~100%-CPU children shows RES ≈ 287 MB and CPU ≈ 300.8% (summed, dimmed); a process with N threads shows its own values, not N×.
Generated (mostly) with Claude Code