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

Add gpu proc info #1276

Merged
merged 12 commits into from
Nov 20, 2023
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ indexmap = "2.0.0"
itertools = "0.11.0"
kstring = { version = "2.0.0", features = ["arc"] }
log = { version = "0.4.20", optional = true }
nvml-wrapper = { version = "0.9.0", optional = true }
nvml-wrapper = { version = "0.9.0", optional = true, features = ["legacy-functions"] }
once_cell = "1.18.0"
regex = "1.9.4"
serde = { version = "=1.0.188 ", features = ["derive"] }
Expand Down
2 changes: 1 addition & 1 deletion docs/content/configuration/command-line-flags.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ see information on these flags by running `btm -h`, or run `btm --help` to displ
| --disable_click | Disables mouse clicks. |
| -m, --dot_marker | Uses a dot marker for graphs. |
| --enable_cache_memory | Enable collecting and displaying cache and buffer memory. |
| --enable_gpu_memory | Enable collecting and displaying GPU memory usage. |
| --enable_gpu | Enable collecting and displaying GPU usage. |
| -e, --expanded | Expand the default widget upon starting the app. |
| -f, --fahrenheit | Sets the temperature type to Fahrenheit. |
| -g, --group | Groups processes with the same name by default. |
Expand Down
2 changes: 1 addition & 1 deletion docs/content/configuration/config-file/flags.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ each time:
| `network_use_binary_prefix` | Boolean | Displays the network widget with binary prefixes. |
| `network_use_bytes` | Boolean | Displays the network widget using bytes. |
| `network_use_log` | Boolean | Displays the network widget with a log scale. |
| `enable_gpu_memory` | Boolean | Shows the GPU memory widget. |
| `enable_gpu` | Boolean | Shows the GPU widgets. |
| `retention` | String (human readable time, such as "10m", "1h", etc.) | How much data is stored at once in terms of time. |
| `unnormalized_cpu` | Boolean | Show process CPU% without normalizing over the number of cores. |
| `expanded_on_startup` | Boolean | Expand the default widget upon starting the app. |
2 changes: 1 addition & 1 deletion docs/content/configuration/config-file/processes.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ You can configure which columns are shown by the process widget by setting the `
```toml
[processes]
# Pick which columns you want to use in any order.
columns = ["cpu%", "mem%", "pid", "name", "read", "write", "Tread", "twrite", "state", "user", "time"]
columns = ["cpu%", "mem%", "pid", "name", "read", "write", "Tread", "twrite", "state", "user", "time", "gmem%", "gpu%"]
jamartin9 marked this conversation as resolved.
Show resolved Hide resolved
```
2 changes: 1 addition & 1 deletion docs/content/usage/widgets/memory.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ If the total RAM or swap available is 0, then it is automatically hidden from th

One can also adjust the displayed time range through either the keyboard or mouse, with a range of 30s to 600s.

This widget can also be configured to display Nvidia GPU memory usage (`--enable_gpu_memory`) or cache memory usage (`--enable_cache_memory`).
This widget can also be configured to display Nvidia GPU memory usage (`--enable_gpu` on Linux/Windows) or cache memory usage (`--enable_cache_memory`).

## Key bindings

Expand Down
11 changes: 11 additions & 0 deletions docs/content/usage/widgets/process.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ It can also additionally display the following columns:

- Process running time

With the feature flag (`--enable_gpu` on Linux/Windows) and gpu process columns enabled in the configuration:

- GPU memory use percentage
- GPU core utilization percentage


See [the processes configuration page](../../configuration/config-file/processes.md) on how to customize which columns
are shown.

Expand Down Expand Up @@ -147,6 +153,9 @@ Note all keywords are case-insensitive. To search for a process/command that col
| `user` | `user=root` | Matches by user; supports regex |
| `state` | `state=running` | Matches by state; supports regex |
| `()` | `(<COND 1> AND <COND 2>) OR <COND 3>` | Group together a condition |
| `gmem` | `gmem > 1000 b` | Matches the gpu memory column in terms of bytes; supports comparison operators |
jamartin9 marked this conversation as resolved.
Show resolved Hide resolved
| `gmem%` | `gmem% < 0.5` | Matches the gpu memory column in terms of percent; supports comparison operators|
| `gpu%` | `gpu% > 0` | Matches the gpu usage column in terms of percent; supports comparison operators |

#### Comparison operators

Expand Down Expand Up @@ -207,6 +216,8 @@ Note that key bindings are generally case-sensitive.
| ++I++ | Invert the current sort |
| ++"%"++ | Toggle between values and percentages for memory usage |
| ++t++ , ++f5++ | Toggle tree mode |
| ++M++ | Sort by gpu memory usage, press again to reverse sorting order |
| ++C++ | Sort by gpu usage, press again to reverse sorting order |

### Sort sub-widget

Expand Down
2 changes: 2 additions & 0 deletions docs/content/usage/widgets/temperature.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ The temperature widget provides a table of temperature sensors and their current

The temperature widget provides the sensor name as well as its current temperature.

This widget can also be configured to display Nvidia GPU temperatures (`--enable_gpu` on Linux/Windows).

## Key bindings

Note that key bindings are generally case-sensitive.
Expand Down
6 changes: 3 additions & 3 deletions sample_configs/default_config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
# Hides advanced options to stop a process on Unix-like systems.
#disable_advanced_kill = false
# Shows GPU(s) memory
#enable_gpu_memory = false
#enable_gpu = false
# Shows cache and buffer memory
#enable_cache_memory = false
# How much data is stored at once in terms of time.
Expand All @@ -83,7 +83,7 @@
# These are flags around the process widget.

#[processes]
#columns = ["PID", "Name", "CPU%", "Mem%", "R/s", "W/s", "T.Read", "T.Write", "User", "State"]
#columns = ["PID", "Name", "CPU%", "Mem%", "R/s", "W/s", "T.Read", "T.Write", "User", "State", "GMEM%", "GPU%"]

# These are all the components that support custom theming. Note that colour support
# will depend on terminal support.
Expand All @@ -103,7 +103,7 @@
#swap_color="LightYellow"
# Represents the colour ARC will use in the memory legend and graph.
#arc_color="LightCyan"
# Represents the colour the GPU will use in the memory legend and graph.
# Represents the colour the GPU will use in the legend and graph.
#gpu_core_colors=["LightGreen", "LightBlue", "LightRed", "Cyan", "Green", "Blue", "Red"]
# Represents the colour rx will use in the network legend and graph.
#rx_color="LightCyan"
Expand Down
35 changes: 33 additions & 2 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ pub struct AppConfigFields {
pub use_old_network_legend: bool,
pub table_gap: u16,
pub disable_click: bool,
pub enable_gpu_memory: bool,
pub enable_gpu: bool,
pub enable_cache_memory: bool,
pub show_table_scroll_position: bool,
pub is_advanced_kill: bool,
Expand Down Expand Up @@ -1277,6 +1277,30 @@ impl App {
disk.set_index(3);
}
}
#[cfg(feature = "gpu")]
'M' => {
if let BottomWidgetType::Proc = self.current_widget.widget_type {
if let Some(proc_widget_state) = self
.states
.proc_state
.get_mut_widget_state(self.current_widget.widget_id)
{
proc_widget_state.select_column(ProcWidgetColumn::GpuMem);
}
}
}
#[cfg(feature = "gpu")]
'C' => {
if let BottomWidgetType::Proc = self.current_widget.widget_type {
if let Some(proc_widget_state) = self
.states
.proc_state
.get_mut_widget_state(self.current_widget.widget_id)
{
proc_widget_state.select_column(ProcWidgetColumn::GpuUtil);
}
}
}
jamartin9 marked this conversation as resolved.
Show resolved Hide resolved
'?' => {
self.help_dialog_state.is_showing_help = true;
self.is_force_redraw = true;
Expand Down Expand Up @@ -2702,7 +2726,14 @@ impl App {
{
if (x >= *tlc_x && y >= *tlc_y) && (x <= *brc_x && y <= *brc_y)
{
battery_widget_state.currently_selected_battery_index = itx;
if itx >= self.converted_data.battery_data.len() {
// range check to keep within current data
battery_widget_state.currently_selected_battery_index =
self.converted_data.battery_data.len() - 1;
} else {
battery_widget_state.currently_selected_battery_index =
itx;
}
ClementTsang marked this conversation as resolved.
Show resolved Hide resolved
break;
}
}
Expand Down
58 changes: 48 additions & 10 deletions src/app/data_harvester.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use std::time::{Duration, Instant};

#[cfg(target_os = "linux")]
#[cfg(any(target_os = "linux", feature = "gpu"))]
use hashbrown::HashMap;
#[cfg(feature = "battery")]
use starship_battery::{Battery, Manager};
Expand Down Expand Up @@ -125,6 +125,11 @@ pub struct DataCollector {

#[cfg(target_family = "unix")]
user_table: processes::UserTable,

#[cfg(feature = "gpu")]
gpu_pids: Option<Vec<HashMap<u32, (u64, u32)>>>,
#[cfg(feature = "gpu")]
gpus_total_mem: Option<u64>,
}

impl DataCollector {
Expand Down Expand Up @@ -153,6 +158,10 @@ impl DataCollector {
filters,
#[cfg(target_family = "unix")]
user_table: Default::default(),
#[cfg(feature = "gpu")]
gpu_pids: None,
#[cfg(feature = "gpu")]
gpus_total_mem: None,
}
}

Expand Down Expand Up @@ -288,17 +297,51 @@ impl DataCollector {

self.update_cpu_usage();
self.update_memory_usage();
self.update_processes();
self.update_temps();
self.update_network_usage();
self.update_disks();

#[cfg(feature = "battery")]
self.update_batteries();
#[cfg(feature = "gpu")]
self.update_gpus(); // update_gpus before procs for gpu_pids but after temps for appending
self.update_processes();
self.update_network_usage();
self.update_disks();

// Update times for future reference.
self.last_collection_time = self.data.collection_time;
}
#[cfg(feature = "gpu")]
jamartin9 marked this conversation as resolved.
Show resolved Hide resolved
#[inline]
fn update_gpus(&mut self) {
jamartin9 marked this conversation as resolved.
Show resolved Hide resolved
if self.widgets_to_harvest.use_gpu {
#[cfg(feature = "nvidia")]
if let Some(data) = nvidia::get_nvidia_vecs(
&self.temperature_type,
&self.filters.temp_filter,
&self.widgets_to_harvest,
) {
if self.widgets_to_harvest.use_temp {
jamartin9 marked this conversation as resolved.
Show resolved Hide resolved
if let Some(mut temp) = data.temperature {
if let Some(ref mut sensors) = self.data.temperature_sensors {
jamartin9 marked this conversation as resolved.
Show resolved Hide resolved
sensors.append(&mut temp);
} else {
self.data.temperature_sensors = Some(temp);
}
}
}
if self.widgets_to_harvest.use_mem {
if let Some(mem) = data.memory {
self.data.gpu = Some(mem);
}
}
if self.widgets_to_harvest.use_proc {
if let Some(proc) = data.procs {
self.gpu_pids = Some(proc.1);
self.gpus_total_mem = Some(proc.0);
}
}
}
}
}

#[inline]
fn update_cpu_usage(&mut self) {
Expand Down Expand Up @@ -365,11 +408,6 @@ impl DataCollector {
{
self.data.arc = memory::arc::get_arc_usage();
}

#[cfg(feature = "gpu")]
if self.widgets_to_harvest.use_gpu {
self.data.gpu = memory::gpu::get_gpu_mem_usage();
}
}
}

Expand Down
4 changes: 0 additions & 4 deletions src/app/data_harvester/cpu.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
//! Data collection for CPU usage and load average.
//!
//! For CPU usage, Linux, macOS, and Windows are handled by Heim, FreeBSD by sysinfo.
//!
//! For load average, macOS and Linux are supported through Heim, FreeBSD by sysinfo.

pub mod sysinfo;
pub use self::sysinfo::*;
Expand Down
3 changes: 0 additions & 3 deletions src/app/data_harvester/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ cfg_if::cfg_if! {
}
}

#[cfg(feature = "gpu")]
pub mod gpu;

#[cfg(feature = "zfs")]
pub mod arc;

Expand Down
47 changes: 0 additions & 47 deletions src/app/data_harvester/memory/gpu.rs

This file was deleted.

Loading