Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/btop_input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -328,13 +328,15 @@ namespace Input {
cur_i = Proc::sort_vector.size() - 1;
Config::set("proc_sorting", Proc::sort_vector.at(cur_i));
Config::set("update_following", true);
if (Config::getB("proc_tree")) no_update = false;
}
else if (key == "right" or (vim_keys and key == "l")) {
int cur_i = v_index(Proc::sort_vector, Config::getS("proc_sorting"));
if (std::cmp_greater(++cur_i, Proc::sort_vector.size() - 1))
cur_i = 0;
Config::set("proc_sorting", Proc::sort_vector.at(cur_i));
Config::set("update_following", true);
if (Config::getB("proc_tree")) no_update = false;
}
else if (is_in(key, "f", "/")) {
Config::flip("proc_filtering");
Expand All @@ -346,6 +348,11 @@ namespace Input {
no_update = false;
Config::set("update_following", true);
}
else if (key == "E" and Config::getB("proc_tree")) {
atomic_wait(Runner::active);
Proc::collapse_all = 1;
no_update = false;
}
else if (is_in(key, "u")) {
Config::flip("pause_proc_list");
}
Expand Down
1 change: 1 addition & 0 deletions src/btop_menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ namespace Menu {
{"c", "Toggle per-core cpu usage of processes."},
{"r", "Reverse sorting order in processes box."},
{"e", "Toggle processes tree view."},
{"E", "Collapse/expand all processes in tree view."},
{"%", "Toggles memory display mode in processes box."},
{"Selected +, -", "Expand/collapse the selected process in tree view."},
{"Selected t", "Terminate selected process with SIGTERM - 15."},
Expand Down
2 changes: 1 addition & 1 deletion src/btop_shared.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ namespace Proc {
extern bool shown, redraw;
extern int select_max;
extern atomic<int> detailed_pid;
extern int selected_pid, start, selected, collapse, expand, filter_found, selected_depth, toggle_children;
extern int selected_pid, start, selected, collapse, expand, filter_found, selected_depth, toggle_children, collapse_all;
extern int scroll_pos;
extern string selected_name;
extern atomic<bool> resized;
Expand Down
25 changes: 24 additions & 1 deletion src/freebsd/btop_collect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1007,7 +1007,7 @@ namespace Proc {
fs::file_time_type passwd_time;

uint64_t cputimes;
int collapse = -1, expand = -1, toggle_children = -1;
int collapse = -1, expand = -1, toggle_children = -1, collapse_all = -1;
uint64_t old_cputimes = 0;
atomic<int> numpids = 0;
int filter_found = 0;
Expand Down Expand Up @@ -1301,6 +1301,29 @@ namespace Proc {
}
collapse = expand = -1;
}

if (collapse_all != -1) {
//? Build sets of all pids and parent pids to identify root processes
std::unordered_set<size_t> pid_set, parent_pids;
for (const auto& p : current_procs) {
pid_set.insert(p.pid);
parent_pids.insert(static_cast<size_t>(p.ppid));
}
//? If any non-root parent is expanded, collapse; otherwise expand
const bool do_collapse = rng::any_of(current_procs, [&parent_pids, &pid_set](const proc_info& p) {
return parent_pids.contains(p.pid)
and pid_set.contains(static_cast<size_t>(p.ppid))
and not p.collapsed;
});
//? Root processes (parent not in tracked list) are never touched
for (auto& p : current_procs) {
if (not pid_set.contains(static_cast<size_t>(p.ppid))) continue;
p.collapsed = do_collapse;
}
collapse_all = -1;
if (Config::ints.at("proc_selected") > 0) locate_selection = true;
}

if (should_filter or not filter.empty()) filter_found = 0;

vector<tree_proc> tree_procs;
Expand Down
25 changes: 24 additions & 1 deletion src/linux/btop_collect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2803,7 +2803,7 @@ namespace Proc {
fs::file_time_type passwd_time;

uint64_t cputimes;
int collapse = -1, expand = -1, toggle_children = -1;
int collapse = -1, expand = -1, toggle_children = -1, collapse_all = -1;
uint64_t old_cputimes{};
atomic<int> numpids{};
int filter_found{};
Expand Down Expand Up @@ -3277,6 +3277,29 @@ namespace Proc {
}
collapse = expand = -1;
}

if (collapse_all != -1) {
//? Build sets of all pids and parent pids to identify root processes
std::unordered_set<size_t> pid_set, parent_pids;
for (const auto& p : current_procs) {
pid_set.insert(p.pid);
parent_pids.insert(static_cast<size_t>(p.ppid));
}
//? If any non-root parent is expanded, collapse; otherwise expand
const bool do_collapse = rng::any_of(current_procs, [&parent_pids, &pid_set](const proc_info& p) {
return parent_pids.contains(p.pid)
and pid_set.contains(static_cast<size_t>(p.ppid))
and not p.collapsed;
});
//? Root processes (parent not in tracked list) are never touched
for (auto& p : current_procs) {
if (not pid_set.contains(static_cast<size_t>(p.ppid))) continue;
p.collapsed = do_collapse;
}
collapse_all = -1;
if (Config::ints.at("proc_selected") > 0) locate_selection = true;
}

if (should_filter or not filter.empty()) filter_found = 0;

vector<tree_proc> tree_procs;
Expand Down
25 changes: 24 additions & 1 deletion src/netbsd/btop_collect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1100,7 +1100,7 @@ namespace Proc {
fs::file_time_type passwd_time;

uint64_t cputimes;
int collapse = -1, expand = -1, toggle_children = -1;
int collapse = -1, expand = -1, toggle_children = -1, collapse_all = -1;
uint64_t old_cputimes = 0;
atomic<int> numpids = 0;
int filter_found = 0;
Expand Down Expand Up @@ -1362,6 +1362,29 @@ namespace Proc {
}
collapse = expand = -1;
}

if (collapse_all != -1) {
//? Build sets of all pids and parent pids to identify root processes
std::unordered_set<size_t> pid_set, parent_pids;
for (const auto& p : current_procs) {
pid_set.insert(p.pid);
parent_pids.insert(static_cast<size_t>(p.ppid));
}
//? If any non-root parent is expanded, collapse; otherwise expand
const bool do_collapse = rng::any_of(current_procs, [&parent_pids, &pid_set](const proc_info& p) {
return parent_pids.contains(p.pid)
and pid_set.contains(static_cast<size_t>(p.ppid))
and not p.collapsed;
});
//? Root processes (parent not in tracked list) are never touched
for (auto& p : current_procs) {
if (not pid_set.contains(static_cast<size_t>(p.ppid))) continue;
p.collapsed = do_collapse;
}
collapse_all = -1;
if (Config::ints.at("proc_selected") > 0) locate_selection = true;
}

if (should_filter or not filter.empty()) filter_found = 0;

vector<tree_proc> tree_procs;
Expand Down
25 changes: 24 additions & 1 deletion src/openbsd/btop_collect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -965,7 +965,7 @@ namespace Proc {
fs::file_time_type passwd_time;

uint64_t cputimes;
int collapse = -1, expand = -1, toggle_children = -1;
int collapse = -1, expand = -1, toggle_children = -1, collapse_all = -1;
uint64_t old_cputimes = 0;
atomic<int> numpids = 0;
int filter_found = 0;
Expand Down Expand Up @@ -1239,6 +1239,29 @@ namespace Proc {
}
collapse = expand = -1;
}

if (collapse_all != -1) {
//? Build sets of all pids and parent pids to identify root processes
std::unordered_set<size_t> pid_set, parent_pids;
for (const auto& p : current_procs) {
pid_set.insert(p.pid);
parent_pids.insert(static_cast<size_t>(p.ppid));
}
//? If any non-root parent is expanded, collapse; otherwise expand
const bool do_collapse = rng::any_of(current_procs, [&parent_pids, &pid_set](const proc_info& p) {
return parent_pids.contains(p.pid)
and pid_set.contains(static_cast<size_t>(p.ppid))
and not p.collapsed;
});
//? Root processes (parent not in tracked list) are never touched
for (auto& p : current_procs) {
if (not pid_set.contains(static_cast<size_t>(p.ppid))) continue;
p.collapsed = do_collapse;
}
collapse_all = -1;
if (Config::ints.at("proc_selected") > 0) locate_selection = true;
}

if (should_filter or not filter.empty()) filter_found = 0;

vector<tree_proc> tree_procs;
Expand Down
25 changes: 24 additions & 1 deletion src/osx/btop_collect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1590,7 +1590,7 @@ namespace Proc {
fs::file_time_type passwd_time;

uint64_t cputimes;
int collapse = -1, expand = -1, toggle_children = -1;
int collapse = -1, expand = -1, toggle_children = -1, collapse_all = -1;
uint64_t old_cputimes = 0;
atomic<int> numpids = 0;
int filter_found = 0;
Expand Down Expand Up @@ -1922,6 +1922,29 @@ namespace Proc {
}
collapse = expand = -1;
}

if (collapse_all != -1) {
//? Build sets of all pids and parent pids to identify root processes
std::unordered_set<size_t> pid_set, parent_pids;
for (const auto& p : current_procs) {
pid_set.insert(p.pid);
parent_pids.insert(static_cast<size_t>(p.ppid));
}
//? If any non-root parent is expanded, collapse; otherwise expand
const bool do_collapse = rng::any_of(current_procs, [&parent_pids, &pid_set](const proc_info& p) {
return parent_pids.contains(p.pid)
and pid_set.contains(static_cast<size_t>(p.ppid))
and not p.collapsed;
});
//? Root processes (parent not in tracked list) are never touched
for (auto& p : current_procs) {
if (not pid_set.contains(static_cast<size_t>(p.ppid))) continue;
p.collapsed = do_collapse;
}
collapse_all = -1;
if (Config::ints.at("proc_selected") > 0) locate_selection = true;
}

if (should_filter or not filter.empty()) filter_found = 0;

vector<tree_proc> tree_procs;
Expand Down
Loading