pub struct MemorySnapshot {
pub ram_bytes: u64,
pub vram_bytes: Option<u64>,
pub vram_total_bytes: Option<u64>,
pub vram_per_process: Option<bool>,
pub gpu_name: Option<String>,
}Expand description
Memory snapshot at a point in time.
Captures process RAM (resident set size) and optionally GPU VRAM.
Use MemorySnapshot::now to take a measurement, and
MemoryReport::new to compute deltas between two snapshots.
§Example
use candle_mi::MemorySnapshot;
let before = MemorySnapshot::now(&candle_core::Device::Cpu)?;
// ... load a model ...
let after = MemorySnapshot::now(&candle_core::Device::Cpu)?;
let report = candle_mi::MemoryReport::new(before, after);
println!("RAM delta: {:+.1} MB", report.ram_delta_mb());Fields§
§ram_bytes: u64Process resident set size (working set on Windows) in bytes.
vram_bytes: Option<u64>GPU memory used in bytes.
Per-process when measured via DXGI/NVML, device-wide when via nvidia-smi fallback.
None if no GPU is present or measurement failed.
vram_total_bytes: Option<u64>Total GPU memory on the active device in bytes.
None if no GPU is present or measurement failed.
vram_per_process: Option<bool>Whether the VRAM measurement is per-process (true) or device-wide (false).
None if no VRAM data is available.
gpu_name: Option<String>GPU adapter name (e.g., NVIDIA GeForce RTX 5060 Ti).
None if not available (non-DXGI path or no GPU).
Implementations§
Source§impl MemorySnapshot
impl MemorySnapshot
Sourcepub fn now(device: &Device) -> Result<Self>
pub fn now(device: &Device) -> Result<Self>
Capture current memory state.
RAM is always measured (per-process RSS). VRAM is measured only if
device is CUDA — first via DXGI (Windows, per-process), then NVML
(Linux, per-process), falling back to nvidia-smi (device-wide).
§Errors
Returns MIError::Memory if the RAM query fails (platform API error).
VRAM measurement failures are non-fatal — vram_bytes is set to None.
Trait Implementations§
Source§impl Clone for MemorySnapshot
impl Clone for MemorySnapshot
Source§fn clone(&self) -> MemorySnapshot
fn clone(&self) -> MemorySnapshot
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for MemorySnapshot
impl RefUnwindSafe for MemorySnapshot
impl Send for MemorySnapshot
impl Sync for MemorySnapshot
impl Unpin for MemorySnapshot
impl UnsafeUnpin for MemorySnapshot
impl UnwindSafe for MemorySnapshot
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more