@@ -43,6 +43,9 @@ pub(crate) fn init() {
4343
4444/// The main loop for the "async-io" thread.
4545fn main_loop ( parker : parking:: Parker ) {
46+ let span = tracing:: trace_span!( "async_io::main_loop" ) ;
47+ let _enter = span. enter ( ) ;
48+
4649 // The last observed reactor tick.
4750 let mut last_tick = 0 ;
4851 // Number of sleeps since this thread has called `react()`.
@@ -61,7 +64,7 @@ fn main_loop(parker: parking::Parker) {
6164 } ;
6265
6366 if let Some ( mut reactor_lock) = reactor_lock {
64- log :: trace!( "main_loop: waiting on I/O" ) ;
67+ tracing :: trace!( "waiting on I/O" ) ;
6568 reactor_lock. react ( None ) . ok ( ) ;
6669 last_tick = Reactor :: get ( ) . ticker ( ) ;
6770 sleeps = 0 ;
@@ -76,9 +79,9 @@ fn main_loop(parker: parking::Parker) {
7679 . get ( sleeps as usize )
7780 . unwrap_or ( & 10_000 ) ;
7881
79- log :: trace!( "main_loop: sleeping for {} us" , delay_us) ;
82+ tracing :: trace!( "sleeping for {} us" , delay_us) ;
8083 if parker. park_timeout ( Duration :: from_micros ( * delay_us) ) {
81- log :: trace!( "main_loop: notified" ) ;
84+ tracing :: trace!( "notified" ) ;
8285
8386 // If notified before timeout, reset the last tick and the sleep counter.
8487 last_tick = Reactor :: get ( ) . ticker ( ) ;
@@ -105,7 +108,8 @@ fn main_loop(parker: parking::Parker) {
105108/// });
106109/// ```
107110pub fn block_on < T > ( future : impl Future < Output = T > ) -> T {
108- log:: trace!( "block_on()" ) ;
111+ let span = tracing:: trace_span!( "async_io::block_on" ) ;
112+ let _enter = span. enter ( ) ;
109113
110114 // Increment `BLOCK_ON_COUNT` so that the "async-io" thread becomes less aggressive.
111115 BLOCK_ON_COUNT . fetch_add ( 1 , Ordering :: SeqCst ) ;
@@ -144,13 +148,13 @@ pub fn block_on<T>(future: impl Future<Output = T>) -> T {
144148 loop {
145149 // Poll the future.
146150 if let Poll :: Ready ( t) = future. as_mut ( ) . poll ( cx) {
147- log :: trace!( "block_on: completed" ) ;
151+ tracing :: trace!( "completed" ) ;
148152 return t;
149153 }
150154
151155 // Check if a notification was received.
152156 if p. park_timeout ( Duration :: from_secs ( 0 ) ) {
153- log :: trace!( "block_on: notified" ) ;
157+ tracing :: trace!( "notified" ) ;
154158
155159 // Try grabbing a lock on the reactor to process I/O events.
156160 if let Some ( mut reactor_lock) = Reactor :: get ( ) . try_lock ( ) {
@@ -183,23 +187,23 @@ pub fn block_on<T>(future: impl Future<Output = T>) -> T {
183187 // Check if a notification has been received before `io_blocked` was updated
184188 // because in that case the reactor won't receive a wakeup.
185189 if p. park_timeout ( Duration :: from_secs ( 0 ) ) {
186- log :: trace!( "block_on: notified" ) ;
190+ tracing :: trace!( "notified" ) ;
187191 break ;
188192 }
189193
190194 // Wait for I/O events.
191- log :: trace!( "block_on: waiting on I/O" ) ;
195+ tracing :: trace!( "waiting on I/O" ) ;
192196 reactor_lock. react ( None ) . ok ( ) ;
193197
194198 // Check if a notification has been received.
195199 if p. park_timeout ( Duration :: from_secs ( 0 ) ) {
196- log :: trace!( "block_on: notified" ) ;
200+ tracing :: trace!( "notified" ) ;
197201 break ;
198202 }
199203
200204 // Check if this thread been handling I/O events for a long time.
201205 if start. elapsed ( ) > Duration :: from_micros ( 500 ) {
202- log :: trace!( "block_on: stops hogging the reactor" ) ;
206+ tracing :: trace!( "stops hogging the reactor" ) ;
203207
204208 // This thread is clearly processing I/O events for some other threads
205209 // because it didn't get a notification yet. It's best to stop hogging the
@@ -218,7 +222,7 @@ pub fn block_on<T>(future: impl Future<Output = T>) -> T {
218222 }
219223 } else {
220224 // Wait for an actual notification.
221- log :: trace!( "block_on: sleep until notification" ) ;
225+ tracing :: trace!( "sleep until notification" ) ;
222226 p. park ( ) ;
223227 }
224228 }
0 commit comments