nvtop 0.1.0

`nvtop`: An NVIDIA SMI'esk GPU Monitoring tool for your terminal. `nvtop` is a command-line utility that provides a replacement for some of the output from `nvidia-smi` (System Management Interface). It offers real-time monitoring and visualization of GPU information: Core Clock, Temps, Fanspeed and Memory Usage. # Usage: ``` # Monitor the GPU and system with a 1-second update interval nvtop --delay 1000 ```
Documentation
use std::{fmt, ops::Deref};

use nvml_wrapper::{enum_wrappers::device::TemperatureSensor, Device};

#[derive(Debug)]
pub struct GpuInfo<'d> {
    pub inner: &'d Device<'d>,
}

impl<'d> Deref for GpuInfo<'d> {
    type Target = &'d Device<'d>;

    fn deref(&self) -> &Self::Target {
        &self.inner
    }
}

impl<'d> fmt::Display for GpuInfo<'d> {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        let meminfo = self.inner.memory_info().unwrap();
        let utilisation = self.inner.utilization_rates().unwrap();
        writeln!(f, "Brand: {:?}", self.inner.brand())?;
        writeln!(f, "core: {:?}%", utilisation.gpu)?;
        writeln!(f, "mem_used: {:?}", meminfo.used as f64 / 1_073_741_824.0)?;
        writeln!(f, "mem {:?}%", (meminfo.total / meminfo.used))?;
        writeln!(
            f,
            "mem_total: {:?}",
            meminfo.total as f64 / 1_073_741_824.0
        )?;
        writeln!(
            f,
            "Temp: {:?}C",
            self.inner.temperature(TemperatureSensor::Gpu)
        )?;

        // TODO: the other stuff we may want to print...

        // for clock_id in [
        //     ClockId::Current,
        //     ClockId::TargetAppClock,
        //     ClockId::DefaultAppClock,
        //     ClockId::CustomerMaxBoost,
        // ]
        // .into_iter()
        // {
        //     [Clock::Graphics, Clock::SM, Clock::Memory, Clock::Video]
        //         .into_iter()
        //         .for_each(|clock_type| {
        //             match self.device.clock(clock_type.clone(), clock_id.clone()) {
        //                 Ok(value) => {
        //                     write!(f, "Clock {:?} for {:?}: {}\n", clock_type, clock_id, value)
        //                         .unwrap_or_default()
        //                 }
        //                 Err(_err) => {
        //                     log::error!("{_err}")
        //                 }
        //             }
        //         });
        // }
        Ok(())
    }
}