@@ -7,7 +7,7 @@ use dyn_clone::DynClone;
77use crate :: sensors:: units;
88use super :: { Record , Domain , CPUStat , CPUCore , RecordGenerator , StatsGenerator } ;
99
10- pub trait Socket : DynClone {
10+ pub trait Socket : DynClone + Send {
1111 fn read_record_uj ( & self ) -> Result < Record , Box < dyn Error > > ;
1212 fn get_record_buffer ( & mut self ) -> & mut Vec < Record > ;
1313 fn get_record_buffer_passive ( & self ) -> & Vec < Record > ;
@@ -16,6 +16,7 @@ pub trait Socket: DynClone {
1616 fn get_domains_passive ( & self ) -> & Vec < Domain > ;
1717 fn get_domains ( & mut self ) -> & mut Vec < Domain > ;
1818 fn get_stat_buffer ( & mut self ) -> & mut Vec < CPUStat > ;
19+ fn get_stat_buffer_passive ( & self ) -> & Vec < CPUStat > ;
1920 fn read_stats ( & self ) -> Option < CPUStat > ;
2021 fn get_cores ( & mut self ) -> & mut Vec < CPUCore > ;
2122 fn get_cores_passive ( & self ) -> & Vec < CPUCore > ;
@@ -133,38 +134,41 @@ impl StatsGenerator for dyn Socket {
133134 /// Generates a new CPUStat object storing current usage statistics of the socket
134135 /// and stores it in the stat_buffer.
135136 fn refresh_stats ( & mut self ) {
136- let stat_buffer = self . get_stat_buffer ( ) ;
137+ let stat_buffer = self . get_stat_buffer_passive ( ) ;
137138 if !stat_buffer. is_empty ( ) {
138139 self . clean_old_stats ( ) ;
139140 }
140- stat_buffer. insert ( 0 , self . read_stats ( ) . unwrap ( ) ) ;
141+ let stats = self . read_stats ( ) ;
142+ self . get_stat_buffer ( ) . insert ( 0 , stats. unwrap ( ) ) ;
141143 }
142144
143145 /// Checks the size in memory of stats_buffer and deletes as many CPUStat
144146 /// instances from the buffer to make it smaller in memory than buffer_max_kbytes.
145147 fn clean_old_stats ( & mut self ) {
148+ let id = self . get_id ( ) ;
149+ let buffer_max_kbytes = self . get_buffer_max_kbytes ( ) ;
146150 let stat_buffer = self . get_stat_buffer ( ) ;
147151 let stat_ptr = & stat_buffer[ 0 ] ;
148152 let size_of_stat = size_of_val ( stat_ptr) ;
149153 let curr_size = size_of_stat * stat_buffer. len ( ) ;
150- trace ! ( "current_size of stats in socket {}: {}" , self . get_id ( ) , curr_size) ;
154+ trace ! ( "current_size of stats in socket {}: {}" , id , curr_size) ;
151155 trace ! (
152156 "estimated max nb of socket stats: {}" ,
153- self . get_buffer_max_kbytes ( ) as f32 * 1000.0 / size_of_stat as f32
157+ buffer_max_kbytes as f32 * 1000.0 / size_of_stat as f32
154158 ) ;
155- if curr_size > ( self . get_buffer_max_kbytes ( ) * 1000 ) as usize {
156- let size_diff = curr_size - ( self . get_buffer_max_kbytes ( ) * 1000 ) as usize ;
159+ if curr_size > ( buffer_max_kbytes * 1000 ) as usize {
160+ let size_diff = curr_size - ( buffer_max_kbytes * 1000 ) as usize ;
157161 trace ! (
158162 "socket {} size_diff: {} size of: {}" ,
159- self . get_id ( ) ,
163+ id ,
160164 size_diff,
161165 size_of_stat
162166 ) ;
163167 if size_diff > size_of_stat {
164168 let nb_stats_to_delete = size_diff as f32 / size_of_stat as f32 ;
165169 trace ! (
166170 "socket {} nb_stats_to_delete: {} size_diff: {} size of: {}" ,
167- self . get_id ( ) ,
171+ id ,
168172 nb_stats_to_delete,
169173 size_diff,
170174 size_of_stat
@@ -175,7 +179,7 @@ impl StatsGenerator for dyn Socket {
175179 let res = stat_buffer. pop ( ) ;
176180 debug ! (
177181 "Cleaning stat buffer of socket {}, removing: {:?}" ,
178- self . get_id ( ) , res
182+ id , res
179183 ) ;
180184 }
181185 }
0 commit comments