htop icon indicating copy to clipboard operation
htop copied to clipboard

Allow sorting just once / pausing sorting

Open eyalroz opened this issue 2 years ago • 16 comments

When processes have been sorted for me according to some order, I often want to do something with these processes, or just look at their data, without them moving elsewhere... which is what happens in sorted mode once every few seconds. A process often disappears from the terminal entirely, e.g. because a top process has many threads/subprocesses or due to high variation of resource usage.

So, I want to be able to have the sort function fire only once rather than on every update. Of course, on-every-update is also a valid and popular mode of use, so perhaps an option to choose between these two kinds of behaviors, or different keyboard shortcuts etc.

eyalroz avatar Jan 12 '22 20:01 eyalroz

Press Z to pause the updates and you can sort as you see fit.

fasterit avatar Jan 12 '22 20:01 fasterit

But I do want to see the updated data. I just don't want the re-sorting.

eyalroz avatar Jan 12 '22 21:01 eyalroz

What @eyalroz requests is a hotkey to temporarily disable sorting. This way user can tag processes without disruptions from new processes or threads inserted into the list (they will be appended to the bottom of the list instead).

Explorer09 avatar Jan 13 '22 03:01 Explorer09

That would get very messy. You would not be shown a consistent state any more because you want to assess e.g. "memory consumption" and the stuff you really should look at is piling up newly at the bottom of the list (whatever bottom of a list in a tree would be). I am not convinced this is a useful request for real-world use cases. /DLange

fasterit avatar Jan 13 '22 07:01 fasterit

@Explorer09 : Hmm. Yeah. I guess that's the proper way to implement this. Indeed, you need sorting enabled in the options to choose the sort order, so whatever key you press is indeed like pausing sorting. To directly implement what I asked for would mean no-sorting by default, then a button which makes you select what to sort by just-once. So, adjusting the title accordingly.

@fasterit : The use case is that you've found some problematic process due to sorting, and now you want to follow its behavior. At the moment, to do this, you have to:

  1. Remember its pid or other identifying details.
  2. Go to the options.
  3. Disable sorting.
  4. Search for the process.

with my suggestion all of this would be a single-key.

About it being a "non-consistent view" - the state of sort-pausing could be indicated somehow. Example : A color change for the sort "key" on the bottom command bar (make it reddish, or gray it out, or add hatching etc).

eyalroz avatar Jan 13 '22 08:01 eyalroz

That single key solution already exists, F to follow a process.

fasterit avatar Jan 13 '22 08:01 fasterit

@eyalroz It's easy to indicate whether sorting is disabled. Just highlight no sort key (table column header) at all. And this feature (disable sorting) obviously won't apply to tree view.

Explorer09 avatar Jan 13 '22 11:01 Explorer09

And this feature (disable sorting) obviously won't apply to tree view.

You know that the tree view in recent versions is sorted?

BenBE avatar Jan 13 '22 12:01 BenBE

@Explorer09 : What BenBE said; why wouldn't it apply to tree view?...

eyalroz avatar Jan 13 '22 19:01 eyalroz

This needs to be handled a bit differently in tree view because tree view (after #893 at least) sorts the tree. Also note that this can be much less useful in tree mode, because tree will still shift due to processes disappearing / appearing in branches above the point you're interested in, and the typical number of processes in that area is probably much higher than in flat mode.

tanriol avatar Jan 13 '22 23:01 tanriol

@eyalroz

why wouldn't it apply to tree view?

Well, it seems that @tanriol has answered it to me. New processes can be created in every branch of the tree, making the disable sorting feature less useful than it can possibly be. What eyalroz wants is that when sorting is disabled, new processes would be added to the end of the list, right?

Explorer09 avatar Jan 14 '22 02:01 Explorer09

@Explorer09 :

What eyalroz wants is that when sorting is disabled, new processes would be added to the end of the list, right?

If it's a flat list, then yes; if it's a tree - added to the end of their parent process' children.

New processes can be created in every branch of the tree,

... which should happen even without sorting. So I'm not sure why that makes the feature less useful in tree mode.

eyalroz avatar Jan 14 '22 08:01 eyalroz

New processes can be created in every branch of the tree,

... which should happen even without sorting. So I'm not sure why that makes the feature less useful in tree mode.

I normally use htop in tree mode sorted by memory and often see the situation when I want to look at some branch, but there's a branch somewhere above it (because at the common level its ancestor uses more RAM) that's actively compiling code, with process counts fluctuating between 5-6 and 40 or so. That results in processes jumping around, yes, and that would still be a problem with paused sorting because they'll still appear/disappear in the same branch above.

tanriol avatar Jan 14 '22 09:01 tanriol

That results in processes jumping around, yes, and that would still be a problem with paused sorting because they'll still appear/disappear in the same branch above.

That's true... but you could collapse the subtree of the top items and this problem would go away; and if you also had a summing-collapse (#920 ), you could track the overall memory usage of all subprocesses.

eyalroz avatar Jan 14 '22 10:01 eyalroz

Just want to chime in here and say that it was totally counter-intuitive to me that processes are sorted in tree view, and while I can see the utility, it would be great to be able to restore the old functionality, which is tree view with no sort. I'm going to try to remember "shift+n" to sort by PID, because that seems to be close enough.

alexanderankin avatar May 23 '22 04:05 alexanderankin

The old behavior wasn't actually to do a stable sort, but to use the random order the processes had internally. Starting a new process could have (in theory) messed up the whole tree. With the new behavior this sorting is stable and sorting the tree (siblings) by PID is the default.

BenBE avatar May 23 '22 05:05 BenBE