Skip to content
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

feature: Adds tree view #223

Merged
merged 21 commits into from
Sep 7, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Update docs
  • Loading branch information
ClementTsang committed Sep 6, 2020
commit 9ab2f2ddbbbdd098d198214626b5be7073f0d19f
47 changes: 33 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ A cross-platform graphical process/system monitor with a customizable interface
- [Processes](#processes)
- [Process searching](#process-searching)
- [Process sorting](#process-sorting)
- [Tree mode](#tree-mode)
- [Zoom](#zoom)
- [Expanding](#expanding)
- [Basic mode](#basic-mode)
Expand Down Expand Up @@ -246,23 +247,24 @@ Run using `btm`.
| `s, F6` | Open process sort widget |
| `I` | Invert current sort |
| `%` | Toggle between values and percentages for memory usage |
| `t`, `F5` | Toggle tree mode |

#### Process search bindings

| | |
| ------------ | -------------------------------------------- |
| `Tab` | Toggle between searching by PID or name |
| `Esc` | Close the search widget (retains the filter) |
| `Ctrl-a` | Skip to the start of the search query |
| `Ctrl-e` | Skip to the end of the search query |
| `Ctrl-u` | Clear the current search query |
| `Backspace` | Delete the character behind the cursor |
| `Delete` | Delete the character at the cursor |
| `Alt-c`/`F1` | Toggle matching case |
| `Alt-w`/`F2` | Toggle matching the entire word |
| `Alt-r`/`F3` | Toggle using regex |
| `Left` | Move cursor left |
| `Right` | Move cursor right |
| | |
| ------------- | -------------------------------------------- |
| `Tab` | Toggle between searching by PID or name |
| `Esc` | Close the search widget (retains the filter) |
| `Ctrl-a` | Skip to the start of the search query |
| `Ctrl-e` | Skip to the end of the search query |
| `Ctrl-u` | Clear the current search query |
| `Backspace` | Delete the character behind the cursor |
| `Delete` | Delete the character at the cursor |
| `Alt-c`, `F1` | Toggle matching case |
| `Alt-w`, `F2` | Toggle matching the entire word |
| `Alt-r`, `F3` | Toggle using regex |
| `Left` | Move cursor left |
| `Right` | Move cursor right |

### Process sort bindings

Expand Down Expand Up @@ -424,6 +426,23 @@ You can sort the processes list by any column you want by pressing `s` while on

![sorting](assets/sort.png)

#### Tree mode

Use `t` or `F5` to toggle tree mode in a process widget. This is somewhat similar to htop's tree
mode.

![Standard tree](assets/trees_1.png)

Sorting works as well, but it is done per groups of siblings. For example, by CPU%:

![Standard tree](assets/trees_2.png)

You can also still filter processes. Branches that entirely do not match the query are pruned out,
but if a branch contains an element that does match the query, any non-matching elements will instead
just be greyed out, so the tree structure is still maintained:

![Standard tree](assets/trees_3.png)

### Zoom

Using the `+`/`-` keys or the scroll wheel will move the current time intervals of the currently selected widget, and `=` to reset the zoom levels to the default.
Expand Down
Binary file added assets/trees_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/trees_2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/trees_3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1216,6 +1216,7 @@ impl App {
'L' | 'D' => self.move_widget_selection(&WidgetDirection::Right),
'K' | 'W' => self.move_widget_selection(&WidgetDirection::Up),
'J' | 'S' => self.move_widget_selection(&WidgetDirection::Down),
't' => self.toggle_tree_mode(),
'+' => self.zoom_in(),
'-' => self.zoom_out(),
'=' => self.reset_zoom(),
Expand Down
2 changes: 1 addition & 1 deletion src/canvas/widgets/process_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ impl ProcessTableWidget for Painter {
} else {
vec![0.1, 0.2, 0.1, 0.1, 0.1, 0.1, 0.15, 0.15]
}
} else if proc_widget_state.is_using_command {
} else if proc_widget_state.is_using_command || proc_widget_state.is_tree_mode {
vec![0.05, 0.7, 0.05, 0.05, 0.03, 0.03, 0.03, 0.03]
} else {
vec![0.1, 0.2, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1]
Expand Down
15 changes: 8 additions & 7 deletions src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ pub const CPU_HELP_TEXT: [&str; 2] = [

// TODO [Help]: Search in help?
// TODO [Help]: Move to using tables for easier formatting?
pub const PROCESS_HELP_TEXT: [&str; 12] = [
pub const PROCESS_HELP_TEXT: [&str; 13] = [
"3 - Process widget\n",
"dd Kill the selected process\n",
"c Sort by CPU usage, press again to reverse sorting order\n",
Expand All @@ -104,7 +104,8 @@ pub const PROCESS_HELP_TEXT: [&str; 12] = [
"P Toggle between showing the full command or just the process name\n",
"s, F6 Open process sort widget\n",
"I Invert current sort\n",
"% Toggle between values and percentages for memory usage",
"% Toggle between values and percentages for memory usage\n",
"t, F5 Toggle tree mode",
];

pub const SEARCH_HELP_TEXT: [&str; 46] = [
Expand All @@ -116,9 +117,9 @@ pub const SEARCH_HELP_TEXT: [&str; 46] = [
"Ctrl-u Clear the current search query\n",
"Backspace Delete the character behind the cursor\n",
"Delete Delete the character at the cursor\n",
"Alt-c/F1 Toggle matching case\n",
"Alt-w/F2 Toggle matching the entire word\n",
"Alt-r/F3 Toggle using regex\n",
"Alt-c, F1 Toggle matching case\n",
"Alt-w, F2 Toggle matching the entire word\n",
"Alt-r, F3 Toggle using regex\n",
"Left, Alt-h Move cursor left\n",
"Right, Alt-l Move cursor right\n",
"\n",
Expand All @@ -142,8 +143,8 @@ pub const SEARCH_HELP_TEXT: [&str; 46] = [
"<= ex: cpu <= 1\n",
"\n",
"Logical operators:\n",
"and/&&/<Space> ex: btm and cpu > 1 and mem > 1\n",
"or/|| ex: btm or firefox\n",
"and, &&, <Space> ex: btm and cpu > 1 and mem > 1\n",
"or, || ex: btm or firefox\n",
"\n",
"Supported units:\n",
"B ex: read > 1 b\n",
Expand Down
12 changes: 9 additions & 3 deletions src/data_conversion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,9 @@ pub fn tree_process_data(
to_sort_vec: &mut Vec<(Pid, &ConvertedProcessData)>, sort_type: &ProcessSorting,
is_sort_descending: bool,
) {
// Sort by PID first (descending)
to_sort_vec.sort_by(|a, b| utils::gen_util::get_ordering(a.1.pid, b.1.pid, false));

match sort_type {
ProcessSorting::CpuPercent => {
to_sort_vec.sort_by(|a, b| {
Expand Down Expand Up @@ -654,9 +657,12 @@ pub fn tree_process_data(
)
}),
ProcessSorting::Pid => {
to_sort_vec.sort_by(|a, b| {
utils::gen_util::get_ordering(a.1.pid, b.1.pid, is_sort_descending)
});
// Note we only sort if is_sort_descending as otherwise it's repeated.
if is_sort_descending {
to_sort_vec.sort_by(|a, b| {
utils::gen_util::get_ordering(a.1.pid, b.1.pid, is_sort_descending)
});
}
}
ProcessSorting::ReadPerSecond => {
to_sort_vec.sort_by(|a, b| {
Expand Down