Skip to content

Commit 5f551b8

Browse files
committed
log on every read for a plot
1 parent 1bd5845 commit 5f551b8

File tree

1 file changed

+39
-14
lines changed

1 file changed

+39
-14
lines changed

src/log/logging_stream.rs

Lines changed: 39 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -105,20 +105,39 @@ 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!(
131+
"{}: SPAN: {} {}",
132+
projected.tag,
133+
duration.as_secs_f64(),
134+
projected.throughput.span_read
135+
);
136+
projected.events.emit(Event {
137+
id: 0,
138+
typ: EventType::Info(log_message),
139+
});
140+
122141
let log_message = format!("{}: READING {}", projected.tag, n);
123142
projected.events.emit(Event {
124143
id: 0,
@@ -150,13 +169,19 @@ impl<S: SessionStream> AsyncWrite for LoggingStream<S> {
150169
.last_read_timestamp
151170
.duration_since(first_read_timestamp);
152171

153-
projected.throughput.total_read = projected
154-
.throughput
155-
.total_read
156-
.saturating_add(projected.throughput.span_read);
172+
// Only measure when more than about 2 MTU is transferred.
173+
// We cannot measure throughput on small responses
174+
// like `A1000 OK`.
175+
if projected.throughput.span_read > 3000 {
176+
projected.throughput.total_read = projected
177+
.throughput
178+
.total_read
179+
.saturating_add(projected.throughput.span_read);
180+
projected.throughput.total_duration =
181+
projected.throughput.total_duration.saturating_add(duration);
182+
}
183+
157184
projected.throughput.span_read = 0;
158-
projected.throughput.total_duration =
159-
projected.throughput.total_duration.saturating_add(duration);
160185
}
161186

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

0 commit comments

Comments
 (0)