mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
performance-metrics: Add util module with shared micro benchmark helpers
These factor out common setup and synchronization patterns used by block layer micro benchmarks. Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
This commit is contained in:
Generated
+1
@@ -1602,6 +1602,7 @@ dependencies = [
|
|||||||
"serde_json",
|
"serde_json",
|
||||||
"test_infra",
|
"test_infra",
|
||||||
"thiserror 2.0.18",
|
"thiserror 2.0.18",
|
||||||
|
"vmm-sys-util",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ serde = { workspace = true, features = ["derive", "rc"] }
|
|||||||
serde_json = { workspace = true }
|
serde_json = { workspace = true }
|
||||||
test_infra = { path = "../test_infra" }
|
test_infra = { path = "../test_infra" }
|
||||||
thiserror = { workspace = true }
|
thiserror = { workspace = true }
|
||||||
|
vmm-sys-util = { workspace = true }
|
||||||
|
|
||||||
[lints]
|
[lints]
|
||||||
workspace = true
|
workspace = true
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
|
|
||||||
// Custom harness to run performance tests
|
// Custom harness to run performance tests
|
||||||
mod performance_tests;
|
mod performance_tests;
|
||||||
|
mod util;
|
||||||
|
|
||||||
use std::process::Command;
|
use std::process::Command;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|||||||
@@ -0,0 +1,36 @@
|
|||||||
|
// Copyright 2026 The Cloud Hypervisor Authors. All rights reserved.
|
||||||
|
//
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
//! Shared benchmark helpers.
|
||||||
|
|
||||||
|
use std::io::ErrorKind;
|
||||||
|
use std::thread;
|
||||||
|
use std::time::Duration;
|
||||||
|
|
||||||
|
use vmm_sys_util::eventfd::EventFd;
|
||||||
|
use vmm_sys_util::tempfile::TempFile;
|
||||||
|
|
||||||
|
pub const BLOCK_SIZE: u64 = 4096;
|
||||||
|
|
||||||
|
/// Create a temporary file pre sized to hold `num_blocks` blocks.
|
||||||
|
pub fn sized_tempfile(num_blocks: usize) -> TempFile {
|
||||||
|
let tmp = TempFile::new().expect("failed to create tempfile");
|
||||||
|
tmp.as_file()
|
||||||
|
.set_len(BLOCK_SIZE * num_blocks as u64)
|
||||||
|
.expect("failed to set file length");
|
||||||
|
tmp
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Spin and wait until the given eventfd becomes readable.
|
||||||
|
pub fn wait_for_eventfd(notifier: &EventFd) {
|
||||||
|
loop {
|
||||||
|
match notifier.read() {
|
||||||
|
Ok(_) => return,
|
||||||
|
Err(e) if e.kind() == ErrorKind::WouldBlock => {
|
||||||
|
thread::sleep(Duration::from_micros(50));
|
||||||
|
}
|
||||||
|
Err(e) => panic!("eventfd read failed: {e}"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user