diff --git a/runtime/executor/src/pool.rs b/runtime/executor/src/pool.rs index a900d24..ff422d1 100644 --- a/runtime/executor/src/pool.rs +++ b/runtime/executor/src/pool.rs @@ -20,6 +20,9 @@ use std::marker::PhantomData; use std::mem::MaybeUninit; use std::sync::Arc; use std::time::Duration; +use tracing::field::FieldSet; +use tracing::metadata::Kind; +use tracing::{Level, Span}; #[derive(Debug)] struct Spooler<'a> { @@ -45,12 +48,21 @@ impl Spooler<'_> { /// Global executor pub struct Executor<'a> { spooler: Arc>, + span: Span, } impl<'a, 'executor: 'a> Executor<'executor> { pub fn new() -> Self { Executor { spooler: Arc::new(Spooler::new()), + span: tracing::span!(Level::INFO, "executor"), + } + } + + pub fn new_with_parent_span(parent: &Span) -> Self { + Executor { + spooler: Arc::new(Spooler::new()), + span: tracing::span!(parent: parent, Level::INFO, "executor"), } } @@ -99,7 +111,15 @@ impl<'a, 'executor: 'a> Executor<'executor> { F: Future + Send + 'a, R: Send + 'a, { + let span = tracing::info_span!( + parent: &self.span, + //target: "executor::spawn", + "runtime.spawn" + ); + let _guard = span.enter(); + let (task, handle) = LightProc::recoverable(future, self.schedule()); + tracing::trace!("spawning sendable task"); task.schedule(); handle } @@ -109,7 +129,14 @@ impl<'a, 'executor: 'a> Executor<'executor> { F: Future + 'a, R: Send + 'a, { + let span = tracing::info_span!( + parent: &self.span, + //target: "executor::spawn", + "runtime.spawn_local" + ); + let _guard = span.enter(); let (task, handle) = LightProc::recoverable(future, schedule_local()); + tracing::trace!("spawning sendable task"); task.schedule(); handle } diff --git a/runtime/lightproc/src/lightproc.rs b/runtime/lightproc/src/lightproc.rs index 3d59379..c94b5fa 100644 --- a/runtime/lightproc/src/lightproc.rs +++ b/runtime/lightproc/src/lightproc.rs @@ -33,7 +33,7 @@ use crate::raw_proc::RawProc; use crate::recoverable_handle::RecoverableHandle; use std::fmt::{self, Debug, Formatter}; use std::future::Future; -use std::mem; +use std::mem::ManuallyDrop; use std::panic::AssertUnwindSafe; use std::ptr::NonNull; @@ -130,9 +130,9 @@ impl LightProc { /// /// Schedule the lightweight process with passed `schedule` function at the build time. pub fn schedule(self) { - let ptr = self.raw_proc.as_ptr(); + let this = ManuallyDrop::new(self); + let ptr = this.raw_proc.as_ptr(); let pdata = ptr as *const ProcData; - mem::forget(self); unsafe { ((*pdata).vtable.schedule)(ptr); @@ -144,9 +144,9 @@ impl LightProc { /// "Running" a lightproc means ticking it once and if it doesn't complete /// immediately re-scheduling it as soon as it's Waker wakes it back up. pub fn run(self) { - let ptr = self.raw_proc.as_ptr(); + let this = ManuallyDrop::new(self); + let ptr = this.raw_proc.as_ptr(); let pdata = ptr as *const ProcData; - mem::forget(self); unsafe { ((*pdata).vtable.tick)(ptr);