allocator_tracer/
analysis.rs

1use crate::AllocationEvent;
2
3pub fn memory_peak(events: &[AllocationEvent]) -> isize {
4    let mut peak = 0;
5
6    for event in events {
7        peak += event.allocated_bytes();
8    }
9
10    peak
11}
12
13pub fn allocation_count(events: &[AllocationEvent]) -> usize {
14    events.iter().filter(|e| e.is_alloc()).count()
15}
16
17pub fn deallocation_count(events: &[AllocationEvent]) -> usize {
18    events.iter().filter(|e| e.is_dealloc()).count()
19}
20
21pub fn reallocation_count(events: &[AllocationEvent]) -> usize {
22    events.iter().filter(|e| e.is_realloc()).count()
23}
24
25pub fn allocated_size(events: &[AllocationEvent]) -> isize {
26    events.iter().map(AllocationEvent::allocated_bytes).sum()
27}
28
29pub fn deallocated_size(events: &[AllocationEvent]) -> isize {
30    -allocated_size(events)
31}
32
33pub fn memory_average(events: &[AllocationEvent]) -> f64 {
34    let mut avg = 0.0;
35    let mut memory = 0; 
36
37    for event in events {
38        memory += event.allocated_bytes();
39        avg += memory as f64;
40    }
41
42    avg / events.len() as f64
43}