Skip to content

Commit f3b9203

Browse files
committed
Make tracing optional
1 parent 8954e93 commit f3b9203

File tree

4 files changed

+30
-4
lines changed

4 files changed

+30
-4
lines changed

.github/workflows/ci.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,12 @@ jobs:
4848
- name: Install Rust
4949
# --no-self-update is necessary because the windows environment cannot self-update rustup.exe.
5050
run: rustup update ${{ matrix.rust }} --no-self-update && rustup default ${{ matrix.rust }}
51+
- name: Install cargo-hack
52+
uses: taiki-e/install-action@v2
53+
with:
54+
tool: cargo-hack
5155
- run: cargo build --all --all-features --all-targets
52-
- name: Run cargo check (without dev-dependencies to catch missing feature flags)
53-
if: startsWith(matrix.rust, 'nightly')
54-
run: cargo check -Z features=dev_dep
56+
- run: cargo hack build --feature-powerset --no-dev-deps
5557
- name: Add rust-src
5658
if: startsWith(matrix.rust, 'nightly') && startsWith(matrix.os, 'ubuntu')
5759
run: rustup component add rust-src

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ parking = "2.0.0"
3535
polling = "3.0.0"
3636
rustix = { version = "1.0.7", default-features = false, features = ["fs", "net", "std"] }
3737
slab = "0.4.2"
38-
tracing = { version = "0.1.37", default-features = false }
38+
tracing = { version = "0.1.37", default-features = false, optional = true }
3939

4040
[target.'cfg(windows)'.dependencies]
4141
windows-sys = { version = "0.59.0", features = ["Win32_Foundation"] }

