Skip to content

Commit

Permalink
Gate the really verbose log messages behind a feature.
Browse files Browse the repository at this point in the history
Otherwise, trying to use the socket buffers instead of BufReader/
BufWriter is doomed to overwhelm the application logic.
whitequark committed Jan 19, 2017
1 parent e1a40d8 commit 874d192
Showing 3 changed files with 17 additions and 1 deletion.
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"]
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
-------------

2 changes: 2 additions & 0 deletions src/socket/tcp.rs
Original file line number Diff line number Diff line change
@@ -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());

0 comments on commit 874d192

Please sign in to comment.