@@ -69,66 +69,66 @@ where
6969
7070 thread:: scope ( |s| {
7171 s. spawn ( || {
72- let mut last_collect_time = Instant :: now ( ) ;
73- let mut total_count_old: u64 = 0 ;
74-
75- #[ cfg( feature = "stats" ) ]
76- let pid = Pid :: from ( std:: process:: id ( ) as usize ) ;
77- #[ cfg( feature = "stats" ) ]
78- let mut system = System :: new_all ( ) ;
79-
80- loop {
81- let current_time = Instant :: now ( ) ;
82- let elapsed = current_time. duration_since ( last_collect_time) . as_secs ( ) ;
83- if elapsed >= SLIDING_WINDOW_SIZE {
84- let total_count_u64 = shared_mutable_stats_slice. sum ( ) ;
85- last_collect_time = Instant :: now ( ) ;
86- let current_count = total_count_u64 - total_count_old;
87- total_count_old = total_count_u64;
88- let throughput = current_count / elapsed;
89- println ! (
90- "Throughput: {} iterations/sec" ,
91- throughput. to_formatted_string( & Locale :: en)
92- ) ;
93-
94- #[ cfg( feature = "stats" ) ]
95- {
96- system. refresh_all ( ) ;
97- if let Some ( process) = system. process ( pid) {
98- println ! (
99- "Memory usage: {:.2} MB" ,
100- process. memory( ) as f64 / ( 1024.0 * 1024.0 )
101- ) ;
102- println ! ( "CPU usage: {}%" , process. cpu_usage( ) / num_threads as f32 ) ;
103- println ! (
104- "Virtual memory usage: {:.2} MB" ,
105- process. virtual_memory( ) as f64 / ( 1024.0 * 1024.0 )
106- ) ;
107- } else {
108- println ! ( "Process not found" ) ;
109- }
72+ let mut last_collect_time = Instant :: now ( ) ;
73+ let mut total_count_old: u64 = 0 ;
74+
75+ #[ cfg( feature = "stats" ) ]
76+ let pid = Pid :: from ( std:: process:: id ( ) as usize ) ;
77+ #[ cfg( feature = "stats" ) ]
78+ let mut system = System :: new_all ( ) ;
79+
80+ loop {
81+ let current_time = Instant :: now ( ) ;
82+ let elapsed = current_time. duration_since ( last_collect_time) . as_secs ( ) ;
83+ if elapsed >= SLIDING_WINDOW_SIZE {
84+ let total_count_u64 = shared_mutable_stats_slice. sum ( ) ;
85+ last_collect_time = Instant :: now ( ) ;
86+ let current_count = total_count_u64 - total_count_old;
87+ total_count_old = total_count_u64;
88+ let throughput = current_count / elapsed;
89+ println ! (
90+ "Throughput: {} iterations/sec" ,
91+ throughput. to_formatted_string( & Locale :: en)
92+ ) ;
93+
94+ #[ cfg( feature = "stats" ) ]
95+ {
96+ system. refresh_all ( ) ;
97+ if let Some ( process) = system. process ( pid) {
98+ println ! (
99+ "Memory usage: {:.2} MB" ,
100+ process. memory( ) as f64 / ( 1024.0 * 1024.0 )
101+ ) ;
102+ println ! ( "CPU usage: {}%" , process. cpu_usage( ) / num_threads as f32 ) ;
103+ println ! (
104+ "Virtual memory usage: {:.2} MB" ,
105+ process. virtual_memory( ) as f64 / ( 1024.0 * 1024.0 )
106+ ) ;
107+ } else {
108+ println ! ( "Process not found" ) ;
110109 }
111-
112- println ! ( "\n " ) ;
113110 }
114-
115- if STOP . load ( Ordering :: SeqCst ) {
116- break ;
117- }
118-
119- thread :: sleep ( Duration :: from_millis ( 5000 ) ) ;
111+
112+ println ! ( " \n " ) ;
113+ }
114+
115+ if STOP . load ( Ordering :: SeqCst ) {
116+ break ;
120117 }
118+
119+ thread:: sleep ( Duration :: from_millis ( 5000 ) ) ;
120+ }
121121 } ) ;
122122
123123 for thread_index in 0 ..num_threads {
124124 let func_arc_clone = Arc :: clone ( & func_arc) ;
125- s. spawn ( move || {
126- loop {
127- func_arc_clone ( ) ;
128- unsafe { shared_mutable_stats_slice. increment ( thread_index) ; }
129- if STOP . load ( Ordering :: SeqCst ) {
130- break ;
131- }
125+ s. spawn ( move || loop {
126+ func_arc_clone ( ) ;
127+ unsafe {
128+ shared_mutable_stats_slice. increment ( thread_index) ;
129+ }
130+ if STOP . load ( Ordering :: SeqCst ) {
131+ break ;
132132 }
133133 } ) ;
134134 }
@@ -160,6 +160,9 @@ impl<'a> UnsafeSlice<'a> {
160160
161161 #[ inline( always) ]
162162 fn sum ( & self ) -> u64 {
163- self . slice . iter ( ) . map ( |cell| unsafe { ( * cell. get ( ) ) . count } ) . sum ( )
163+ self . slice
164+ . iter ( )
165+ . map ( |cell| unsafe { ( * cell. get ( ) ) . count } )
166+ . sum ( )
164167 }
165168}
0 commit comments