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: Support AMDGPU Data Collection #1641

Merged
merged 3 commits into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 3 additions & 3 deletions docs/content/configuration/command-line-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ see information on these options by running `btm -h`, or run `btm --help` to dis

## GPU Options

| Option | Behaviour |
| --------------- | --------------------------------------------------------- |
| `--disable_gpu` | Disable collecting and displaying NVIDIA GPU information. |
| Option | Behaviour |
| --------------- | ----------------------------------------------------------------- |
| `--disable_gpu` | Disable collecting and displaying NVIDIA and AMD GPU information. |

## Style Options

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 @@ -44,7 +44,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. |
| `disable_gpu` | Boolean | Disable NVIDIA GPU data collection. |
| `disable_gpu` | Boolean | Disable NVIDIA and AMD GPU data collection. |
| `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` | Boolean | Expand the default widget upon starting the app. |
Expand Down
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 (`--disable_gpu` on Linux/Windows to disable) or cache memory usage (`--enable_cache_memory`).
This widget can also be configured to display Nvidia and AMD GPU memory usage (`--disable_gpu` on Linux/Windows to disable) or cache memory usage (`--enable_cache_memory`).

## Key bindings

Expand Down
2 changes: 1 addition & 1 deletion docs/content/usage/widgets/temperature.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ 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 (`--disable_gpu` on Linux/Windows to disable).
This widget can also be configured to display Nvidia and AMD GPU temperatures (`--disable_gpu` on Linux/Windows to disable).

## Key bindings

Expand Down
44 changes: 39 additions & 5 deletions src/data_collection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
#[cfg(feature = "nvidia")]
pub mod nvidia;

#[cfg(all(target_os = "linux", feature = "gpu"))]
pub mod amd;

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

Expand Down Expand Up @@ -347,6 +350,10 @@ impl DataCollector {
#[inline]
fn update_gpus(&mut self) {
if self.widgets_to_harvest.use_gpu {
let mut local_gpu: Vec<(String, memory::MemHarvest)> = Vec::new();
let mut local_gpu_pids: Vec<HashMap<u32, (u64, u32)>> = Vec::new();
let mut local_gpu_total_mem: u64 = 0;

#[cfg(feature = "nvidia")]
if let Some(data) = nvidia::get_nvidia_vecs(
&self.temperature_type,
Expand All @@ -360,14 +367,41 @@ impl DataCollector {
self.data.temperature_sensors = Some(temp);
}
}
if let Some(mem) = data.memory {
self.data.gpu = Some(mem);
if let Some(mut mem) = data.memory {
local_gpu.append(&mut mem);
}
if let Some(mut proc) = data.procs {
local_gpu_pids.append(&mut proc.1);
local_gpu_total_mem += proc.0;
}
}

#[cfg(target_os = "linux")]
if let Some(data) = amd::get_amd_vecs(
&self.temperature_type,
&self.filters.temp_filter,
&self.widgets_to_harvest,
self.last_collection_time,
) {
if let Some(mut temp) = data.temperature {
if let Some(sensors) = &mut self.data.temperature_sensors {
sensors.append(&mut temp);
} else {
self.data.temperature_sensors = Some(temp);
}
}
if let Some(mut mem) = data.memory {
local_gpu.append(&mut mem);
}
if let Some(proc) = data.procs {
self.gpu_pids = Some(proc.1);
self.gpus_total_mem = Some(proc.0);
if let Some(mut proc) = data.procs {
local_gpu_pids.append(&mut proc.1);
local_gpu_total_mem += proc.0;
}
}

self.data.gpu = (!local_gpu.is_empty()).then_some(local_gpu);
self.gpu_pids = (!local_gpu_pids.is_empty()).then_some(local_gpu_pids);
self.gpus_total_mem = (local_gpu_total_mem > 0).then_some(local_gpu_total_mem);
}
}

Expand Down
Loading
Loading