Skip to content

Commit 858b1e6

Browse files
committed
feat(allocation-stats): support regularly printing allocation stats
Talc can optionally collect and expose some basic statistics about allocations. Provide a feature that regularly prints these statistics via another executor tassk.
1 parent 2a7a4e9 commit 858b1e6

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ trace = []
6969
udp = ["smoltcp", "smoltcp/socket-udp"]
7070
vga = []
7171
vsock = ["pci"]
72+
allocation-stats = ["talc/counters"]
7273

7374
[lints.rust]
7475
rust_2018_idioms = "warn"

src/executor/alloc_stats.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
use core::task::Poll;
2+
3+
use crate::executor::spawn;
4+
use crate::mm::ALLOCATOR;
5+
6+
async fn print_alloc_stats() {
7+
core::future::poll_fn::<(), _>(|_cx| {
8+
let talc = ALLOCATOR.inner().lock();
9+
10+
debug!("<alloc-stats>\n{}", talc.get_counters());
11+
12+
Poll::Pending
13+
})
14+
.await;
15+
}
16+
17+
pub(crate) fn init() {
18+
info!("Spawning allocation stats printing task");
19+
spawn(print_alloc_stats());
20+
}

src/executor/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#![allow(dead_code)]
22

3+
#[cfg(feature = "allocation-stats")]
4+
mod alloc_stats;
35
#[cfg(any(feature = "tcp", feature = "udp"))]
46
pub(crate) mod device;
57
#[cfg(any(feature = "tcp", feature = "udp"))]
@@ -127,6 +129,8 @@ pub fn init() {
127129
crate::executor::network::init();
128130
#[cfg(feature = "vsock")]
129131
crate::executor::vsock::init();
132+
#[cfg(feature = "allocation-stats")]
133+
crate::executor::alloc_stats::init();
130134
}
131135

132136
/// Blocks the current thread on `f`, running the executor when idling.

0 commit comments

Comments
 (0)