feat: add memory footprint to /stats and dashboard
Per-structure heap estimation (cache, blocklist, query log, SRTT, overrides) with process RSS via mach_task_basic_info / sysconf. Dashboard gets a 6th stat card and a sidebar breakdown panel with stacked bar visualization. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -66,6 +66,25 @@ impl DnsPacket {
|
||||
pkt
|
||||
}
|
||||
|
||||
pub fn heap_bytes(&self) -> usize {
|
||||
fn records_heap(records: &[DnsRecord]) -> usize {
|
||||
records
|
||||
.iter()
|
||||
.map(|r| std::mem::size_of::<DnsRecord>() + r.heap_bytes())
|
||||
.sum::<usize>()
|
||||
}
|
||||
let questions: usize = self
|
||||
.questions
|
||||
.iter()
|
||||
.map(|q| std::mem::size_of::<DnsQuestion>() + q.name.capacity())
|
||||
.sum();
|
||||
questions
|
||||
+ records_heap(&self.answers)
|
||||
+ records_heap(&self.authorities)
|
||||
+ records_heap(&self.resources)
|
||||
+ self.edns.as_ref().map_or(0, |e| e.options.capacity())
|
||||
}
|
||||
|
||||
pub fn response_from(query: &DnsPacket, rescode: crate::header::ResultCode) -> DnsPacket {
|
||||
let mut resp = DnsPacket::new();
|
||||
resp.header.id = query.header.id;
|
||||
|
||||
Reference in New Issue
Block a user