@@ -43,6 +43,9 @@ pub(crate) fn init() {
43
43
44
44
/// The main loop for the "async-io" thread.
45
45
fn main_loop ( parker : parking:: Parker ) {
46
+ let span = tracing:: trace_span!( "async_io::main_loop" ) ;
47
+ let _enter = span. enter ( ) ;
48
+
46
49
// The last observed reactor tick.
47
50
let mut last_tick = 0 ;
48
51
// Number of sleeps since this thread has called `react()`.
@@ -61,7 +64,7 @@ fn main_loop(parker: parking::Parker) {
61
64
} ;
62
65
63
66
if let Some ( mut reactor_lock) = reactor_lock {
64
- log :: trace!( "main_loop: waiting on I/O" ) ;
67
+ tracing :: trace!( "waiting on I/O" ) ;
65
68
reactor_lock. react ( None ) . ok ( ) ;
66
69
last_tick = Reactor :: get ( ) . ticker ( ) ;
67
70
sleeps = 0 ;
@@ -76,9 +79,9 @@ fn main_loop(parker: parking::Parker) {
76
79
. get ( sleeps as usize )
77
80
. unwrap_or ( & 10_000 ) ;
78
81
79
- log :: trace!( "main_loop: sleeping for {} us" , delay_us) ;
82
+ tracing :: trace!( "sleeping for {} us" , delay_us) ;
80
83
if parker. park_timeout ( Duration :: from_micros ( * delay_us) ) {
81
- log :: trace!( "main_loop: notified" ) ;
84
+ tracing :: trace!( "notified" ) ;
82
85
83
86
// If notified before timeout, reset the last tick and the sleep counter.
84
87
last_tick = Reactor :: get ( ) . ticker ( ) ;
@@ -105,7 +108,8 @@ fn main_loop(parker: parking::Parker) {
105
108
/// });
106
109
/// ```
107
110
pub 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 ( ) ;
109
113
110
114
// Increment `BLOCK_ON_COUNT` so that the "async-io" thread becomes less aggressive.
111
115
BLOCK_ON_COUNT . fetch_add ( 1 , Ordering :: SeqCst ) ;
@@ -144,13 +148,13 @@ pub fn block_on<T>(future: impl Future<Output = T>) -> T {
144
148
loop {
145
149
// Poll the future.
146
150
if let Poll :: Ready ( t) = future. as_mut ( ) . poll ( cx) {
147
- log :: trace!( "block_on: completed" ) ;
151
+ tracing :: trace!( "completed" ) ;
148
152
return t;
149
153
}
150
154
151
155
// Check if a notification was received.
152
156
if p. park_timeout ( Duration :: from_secs ( 0 ) ) {
153
- log :: trace!( "block_on: notified" ) ;
157
+ tracing :: trace!( "notified" ) ;
154
158
155
159
// Try grabbing a lock on the reactor to process I/O events.
156
160
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 {
183
187
// Check if a notification has been received before `io_blocked` was updated
184
188
// because in that case the reactor won't receive a wakeup.
185
189
if p. park_timeout ( Duration :: from_secs ( 0 ) ) {
186
- log :: trace!( "block_on: notified" ) ;
190
+ tracing :: trace!( "notified" ) ;
187
191
break ;
188
192
}
189
193
190
194
// Wait for I/O events.
191
- log :: trace!( "block_on: waiting on I/O" ) ;
195
+ tracing :: trace!( "waiting on I/O" ) ;
192
196
reactor_lock. react ( None ) . ok ( ) ;
193
197
194
198
// Check if a notification has been received.
195
199
if p. park_timeout ( Duration :: from_secs ( 0 ) ) {
196
- log :: trace!( "block_on: notified" ) ;
200
+ tracing :: trace!( "notified" ) ;
197
201
break ;
198
202
}
199
203
200
204
// Check if this thread been handling I/O events for a long time.
201
205
if start. elapsed ( ) > Duration :: from_micros ( 500 ) {
202
- log :: trace!( "block_on: stops hogging the reactor" ) ;
206
+ tracing :: trace!( "stops hogging the reactor" ) ;
203
207
204
208
// This thread is clearly processing I/O events for some other threads
205
209
// 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 {
218
222
}
219
223
} else {
220
224
// Wait for an actual notification.
221
- log :: trace!( "block_on: sleep until notification" ) ;
225
+ tracing :: trace!( "sleep until notification" ) ;
222
226
p. park ( ) ;
223
227
}
224
228
}
0 commit comments