src/driver.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ pub(crate) fn init() {
4444

4545
/// The main loop for the "async-io" thread.
4646
fn main_loop(parker: parking::Parker) {
47+
#[cfg(feature = "tracing")]
4748
let span = tracing::trace_span!("async_io::main_loop");
49+
#[cfg(feature = "tracing")]
4850
let _enter = span.enter();
4951

5052
// The last observed reactor tick.
@@ -65,6 +67,7 @@ fn main_loop(parker: parking::Parker) {
6567
};
6668

6769
if let Some(mut reactor_lock) = reactor_lock {
70+
#[cfg(feature = "tracing")]
6871
tracing::trace!("waiting on I/O");
6972
reactor_lock.react(None).ok();
7073
last_tick = Reactor::get().ticker();
@@ -80,8 +83,10 @@ fn main_loop(parker: parking::Parker) {
8083
.get(sleeps as usize)
8184
.unwrap_or(&10_000);
8285

86+
#[cfg(feature = "tracing")]
8387
tracing::trace!("sleeping for {} us", delay_us);
8488
if parker.park_timeout(Duration::from_micros(*delay_us)) {
89+
#[cfg(feature = "tracing")]
8590
tracing::trace!("notified");
8691

8792
// If notified before timeout, reset the last tick and the sleep counter.
@@ -109,7 +114,9 @@ fn main_loop(parker: parking::Parker) {
109114
/// });
110115
/// ```
111116
pub fn block_on<T>(future: impl Future<Output = T>) -> T {
117+
#[cfg(feature = "tracing")]
112118
let span = tracing::trace_span!("async_io::block_on");
119+
#[cfg(feature = "tracing")]
113120
let _enter = span.enter();
114121

115122
// 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 {
200207
// Ensure the cached parker is reset to the unnotified state for future block_on calls,
201208
// in case this future called wake and then immediately returned Poll::Ready.
202209
p.park_timeout(Duration::from_secs(0));
210+
#[cfg(feature = "tracing")]
203211
tracing::trace!("completed");
204212
return t;
205213
}
206214

207215
// Check if a notification was received.
208216
if p.park_timeout(Duration::from_secs(0)) {
217+
#[cfg(feature = "tracing")]
209218
tracing::trace!("notified");
210219

211220
// 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 {
239248
// Check if a notification has been received before `io_blocked` was updated
240249
// because in that case the reactor won't receive a wakeup.
241250
if p.park_timeout(Duration::from_secs(0)) {
251+
#[cfg(feature = "tracing")]
242252
tracing::trace!("notified");
243253
break;
244254
}
245255

246256
// Wait for I/O events.
257+
#[cfg(feature = "tracing")]
247258
tracing::trace!("waiting on I/O");
248259
reactor_lock.react(None).ok();
249260

250261
// Check if a notification has been received.
251262
if p.park_timeout(Duration::from_secs(0)) {
263+
#[cfg(feature = "tracing")]
252264
tracing::trace!("notified");
253265
break;
254266
}
255267

256268
// Check if this thread been handling I/O events for a long time.
257269
if start.elapsed() > Duration::from_micros(500) {
270+
#[cfg(feature = "tracing")]
258271
tracing::trace!("stops hogging the reactor");
259272

260273
// 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 {
274287
}
275288
} else {
276289
// Wait for an actual notification.
290+
#[cfg(feature = "tracing")]
277291
tracing::trace!("sleep until notification");
278292
p.park();
279293
}

src/reactor.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,9 @@ impl Reactor {
204204
///
205205
/// Returns the duration until the next timer before this method was called.
206206
fn process_timers(&self, wakers: &mut Vec<Waker>) -> Option<Duration> {
207+
#[cfg(feature = "tracing")]
207208
let span = tracing::trace_span!("process_timers");
209+
#[cfg(feature = "tracing")]
208210
let _enter = span.enter();
209211

210212
let mut timers = self.timers.lock().unwrap();
@@ -235,6 +237,7 @@ impl Reactor {
235237
drop(timers);
236238

237239
// Add wakers to the list.
240+
#[cfg(feature = "tracing")]
238241
tracing::trace!("{} ready wakers", ready.len());
239242

240243
for (_, waker) in ready {
@@ -271,7 +274,9 @@ pub(crate) struct ReactorLock<'a> {
271274
impl ReactorLock<'_> {
272275
/// Processes new events, blocking until the first event or the timeout.
273276
pub(crate) fn react(&mut self, timeout: Option<Duration>) -> io::Result<()> {
277+
#[cfg(feature = "tracing")]
274278
let span = tracing::trace_span!("react");
279+
#[cfg(feature = "tracing")]
275280
let _enter = span.enter();
276281

277282
let mut wakers = Vec::new();
@@ -353,6 +358,7 @@ impl ReactorLock<'_> {
353358
};
354359

355360
// Wake up ready tasks.
361+
#[cfg(feature = "tracing")]
356362
tracing::trace!("{} ready wakers", wakers.len());
357363
for waker in wakers {
358364
// Don't let a panicking waker blow everything up.
@@ -518,6 +524,7 @@ impl<T> Future for Readable<'_, T> {
518524

519525
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
520526
ready!(Pin::new(&mut self.0).poll(cx))?;
527+
#[cfg(feature = "tracing")]
521528
tracing::trace!(fd = ?self.0.handle.source.registration, "readable");
522529
Poll::Ready(Ok(()))
523530
}
@@ -538,6 +545,7 @@ impl<T> Future for ReadableOwned<T> {
538545

539546
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
540547
ready!(Pin::new(&mut self.0).poll(cx))?;
548+
#[cfg(feature = "tracing")]
541549
tracing::trace!(fd = ?self.0.handle.source.registration, "readable_owned");
542550
Poll::Ready(Ok(()))
543551
}
@@ -558,6 +566,7 @@ impl<T> Future for Writable<'_, T> {
558566

559567
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
560568
ready!(Pin::new(&mut self.0).poll(cx))?;
569+
#[cfg(feature = "tracing")]
561570
tracing::trace!(fd = ?self.0.handle.source.registration, "writable");
562571
Poll::Ready(Ok(()))
563572
}
@@ -578,6 +587,7 @@ impl<T> Future for WritableOwned<T> {
578587

579588
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
580589
ready!(Pin::new(&mut self.0).poll(cx))?;
590+
#[cfg(feature = "tracing")]
581591
tracing::trace!(fd = ?self.0.handle.source.registration, "writable_owned");
582592
Poll::Ready(Ok(()))
583593
}

0 commit comments

Comments
 (0)