@@ -312,7 +312,7 @@ pub fn write_vm_profile(
312312 }
313313
314314 let profile = VmProfile {
315- profile_version : "1.1 " . to_string ( ) ,
315+ profile_version : "1.0 " . to_string ( ) ,
316316 source : "miden-base/bin/bench-transaction" . to_string ( ) ,
317317 timestamp : chrono:: Utc :: now ( ) . to_rfc3339 ( ) ,
318318 miden_vm_version : env ! ( "CARGO_PKG_VERSION" ) . to_string ( ) ,
@@ -368,6 +368,7 @@ fn signature_verify_count(total_cycles: u64, instruction_mix: &InstructionMix) -
368368#[ cfg( test) ]
369369mod tests {
370370 use super :: * ;
371+ use crate :: context_setups:: tx_consume_single_p2id_note;
371372
372373 /// Test that operation details are generated with correct hashing split
373374 #[ test]
@@ -570,4 +571,35 @@ mod tests {
570571 ) ;
571572
572573 }
574+
575+ /// Test that ratios can be extracted from the real transaction kernel
576+ #[ tokio:: test( flavor = "current_thread" ) ]
577+ async fn write_vm_profile_extracts_real_kernel_mix ( ) {
578+ let measurements = tx_consume_single_p2id_note ( )
579+ . expect ( "build tx" )
580+ . execute ( )
581+ . await
582+ . map ( miden_protocol:: transaction:: TransactionMeasurements :: from)
583+ . expect ( "execute tx" ) ;
584+
585+ let tx_benchmarks = vec ! [ (
586+ ExecutionBenchmark :: ConsumeSingleP2ID ,
587+ MeasurementsPrinter :: from( measurements) ,
588+ ) ] ;
589+
590+ let temp_dir = tempfile:: tempdir ( ) . expect ( "create temp dir" ) ;
591+ let path = temp_dir. path ( ) . join ( "vm_profile_real_kernel.json" ) ;
592+ write_vm_profile ( & path, & tx_benchmarks) . expect ( "write vm profile" ) ;
593+
594+ let json = read_to_string ( & path) . expect ( "read vm profile" ) ;
595+ let profile: VmProfile = serde_json:: from_str ( & json) . expect ( "deserialize vm profile" ) ;
596+
597+ let mix = & profile. transaction_kernel . instruction_mix ;
598+ let mix_sum =
599+ mix. arithmetic + mix. hashing + mix. memory + mix. control_flow + mix. signature_verify ;
600+ assert ! ( mix_sum. is_finite( ) ) ;
601+ assert ! ( ( mix_sum - 1.0 ) . abs( ) < MIX_SUM_TOLERANCE ) ;
602+ assert ! ( profile. transaction_kernel. total_cycles > 0 ) ;
603+ assert ! ( !profile. transaction_kernel. operation_details. is_empty( ) ) ;
604+ }
573605}
0 commit comments