fixed hardware_db and improved stability and robustness of generic sal
This commit is contained in:
64
src/main.rs
64
src/main.rs
@@ -6,7 +6,7 @@ mod ui;
|
||||
mod engine;
|
||||
mod cli;
|
||||
|
||||
use miette::{Result, IntoDiagnostic, Diagnostic, Report};
|
||||
use miette::{Result, IntoDiagnostic, Diagnostic, Report, Context};
|
||||
use thiserror::Error;
|
||||
use std::sync::mpsc;
|
||||
use std::thread;
|
||||
@@ -30,7 +30,7 @@ use mediator::{TelemetryState, UiCommand, BenchmarkPhase};
|
||||
use sal::traits::{AuditError, PlatformSal};
|
||||
use sal::mock::MockSal;
|
||||
use sal::heuristic::engine::HeuristicEngine;
|
||||
use load::StressNg;
|
||||
use load::{StressNg, Workload};
|
||||
use orchestrator::BenchmarkOrchestrator;
|
||||
use ui::dashboard::{draw_dashboard, DashboardState};
|
||||
use engine::OptimizationResult;
|
||||
@@ -108,10 +108,10 @@ fn main() -> Result<()> {
|
||||
info!("ember-tune starting with args: {:?}", args);
|
||||
|
||||
// 2. Platform Detection & Audit
|
||||
let sal: Box<dyn PlatformSal> = if args.mock {
|
||||
Box::new(MockSal::new())
|
||||
let sal: Arc<dyn PlatformSal> = if args.mock {
|
||||
Arc::new(MockSal::new())
|
||||
} else {
|
||||
HeuristicEngine::detect_and_build()?
|
||||
HeuristicEngine::detect_and_build()?.into()
|
||||
};
|
||||
|
||||
println!("{}", console::style("─── Pre-flight System Audit ───").bold().cyan());
|
||||
@@ -122,9 +122,7 @@ fn main() -> Result<()> {
|
||||
io::Write::flush(&mut io::stdout()).into_diagnostic()?;
|
||||
|
||||
match step.outcome {
|
||||
Ok(_) => {
|
||||
println!("{}", console::style("[✓]").green());
|
||||
}
|
||||
Ok(_) => { println!("{}", console::style("[✓]").green()); }
|
||||
Err(e) => {
|
||||
println!("{}", console::style("[✗]").red());
|
||||
audit_failures.push(e);
|
||||
@@ -137,10 +135,8 @@ fn main() -> Result<()> {
|
||||
return Err(Report::new(MultiAuditError { errors: audit_failures }));
|
||||
}
|
||||
|
||||
println!("{}", console::style("✓ All pre-flight audits passed.").green().bold());
|
||||
thread::sleep(Duration::from_secs(1));
|
||||
|
||||
if args.audit_only {
|
||||
println!("{}", console::style("✓ All pre-flight audits passed.").green().bold());
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
@@ -159,21 +155,22 @@ fn main() -> Result<()> {
|
||||
let (telemetry_tx, telemetry_rx) = mpsc::channel::<TelemetryState>();
|
||||
let (command_tx, command_rx) = mpsc::channel::<UiCommand>();
|
||||
|
||||
let c_tx = command_tx.clone();
|
||||
ctrlc::set_handler(move || {
|
||||
let _ = c_tx.send(UiCommand::Abort);
|
||||
r.store(false, Ordering::SeqCst);
|
||||
}).expect("Error setting Ctrl-C handler");
|
||||
|
||||
// 5. Spawn Backend Orchestrator
|
||||
let sal_backend = sal.clone();
|
||||
let backend_handle = thread::spawn(move || {
|
||||
let workload = Box::new(StressNg::new());
|
||||
|
||||
let mut orchestrator = BenchmarkOrchestrator::new(
|
||||
sal,
|
||||
sal_backend,
|
||||
workload,
|
||||
telemetry_tx,
|
||||
command_rx,
|
||||
);
|
||||
|
||||
orchestrator.run()
|
||||
});
|
||||
|
||||
@@ -197,6 +194,8 @@ fn main() -> Result<()> {
|
||||
history_mhz: Vec::new(),
|
||||
log_event: None,
|
||||
metadata: std::collections::HashMap::new(),
|
||||
is_emergency: false,
|
||||
emergency_reason: None,
|
||||
};
|
||||
|
||||
let tick_rate = Duration::from_millis(100);
|
||||
@@ -233,29 +232,38 @@ fn main() -> Result<()> {
|
||||
}
|
||||
}
|
||||
|
||||
if last_tick.elapsed() >= tick_rate {
|
||||
last_tick = Instant::now();
|
||||
}
|
||||
|
||||
if backend_handle.is_finished() {
|
||||
thread::sleep(Duration::from_secs(1));
|
||||
break;
|
||||
}
|
||||
if last_tick.elapsed() >= tick_rate { last_tick = Instant::now(); }
|
||||
if backend_handle.is_finished() { break; }
|
||||
}
|
||||
|
||||
// 7. Terminal Restoration
|
||||
disable_raw_mode().into_diagnostic()?;
|
||||
execute!(terminal.backend_mut(), LeaveAlternateScreen).into_diagnostic()?;
|
||||
terminal.show_cursor().into_diagnostic()?;
|
||||
let _ = disable_raw_mode();
|
||||
let _ = execute!(terminal.backend_mut(), LeaveAlternateScreen);
|
||||
let _ = terminal.show_cursor();
|
||||
|
||||
// 8. Final Report (Post-TUI)
|
||||
match backend_handle.join() {
|
||||
// 8. Final Report & Hardware Restoration
|
||||
let join_res = backend_handle.join();
|
||||
|
||||
// Explicit hardware restoration
|
||||
info!("Restoring hardware state...");
|
||||
if let Err(e) = sal.restore() {
|
||||
error!("Failed to restore hardware state: {}", e);
|
||||
}
|
||||
|
||||
match join_res {
|
||||
Ok(Ok(result)) => {
|
||||
print_summary_report(&result);
|
||||
}
|
||||
Ok(Err(e)) => {
|
||||
if e.to_string() == "ABORTED" {
|
||||
let err_str = e.to_string();
|
||||
if err_str == "ABORTED" {
|
||||
println!("{}", "Benchmark aborted by user.".yellow());
|
||||
} else if err_str.contains("EMERGENCY_ABORT") {
|
||||
println!();
|
||||
println!("{}", " 🚨 EMERGENCY ABORT TRIGGERED ".bold().on_red().white());
|
||||
println!("Reason: {}", err_str.replace("EMERGENCY_ABORT: ", "").red().bold());
|
||||
println!("{}", "Hardware state has been restored to safe defaults.".yellow());
|
||||
println!();
|
||||
} else {
|
||||
error!("Orchestrator encountered error: {}", e);
|
||||
eprintln!("{} {}", "Error:".red().bold(), e);
|
||||
|
||||
Reference in New Issue
Block a user