@@ -157,35 +157,83 @@ pub fn main() {
157157 verifier. bucket_stats . iter ( ) . map ( |( _, v) | f ( v) ) . sum :: < std:: time:: Duration > ( ) . as_millis ( )
158158 }
159159
160- let mut smt_init_times = verifier
161- . bucket_stats
162- . iter ( )
163- . filter ( |( k, _) | k. function ( ) . is_none ( ) )
164- . map ( |( k, v) | ( k. module ( ) , v. time_smt_init . as_millis ( ) ) )
165- . collect :: < Vec < _ > > ( ) ;
166- smt_init_times. sort_by ( |( _, a) , ( _, b) | b. cmp ( a) ) ;
167- let total_smt_init: u128 = compute_total ( & verifier, |v| v. time_smt_init ) ;
168-
169- struct SmtStats {
160+ #[ derive( Debug , Clone ) ]
161+ struct SmtStat {
170162 time_millis : u128 ,
163+ time_micros : u128 ,
171164 rlimit_count : Option < u64 > , // at the moment, only available for Z3
172165 }
173166
174- let mut smt_run_stats: Vec < ( & std:: sync:: Arc < vir:: ast:: PathX > , SmtStats ) > = verifier
175- . bucket_stats
176- . iter ( )
177- . filter ( |( k, _) | k. function ( ) . is_none ( ) )
178- . map ( |( k, v) | {
179- (
180- k. module ( ) ,
181- SmtStats {
167+ impl Default for SmtStat {
168+ fn default ( ) -> Self {
169+ Self { time_millis : 0 , time_micros : 0 , rlimit_count : None }
170+ }
171+ }
172+
173+ impl SmtStat {
174+ fn add ( & mut self , other : SmtStat ) {
175+ self . time_millis += other. time_millis ;
176+ self . time_micros += other. time_micros ;
177+ self . rlimit_count = match ( self . rlimit_count , other. rlimit_count ) {
178+ ( Some ( a) , Some ( b) ) => Some ( a + b) ,
179+ ( Some ( a) , None ) => Some ( a) ,
180+ ( None , Some ( b) ) => Some ( b) ,
181+ ( None , None ) => None ,
182+ } ;
183+ }
184+ }
185+
186+ #[ derive( Clone , Debug , Default ) ]
187+ struct SmtStats {
188+ init : SmtStat ,
189+ run : SmtStat ,
190+ }
191+
192+ impl SmtStats {
193+ fn add ( & mut self , other : SmtStats ) {
194+ self . init . add ( other. init ) ;
195+ self . run . add ( other. run ) ;
196+ }
197+ }
198+
199+ let smt_module_stats = {
200+ let mut smt_module_stats: std:: collections:: HashMap <
201+ std:: sync:: Arc < vir:: ast:: PathX > ,
202+ SmtStats ,
203+ > = std:: collections:: HashMap :: new ( ) ;
204+
205+ for ( k, v) in verifier. bucket_stats . iter ( ) {
206+ smt_module_stats. entry ( k. module ( ) . clone ( ) ) . or_default ( ) . add ( SmtStats {
207+ init : SmtStat {
208+ time_millis : v. time_smt_init . as_millis ( ) ,
209+ time_micros : v. time_smt_init . as_micros ( ) ,
210+ rlimit_count : v. rlimit_count ,
211+ } ,
212+ run : SmtStat {
182213 time_millis : v. time_smt_run . as_millis ( ) ,
214+ time_micros : v. time_smt_run . as_micros ( ) ,
183215 rlimit_count : v. rlimit_count ,
184216 } ,
185- )
186- } )
187- . collect :: < Vec < _ > > ( ) ;
188- smt_run_stats. sort_by ( |( _, a) , ( _, b) | b. time_millis . cmp ( & a. time_millis ) ) ;
217+ } ) ;
218+ }
219+
220+ smt_module_stats
221+ } ;
222+
223+ fn sorted_smt_stats (
224+ smt_module_stats : & std:: collections:: HashMap < std:: sync:: Arc < vir:: ast:: PathX > , SmtStats > ,
225+ selector : impl Fn ( & SmtStats ) -> & SmtStat ,
226+ ) -> Vec < ( & std:: sync:: Arc < vir:: ast:: PathX > , SmtStat ) > {
227+ let mut stats: Vec < ( & std:: sync:: Arc < vir:: ast:: PathX > , SmtStat ) > =
228+ smt_module_stats. iter ( ) . map ( |( k, v) | ( k, selector ( v) . clone ( ) ) ) . collect ( ) ;
229+ stats. sort_by ( |( _, a) , ( _, b) | b. time_micros . cmp ( & a. time_micros ) ) ;
230+ stats
231+ }
232+
233+ let smt_init_times = sorted_smt_stats ( & smt_module_stats, |v| & v. init ) ;
234+ let total_smt_init: u128 = compute_total ( & verifier, |v| v. time_smt_init ) ;
235+
236+ let smt_run_stats = sorted_smt_stats ( & smt_module_stats, |v| & v. run ) ;
189237 let total_smt_run: u128 = compute_total ( & verifier, |v| v. time_smt_run ) ;
190238 let rlimit_counts: Option < Vec < u64 > > =
191239 smt_run_stats. iter ( ) . map ( |( _, v) | v. rlimit_count ) . collect ( ) ;
@@ -203,8 +251,9 @@ pub fn main() {
203251 k. module ( ) . clone ( ) ,
204252 (
205253 f. clone ( ) ,
206- SmtStats {
254+ SmtStat {
207255 time_millis : t. smt_time . as_millis ( ) ,
256+ time_micros : t. smt_time . as_micros ( ) ,
208257 rlimit_count : t. rlimit_count ,
209258 } ,
210259 ) ,
@@ -215,7 +264,7 @@ pub fn main() {
215264 . collect ( ) ;
216265 let mut per_module: std:: collections:: HashMap <
217266 vir:: ast:: Path ,
218- Vec < ( vir:: ast:: Fun , SmtStats ) > ,
267+ Vec < ( vir:: ast:: Fun , SmtStat ) > ,
219268 > = std:: collections:: HashMap :: new ( ) ;
220269 for ( m, f_t) in mod_fun_times {
221270 per_module. entry ( m) . or_insert ( Vec :: new ( ) ) . push ( f_t) ;
@@ -226,7 +275,6 @@ pub fn main() {
226275 let mut air_times = verifier
227276 . bucket_stats
228277 . iter ( )
229- . filter ( |( k, _) | k. function ( ) . is_none ( ) )
230278 . map ( |( k, v) | {
231279 ( k. module ( ) , ( v. time_air - ( v. time_smt_init + v. time_smt_run ) ) . as_millis ( ) )
232280 } )
@@ -238,7 +286,6 @@ pub fn main() {
238286 let mut verify_times = verifier
239287 . bucket_stats
240288 . iter ( )
241- . filter ( |( k, _) | k. function ( ) . is_none ( ) )
242289 . map ( |( k, v) | ( k. module ( ) , ( v. time_verify ) . as_millis ( ) ) )
243290 . collect :: < Vec < _ > > ( ) ;
244291 verify_times. sort_by ( |( _, a) , ( _, b) | b. cmp ( a) ) ;
@@ -331,20 +378,24 @@ pub fn main() {
331378 "smt-init-module-times" : smt_init_times. iter( ) . map( |( m, t) | {
332379 serde_json:: json!( {
333380 "module" : rust_verify:: verifier:: module_name( m) ,
334- "time" : t
381+ "time" : t. time_millis,
382+ "time-micros" : t. time_micros,
383+ "rlimit-count" : t. rlimit_count,
335384 } )
336385 } ) . collect:: <Vec <serde_json:: Value >>( ) ,
337386 "smt-run" : total_smt_run,
338387 "smt-run-module-times" : smt_run_stats. iter( ) . map( |( m, t) | {
339388 serde_json:: json!( {
340389 "module" : rust_verify:: verifier:: module_name( m) ,
341390 "time" : t. time_millis,
391+ "time-micros" : t. time_micros,
342392 "rlimit-count" : t. rlimit_count,
343393 "function-breakdown" : smt_function_breakdown. get_mut( * m) . map( |b| b. iter( ) . map( |( f, t) | {
344394 serde_json:: json!( {
345395 "function" : vir:: ast_util:: fun_as_friendly_rust_name( f) ,
346396 "mode:" : verifier. get_function_mode( f) . map( |m| m. to_string( ) ) ,
347397 "time" : t. time_millis,
398+ "time-micros" : t. time_micros,
348399 "rlimit-count" : t. rlimit_count,
349400 "success" : !verifier. func_fails. contains( f) ,
350401 } )
@@ -423,7 +474,7 @@ pub fn main() {
423474 " {}. {:<40} {:>10} ms" ,
424475 i + 1 ,
425476 rust_verify:: verifier:: module_name( m) ,
426- t
477+ t. time_millis
427478 ) ;
428479 }
429480 }
0 commit comments