Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ harness = false
[features]
default = ["kernel-stack", "pci", "pci-ids", "acpi", "fsgsbase", "smp", "tcp", "dhcpv4", "fuse", "virtio-net", "vsock"]
acpi = []
alloc-stats = ["talc/counters"]
common-os = []
console = ["virtio"]
dhcpv4 = ["net", "smoltcp", "smoltcp/proto-dhcpv4", "smoltcp/socket-dhcpv4"]
Expand Down
22 changes: 22 additions & 0 deletions src/executor/alloc_stats.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
use core::future;
use core::task::Poll;

use crate::executor::spawn;
use crate::mm::ALLOCATOR;

async fn print_alloc_stats() {
future::poll_fn(|cx| {
let talc = ALLOCATOR.lock();

debug!("<alloc-stats>\n{}", talc.get_counters());

cx.waker().wake_by_ref();
Poll::<()>::Pending
})
.await;
}

pub(crate) fn init() {
info!("Spawning allocation stats printing task");
spawn(print_alloc_stats());
}
11 changes: 10 additions & 1 deletion src/executor/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#[cfg(feature = "alloc-stats")]
mod alloc_stats;
#[cfg(feature = "net")]
pub(crate) mod device;
#[cfg(feature = "net")]
Expand Down Expand Up @@ -108,7 +110,12 @@ pub(crate) fn run() {

/// Spawns a future on the executor.
#[cfg_attr(
not(any(feature = "shell", feature = "net", feature = "vsock")),
not(any(
feature = "alloc-stats",
feature = "shell",
feature = "net",
feature = "vsock"
)),
expect(dead_code)
)]
pub(crate) fn spawn<F>(future: F)
Expand All @@ -123,6 +130,8 @@ pub fn init() {
crate::executor::network::init();
#[cfg(feature = "vsock")]
crate::executor::vsock::init();
#[cfg(feature = "alloc-stats")]
crate::executor::alloc_stats::init();
}

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