Mercurial > core / rust/lib/alch/src/tr.rs
changeset 698: |
96958d3eb5b0 |
parent: |
1227f932b628
|
author: |
Richard Westhaver <ellis@rwest.io> |
date: |
Fri, 04 Oct 2024 22:04:59 -0400 |
permissions: |
-rw-r--r-- |
description: |
fixes |
2 alloc::{GlobalAlloc, Layout, System}, 3 sync::atomic::{AtomicU64, Ordering}, 6 /// a simple global allocator for tracing memory usage 7 /// from https://github.com/datafuselabs/databend/issues/1148#issuecomment-907829698 8 pub struct TrAlloc(System, AtomicU64, AtomicU64); 10 unsafe impl GlobalAlloc for TrAlloc { 11 unsafe fn alloc(&self, l: Layout) -> *mut u8 { 12 self.1.fetch_add(l.size() as u64, Ordering::SeqCst); 13 self.2.fetch_add(l.size() as u64, Ordering::SeqCst); 16 unsafe fn dealloc(&self, ptr: *mut u8, l: Layout) { 17 self.0.dealloc(ptr, l); 18 self.1.fetch_sub(l.size() as u64, Ordering::SeqCst); 23 pub const fn new(s: System) -> Self { 24 TrAlloc(s, AtomicU64::new(0), AtomicU64::new(0)) 28 self.1.store(0, Ordering::SeqCst); 29 self.2.store(0, Ordering::SeqCst); 32 pub fn get(&self) -> u64 { 33 self.1.load(Ordering::SeqCst) 36 pub fn get_sum(&self) -> u64 { 37 self.2.load(Ordering::SeqCst)