Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
520 changes: 520 additions & 0 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ httpdate = "1.0"
ctrlc = { version = "3.5", features = ["termination"] }
console = { version = "0.16", default-features = false, features = ["std"] }
indicatif = { version = "0.18", default-features = false, features = ["unicode-width"] }
ratatui = { version = "0.30.0", default-features = false, features = ["crossterm"] }
crossterm = { version = "0.29.0", default-features = false, features = ["events"] }

[target.'cfg(any(target_os = "linux", target_os = "macos"))'.dev-dependencies]
nix = { version = "0.32", features = ["term"] }
16 changes: 15 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ Options:
Maximum total run duration in seconds [default: 120]
--max-retry-wait <MAX_RETRY_WAIT>
Maximum cumulative retry wait in seconds [default: 30]
--tui
Open the experimental full-screen speed test dashboard
-h, --help
Print help
-V, --version
Expand All @@ -68,6 +70,18 @@ Example with json-pretty output:

In human-readable mode, live progress is shown on stderr only when it is a terminal. When both stdout and stderr are terminals, each completed transfer size adds a row to the results table. Redirecting stdout keeps the end-of-run summary instead, without progress redraws. CSV and JSON modes never draw a progress bar.

### Experimental dashboard

```sh
cfspeedtest --tui
```

The dashboard charts valid samples as they arrive and shows the current payload, retry countdown, and sample distributions. Dots on the timeline mark payload batches that were skipped or left unrun when the test stopped. The large Mbps figures are the 90th percentiles of the valid samples for each direction. Latency is the average of the unloaded probes. Jitter is the mean absolute change between consecutive valid probes. The dashboard does not measure loaded latency or packet loss.

Press **Tab** to switch between Overview, Samples, and Events. Use **↑/↓** to scroll through samples and errors, **R** to rerun after the test ends, or **Q** to quit. Pressing **Q** or **Ctrl-C** during a run requests cancellation. The dashboard waits for any in-flight request to finish before restoring the terminal.

`--tui` requires an interactive terminal and cannot be combined with `--output-format` or `--verbose`. Use the Events view for measurement diagnostics. Leave `RUST_LOG` unset so diagnostic logs do not interrupt the display. Without `--tui`, the existing CLI runs as before.

### Run limits and failures

Runs have a shared 120-second measurement deadline and a 30-second cumulative retry-wait budget by default. Both limits cover the entire run, including metadata, latency, and both transfer directions. Each request is limited to the smaller of 30 seconds and the remaining run time.
Expand All @@ -88,7 +102,7 @@ Ctrl-C stops new measurements and interrupts retry waits. An in-flight blocking
| 3 | Partial: some valid throughput samples exist, but a sample target was missed or a run limit stopped testing. |
| 130 | Cancelled; any completed measurements are retained. |

Metadata is optional: an unavailable or invalid trace response is reported as an error, but does not by itself make a successful measurement run fail. Failed samples that are replaced by successful retries remain in the error history without making a completed run partial. Operational diagnostics go to stderr in every CLI output mode. In human-readable mode, recorded errors are grouped by stage and payload under the run outcome. A run without recorded errors does not print that heading. A closed stdout, as in `cfspeedtest | head`, is not treated as an error; any other stdout write failure is reported once on stderr.
Metadata is optional: an unavailable or invalid trace response is reported as an error, but does not by itself make a successful measurement run fail. Failed samples that are replaced by successful retries remain in the error history without making a completed run partial. Outside the dashboard, operational diagnostics go to stderr. In human-readable mode, recorded errors are grouped by stage and payload under the run outcome. A run without recorded errors does not print that heading. A closed stdout, as in `cfspeedtest | head`, is not treated as an error; any other stdout write failure is reported once on stderr.

JSON includes `status`, `stop_reason` (`deadline`, `retry_budget`, `cancelled`, or null), and structured `errors` with stage, payload size, HTTP status when available, and reason. Missing metadata is null. `latency_measurement` is always present and includes `status`, `attempts`, `successes`, `target_samples`, and `errors`. Its summary values are null when no valid samples exist; human output uses N/A. `--nr-latency-tests 0` explicitly disables latency testing. CSV retains its throughput-only columns; use the exit code and stderr to detect failures, or JSON for the full outcome.

