69
69
let worker_stats_shared_monitor = Arc :: clone ( & worker_stats_shared) ;
70
70
71
71
let handle_main_thread = thread:: spawn ( move || {
72
- let mut start_time = Instant :: now ( ) ;
73
- let mut end_time = start_time;
72
+ let mut last_collect_time = Instant :: now ( ) ;
74
73
let mut total_count_old: u64 = 0 ;
75
74
76
75
#[ cfg( feature = "stats" ) ]
@@ -79,12 +78,14 @@ where
79
78
let mut system = System :: new_all ( ) ;
80
79
81
80
loop {
82
- let elapsed = end_time. duration_since ( start_time) . as_secs ( ) ;
81
+ let current_time = Instant :: now ( ) ;
82
+ let elapsed = current_time. duration_since ( last_collect_time) . as_secs ( ) ;
83
83
if elapsed >= SLIDING_WINDOW_SIZE {
84
84
let total_count_u64: u64 = worker_stats_shared_monitor
85
85
. iter ( )
86
86
. map ( |worker_stat| worker_stat. count . load ( Ordering :: Relaxed ) )
87
87
. sum ( ) ;
88
+ last_collect_time = Instant :: now ( ) ;
88
89
let current_count = total_count_u64 - total_count_old;
89
90
total_count_old = total_count_u64;
90
91
let throughput = current_count / elapsed;
@@ -112,14 +113,12 @@ where
112
113
}
113
114
114
115
println ! ( "\n " ) ;
115
- start_time = Instant :: now ( ) ;
116
116
}
117
117
118
118
if STOP . load ( Ordering :: SeqCst ) {
119
119
break ;
120
120
}
121
121
122
- end_time = Instant :: now ( ) ;
123
122
thread:: sleep ( Duration :: from_millis ( 5000 ) ) ;
124
123
}
125
124
} ) ;
0 commit comments