File tree Expand file tree Collapse file tree 1 file changed +24
-4
lines changed
Expand file tree Collapse file tree 1 file changed +24
-4
lines changed Original file line number Diff line number Diff line change @@ -314,9 +314,20 @@ impl StreamStats {
314314 }
315315 }
316316
317- let count = self . arrivals . len ( ) as f64 ;
318- let win_secs = window. as_secs_f64 ( ) . max ( 1e-6 ) ;
319- self . rate_smps = count / win_secs;
317+ self . rate_smps = if let ( Some ( from_time) , Some ( to_time) ) =
318+ ( self . arrivals . front ( ) , self . arrivals . back ( ) )
319+ {
320+ // Count fence sections, not fence posts: two data points one second
321+ // apart are sent at a rate of 1 sps, not 2sps
322+ let count = ( self . arrivals . len ( ) - 1 ) as f64 ;
323+ if from_time >= to_time {
324+ 0.0
325+ } else {
326+ count / ( to_time. duration_since ( * from_time) ) . as_secs_f64 ( )
327+ }
328+ } else {
329+ 0.0
330+ } ;
320331 self . rate_smps
321332 }
322333
@@ -745,7 +756,16 @@ fn main() {
745756 std:: thread:: spawn ( move || {
746757 let mut tree = tree;
747758 let mut buffer = buffer;
748-
759+ let start_time = Instant :: now ( )
760+ . checked_add ( Duration :: from_millis ( 500 ) )
761+ . expect ( "now() near end of time" ) ;
762+
763+ while Instant :: now ( ) < start_time {
764+ if let Err ( e) = tree. next ( ) {
765+ eprintln ! ( "Device error: {:?}" , e) ;
766+ return ;
767+ }
768+ }
749769 loop {
750770 match tree. next ( ) {
751771 Ok ( ( sample, route) ) => {
You can’t perform that action at this time.
0 commit comments