rustress 0.1.1

High-performance load testing engine with an interactive terminal dashboard. Open-loop (RPS) and closed-loop (virtual users) load models with live p50/p90/p95/p99 latency telemetry.
Documentation
use crate::core::config::Config;
use crate::core::snapshot::StatsSnapshot;

/// Run the interactive TUI.
///
/// The engine is created, started and drained by `runner::RunController` inside
/// the event loop. This function previously built a `LoadEngine`, never ran it,
/// and printed a summary of zero requests -- the dashboard's "RUNNING" state
/// had no traffic behind it.
pub async fn run_tui(cfg: Config) -> anyhow::Result<()> {
    let stats = crate::tui::run_tui(cfg).await?;

    // Report from the authoritative counters. The retention ring holds at most
    // RESULT_RING_CAPACITY samples, so deriving totals from it would print
    // "Total: 50000" for a three-million-request run and compute the success
    // rate over the last 50k alone.
    if let Some(stats) = stats {
        let final_snap = stats.snapshot();
        if final_snap.requests > 0 {
            print_summary(&final_snap);
        }
    }

    Ok(())
}

/// Print a post-run summary from a stats snapshot.
fn print_summary(snap: &StatsSnapshot) {
    let total = snap.requests;

    println!("\n{}", "═".repeat(60));
    println!("  SUMMARY");
    println!("{}", "═".repeat(60));
    println!("  Total:     {}", total);
    println!("  Success:   {}", snap.success);
    println!("  Failed:    {}", snap.fail);
    if total > 0 {
        println!(
            "  Rate:      {:.1}%",
            snap.success as f64 / total as f64 * 100.0
        );
    }
    println!("  P50:       {:.1}ms", snap.p50_service_ms);
    println!("  P90:       {:.1}ms", snap.p90_service_ms);
    println!("  P95:       {:.1}ms", snap.p95_service_ms);
    println!("  P99:       {:.1}ms", snap.p99_service_ms);
    println!("  Max:       {:.1}ms", snap.max_service_ms);
    println!("  Bytes:     {}", snap.bytes);

    if snap.dropped_scheduled > 0 {
        println!();
        println!(
            "  ⚠ {} REQUEST(S) SHED — the generator was saturated, so the",
            snap.dropped_scheduled
        );
        println!("    latency figures above do not describe the target.");
    }
    if snap.dropped_results > 0 {
        println!();
        println!(
            "  {} result(s) were evicted from the retention ring and are",
            snap.dropped_results
        );
        println!("    absent from any exported report.");
    }

    println!("{}", "═".repeat(60));
}