@@ -44,7 +44,9 @@ pub(crate) fn init() {
44
44
45
45
/// The main loop for the "async-io" thread.
46
46
fn main_loop ( parker : parking:: Parker ) {
47
+ #[ cfg( feature = "tracing" ) ]
47
48
let span = tracing:: trace_span!( "async_io::main_loop" ) ;
49
+ #[ cfg( feature = "tracing" ) ]
48
50
let _enter = span. enter ( ) ;
49
51
50
52
// The last observed reactor tick.
@@ -65,6 +67,7 @@ fn main_loop(parker: parking::Parker) {
65
67
} ;
66
68
67
69
if let Some ( mut reactor_lock) = reactor_lock {
70
+ #[ cfg( feature = "tracing" ) ]
68
71
tracing:: trace!( "waiting on I/O" ) ;
69
72
reactor_lock. react ( None ) . ok ( ) ;
70
73
last_tick = Reactor :: get ( ) . ticker ( ) ;
@@ -80,8 +83,10 @@ fn main_loop(parker: parking::Parker) {
80
83
. get ( sleeps as usize )
81
84
. unwrap_or ( & 10_000 ) ;
82
85
86
+ #[ cfg( feature = "tracing" ) ]
83
87
tracing:: trace!( "sleeping for {} us" , delay_us) ;
84
88
if parker. park_timeout ( Duration :: from_micros ( * delay_us) ) {
89
+ #[ cfg( feature = "tracing" ) ]
85
90
tracing:: trace!( "notified" ) ;
86
91
87
92
// If notified before timeout, reset the last tick and the sleep counter.
@@ -109,7 +114,9 @@ fn main_loop(parker: parking::Parker) {
109
114
/// });
110
115
/// ```
111
116
pub fn block_on < T > ( future : impl Future < Output = T > ) -> T {
117
+ #[ cfg( feature = "tracing" ) ]
112
118
let span = tracing:: trace_span!( "async_io::block_on" ) ;
119
+ #[ cfg( feature = "tracing" ) ]
113
120
let _enter = span. enter ( ) ;
114
121
115
122
// Increment `BLOCK_ON_COUNT` so that the "async-io" thread becomes less aggressive.
@@ -200,12 +207,14 @@ pub fn block_on<T>(future: impl Future<Output = T>) -> T {
200
207
// Ensure the cached parker is reset to the unnotified state for future block_on calls,
201
208
// in case this future called wake and then immediately returned Poll::Ready.
202
209
p. park_timeout ( Duration :: from_secs ( 0 ) ) ;
210
+ #[ cfg( feature = "tracing" ) ]
203
211
tracing:: trace!( "completed" ) ;
204
212
return t;
205
213
}
206
214
207
215
// Check if a notification was received.
208
216
if p. park_timeout ( Duration :: from_secs ( 0 ) ) {
217
+ #[ cfg( feature = "tracing" ) ]
209
218
tracing:: trace!( "notified" ) ;
210
219
211
220
// Try grabbing a lock on the reactor to process I/O events.
@@ -239,22 +248,26 @@ pub fn block_on<T>(future: impl Future<Output = T>) -> T {
239
248
// Check if a notification has been received before `io_blocked` was updated
240
249
// because in that case the reactor won't receive a wakeup.
241
250
if p. park_timeout ( Duration :: from_secs ( 0 ) ) {
251
+ #[ cfg( feature = "tracing" ) ]
242
252
tracing:: trace!( "notified" ) ;
243
253
break ;
244
254
}
245
255
246
256
// Wait for I/O events.
257
+ #[ cfg( feature = "tracing" ) ]
247
258
tracing:: trace!( "waiting on I/O" ) ;
248
259
reactor_lock. react ( None ) . ok ( ) ;
249
260
250
261
// Check if a notification has been received.
251
262
if p. park_timeout ( Duration :: from_secs ( 0 ) ) {
263
+ #[ cfg( feature = "tracing" ) ]
252
264
tracing:: trace!( "notified" ) ;
253
265
break ;
254
266
}
255
267
256
268
// Check if this thread been handling I/O events for a long time.
257
269
if start. elapsed ( ) > Duration :: from_micros ( 500 ) {
270
+ #[ cfg( feature = "tracing" ) ]
258
271
tracing:: trace!( "stops hogging the reactor" ) ;
259
272
260
273
// This thread is clearly processing I/O events for some other threads
@@ -274,6 +287,7 @@ pub fn block_on<T>(future: impl Future<Output = T>) -> T {
274
287
}
275
288
} else {
276
289
// Wait for an actual notification.
290
+ #[ cfg( feature = "tracing" ) ]
277
291
tracing:: trace!( "sleep until notification" ) ;
278
292
p. park ( ) ;
279
293
}
0 commit comments