dyanmic update interval for pps stats

This commit is contained in:
Bob 2025-12-15 08:57:14 -08:00
parent d290589888
commit 08d75fc645
1 changed files with 13 additions and 2 deletions

View File

@ -285,7 +285,7 @@ static esp_err_t iperf_start_udp_client(iperf_ctrl_t *ctrl) {
int64_t last_rate_check = esp_timer_get_time(); int64_t last_rate_check = esp_timer_get_time();
uint32_t packets_since_check = 0; uint32_t packets_since_check = 0;
int32_t packet_id = 0; int32_t packet_id = 0;
uint32_t current_rate_check_interval_us = MIN_RATE_CHECK_INTERVAL_US;
struct timespec ts; struct timespec ts;
while (!ctrl->finish && esp_timer_get_time() < end_time) { while (!ctrl->finish && esp_timer_get_time() < end_time) {
@ -320,8 +320,19 @@ static esp_err_t iperf_start_udp_client(iperf_ctrl_t *ctrl) {
} }
now = esp_timer_get_time(); now = esp_timer_get_time();
if (now - last_rate_check > RATE_CHECK_INTERVAL_US) { // Modified check to use dynamic interval
if (now - last_rate_check > current_rate_check_interval_us) {
uint32_t interval_us = (uint32_t)(now - last_rate_check); uint32_t interval_us = (uint32_t)(now - last_rate_check);
// Dynamic Interval Calculation ---
uint32_t config_pps = iperf_get_pps();
if (config_pps > 0) {
// Calculate time needed to send 25 packets based on the CONFIG PPS
uint32_t needed_time_us = (25ULL * 1000000ULL) / config_pps;
// Set new interval: needed_time_us, but not lower than 250ms
current_rate_check_interval_us = (needed_time_us > MIN_RATE_CHECK_INTERVAL_US) ? needed_time_us : MIN_RATE_CHECK_INTERVAL_US;
}
if (interval_us > 0) { if (interval_us > 0) {
// Calculate Instantaneous PPS // Calculate Instantaneous PPS
s_stats.actual_pps = (uint32_t)((uint64_t)packets_since_check * 1000000 / interval_us); s_stats.actual_pps = (uint32_t)((uint64_t)packets_since_check * 1000000 / interval_us);