Skip to content

Commit

Permalink
feat(kernel): add dump rt command (#375)
Browse files Browse the repository at this point in the history
This adds a shell command that prints the state of the kernel's async
runtime.
  • Loading branch information
hawkw committed Dec 1, 2022
1 parent bf86b6e commit 0c2e5ee
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/rt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use maitake::{
scheduler::{self, StaticScheduler, Stealer},
time,
};
use mycelium_util::sync::InitOnce;
use mycelium_util::{fmt, sync::InitOnce};
use rand::Rng;

pub use maitake::task::JoinHandle;
Expand Down Expand Up @@ -95,6 +95,13 @@ pub fn init() {
tracing::info!("kernel runtime initialized");
}

pub const DUMP_RT: crate::shell::Command = crate::shell::Command::new("rt")
.with_help("print the kernel's async runtime")
.with_fn(|_| {
tracing::info!(runtime = ?RUNTIME);
Ok(())
});

static SCHEDULER: arch::LocalKey<Cell<Option<&'static StaticScheduler>>> =
arch::LocalKey::new(|| Cell::new(None));

Expand Down Expand Up @@ -281,3 +288,14 @@ impl Runtime {
self.cores[idx].try_get()?.try_steal().ok()
}
}

impl fmt::Debug for Runtime {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let cores = self.active_cores();
f.debug_struct("Runtime")
.field("active_cores", &cores)
.field("cores", &&self.cores[..cores])
.field("injector", &self.injector)
.finish()
}
}
1 change: 1 addition & 0 deletions src/shell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ pub fn eval(line: &str) {
tracing::info!(timer = ?crate::rt::TIMER);
Ok(())
}),
crate::rt::DUMP_RT,
crate::arch::shell::DUMP_ARCH,
Command::new("heap")
.with_help("print kernel heap statistics")
Expand Down

0 comments on commit 0c2e5ee

Please sign in to comment.