Add back jemalloc support

This commit is contained in:
Jonas Schievink 2021-01-18 19:25:55 +01:00
parent 6764d790ac
commit 9b5fa1c61a
7 changed files with 94 additions and 4 deletions

View file

@ -24,7 +24,12 @@ impl std::ops::Sub for MemoryUsage {
impl MemoryUsage {
pub fn current() -> MemoryUsage {
cfg_if! {
if #[cfg(all(target_os = "linux", target_env = "gnu"))] {
if #[cfg(all(feature = "jemalloc", not(target_env = "msvc")))] {
jemalloc_ctl::epoch::advance().unwrap();
MemoryUsage {
allocated: Bytes(jemalloc_ctl::stats::allocated::read().unwrap() as isize),
}
} else if #[cfg(all(target_os = "linux", target_env = "gnu"))] {
// Note: This is incredibly slow.
let alloc = unsafe { libc::mallinfo() }.uordblks as isize;
MemoryUsage { allocated: Bytes(alloc) }