Expand Down
2 changes: 2 additions & 0 deletions _typos.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[default.extend-identifiers]
ratatui = "ratatui"
139 changes: 139 additions & 0 deletions src/dashboard/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
mod state;
mod view;

use cfspeedtest::{run::RunConfig, speedtest::observe_speed_test, SpeedTestCLIOptions};
use crossterm::{
cursor::Show,
event::{self, Event, KeyCode, KeyEventKind, KeyModifiers},
execute,
terminal::{disable_raw_mode, enable_raw_mode, EnterAlternateScreen, LeaveAlternateScreen},
};
use ratatui::{backend::CrosstermBackend, Terminal};
use reqwest::blocking::Client;
use state::{Dashboard, Outcome, Update};
use std::{
io,
sync::{atomic::Ordering, mpsc},
thread,
time::Duration,
};

struct Screen;

impl Screen {
fn enter() -> io::Result<Self> {
enable_raw_mode()?;
let screen = Self;
execute!(io::stdout(), EnterAlternateScreen)?;
Ok(screen)
}
}

impl Drop for Screen {
fn drop(&mut self) {
let _ = disable_raw_mode();
let _ = execute!(io::stdout(), LeaveAlternateScreen, Show);
}
}

fn start_run(
client: Client,
options: SpeedTestCLIOptions,
config: RunConfig,
) -> io::Result<mpsc::Receiver<Update>> {
let (send, receive) = mpsc::channel();
thread::Builder::new()
.name("speedtest".into())
.spawn(move || {
let report = observe_speed_test(client, options, config, |event| {
let _ = send.send(Update::Run(event));
});
let _ = send.send(Update::Finished(Outcome {
status: report.status,
stop: report.stop_reason,
exit: report.exit_code(),
}));
})?;
Ok(receive)
}

pub(super) fn run(
client: Client,
options: SpeedTestCLIOptions,
config: RunConfig,
host: &str,
) -> io::Result<u8> {
let _screen = Screen::enter()?;
let mut terminal = Terminal::new(CrosstermBackend::new(io::stdout()))?;
let result = run_loop(&mut terminal, client, options, &config, host);
if result.is_err() {
config.cancelled.store(true, Ordering::SeqCst);
}
result
}

fn run_loop(
terminal: &mut Terminal<CrosstermBackend<io::Stdout>>,
client: Client,
options: SpeedTestCLIOptions,
config: &RunConfig,
host: &str,
) -> io::Result<u8> {
let mut app = Dashboard::new(&options, host);
let mut receive = start_run(client.clone(), options.clone(), config.clone())?;
loop {
loop {
match receive.try_recv() {
Ok(update) => app.apply(update),
Err(mpsc::TryRecvError::Empty) => break,
Err(mpsc::TryRecvError::Disconnected) if app.outcome.is_some() => break,
Err(mpsc::TryRecvError::Disconnected) => {
return Err(io::Error::other(
"measurement worker ended without a report",
));
}
}
}
app.stopping = config.cancelled.load(Ordering::SeqCst);
if let Some(outcome) = &app.outcome {
if app.stopping {
return Ok(outcome.exit);
}
}
terminal.draw(|frame| view::render(frame, &app))?;
if !event::poll(Duration::from_millis(80))? {
continue;
}
let Event::Key(key) = event::read()? else {
continue;
};
if key.kind == KeyEventKind::Release {
continue;
}
match key.code {
KeyCode::Esc | KeyCode::Char('q') => {
if let Some(outcome) = &app.outcome {
return Ok(outcome.exit);
}
config.cancelled.store(true, Ordering::SeqCst);
}
KeyCode::Char('c') if key.modifiers.contains(KeyModifiers::CONTROL) => {
if app.outcome.is_some() {
return Ok(130);
}
config.cancelled.store(true, Ordering::SeqCst);
}
KeyCode::Tab | KeyCode::Right => app.switch_view(1),
KeyCode::BackTab | KeyCode::Left => app.switch_view(-1),
KeyCode::Down | KeyCode::Char('j') => app.scroll(1),
KeyCode::Up | KeyCode::Char('k') => app.scroll(-1),
KeyCode::PageDown => app.scroll(8),
KeyCode::PageUp => app.scroll(-8),
KeyCode::Char('r') if app.outcome.is_some() => {
app = Dashboard::new(&options, host);
receive = start_run(client.clone(), options.clone(), config.clone())?;
}
_ => {}
}
}
}
Loading
Loading