sim: account where the mod's memory goes (Sim::memory, per-cache bytes)
The fullscreen-map OOM (Ground::answer rehash under a large raid) needs a measured breakdown, not a guess: Sim::memory estimates each consumer's allocated capacity (hashbrown tables with their control bytes, vec capacities, BTreeMap nodes) — Ground.known, WorldCache.secs and rays, the sim vectors and radar tracks, the recording and kept replays, Intel/recon, routes, sites, strikes, the raid plan. MemoryReport::rehash_headroom names the transient a rehash adds (old + new table of the biggest map). Ground::known_len exposes the column count the budget tests guard. Co-Authored-By: Kimi Code <noreply@moonshot.ai>
This commit is contained in:
@@ -919,6 +919,35 @@ impl Recording {
|
||||
}
|
||||
}
|
||||
|
||||
/// What the recording holds, about: tracks and their points, the event and scene
|
||||
/// journals, the systems' poses and the by-time index (see `sim::memory`).
|
||||
pub fn bytes(&self) -> usize {
|
||||
use super::memory::{map_bytes, vec_bytes};
|
||||
let mut n = vec_bytes(&self.tracks)
|
||||
+ self.tracks.iter().map(|t| vec_bytes(&t.points)).sum::<usize>()
|
||||
+ map_bytes(self.index.len(), std::mem::size_of::<u32>() + std::mem::size_of::<usize>())
|
||||
+ vec_bytes(&self.events)
|
||||
+ vec_bytes(&self.sam_tracks)
|
||||
+ self.sam_tracks.iter().map(|t| vec_bytes(&t.keys)).sum::<usize>()
|
||||
+ map_bytes(self.sam_index.len(), std::mem::size_of::<u32>() + std::mem::size_of::<usize>())
|
||||
+ vec_bytes(&self.ticks)
|
||||
+ vec_bytes(&self.times)
|
||||
+ vec_bytes(&self.sams)
|
||||
+ vec_bytes(&self.objects)
|
||||
+ self.index_bytes()
|
||||
+ std::mem::size_of::<Tally>();
|
||||
if let Some(scene) = &self.scene {
|
||||
n += vec_bytes(&scene.events)
|
||||
+ map_bytes(scene.tracks.len(), std::mem::size_of::<(u32, u32)>() + std::mem::size_of::<(bool, bool, DVec3)>())
|
||||
+ map_bytes(scene.fires.len(), std::mem::size_of::<u32>() + std::mem::size_of::<(DVec3, u32, f32, bool, bool, Option<bool>)>())
|
||||
+ vec_bytes(&scene.fire_events)
|
||||
+ map_bytes(scene.launches.len(), std::mem::size_of::<u32>() + std::mem::size_of::<usize>())
|
||||
+ map_bytes(scene.ignitions.len(), std::mem::size_of::<u32>() + std::mem::size_of::<usize>())
|
||||
+ map_bytes(scene.burnouts.len(), std::mem::size_of::<u32>() + std::mem::size_of::<usize>());
|
||||
}
|
||||
n
|
||||
}
|
||||
|
||||
/// The bytes the by-time index adds to a recording (its own journal aside).
|
||||
pub fn index_bytes(&self) -> usize {
|
||||
let order = self.time_order.as_ref().map_or(0, |o| o.capacity() * std::mem::size_of::<u32>());
|
||||
|
||||
Reference in New Issue
Block a user