@@ -105,20 +105,39 @@ impl<S: SessionStream> AsyncRead for LoggingStream<S> {
105
105
let old_remaining = buf. remaining ( ) ;
106
106
107
107
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
-
112
108
let res = projected. inner . poll_read ( cx, buf) ;
113
109
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 {
117
121
projected. throughput . last_read_timestamp = now;
118
-
119
122
projected. throughput . span_read = projected. throughput . span_read . saturating_add ( n) ;
120
123
}
121
124
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
+
122
141
let log_message = format ! ( "{}: READING {}" , projected. tag, n) ;
123
142
projected. events . emit ( Event {
124
143
id : 0 ,
@@ -150,13 +169,19 @@ impl<S: SessionStream> AsyncWrite for LoggingStream<S> {
150
169
. last_read_timestamp
151
170
. duration_since ( first_read_timestamp) ;
152
171
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
+
157
184
projected. throughput . span_read = 0 ;
158
- projected. throughput . total_duration =
159
- projected. throughput . total_duration . saturating_add ( duration) ;
160
185
}
161
186
162
187
if let Some ( throughput) = projected. throughput . throughput ( ) {
0 commit comments