diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e1beb237..c2f78c46 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -51,7 +51,7 @@ jobs: needs: pre-job if: ${{ needs.pre-job.outputs.should_skip != 'true' }} runs-on: ${{ matrix.info.os }} - timeout-minutes: 12 + timeout-minutes: 20 strategy: fail-fast: false matrix: @@ -276,7 +276,7 @@ jobs: } runs-on: ${{ matrix.info.os }} if: ${{ needs.pre-job.outputs.should_skip != 'true' }} - timeout-minutes: 12 + timeout-minutes: 20 steps: - name: Checkout repository uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 diff --git a/CHANGELOG.md b/CHANGELOG.md index bcbd916d..ab34ef10 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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): 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]`. +- [#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 diff --git a/docs/content/configuration/config-file/cpu-graph.md b/docs/content/configuration/config-file/cpu-graph.md new file mode 100644 index 00000000..30915fe0 --- /dev/null +++ b/docs/content/configuration/config-file/cpu-graph.md @@ -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 +``` diff --git a/docs/content/configuration/config-file/cpu.md b/docs/content/configuration/config-file/cpu.md deleted file mode 100644 index 10223c36..00000000 --- a/docs/content/configuration/config-file/cpu.md +++ /dev/null @@ -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 -``` diff --git a/docs/content/configuration/config-file/memory-graph.md b/docs/content/configuration/config-file/memory-graph.md index ec599da4..ced02c42 100644 --- a/docs/content/configuration/config-file/memory-graph.md +++ b/docs/content/configuration/config-file/memory-graph.md @@ -1,9 +1,34 @@ # 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 | -| ----------------- | ------------------------------------------------------------------------------------------------------------------ | -------------------------------------------------- | -| `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. | +You can change where the legend for the graph is placed within the widget itself (or hidden with `"none"`). The default is `"top-right"`. + +```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 +``` diff --git a/docs/content/usage/widgets/cpu.md b/docs/content/usage/widgets/cpu-graph.md similarity index 100% rename from docs/content/usage/widgets/cpu.md rename to docs/content/usage/widgets/cpu-graph.md diff --git a/docs/mkdocs.yml b/docs/mkdocs.yml index 2e6559c1..8738e4ff 100644 --- a/docs/mkdocs.yml +++ b/docs/mkdocs.yml @@ -161,7 +161,7 @@ nav: - "General Usage": usage/general-usage.md - "Basic Mode": usage/basic-mode.md - "Widgets": - - "CPU Widget": usage/widgets/cpu.md + - "CPU Widget": usage/widgets/cpu-graph.md - "Memory Graph Widget": usage/widgets/memory-graph.md - "Network Graph Widget": usage/widgets/network-graph.md - "Process Widget": usage/widgets/process.md @@ -174,7 +174,7 @@ nav: - "Command-line Options": configuration/command-line-options.md - "Config File": - 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 - "Memory Graph Widget": configuration/config-file/memory-graph.md - "Network Graph Widget": configuration/config-file/network-graph.md diff --git a/schema/nightly/bottom.json b/schema/nightly/bottom.json index d19b877f..11764829 100644 --- a/schema/nightly/bottom.json +++ b/schema/nightly/bottom.json @@ -152,10 +152,31 @@ "description": "CPU column settings.", "type": "object", "properties": { + "basic_average_cpu_row": { + "description": "Whether to give the average CPU entry a dedicated row in basic mode.", + "type": [ + "boolean", + "null" + ] + }, "default": { "description": "The default selected entry of the CPU widget.", "$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": { "description": "Whether to show a decimal place for CPU usage values.", "type": [ @@ -665,6 +686,20 @@ "description": "Memory-related configuration file options.", "type": "object", "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": { "description": "Where to place the legend for the memory chart widget.", "type": [ @@ -980,7 +1015,7 @@ ] }, "hide_k_threads": { - "description": "Hide kernel threads from being shown.", + "description": "Hide kernel threads from being shown. Linux only.", "type": [ "boolean", "null" diff --git a/src/options.rs b/src/options.rs index 11312bdd..d8dde2ee 100644 --- a/src/options.rs +++ b/src/options.rs @@ -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 expanded = is_flag_enabled!(expanded, args.general, config); + #[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 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_cpu_decimal: config_or!(config, cpu.show_decimal, false), 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!( args.process.current_usage, config, @@ -445,7 +456,12 @@ pub(crate) fn init_app(args: BottomArgs, config: Config) -> Result<(App, BottomL network_use_binary_prefix, network_show_packets, 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, #[cfg(feature = "zfs")] free_arc, @@ -716,7 +732,12 @@ pub(crate) fn init_app(args: BottomArgs, config: Config) -> Result<(App, BottomL fn get_widget_layout( args: &BottomArgs, config: &Config, ) -> OptionResult<(BottomLayout, u64, Option)> { - 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) = get_default_widget_and_count(args, config)?; @@ -903,9 +924,12 @@ fn get_temperature(args: &BottomArgs, config: &Config) -> OptionResult bool { if args.cpu.hide_avg_cpu { return false; + } else if let Some(cpu) = &config.cpu { + return !cpu.hide_avg_cpu.unwrap_or(false); } else if let Some(flags) = &config.flags { - if let Some(avg_cpu) = flags.hide_avg_cpu { - return !avg_cpu; + if let Some(hide) = flags.hide_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"))] 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")] diff --git a/src/options/config.rs b/src/options/config.rs index d8d7ad39..44773876 100644 --- a/src/options/config.rs +++ b/src/options/config.rs @@ -36,6 +36,7 @@ pub struct Config { pub(crate) temperature_graph: Option, #[serde(alias = "network")] pub(crate) network_graph: Option, + #[serde(alias = "memory")] pub(crate) memory_graph: Option, pub(crate) cpu: Option, } diff --git a/src/options/config/cpu.rs b/src/options/config/cpu.rs index 58995281..c7071609 100644 --- a/src/options/config/cpu.rs +++ b/src/options/config/cpu.rs @@ -23,6 +23,15 @@ pub(crate) struct CpuConfig { /// Whether to show a decimal place for CPU usage values. pub(crate) show_decimal: Option, + + /// Whether to hide the average CPU entry. + pub(crate) hide_avg_cpu: Option, + + /// Whether to put the CPU chart legend on the left side. + pub(crate) left_legend: Option, + + /// Whether to give the average CPU entry a dedicated row in basic mode. + pub(crate) basic_average_cpu_row: Option, } #[cfg(test)] diff --git a/src/options/config/flags.rs b/src/options/config/flags.rs index 8ccbfc01..cafaf54c 100644 --- a/src/options/config/flags.rs +++ b/src/options/config/flags.rs @@ -27,11 +27,9 @@ impl TableGap { #[cfg_attr(feature = "generate_schema", derive(schemars::JsonSchema))] #[cfg_attr(test, serde(deny_unknown_fields), derive(PartialEq, Eq))] pub(crate) struct GeneralConfig { - pub(crate) hide_avg_cpu: Option, pub(crate) dot_marker: Option, pub(crate) temperature_type: Option, pub(crate) rate: Option, - pub(crate) cpu_left_legend: Option, pub(crate) basic: Option, pub(crate) default_time_value: Option, pub(crate) time_delta: Option, @@ -50,16 +48,16 @@ pub(crate) struct GeneralConfig { pub(crate) show_table_scroll_position: Option, pub(crate) show_table_scroll_bar: Option, pub(crate) read_only: Option, - // #[cfg(feature = "zfs")] - pub(crate) free_arc: Option, pub(crate) disable_gpu: Option, - // 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, - pub(crate) enable_cache_memory: Option, pub(crate) retention: Option, // FIXME: Deprecate these in the future. + pub(crate) hide_avg_cpu: Option, + pub(crate) cpu_left_legend: Option, + pub(crate) average_cpu_row: Option, + pub(crate) enable_cache_memory: Option, + // #[cfg(feature = "zfs")] + pub(crate) free_arc: Option, pub(crate) network_use_bytes: Option, pub(crate) network_use_log: Option, pub(crate) network_use_binary_prefix: Option, diff --git a/src/options/config/memory_graph.rs b/src/options/config/memory_graph.rs index e751aac8..8b4cbbbd 100644 --- a/src/options/config/memory_graph.rs +++ b/src/options/config/memory_graph.rs @@ -11,4 +11,12 @@ pub struct MemoryGraphConfig { // (e.g. table-style, list-style) then we probably need a new system outright. /// Where to place the legend for the memory chart widget. pub(crate) legend_position: Option, + + /// 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, + + /// Whether to subtract freeable ARC from memory usage. + #[cfg_attr(not(feature = "zfs"), allow(dead_code))] + pub(crate) free_arc: Option, } diff --git a/tests/integration/valid_config_tests.rs b/tests/integration/valid_config_tests.rs index 3edd848b..3718624e 100644 --- a/tests/integration/valid_config_tests.rs +++ b/tests/integration/valid_config_tests.rs @@ -212,14 +212,13 @@ fn test_proc_default_sort() { } #[test] -fn test_newer_mem_network() { - run_and_kill(&["-C", "./tests/valid_configs/newer_mem_network.toml"]); +fn test_newer_memory() { + 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] -fn test_deprecated_mem_network() { - run_and_kill(&["-C", "./tests/valid_configs/deprecated/mem_network.toml"]); +fn test_newer_cpu() { + run_and_kill(&["-C", "./tests/valid_configs/newer_cpu.toml"]); } #[test] @@ -227,13 +226,36 @@ fn test_newer_processes() { 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. #[test] fn test_deprecated_processes() { 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] -fn test_network_alias() { - run_and_kill(&["-C", "./tests/valid_configs/network_alias.toml"]); +fn test_deprecated_cpu() { + 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"]); } diff --git a/tests/valid_configs/deprecated/cpu.toml b/tests/valid_configs/deprecated/cpu.toml new file mode 100644 index 00000000..175b2c1c --- /dev/null +++ b/tests/valid_configs/deprecated/cpu.toml @@ -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 diff --git a/tests/valid_configs/deprecated/mem_network.toml b/tests/valid_configs/deprecated/mem_network.toml deleted file mode 100644 index 618fcd0a..00000000 --- a/tests/valid_configs/deprecated/mem_network.toml +++ /dev/null @@ -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" diff --git a/tests/valid_configs/deprecated/memory.toml b/tests/valid_configs/deprecated/memory.toml new file mode 100644 index 00000000..83ae3be0 --- /dev/null +++ b/tests/valid_configs/deprecated/memory.toml @@ -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" diff --git a/tests/valid_configs/deprecated/network.toml b/tests/valid_configs/deprecated/network.toml new file mode 100644 index 00000000..498456f8 --- /dev/null +++ b/tests/valid_configs/deprecated/network.toml @@ -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" diff --git a/tests/valid_configs/newer_cpu.toml b/tests/valid_configs/newer_cpu.toml new file mode 100644 index 00000000..4ebe0043 --- /dev/null +++ b/tests/valid_configs/newer_cpu.toml @@ -0,0 +1,6 @@ +# This uses the newer CPU config location. + +[cpu] +hide_avg_cpu = true +left_legend = true +basic_average_cpu_row = true diff --git a/tests/valid_configs/newer_memory.toml b/tests/valid_configs/newer_memory.toml new file mode 100644 index 00000000..6cbb5574 --- /dev/null +++ b/tests/valid_configs/newer_memory.toml @@ -0,0 +1,6 @@ +# This uses the newer memory config location. + +[memory_graph] +cache_memory = true +free_arc = true +legend_position = "left" diff --git a/tests/valid_configs/newer_mem_network.toml b/tests/valid_configs/newer_network.toml similarity index 78% rename from tests/valid_configs/newer_mem_network.toml rename to tests/valid_configs/newer_network.toml index 8b0301ef..a7aec6e9 100644 --- a/tests/valid_configs/newer_mem_network.toml +++ b/tests/valid_configs/newer_network.toml @@ -5,6 +5,3 @@ use_log = true use_bytes = true use_binary_prefix = true legend_position = "left" - -[memory_graph] -legend_position = "left"