Skip to content

Commit 0d5ca43

Browse files
committed
log on every read for a plot
1 parent b048011 commit 0d5ca43

File tree

1 file changed

+34
-14
lines changed

1 file changed

+34
-14
lines changed

src/log/logging_stream.rs

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -105,20 +105,34 @@ impl<S: SessionStream> AsyncRead for LoggingStream<S> {
105105
let old_remaining = buf.remaining();
106106

107107
let now = Instant::now();
108-
if projected.throughput.first_read_timestamp.is_none() && projected.throughput.enabled {
109-
projected.throughput.first_read_timestamp = Some(now);
110-
}
111-
112108
let res = projected.inner.poll_read(cx, buf);
113109

114-
let n = old_remaining - buf.remaining();
115-
if n > 0 {
116-
if projected.throughput.enabled {
110+
if projected.throughput.enabled {
111+
let first_read_timestamp =
112+
if let Some(first_read_timestamp) = projected.throughput.first_read_timestamp {
113+
first_read_timestamp
114+
} else {
115+
projected.throughput.first_read_timestamp = Some(now);
116+
now
117+
};
118+
119+
let n = old_remaining - buf.remaining();
120+
if n > 0 {
117121
projected.throughput.last_read_timestamp = now;
118-
119122
projected.throughput.span_read = projected.throughput.span_read.saturating_add(n);
120123
}
121124

125+
let duration = projected
126+
.throughput
127+
.last_read_timestamp
128+
.duration_since(first_read_timestamp);
129+
130+
let log_message = format!("{}: SPAN: {} {}", projected.tag, duration.as_secs_f64(), projected.throughput.span_read);
131+
projected.events.emit(Event {
132+
id: 0,
133+
typ: EventType::Info(log_message),
134+
});
135+
122136
let log_message = format!("{}: READING {}", projected.tag, n);
123137
projected.events.emit(Event {
124138
id: 0,
@@ -150,13 +164,19 @@ impl<S: SessionStream> AsyncWrite for LoggingStream<S> {
150164
.last_read_timestamp
151165
.duration_since(first_read_timestamp);
152166

153-
projected.throughput.total_read = projected
154-
.throughput
155-
.total_read
156-
.saturating_add(projected.throughput.span_read);
167+
// Only measure when more than about 2 MTU is transferred.
168+
// We cannot measure throughput on small responses
169+
// like `A1000 OK`.
170+
if projected.throughput.span_read > 3000 {
171+
projected.throughput.total_read = projected
172+
.throughput
173+
.total_read
174+
.saturating_add(projected.throughput.span_read);
175+
projected.throughput.total_duration =
176+
projected.throughput.total_duration.saturating_add(duration);
177+
}
178+
157179
projected.throughput.span_read = 0;
158-
projected.throughput.total_duration =
159-
projected.throughput.total_duration.saturating_add(duration);
160180
}
161181

162182
if let Some(throughput) = projected.throughput.throughput() {

0 commit comments

Comments
 (0)