From 34d32f67a2cb324f8553fbc9b5b836750ad06541 Mon Sep 17 00:00:00 2001 From: whitequark Date: Thu, 19 Jan 2017 12:23:32 +0000 Subject: [PATCH] Gate the really verbose log messages behind a feature. Otherwise, trying to use the socket buffers instead of BufReader/ BufWriter is doomed to overwhelm the application logic. --- Cargo.toml | 3 ++- README.md | 13 +++++++++++++ src/socket/tcp.rs | 2 ++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 67f6e07..e4c89eb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -25,4 +25,5 @@ use_std = ["managed/use_std", "libc"] use_alloc = ["managed/use_alloc"] use_collections = ["managed/use_collections"] use_log = ["log"] -default = ["use_std", "use_log"] +verbose = [] +default = ["use_std", "use_log", "verbose"] diff --git a/README.md b/README.md index e395870..fed408c 100644 --- a/README.md +++ b/README.md @@ -86,6 +86,8 @@ The `use_std` feature enables use of objects and slices owned by the networking dependency on `std::boxed::Box` and `std::vec::Vec`. It also enables `smoltcp::phy::RawSocket` and `smoltcp::phy::TapInterface`, if the platform supports it. +This feature is enabled by default. + ### Feature `use_alloc` The `use_alloc` feature enables use of objects owned by the networking stack through a dependency @@ -103,6 +105,17 @@ the [log crate][log]. The events are emitted with the TRACE log level. [log]: https://crates.io/crates/log +This feature is enabled by default. + +### Feature `verbose` + +The `verbose` feature enables logging of events where the logging itself may incur very high +overhead. For example, emitting a log line every time an application reads or writes as little +as 1 octet from a socket is likely to overwhelm the application logic unless a `BufReader` +or `BufWriter` is used, which are of course not available on heap-less systems. + +This feature is disabled by default. + Usage example ------------- diff --git a/src/socket/tcp.rs b/src/socket/tcp.rs index 91fad10..24e989e 100644 --- a/src/socket/tcp.rs +++ b/src/socket/tcp.rs @@ -480,6 +480,7 @@ impl<'a> TcpSocket<'a> { let old_length = self.tx_buffer.len(); let buffer = self.tx_buffer.enqueue(size); if buffer.len() > 0 { + #[cfg(any(test, feature = "verbose"))] net_trace!("[{}]{}:{}: tx buffer: enqueueing {} octets (now {})", self.debug_id, self.local_endpoint, self.remote_endpoint, buffer.len(), old_length + buffer.len()); @@ -515,6 +516,7 @@ impl<'a> TcpSocket<'a> { let buffer = self.rx_buffer.dequeue(size); self.remote_seq_no += buffer.len(); if buffer.len() > 0 { + #[cfg(any(test, feature = "verbose"))] net_trace!("[{}]{}:{}: rx buffer: dequeueing {} octets (now {})", self.debug_id, self.local_endpoint, self.remote_endpoint, buffer.len(), old_length - buffer.len());