fixed hardware_db and improved stability and robustness of generic sal

This commit is contained in:
2026-02-26 15:52:44 +01:00
parent f87efa1d24
commit 073414a25e
13 changed files with 488 additions and 225 deletions

View File

@@ -1,16 +1,16 @@
use anyhow::Result;
use std::process::Child;
use std::time::{Duration, Instant};
use std::thread;
pub trait Workload {
/// Starts the workload with specified threads and load percentage.
pub trait Workload: Send + Sync {
fn start(&mut self, threads: usize, load_percent: usize) -> Result<()>;
/// Stops the workload.
fn stop(&mut self) -> Result<()>;
/// Returns the current throughput (e.g., ops/sec).
fn get_throughput(&self) -> Result<f64>;
}
pub struct StressNg {
child: Option<std::process::Child>,
child: Option<Child>,
}
impl StressNg {
@@ -21,7 +21,7 @@ impl StressNg {
impl Workload for StressNg {
fn start(&mut self, threads: usize, load_percent: usize) -> Result<()> {
self.stop()?; // Ensure any previous instance is stopped
self.stop()?;
let child = std::process::Command::new("stress-ng")
.args([
@@ -37,15 +37,32 @@ impl Workload for StressNg {
fn stop(&mut self) -> Result<()> {
if let Some(mut child) = self.child.take() {
let _ = child.kill();
let _ = child.wait();
// Try SIGTERM first
#[cfg(unix)]
{
use libc::{kill, SIGTERM};
unsafe { kill(child.id() as i32, SIGTERM); }
}
let start = Instant::now();
let mut exited = false;
while start.elapsed() < Duration::from_secs(2) {
if let Ok(Some(_)) = child.try_wait() {
exited = true;
break;
}
thread::sleep(Duration::from_millis(100));
}
if !exited {
let _ = child.kill();
let _ = child.wait();
}
}
Ok(())
}
fn get_throughput(&self) -> Result<f64> {
// In a real implementation, we would parse stress-ng's temporary results
// or use a different workload that provides live throughput.
Ok(0.0)
}
}