other: move cpu and memory settings over (#2064)

This commit is contained in:
Clement Tsang
2026-05-15 20:00:44 -04:00
committed by GitHub
parent 899914591e
commit 65acf5e49e
21 changed files with 243 additions and 64 deletions
+2 -2
View File
@@ -51,7 +51,7 @@ jobs:
needs: pre-job needs: pre-job
if: ${{ needs.pre-job.outputs.should_skip != 'true' }} if: ${{ needs.pre-job.outputs.should_skip != 'true' }}
runs-on: ${{ matrix.info.os }} runs-on: ${{ matrix.info.os }}
timeout-minutes: 12 timeout-minutes: 20
strategy: strategy:
fail-fast: false fail-fast: false
matrix: matrix:
@@ -276,7 +276,7 @@ jobs:
} }
runs-on: ${{ matrix.info.os }} runs-on: ${{ matrix.info.os }}
if: ${{ needs.pre-job.outputs.should_skip != 'true' }} if: ${{ needs.pre-job.outputs.should_skip != 'true' }}
timeout-minutes: 12 timeout-minutes: 20
steps: steps:
- name: Checkout repository - name: Checkout repository
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
+2
View File
@@ -48,6 +48,8 @@ That said, these are more guidelines rather than hard rules, though the project
- [#2062](https://github.com/ClementTsang/bottom/pull/2062): Rename `[network]` to `[network_graph]` in the config file; `[network]` remains valid as an alias. - [#2062](https://github.com/ClementTsang/bottom/pull/2062): Rename `[network]` to `[network_graph]` in the config file; `[network]` remains valid as an alias.
- [#2062](https://github.com/ClementTsang/bottom/pull/2062): Move network and memory graph config file options from `[flags]` to be under `[network_graph]` and `[memory_graph]`. - [#2062](https://github.com/ClementTsang/bottom/pull/2062): Move network and memory graph config file options from `[flags]` to be under `[network_graph]` and `[memory_graph]`.
- [#2063](https://github.com/ClementTsang/bottom/pull/2063): Move process config file options from `[flags]` to be under `[processes]`. - [#2063](https://github.com/ClementTsang/bottom/pull/2063): Move process config file options from `[flags]` to be under `[processes]`.
- [#2064](https://github.com/ClementTsang/bottom/pull/2064): Move CPU config file options from `[flags]` to be under `[cpu]`.
- [#2064](https://github.com/ClementTsang/bottom/pull/2064): Move memory config file options from `[flags]` to be under `[memory_graph]`.
### Other ### Other
@@ -0,0 +1,51 @@
# CPU
If you want to change some of the default behaviour of the CPU graph widget, you can configure things under the `[cpu]` section.
## Default CPU graph selection
You can configure which CPU graph is shown by default on startup by setting `cpu.default`. Defaults to `"all"`, which
shows all entries.
```toml
[cpu]
# One of "all" (default), "average"/"avg"
default = "average"
```
## Show decimal
You can configure whether CPU usage values are shown with a decimal place by setting `cpu.show_decimal`. Defaults
to `false`.
```toml
[cpu]
show_decimal = true
```
## Hide average CPU entry
You can hide the average CPU entry entirely by setting `cpu.hide_avg_cpu`. Defaults to `false`.
```toml
[cpu]
hide_avg_cpu = true
```
## Place legend on the left
You can place the CPU chart legend on the left side by setting `cpu.left_legend`. Defaults to `false`.
```toml
[cpu]
left_legend = true
```
## Average CPU row
In basic mode, you can give the average CPU entry a dedicated row by setting `cpu.basic_average_cpu_row`. Defaults to `false`.
```toml
[cpu]
basic_average_cpu_row = true
```
@@ -1,20 +0,0 @@
# CPU
## Default CPU Graph Selection
You can configure which CPU graph is shown by default when starting up bottom by setting `cpu.default`.
```toml
[cpu]
# One of "all" (default), "average"/"avg"
default = "average"
```
## Show Decimal
You can configure whether CPU usage values are shown with a decimal place by setting `cpu.show_decimal`. Defaults to `false`.
```toml
[cpu]
show_decimal = true
```
@@ -1,9 +1,34 @@
# Memory Graph # Memory Graph
## Settings If you want to change some of the default behaviour of the memory graph widget, you can configure things under the `[memory_graph]` (or `[memory]`) section.
If you want to change some of the default behaviour of the memory graph widget, you can configure some things in the config file. ## Graph legend position
| Field | Type | Functionality | You can change where the legend for the graph is placed within the widget itself (or hidden with `"none"`). The default is `"top-right"`.
| ----------------- | ------------------------------------------------------------------------------------------------------------------ | -------------------------------------------------- |
| `legend_position` | String (one of ["none", "top-left", "top", "top-right", "left", "right", "bottom-left", "bottom", "bottom-right"]) | Where to place the legend for the memory widget. | ```toml
[memory_graph]
# One of ["none", "top-left", "top", "top-right", "left", "right", "bottom-left", "bottom", "bottom-right"]
legend_position = "top-left"
```
## Collect/show cache memory
On Linux, you can change whether the memory used by [cache/slabs](https://serverfault.com/a/1025189) is collected and
shown. By default, it is `false`.
```toml
[memory_graph]
cache_memory = true
```
## Subtract free-able ARC from memory
If ZFS is detected (note that the `zfs` feature must be enabled if built manually), you can enable `memory_graph.free_arc` to
not count [ARC](https://www.45drives.com/community/articles/zfs-caching/) memory in the RAM usage calculations. Disabled
by default.
```toml
[memory_graph]
free_arc = true
```
+2 -2
View File
@@ -161,7 +161,7 @@ nav:
- "General Usage": usage/general-usage.md - "General Usage": usage/general-usage.md
- "Basic Mode": usage/basic-mode.md - "Basic Mode": usage/basic-mode.md
- "Widgets": - "Widgets":
- "CPU Widget": usage/widgets/cpu.md - "CPU Widget": usage/widgets/cpu-graph.md
- "Memory Graph Widget": usage/widgets/memory-graph.md - "Memory Graph Widget": usage/widgets/memory-graph.md
- "Network Graph Widget": usage/widgets/network-graph.md - "Network Graph Widget": usage/widgets/network-graph.md
- "Process Widget": usage/widgets/process.md - "Process Widget": usage/widgets/process.md
@@ -174,7 +174,7 @@ nav:
- "Command-line Options": configuration/command-line-options.md - "Command-line Options": configuration/command-line-options.md
- "Config File": - "Config File":
- configuration/config-file/index.md - configuration/config-file/index.md
- "CPU Widget": configuration/config-file/cpu.md - "CPU Widget": configuration/config-file/cpu-graph.md
- "Disk Table Widget": configuration/config-file/disk-table.md - "Disk Table Widget": configuration/config-file/disk-table.md
- "Memory Graph Widget": configuration/config-file/memory-graph.md - "Memory Graph Widget": configuration/config-file/memory-graph.md
- "Network Graph Widget": configuration/config-file/network-graph.md - "Network Graph Widget": configuration/config-file/network-graph.md
+36 -1
View File
@@ -152,10 +152,31 @@
"description": "CPU column settings.", "description": "CPU column settings.",
"type": "object", "type": "object",
"properties": { "properties": {
"basic_average_cpu_row": {
"description": "Whether to give the average CPU entry a dedicated row in basic mode.",
"type": [
"boolean",
"null"
]
},
"default": { "default": {
"description": "The default selected entry of the CPU widget.", "description": "The default selected entry of the CPU widget.",
"$ref": "#/$defs/CpuDefault" "$ref": "#/$defs/CpuDefault"
}, },
"hide_avg_cpu": {
"description": "Whether to hide the average CPU entry.",
"type": [
"boolean",
"null"
]
},
"left_legend": {
"description": "Whether to put the CPU chart legend on the left side.",
"type": [
"boolean",
"null"
]
},
"show_decimal": { "show_decimal": {
"description": "Whether to show a decimal place for CPU usage values.", "description": "Whether to show a decimal place for CPU usage values.",
"type": [ "type": [
@@ -665,6 +686,20 @@
"description": "Memory-related configuration file options.", "description": "Memory-related configuration file options.",
"type": "object", "type": "object",
"properties": { "properties": {
"cache_memory": {
"description": "Whether to collect and display cache and buffer memory. Not available on Windows.",
"type": [
"boolean",
"null"
]
},
"free_arc": {
"description": "Whether to subtract freeable ARC from memory usage.",
"type": [
"boolean",
"null"
]
},
"legend_position": { "legend_position": {
"description": "Where to place the legend for the memory chart widget.", "description": "Where to place the legend for the memory chart widget.",
"type": [ "type": [
@@ -980,7 +1015,7 @@
] ]
}, },
"hide_k_threads": { "hide_k_threads": {
"description": "Hide kernel threads from being shown.", "description": "Hide kernel threads from being shown. Linux only.",
"type": [ "type": [
"boolean", "boolean",
"null" "null"
+36 -7
View File
@@ -275,8 +275,14 @@ pub(crate) fn init_app(args: BottomArgs, config: Config) -> Result<(App, BottomL
let use_basic_mode = is_flag_enabled!(basic, args.general, config); let use_basic_mode = is_flag_enabled!(basic, args.general, config);
let expanded = is_flag_enabled!(expanded, args.general, config); let expanded = is_flag_enabled!(expanded, args.general, config);
#[cfg(feature = "zfs")] #[cfg(feature = "zfs")]
let free_arc = is_flag_enabled!(free_arc, args.memory, config); let free_arc = enabled_option_with_deprecated!(
args.memory.free_arc,
config,
memory_graph.free_arc,
flags.free_arc,
);
// For processes // For processes
let is_grouped = enabled_option_with_deprecated!( let is_grouped = enabled_option_with_deprecated!(
@@ -402,7 +408,12 @@ pub(crate) fn init_app(args: BottomArgs, config: Config) -> Result<(App, BottomL
show_average_cpu: get_show_average_cpu(args, config), show_average_cpu: get_show_average_cpu(args, config),
show_cpu_decimal: config_or!(config, cpu.show_decimal, false), show_cpu_decimal: config_or!(config, cpu.show_decimal, false),
use_dot: is_flag_enabled!(dot_marker, args.general, config), use_dot: is_flag_enabled!(dot_marker, args.general, config),
cpu_left_legend: is_flag_enabled!(cpu_left_legend, args.cpu, config), cpu_left_legend: enabled_option_with_deprecated!(
args.cpu.cpu_left_legend,
config,
cpu.left_legend,
flags.cpu_left_legend,
),
use_current_cpu_total: enabled_option_with_deprecated!( use_current_cpu_total: enabled_option_with_deprecated!(
args.process.current_usage, args.process.current_usage,
config, config,
@@ -445,7 +456,12 @@ pub(crate) fn init_app(args: BottomArgs, config: Config) -> Result<(App, BottomL
network_use_binary_prefix, network_use_binary_prefix,
network_show_packets, network_show_packets,
retention_ms, retention_ms,
dedicated_average_row: config_or!(config, flags.average_cpu_row, false), dedicated_average_row: enabled_option_with_deprecated!(
false,
config,
cpu.basic_average_cpu_row,
flags.average_cpu_row,
),
default_tree_collapse: is_default_tree_collapsed, default_tree_collapse: is_default_tree_collapsed,
#[cfg(feature = "zfs")] #[cfg(feature = "zfs")]
free_arc, free_arc,
@@ -716,7 +732,12 @@ pub(crate) fn init_app(args: BottomArgs, config: Config) -> Result<(App, BottomL
fn get_widget_layout( fn get_widget_layout(
args: &BottomArgs, config: &Config, args: &BottomArgs, config: &Config,
) -> OptionResult<(BottomLayout, u64, Option<BottomWidgetType>)> { ) -> OptionResult<(BottomLayout, u64, Option<BottomWidgetType>)> {
let cpu_left_legend = is_flag_enabled!(cpu_left_legend, args.cpu, config); let cpu_left_legend = enabled_option_with_deprecated!(
args.cpu.cpu_left_legend,
config,
cpu.left_legend,
flags.cpu_left_legend,
);
let (default_widget_type, mut default_widget_count) = let (default_widget_type, mut default_widget_count) =
get_default_widget_and_count(args, config)?; get_default_widget_and_count(args, config)?;
@@ -903,9 +924,12 @@ fn get_temperature(args: &BottomArgs, config: &Config) -> OptionResult<Temperatu
fn get_show_average_cpu(args: &BottomArgs, config: &Config) -> bool { fn get_show_average_cpu(args: &BottomArgs, config: &Config) -> bool {
if args.cpu.hide_avg_cpu { if args.cpu.hide_avg_cpu {
return false; return false;
} else if let Some(cpu) = &config.cpu {
return !cpu.hide_avg_cpu.unwrap_or(false);
} else if let Some(flags) = &config.flags { } else if let Some(flags) = &config.flags {
if let Some(avg_cpu) = flags.hide_avg_cpu { if let Some(hide) = flags.hide_avg_cpu {
return !avg_cpu; deprecated_warning("hide_avg_cpu", "cpu.hide_avg_cpu");
return !hide;
} }
} }
@@ -1057,7 +1081,12 @@ fn get_enable_gpu(_: &BottomArgs, _: &Config) -> bool {
#[cfg(not(target_os = "windows"))] #[cfg(not(target_os = "windows"))]
fn get_enable_cache_memory(args: &BottomArgs, config: &Config) -> bool { fn get_enable_cache_memory(args: &BottomArgs, config: &Config) -> bool {
is_flag_enabled!(enable_cache_memory, args.memory, config) enabled_option_with_deprecated!(
args.memory.enable_cache_memory,
config,
memory_graph.cache_memory,
flags.enable_cache_memory,
)
} }
#[cfg(target_os = "windows")] #[cfg(target_os = "windows")]
+1
View File
@@ -36,6 +36,7 @@ pub struct Config {
pub(crate) temperature_graph: Option<TempGraphConfig>, pub(crate) temperature_graph: Option<TempGraphConfig>,
#[serde(alias = "network")] #[serde(alias = "network")]
pub(crate) network_graph: Option<NetworkGraphConfig>, pub(crate) network_graph: Option<NetworkGraphConfig>,
#[serde(alias = "memory")]
pub(crate) memory_graph: Option<MemoryGraphConfig>, pub(crate) memory_graph: Option<MemoryGraphConfig>,
pub(crate) cpu: Option<CpuConfig>, pub(crate) cpu: Option<CpuConfig>,
} }
+9
View File
@@ -23,6 +23,15 @@ pub(crate) struct CpuConfig {
/// Whether to show a decimal place for CPU usage values. /// Whether to show a decimal place for CPU usage values.
pub(crate) show_decimal: Option<bool>, pub(crate) show_decimal: Option<bool>,
/// Whether to hide the average CPU entry.
pub(crate) hide_avg_cpu: Option<bool>,
/// Whether to put the CPU chart legend on the left side.
pub(crate) left_legend: Option<bool>,
/// Whether to give the average CPU entry a dedicated row in basic mode.
pub(crate) basic_average_cpu_row: Option<bool>,
} }
#[cfg(test)] #[cfg(test)]
+6 -8
View File
@@ -27,11 +27,9 @@ impl TableGap {
#[cfg_attr(feature = "generate_schema", derive(schemars::JsonSchema))] #[cfg_attr(feature = "generate_schema", derive(schemars::JsonSchema))]
#[cfg_attr(test, serde(deny_unknown_fields), derive(PartialEq, Eq))] #[cfg_attr(test, serde(deny_unknown_fields), derive(PartialEq, Eq))]
pub(crate) struct GeneralConfig { pub(crate) struct GeneralConfig {
pub(crate) hide_avg_cpu: Option<bool>,
pub(crate) dot_marker: Option<bool>, pub(crate) dot_marker: Option<bool>,
pub(crate) temperature_type: Option<String>, pub(crate) temperature_type: Option<String>,
pub(crate) rate: Option<StringOrNum>, pub(crate) rate: Option<StringOrNum>,
pub(crate) cpu_left_legend: Option<bool>,
pub(crate) basic: Option<bool>, pub(crate) basic: Option<bool>,
pub(crate) default_time_value: Option<StringOrNum>, pub(crate) default_time_value: Option<StringOrNum>,
pub(crate) time_delta: Option<StringOrNum>, pub(crate) time_delta: Option<StringOrNum>,
@@ -50,16 +48,16 @@ pub(crate) struct GeneralConfig {
pub(crate) show_table_scroll_position: Option<bool>, pub(crate) show_table_scroll_position: Option<bool>,
pub(crate) show_table_scroll_bar: Option<bool>, pub(crate) show_table_scroll_bar: Option<bool>,
pub(crate) read_only: Option<bool>, pub(crate) read_only: Option<bool>,
// #[cfg(feature = "zfs")]
pub(crate) free_arc: Option<bool>,
pub(crate) disable_gpu: Option<bool>, pub(crate) disable_gpu: Option<bool>,
// FIXME: This makes no sense outside of basic mode, add a basic mode config section.
// FIXME: This also should be moved to CPU-specific... same with all the other entries.
pub(crate) average_cpu_row: Option<bool>,
pub(crate) enable_cache_memory: Option<bool>,
pub(crate) retention: Option<StringOrNum>, pub(crate) retention: Option<StringOrNum>,
// FIXME: Deprecate these in the future. // FIXME: Deprecate these in the future.
pub(crate) hide_avg_cpu: Option<bool>,
pub(crate) cpu_left_legend: Option<bool>,
pub(crate) average_cpu_row: Option<bool>,
pub(crate) enable_cache_memory: Option<bool>,
// #[cfg(feature = "zfs")]
pub(crate) free_arc: Option<bool>,
pub(crate) network_use_bytes: Option<bool>, pub(crate) network_use_bytes: Option<bool>,
pub(crate) network_use_log: Option<bool>, pub(crate) network_use_log: Option<bool>,
pub(crate) network_use_binary_prefix: Option<bool>, pub(crate) network_use_binary_prefix: Option<bool>,
+8
View File
@@ -11,4 +11,12 @@ pub struct MemoryGraphConfig {
// (e.g. table-style, list-style) then we probably need a new system outright. // (e.g. table-style, list-style) then we probably need a new system outright.
/// Where to place the legend for the memory chart widget. /// Where to place the legend for the memory chart widget.
pub(crate) legend_position: Option<String>, pub(crate) legend_position: Option<String>,
/// Whether to collect and display cache and buffer memory. Not available on Windows.
#[cfg_attr(target_os = "windows", allow(dead_code))]
pub(crate) cache_memory: Option<bool>,
/// Whether to subtract freeable ARC from memory usage.
#[cfg_attr(not(feature = "zfs"), allow(dead_code))]
pub(crate) free_arc: Option<bool>,
} }
+29 -7
View File
@@ -212,14 +212,13 @@ fn test_proc_default_sort() {
} }
#[test] #[test]
fn test_newer_mem_network() { fn test_newer_memory() {
run_and_kill(&["-C", "./tests/valid_configs/newer_mem_network.toml"]); run_and_kill(&["-C", "./tests/valid_configs/newer_memory.toml"]);
} }
/// This uses deprecated network and memory settings - once they are removed, this test file should be moved to invalid configs.
#[test] #[test]
fn test_deprecated_mem_network() { fn test_newer_cpu() {
run_and_kill(&["-C", "./tests/valid_configs/deprecated/mem_network.toml"]); run_and_kill(&["-C", "./tests/valid_configs/newer_cpu.toml"]);
} }
#[test] #[test]
@@ -227,13 +226,36 @@ fn test_newer_processes() {
run_and_kill(&["-C", "./tests/valid_configs/newer_processes.toml"]); run_and_kill(&["-C", "./tests/valid_configs/newer_processes.toml"]);
} }
#[test]
fn test_newer_network() {
run_and_kill(&["-C", "./tests/valid_configs/newer_network.toml"]);
}
#[test]
fn test_network_alias() {
run_and_kill(&["-C", "./tests/valid_configs/network_alias.toml"]);
}
/// This uses deprecated network settings - once they are removed, this test file should be moved to invalid configs.
#[test]
fn test_deprecated_network() {
run_and_kill(&["-C", "./tests/valid_configs/deprecated/network.toml"]);
}
/// This uses deprecated process settings - once they are removed, this test file should be moved to invalid configs. /// This uses deprecated process settings - once they are removed, this test file should be moved to invalid configs.
#[test] #[test]
fn test_deprecated_processes() { fn test_deprecated_processes() {
run_and_kill(&["-C", "./tests/valid_configs/deprecated/processes.toml"]); run_and_kill(&["-C", "./tests/valid_configs/deprecated/processes.toml"]);
} }
/// This uses deprecated CPU settings - once they are removed, this test file should be moved to invalid configs.
#[test] #[test]
fn test_network_alias() { fn test_deprecated_cpu() {
run_and_kill(&["-C", "./tests/valid_configs/network_alias.toml"]); run_and_kill(&["-C", "./tests/valid_configs/deprecated/cpu.toml"]);
}
/// This uses deprecated memory settings - once they are removed, this test file should be moved to invalid configs.
#[test]
fn test_deprecated_memory() {
run_and_kill(&["-C", "./tests/valid_configs/deprecated/memory.toml"]);
} }
+6
View File
@@ -0,0 +1,6 @@
# This uses deprecated CPU settings - once they are removed, this test file should be moved to invalid configs.
[flags]
hide_avg_cpu = true
cpu_left_legend = true
average_cpu_row = true
@@ -1,9 +0,0 @@
# This uses deprecated network and memory settings - once they are removed, this test file should be moved to invalid configs.
[flags]
network_use_bytes = true
network_use_log = true
network_use_binary_prefix = true
network_legend = "left"
memory_legend = "left"
@@ -0,0 +1,6 @@
# This uses deprecated memory settings - once they are removed, this test file should be moved to invalid configs.
[flags]
enable_cache_memory = true
free_arc = true
memory_legend = "left"
@@ -0,0 +1,7 @@
# This uses deprecated network settings - once they are removed, this test file should be moved to invalid configs.
[flags]
network_use_bytes = true
network_use_log = true
network_use_binary_prefix = true
network_legend = "left"
+6
View File
@@ -0,0 +1,6 @@
# This uses the newer CPU config location.
[cpu]
hide_avg_cpu = true
left_legend = true
basic_average_cpu_row = true
+6
View File
@@ -0,0 +1,6 @@
# This uses the newer memory config location.
[memory_graph]
cache_memory = true
free_arc = true
legend_position = "left"
@@ -5,6 +5,3 @@ use_log = true
use_bytes = true use_bytes = true
use_binary_prefix = true use_binary_prefix = true
legend_position = "left" legend_position = "left"
[memory_graph]
legend_position = "left"