@@ -70,6 +70,16 @@ impl<S: SessionStream> LoggingStream<S> {
70
70
enable_stats : true
71
71
}
72
72
}
73
+
74
+ /// Returns throughput in bps.
75
+ pub fn throughput ( & self ) -> f64 {
76
+ let total_duration_secs = self . total_duration . as_secs_f64 ( ) ;
77
+ if total_duration_secs > 0.0 {
78
+ ( self . total_read as f64 ) / total_duration_secs
79
+ } else {
80
+ 0.0
81
+ }
82
+ }
73
83
}
74
84
75
85
impl < S : SessionStream > AsyncRead for LoggingStream < S > {
@@ -110,38 +120,24 @@ impl<S: SessionStream> AsyncWrite for LoggingStream<S> {
110
120
cx : & mut std:: task:: Context < ' _ > ,
111
121
buf : & [ u8 ] ,
112
122
) -> Poll < std:: io:: Result < usize > > {
113
- let log_message = format ! ( "{}: WRITING {}" , self . tag, buf. len( ) ) ;
114
-
115
- let projected = self . project ( ) ;
116
- projected. events . emit ( Event {
117
- id : 0 ,
118
- typ : EventType :: Info ( log_message) ,
119
- } ) ;
120
-
121
- projected. inner . poll_write ( cx, buf)
123
+ self . project ( ) . inner . poll_write ( cx, buf)
122
124
}
123
125
124
126
fn poll_flush (
125
127
self : Pin < & mut Self > ,
126
128
cx : & mut std:: task:: Context < ' _ > ,
127
129
) -> Poll < std:: io:: Result < ( ) > > {
128
- let projected = self . project ( ) ;
130
+ let throughput = self . throughput ( ) ;
129
131
132
+ let projected = self . project ( ) ;
130
133
if let Some ( first_read_timestamp) = projected. first_read_timestamp . take ( ) {
131
134
let duration = projected. last_read_timestamp . duration_since ( first_read_timestamp) ;
132
135
133
136
* projected. total_read = projected. total_read . saturating_add ( * projected. span_read ) ;
134
137
* projected. span_read = 0 ;
135
138
* projected. total_duration = projected. total_duration . saturating_add ( duration) ;
136
139
137
- let total_duration_secs = projected. total_duration . as_secs_f64 ( ) ;
138
- let throughput = if total_duration_secs > 0.0 {
139
- ( * projected. total_read as f64 ) / total_duration_secs
140
- } else {
141
- 0.0
142
- } ;
143
-
144
- let log_message = format ! ( "{}: FLUSH: read={}, duration={}, {} kbps" , projected. tag, * projected. total_read, total_duration_secs, throughput * 8e-3 ) ;
140
+ let log_message = format ! ( "{}: FLUSH: {} kbps" , projected. tag, throughput * 8e-3 ) ;
145
141
146
142
projected. events . emit ( Event {
147
143
id : 0 ,
0 commit comments