@@ -105,20 +105,34 @@ 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 ! ( "{}: 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
+
122
136
let log_message = format ! ( "{}: READING {}" , projected. tag, n) ;
123
137
projected. events . emit ( Event {
124
138
id : 0 ,
@@ -150,13 +164,19 @@ impl<S: SessionStream> AsyncWrite for LoggingStream<S> {
150
164
. last_read_timestamp
151
165
. duration_since ( first_read_timestamp) ;
152
166
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
+
157
179
projected. throughput . span_read = 0 ;
158
- projected. throughput . total_duration =
159
- projected. throughput . total_duration . saturating_add ( duration) ;
160
180
}
161
181
162
182
if let Some ( throughput) = projected. throughput . throughput ( ) {
0 commit comments