Harden BLE host link and expose latency tools in the dashboard.
Add BLE RTT/stream tests and live tick median in the UI, fix concurrent WebSocket writes and late BATTERY replies, and skip 2M PHY updates that assert under ESP-NOW coexistence. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
+5
-56
@@ -3,8 +3,6 @@ package main
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"math"
|
||||
"sort"
|
||||
"time"
|
||||
)
|
||||
|
||||
@@ -16,62 +14,13 @@ func runBleRtt(h hostConn, args []string) error {
|
||||
if err := fs.Parse(args); err != nil {
|
||||
return err
|
||||
}
|
||||
if *count < 1 {
|
||||
return fmt.Errorf("--count must be >= 1")
|
||||
}
|
||||
if *warmup < 0 {
|
||||
return fmt.Errorf("--warmup must be >= 0")
|
||||
}
|
||||
|
||||
if *settle > 0 {
|
||||
fmt.Printf("settling %.1fs…\n", *settle)
|
||||
time.Sleep(time.Duration(*settle * float64(time.Second)))
|
||||
out := measureBleRtt(h, *count, *warmup, time.Duration(*settle*float64(time.Second)))
|
||||
if !out.Success {
|
||||
return fmt.Errorf("%s", out.Error)
|
||||
}
|
||||
|
||||
total := *warmup + *count
|
||||
samples := make([]float64, 0, *count)
|
||||
for i := 0; i < total; i++ {
|
||||
t0 := time.Now()
|
||||
if _, err := hostGetVersion(h); err != nil {
|
||||
return fmt.Errorf("VERSION round-trip %d: %w", i, err)
|
||||
}
|
||||
ms := float64(time.Since(t0).Microseconds()) / 1000.0
|
||||
if i >= *warmup {
|
||||
samples = append(samples, ms)
|
||||
}
|
||||
}
|
||||
|
||||
sort.Float64s(samples)
|
||||
fmt.Printf("ble-rtt (VERSION): n=%d warmup=%d\n", len(samples), *warmup)
|
||||
fmt.Printf("ble-rtt (VERSION): n=%d warmup=%d\n", out.Stats.N, out.Warmup)
|
||||
fmt.Printf(" min=%.3f median=%.3f mean=%.3f max=%.3f ms\n",
|
||||
samples[0], percentile(samples, 0.5), mean(samples), samples[len(samples)-1])
|
||||
out.Stats.MinMs, out.Stats.MedMs, out.Stats.MeanMs, out.Stats.MaxMs)
|
||||
return nil
|
||||
}
|
||||
|
||||
func mean(v []float64) float64 {
|
||||
if len(v) == 0 {
|
||||
return math.NaN()
|
||||
}
|
||||
var s float64
|
||||
for _, x := range v {
|
||||
s += x
|
||||
}
|
||||
return s / float64(len(v))
|
||||
}
|
||||
|
||||
func percentile(sorted []float64, p float64) float64 {
|
||||
if len(sorted) == 0 {
|
||||
return math.NaN()
|
||||
}
|
||||
if len(sorted) == 1 {
|
||||
return sorted[0]
|
||||
}
|
||||
idx := p * float64(len(sorted)-1)
|
||||
lo := int(idx)
|
||||
hi := lo + 1
|
||||
if hi >= len(sorted) {
|
||||
return sorted[lo]
|
||||
}
|
||||
frac := idx - float64(lo)
|
||||
return sorted[lo]*(1-frac) + sorted[hi]*frac
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user