mod common;
use mimalloc_pprof::{prof, sys};
#[test]
fn profiler_accounting_survives_the_realloc_matrix() {
common::start(4096, 0x83);
let before = prof::stats();
unsafe {
let mut blocks: Vec<*mut u8> = Vec::new();
for round in 0..64usize {
let p = sys::mi_malloc(8192).cast::<u8>();
assert!(!p.is_null());
let q = match round % 4 {
0 => sys::mi_realloc(p.cast(), 16384).cast::<u8>(), 1 => sys::mi_realloc(p.cast(), 128).cast::<u8>(), 2 => mimalloc_pprof::rezalloc(p, 32768), _ => mimalloc_pprof::recalloc(p, 512, 64), };
assert!(!q.is_null());
blocks.push(q);
}
for b in blocks {
sys::mi_free(b.cast());
}
}
let after = prof::stats();
assert_eq!(
after.live_samples, before.live_samples,
"live sample count changed across a fully-freed realloc matrix \
(before={}, after={})",
before.live_samples, after.live_samples
);
assert_eq!(
after.live_bytes, before.live_bytes,
"live sampled bytes changed across a fully-freed realloc matrix \
(before={}, after={})",
before.live_bytes, after.live_bytes
);
prof::stop();
}