summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorClement Tsang <34804052+ClementTsang@users.noreply.github.com>2020-08-22 12:38:13 -0700
committerGitHub <noreply@github.com>2020-08-22 15:38:13 -0400
commit3394b9ee6699195c400d152cf82cd9ab92585164 (patch)
tree9ec9dfe2910b5d3f64dd183a774ae6407c44d475
parentc82f4d40b40649ae53037701fadc2f5c1be9e901 (diff)
feature: allow searching by state, add more keyword variants
Allows searching by state (`state = sleep`), and adds more keyword variants for searching: `cpu%`, `mem%`, `r/s`, `w/s`, matching the columns.
-rw-r--r--CHANGELOG.md6
-rw-r--r--README.md28
-rw-r--r--src/app/data_harvester/processes.rs4
-rw-r--r--src/app/query.rs21
-rw-r--r--src/constants.rs172
5 files changed, 119 insertions, 112 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 2f497032..e99d7424 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -15,6 +15,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- [#183](https://github.com/ClementTsang/bottom/pull/183): Added sorting capabilities to any column.
+- Add (estimated) memory usage values, toggle this from percent to values for processes with `%`.
+
+- Support searching processes by process state.
+
### Changes
- Added `WASD` as an alternative widget movement system.
@@ -43,8 +47,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- [#114](https://github.com/ClementTsang/bottom/pull/114): Show process state per process (originally in 0.4.0, moved to later). This only shows if the processes are not merged together; I couldn't think of a nice way to show it when grouped together, unfortunately.
-- Add (estimated) memory usage values, toggle this from percent to values for processes with `%`.
-
### Changes
- [#156](https://github.com/ClementTsang/bottom/issues/156) - Removal of the `/` CPU core showing in the chart. It felt clunky to use, was not really useful, and hard to work with with large core counts.
diff --git a/README.md b/README.md
index 8b75f21e..a8636d68 100644
--- a/README.md
+++ b/README.md
@@ -275,20 +275,20 @@ Run using `btm`.
![quote searching](assets/quote_search.png)
-#### Supported keywords
-
-Searching without a keyword will search by process or command name (depends on what column is being shown by the current process widget).
-
-| Keywords | Example | Description |
-| -------- | ------------------ | ------------------------------------------------------------------------------------------------- |
-| `pid` | `pid: 1044` | Matches by PID; supports regex and requiring matching the entire PID |
-| `cpu` | `cpu > 0.5` | Matches the condition for the CPU column; supports comparison operators |
-| `memb` | `memb > 1000 b` | Matches the condition for the memory column in terms of bytes; supports comparison operators |
-| `mem` | `mem < 0.5` | Matches the condition for the memory column in terms of percent; supports comparison operators |
-| `read` | `read = 1 mb` | Matches the condition for the read/s column in terms of bytes; supports comparison operators |
-| `write` | `write >= 1 kb` | Matches the condition for the write/s column in terms of bytes; supports comparison operators |
-| `tread` | `tread <= 1024 gb` | Matches the condition for the total read column in terms of bytes; supports comparison operators |
-| `twrite` | `twrite > 1024 tb` | Matches the condition for the total write column in terms of bytes; supports comparison operators |
+#### Supported search types
+
+| Keywords | Example | Description |
+| ------------------- | ------------------ | ------------------------------------------------------------------------------- |
+| | `btm` | Matches by process or command name; supports regex |
+| `pid` | `pid=1044` | Matches by PID; supports regex |
+| `cpu`, `cpu%` | `cpu > 0.5` | Matches the CPU column; supports comparison operators |
+| `memb` | `memb > 1000 b` | Matches the memory column in terms of bytes; supports comparison operators |
+| `mem`, `mem%` | `mem < 0.5` | Matches the memory column in terms of percent; supports comparison operators |
+| `read`, `r/s` | `read = 1 mb` | Matches the read/s column in terms of bytes; supports comparison operators |
+| `write`, `w/s` | `write >= 1 kb` | Matches the write/s column in terms of bytes; supports comparison operators |
+| `tread`, `t.read` | `tread <= 1024 gb` | Matches he total read column in terms of bytes; supports comparison operators |
+| `twrite`, `t.write` | `twrite > 1024 tb` | Matches the total write column in terms of bytes; supports comparison operators |
+| `state` | `state=running` | Matches by state; supports regex |
#### Supported comparison operators
diff --git a/src/app/data_harvester/processes.rs b/src/app/data_harvester/processes.rs
index f87b700c..aed45d56 100644
--- a/src/app/data_harvester/processes.rs
+++ b/src/app/data_harvester/processes.rs
@@ -38,8 +38,8 @@ impl std::fmt::Display for ProcessSorting {
Mem => "Mem",
ReadPerSecond => "R/s",
WritePerSecond => "W/s",
- TotalRead => "Read",
- TotalWrite => "Write",
+ TotalRead => "T.Read",
+ TotalWrite => "T.Write",
State => "State",
ProcessName => "Name",
Command => "Command",
diff --git a/src/app/query.rs b/src/app/query.rs
index 926c5901..fcff1d0d 100644
--- a/src/app/query.rs
+++ b/src/app/query.rs
@@ -258,7 +258,7 @@ impl ProcessQuery for ProcWidgetState {
compare_prefix: None,
})
}
- PrefixType::Pid => {
+ PrefixType::Pid | PrefixType::State => {
// We have to check if someone put an "="...
if content == "=" {
// Check next string if possible
@@ -571,6 +571,7 @@ pub enum PrefixType {
TRead,
TWrite,
Name,
+ State,
__Nonexhaustive,
}
@@ -581,17 +582,18 @@ impl std::str::FromStr for PrefixType {
use PrefixType::*;
let lower_case = s.to_lowercase();
- // Didn't add %cpu, %mem, mem_bytes, total_read, and total_write
+ // Didn't add mem_bytes, total_read, and total_write
// for now as it causes help to be clogged.
match lower_case.as_str() {
- "cpu" => Ok(PCpu),
- "mem" => Ok(PMem),
+ "cpu" | "cpu%" => Ok(PCpu),
+ "mem" | "mem%" => Ok(PMem),
"memb" => Ok(MemBytes),
- "read" => Ok(Rps),
- "write" => Ok(Wps),
- "tread" => Ok(TRead),
- "twrite" => Ok(TWrite),
+ "read" | "r/s" => Ok(Rps),
+ "write" | "w/s" => Ok(Wps),
+ "tread" | "t.read" => Ok(TRead),
+ "twrite" | "t.write" => Ok(TWrite),
"pid" => Ok(Pid),
+ "state" => Ok(State),
_ => Ok(Name),
}
}
@@ -618,7 +620,7 @@ impl Prefix {
} else if let Some((prefix_type, query_content)) = &mut self.regex_prefix {
if let StringQuery::Value(regex_string) = query_content {
match prefix_type {
- PrefixType::Pid | PrefixType::Name => {
+ PrefixType::Pid | PrefixType::Name | PrefixType::State => {
let escaped_regex: String;
let final_regex_string = &format!(
"{}{}{}{}",
@@ -667,6 +669,7 @@ impl Prefix {
match prefix_type {
PrefixType::Name => r.is_match(process.name.as_str()),
PrefixType::Pid => r.is_match(process.pid.to_string().as_str()),
+ PrefixType::State => r.is_match(process.process_state.as_str()),
_ => true,
}
} else {
diff --git a/src/constants.rs b/src/constants.rs
index e0338ea7..f8852cc9 100644
--- a/src/constants.rs
+++ b/src/constants.rs
@@ -55,123 +55,125 @@ pub const HELP_CONTENTS_TEXT: [&str; 8] = [
pub const GENERAL_HELP_TEXT: [&str; 29] = [
"1 - General\n",
- "q, Ctrl-c Quit\n",
- "Esc Close dialog windows, search, widgets, or exit expanded mode\n",
- "Ctrl-r Reset display and any collected data\n",
- "f Freeze/unfreeze updating with new data\n",
- "Ctrl-Left, \n",
- "Shift-Left, Move widget selection left\n",
- "H, A \n",
- "Ctrl-Right, \n",
- "Shift-Right, Move widget selection right\n",
- "L, D \n",
- "Ctrl-Up, \n",
- "Shift-Up, Move widget selection up\n",
- "K, W \n",
- "Ctrl-Down, \n",
- "Shift-Down, Move widget selection down\n",
- "J, S \n",
- "Left, h Move left within widget\n",
- "Down, j Move down within widget\n",
- "Up, k Move up within widget\n",
- "Right, l Move right within widget\n",
- "? Open help menu\n",
- "gg Jump to the first entry\n",
- "G Jump to the last entry\n",
- "e Expand the currently selected widget\n",
- "+ Zoom in on chart (decrease time range)\n",
- "- Zoom out on chart (increase time range)\n",
- "= Reset zoom\n",
- "Mouse scroll Scroll through the tables or zoom in/out of charts by scrolling up/down",
+ "q, Ctrl-c Quit\n",
+ "Esc Close dialog windows, search, widgets, or exit expanded mode\n",
+ "Ctrl-r Reset display and any collected data\n",
+ "f Freeze/unfreeze updating with new data\n",
+ "Ctrl-Left, \n",
+ "Shift-Left, Move widget selection left\n",
+ "H, A \n",
+ "Ctrl-Right, \n",
+ "Shift-Right, Move widget selection right\n",
+ "L, D \n",
+ "Ctrl-Up, \n",
+ "Shift-Up, Move widget selection up\n",
+ "K, W \n",
+ "Ctrl-Down, \n",
+ "Shift-Down, Move widget selection down\n",
+ "J, S \n",
+ "Left, h Move left within widget\n",
+ "Down, j Move down within widget\n",
+ "Up, k Move up within widget\n",
+ "Right, l Move right within widget\n",
+ "? Open help menu\n",
+ "gg Jump to the first entry\n",
+ "G Jump to the last entry\n",
+ "e Expand the currently selected widget\n",
+ "+ Zoom in on chart (decrease time range)\n",
+ "- Zoom out on chart (increase time range)\n",
+ "= Reset zoom\n",
+ "Mouse scroll Scroll through the tables or zoom in/out of charts by scrolling up/down",
];
pub const CPU_HELP_TEXT: [&str; 2] = [
"2 - CPU widget\n",
- "Mouse scroll Scrolling over an CPU core/average shows only that entry on the chart",
+ "Mouse scroll Scrolling over an CPU core/average shows only that entry on the chart",
];
// TODO [Help]: Search in help?
// TODO [Help]: Move to using tables for easier formatting?
pub const PROCESS_HELP_TEXT: [&str; 12] = [
"3 - Process widget\n",
- "dd Kill the selected process\n",
- "c Sort by CPU usage, press again to reverse sorting order\n",
- "m Sort by memory usage, press again to reverse sorting order\n",
- "p Sort by PID name, press again to reverse sorting order\n",
- "n Sort by process name, press again to reverse sorting order\n",
- "Tab Group/un-group processes with the same name\n",
- "Ctrl-f, / Open process search widget\n",
- "P Toggle between showing the full path 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",
+ "dd Kill the selected process\n",
+ "c Sort by CPU usage, press again to reverse sorting order\n",
+ "m Sort by memory usage, press again to reverse sorting order\n",
+ "p Sort by PID name, press again to reverse sorting order\n",
+ "n Sort by process name, press again to reverse sorting order\n",
+ "Tab Group/un-group processes with the same name\n",
+ "Ctrl-f, / Open process search widget\n",
+ "P Toggle between showing the full path 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",
];
-pub const SEARCH_HELP_TEXT: [&str; 44] = [
+pub const SEARCH_HELP_TEXT: [&str; 46] = [
"4 - Process search widget\n",
- "Tab Toggle between searching for PID and name\n",
- "Esc Close the search widget (retains the filter)\n",
- "Ctrl-a Skip to the start of the search query\n",
- "Ctrl-e Skip to the end of the search query\n",
- "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",
- "Left, Alt-h Move cursor left\n",
- "Right, Alt-l Move cursor right\n",
+ "Tab Toggle between searching for PID and name\n",
+ "Esc Close the search widget (retains the filter)\n",
+ "Ctrl-a Skip to the start of the search query\n",
+ "Ctrl-e Skip to the end of the search query\n",
+ "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",
+ "Left, Alt-h Move cursor left\n",
+ "Right, Alt-l Move cursor right\n",
"\n",
- "Search keywords:\n",
- "pid ex: pid 825\n",
- "cpu ex: cpu > 4.2\n",
- "mem ex: mem < 4.2\n",
- "memb ex: memb < 100 kb\n",
- "read ex: read >= 1 b\n",
- "write ex: write <= 1 tb\n",
- "tread ex: tread = 1\n",
- "twrite ex: twrite = 1\n",
+ "Supported search types:\n",
+ "<by name/cmd> ex: btm\n",
+ "pid ex: pid 825\n",
+ "cpu, cpu% ex: cpu > 4.2\n",
+ "mem, mem% ex: mem < 4.2\n",
+ "memb ex: memb < 100 kb\n",
+ "read, r/s ex: read >= 1 b\n",
+ "write, w/s ex: write <= 1 tb\n",
+ "tread, t.read ex: tread = 1\n",
+ "twrite, t.write ex: twrite = 1\n",
+ "state ex: state = running\n",
"\n",
"Comparison operators:\n",
- "= ex: cpu = 1\n",
- "> ex: cpu > 1\n",
- "< ex: cpu < 1\n",
- ">= ex: cpu >= 1\n",
- "<= ex: cpu <= 1\n",
+ "= ex: cpu = 1\n",
+ "> ex: cpu > 1\n",
+ "< ex: cpu < 1\n",
+ ">= ex: cpu >= 1\n",
+ "<= 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",
- "KB ex: read > 1 kb\n",
- "MB ex: read > 1 mb\n",
- "TB ex: read > 1 tb\n",
- "KiB ex: read > 1 kib\n",
- "MiB ex: read > 1 mib\n",
- "GiB ex: read > 1 gib\n",
- "TiB ex: read > 1 tib",
+ "B ex: read > 1 b\n",
+ "KB ex: read > 1 kb\n",
+ "MB ex: read > 1 mb\n",
+ "TB ex: read > 1 tb\n",
+ "KiB ex: read > 1 kib\n",
+ "MiB ex: read > 1 mib\n",
+ "GiB ex: read > 1 gib\n",
+ "TiB ex: read > 1 tib",
];
pub const SORT_HELP_TEXT: [&str; 6] = [
"5 - Sort widget\n",
- "Down, 'j' Scroll down in list\n",
- "Up, 'k' Scroll up in list\n",
- "Mouse scroll Scroll through sort widget\n",
- "Esc Close the sort widget\n",
- "Enter Sort by current selected column",
+ "Down, 'j' Scroll down in list\n",
+ "Up, 'k' Scroll up in list\n",
+ "Mouse scroll Scroll through sort widget\n",
+ "Esc Close the sort widget\n",
+ "Enter Sort by current selected column",
];
pub const BATTERY_HELP_TEXT: [&str; 3] = [
"6 - Battery widget\n",
- "Left Go to previous battery\n",
- "Right Go to next battery",
+ "Left Go to previous battery\n",
+ "Right Go to next battery",
];
pub const BASIC_MEM_HELP_TEXT: [&str; 2] = [
"7 - Basic memory widget\n",
- "% Toggle between values and percentages for memory usage",
+ "% Toggle between values and percentages for memory usage",
];
lazy_static! {