-
-
Notifications
You must be signed in to change notification settings - Fork 439
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add options to display parents and children processes of filtered pro… #1139
base: main
Are you sure you want to change the base?
Add options to display parents and children processes of filtered pro… #1139
Conversation
…cesses Co-authored-by: yurenchen000 <[email protected]>
Exactly what I wanted. Works good for me. |
ProcessList.c
Outdated
@@ -370,6 +370,16 @@ void ProcessList_collapseAllBranches(ProcessList* this) { | |||
} | |||
} | |||
|
|||
static void ProcessList_filterChildern(ProcessList *this, pid_t pid, Hashtable *processFilter) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo Childern -> Children
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed it
ProcessList.c
Outdated
continue; | ||
|
||
if (this->settings->showChildrenInFilter) | ||
ProcessList_filterChildern(this, p->pid, filteredProcesses); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo Childern -> Children
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nice work @yurenchen000.
This should have a key binding to be quickly toggled as well. May be Shift-F4 + Ctrl-F4?
(Marked the typo Childern, please fix)
got it, I'll fix typo right now. but I'm not sure if I can add keybinding for it |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think those options should probably be exclusive: Either show parents or children, but showing both does not make any sense with filtering.
code style format Co-authored-by: BenBE <[email protected]>
I think it has practical uses, imagine this scenario:
// equivalent to viewing its family tree |
I was assuming this refered to the whole tree, not just the next level in each direction. In that case having both makes sense. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a couple of problems with this implementation. Also, I'm a bit worried about growing another thing dealing with process trees completely separate from tree view implementation. Would be nice to share the hard part in some reasonable way.
Process *p = (Process*) (Vector_get(this->processes, i)); | ||
if (p->pid != pid && Process_isChildOf(p, pid)) { | ||
Hashtable_put(processFilter, p->pid, (void*) 1); | ||
ProcessList_filterChildren(this, p->pid, processFilter); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks quadratic to me (for every descendant of the target process iterate over all processes/threads). Could we do better?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you have an idea how to do better?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Even a single loop over processes with walking up from every process would be better (although it would need some cycle detection too) as it can easily be made worst case linear in the total process number. I personally think something like the tree mode "sort by parent" would be even better, but I'm a bit out of context at the moment and not sure how feasible it would be to share that part instead of reimplementing it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could make the hit detection (in subtree/any parent) in O(1) if we tracked some item ranges for nested sets (similar to what Joomla is doing for its menus). Unfortunately, when we tried to implement this in-place while building the tree, this made tree creation kinda slow (O(n²)
). One option could be to calculate the nested set ranges on the fly from the Table->displayList
based on the indent columns; takes at most O(n*m)
with m
being the maximum tree depth (which is fixed at 32).
Hashtable_put(filteredProcesses, p->pid, (void*) 1); | ||
ppid = Process_getParentPid(p); | ||
p = Hashtable_get(this->processTable, ppid); | ||
} while (this->settings->showParentsInFilter && p && p->pid != p->ppid); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As we know from #1017 (which I still need to rebase/reimplement), in some cases two processes may be parents of each other and thus this loop becomes an infinite one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
got it,
I will keep an eye on the progress of that issue
Also, do these options make sense in flat view or are they intended for tree mode only? |
@BenBE |
@tanriol Did you mean that limit this functionality to tree view mode, |
Depending on the task it can make sense to have this available outside tree view too. |
anyone working on this ? for now I am achieving similar with:
|
This PR based on @ashamza 's work
hishamhm/htop#973 (comment)
#76 (comment)
// co-authors added in commits seem doesn't link to github users
The only thing I did was update the patch to fit the current version code.