htop icon indicating copy to clipboard operation
htop copied to clipboard

Allow summing-collapse of a process/thread tree

Open eyalroz opened this issue 3 years ago • 13 comments

I often want to see the total memory and CPU usage for some process and its subprocess (e.g. Firefox, Chromium). I can htop to consider all threads of a process together (although even that is a global setting) - but I can't do that for processes. I wish that, in tree view, when I collapse a node (with the - key) - I will see the sum of the memory usage percentage, CPU usage percentage etc of its entire subtree.

Now, I realize that for some columns, summation may not be obvious (e.g. if a process started T seconds ago and runs N subprocesses after T/2 seconds, it's not clear whether the time is (N+1)*T/2 or T), or not relevant, but any reasonable default will do AFAIAC. Plus people can always file other bugs about that later on...

eyalroz avatar Jan 12 '22 20:01 eyalroz

You can collapse a tree branch with - (minus key). This will - however - not "sum" memory or CPU usages at the moment.

fasterit avatar Jan 12 '22 20:01 fasterit

@fasterit : Rephrasing to emphasize the main request.

eyalroz avatar Jan 12 '22 20:01 eyalroz

Is this request substantially different from #301 / #303?

fasterit avatar Jan 12 '22 20:01 fasterit

@fasterit : #303 is about global merging, with no option of expansion. #301 is also global, and would not be affected by collapsing; also, it involves merging more than is currently being merged, while my proposal is orthogonal of that. That being said - if #301 were implemented I would not bother to file this issue.

eyalroz avatar Jan 12 '22 22:01 eyalroz

@fasterit This feature request is different from #301. This is more about usability improvement for tree view when a process/thread "subtree" is collapsed.

  • When a process group is collapsed this way, the CPU time and memory usage should sum up and display the total for the group, perhaps with a different text color to indicate it's a summary result.
  • The "state" / "S" flag might also need to be updated for the summary. I.e. when a child process in a group is Running, the whole collapsed process subtree should show "R" in its state despite the parent process Sleeping.
  • For "user" column a collapsed subtree might need to show "(multi)" if there are child process owned by multiple users.

Explorer09 avatar Jan 13 '22 03:01 Explorer09

i want this feature so much i could create PR but my main lang is Java, not C COULD SOMEBODY SUMMON C ENGINEER!?

Catzy44 avatar Jul 04 '23 01:07 Catzy44

I would also love it if the default behavior was changed so that the percentages were cumulative! 🙏🏻

langfield avatar Oct 12 '23 01:10 langfield

I want this too.

xrchz avatar Jan 12 '24 17:01 xrchz

Chance of this getting implemented in the next six months?

There are many situations in which this would be helpful such as ascertaining total CPU usage of a bash script that spawns multiple background processes:

image

lynxthecat avatar Feb 28 '24 10:02 lynxthecat

Chance of this getting implemented in the next six months?

That depends on how many pull-requests we get for this feature.

BenBE avatar Feb 28 '24 12:02 BenBE