use emath::History;
pub struct MemoryHistory {
pub resident: History<i64>,
pub counted: History<i64>,
pub counted_gpu: History<i64>,
pub counted_store: History<i64>,
pub counted_primary_caches: History<i64>,
pub counted_blueprint: History<i64>,
}
impl Default for MemoryHistory {
fn default() -> Self {
let max_elems = 32 * 1024;
let max_seconds = f32::INFINITY;
Self {
resident: History::new(0..max_elems, max_seconds),
counted: History::new(0..max_elems, max_seconds),
counted_gpu: History::new(0..max_elems, max_seconds),
counted_store: History::new(0..max_elems, max_seconds),
counted_primary_caches: History::new(0..max_elems, max_seconds),
counted_blueprint: History::new(0..max_elems, max_seconds),
}
}
}
impl MemoryHistory {
pub fn is_empty(&self) -> bool {
let Self {
resident,
counted,
counted_gpu,
counted_store,
counted_primary_caches,
counted_blueprint,
} = self;
resident.is_empty()
&& counted.is_empty()
&& counted_gpu.is_empty()
&& counted_store.is_empty()
&& counted_primary_caches.is_empty()
&& counted_blueprint.is_empty()
}
pub fn capture(
&mut self,
updated_counted_gpu: Option<i64>,
updated_counted_store: Option<i64>,
updated_counted_primary_caches: Option<i64>,
updated_counted_blueprint: Option<i64>,
) {
let mem_use = crate::MemoryUse::capture();
let now = crate::util::sec_since_start();
let Self {
resident,
counted,
counted_gpu,
counted_store,
counted_primary_caches,
counted_blueprint,
} = self;
if let Some(updated_resident) = mem_use.resident {
resident.add(now, updated_resident);
}
if let Some(updated_counted) = mem_use.counted {
counted.add(now, updated_counted);
}
if let Some(updated_counted_gpu) = updated_counted_gpu {
counted_gpu.add(now, updated_counted_gpu);
}
if let Some(updated_counted_store) = updated_counted_store {
counted_store.add(now, updated_counted_store);
}
if let Some(updated_counted_primary_caches) = updated_counted_primary_caches {
counted_primary_caches.add(now, updated_counted_primary_caches);
}
if let Some(updated_counted_blueprint) = updated_counted_blueprint {
counted_blueprint.add(now, updated_counted_blueprint);
}
}
}