Skip to content

Commit

Permalink
feat(alloc): collect heap statistics (#269)
Browse files Browse the repository at this point in the history
  • Loading branch information
hawkw authored Sep 13, 2023
1 parent efbc428 commit 34cfc07
Show file tree
Hide file tree
Showing 6 changed files with 325 additions and 9 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion platforms/allwinner-d1/boards/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ static AHEAP: MnemosAlloc<SingleThreadedLinkedListAllocator> = MnemosAlloc::new(
///
/// Only call this once!
pub unsafe fn initialize_heap<const HEAP_SIZE: usize>(buf: &'static Ram<HEAP_SIZE>) {
AHEAP.init(NonNull::new(buf.as_ptr()).unwrap(), HEAP_SIZE);
AHEAP
.init(NonNull::new(buf.as_ptr()).unwrap(), HEAP_SIZE)
.expect("heap should only be initialized once!");
}

#[panic_handler]
Expand Down
4 changes: 3 additions & 1 deletion platforms/esp32c3-buddy/src/heap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ pub unsafe fn init() {
};

unsafe {
AHEAP.init(heap_start, HEAP_SIZE);
AHEAP
.init(heap_start, HEAP_SIZE)
.expect("heap initialized more than once!")
}
}

Expand Down
10 changes: 10 additions & 0 deletions source/alloc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,16 @@ features = ["defmt-impl"]
version = "0.10.1"
default-features = false

[dependencies.portable-atomic]
version = "1.3.3"
default-features = false

[features]
default = []
use-std = []
# enables tracking heap allocation statistics.
stats = []

[package.metadata.docs.rs]
all-features = true
rustdoc-args = ["--cfg", "docsrs"]
Loading

0 comments on commit 34cfc07

Please sign in to comment.