Skip to content

Commit 9df7700

Browse files
committed
Add kernel profile extraction test
1 parent bdf7869 commit 9df7700

4 files changed

Lines changed: 37 additions & 45 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,4 @@ env/
2222
node_modules/
2323
*DS_Store
2424
*.iml
25+
bin/bench-transaction/bench-tx-vm-profile.json

bin/bench-transaction/bench-tx-vm-profile.json

Lines changed: 0 additions & 41 deletions
This file was deleted.

bin/bench-transaction/src/cycle_counting_benchmarks/utils.rs

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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)]
369369
mod 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
}

bin/bench-transaction/src/vm_profile.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ mod tests {
9898
#[test]
9999
fn deserialize_profile_with_operation_details() {
100100
let json = r#"{
101-
"profile_version": "1.1",
101+
"profile_version": "1.0",
102102
"source": "test",
103103
"timestamp": "2025-01-01T00:00:00Z",
104104
"miden_vm_version": "0.20.0",
@@ -148,7 +148,7 @@ mod tests {
148148
fn operation_details_consistent_with_total_cycles() {
149149
// Profile with realistic operation mix
150150
let profile = VmProfile {
151-
profile_version: "1.1".to_string(),
151+
profile_version: "1.0".to_string(),
152152
source: "test".to_string(),
153153
timestamp: "2025-01-01T00:00:00Z".to_string(),
154154
miden_vm_version: "0.20.0".to_string(),
@@ -205,7 +205,7 @@ mod tests {
205205
fn tiny_workload_no_minimum_inflation() {
206206
// Small profile with low operation counts
207207
let profile = VmProfile {
208-
profile_version: "1.1".to_string(),
208+
profile_version: "1.0".to_string(),
209209
source: "test".to_string(),
210210
timestamp: "2025-01-01T00:00:00Z".to_string(),
211211
miden_vm_version: "0.20.0".to_string(),

0 commit comments

Comments
 (0)