mod common;
use std::hint::black_box;
use stoolap_jemalloc::{Jemalloc, prof};
#[global_allocator]
static GLOBAL: Jemalloc = Jemalloc::new().with_profiling();
#[inline(never)]
fn startup_block() -> Vec<u8> {
black_box(vec![1u8; 8 << 20])
}
#[test]
fn profiling_runs_from_the_first_allocation() {
assert!(prof::is_active(), "on before the test ran");
let kept = startup_block();
let profile = prof::dump_pprof().unwrap();
#[cfg(feature = "symbolize")]
{
let live = common::parse(&profile).totals("startup_block")[3];
assert!(live >= 8 << 20, "{live} live bytes for 8 MiB");
}
#[cfg(not(feature = "symbolize"))]
assert!(profile.len() > 16);
drop(kept);
prof::deactivate();
drop(black_box(vec![0u8; 4 << 20]));
assert!(!prof::is_active());
}