gpu-histop 0.1.0

High-resolution GPU history monitor for NVIDIA, AMDGPU, and Apple Silicon
Documentation
use anyhow::Result;
use gpu_histop::backend::create_backend;
use gpu_histop::config::BackendChoice;

fn main() -> Result<()> {
    let mut backend = create_backend(BackendChoice::Auto)?;

    for sample in backend.sample()? {
        println!(
            "GPU {}: {} process(es)",
            sample.gpu_id,
            sample.processes.len()
        );
        for process in sample.processes {
            let user = process.user.as_deref().unwrap_or("?");
            let command = process.command.as_deref().unwrap_or("?");
            let memory = process
                .used_gpu_memory_bytes
                .map(|bytes| format!("{:.1} GiB", bytes as f64 / 1024.0 / 1024.0 / 1024.0))
                .unwrap_or_else(|| "n/a".to_owned());
            println!(
                "  {:<7} pid={:<8} user={:<12} mem={:<8} {}",
                process.kind_label(),
                process.pid,
                user,
                memory,
                command
            );
        }
    }

    Ok(())
}