From 956b57fbea889b9838f80f6f62df942bb5a8a76f Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Thu, 15 Dec 2022 20:52:37 +0000 Subject: mwrap_httpd: show current bytes consistently We actually want to read total_bytes_dec before total_bytes_inc to ensure a greater likelyhood of the resulting total being positive (or not underflowed into SIZE_MAX territory) --- mwrap_httpd.h | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/mwrap_httpd.h b/mwrap_httpd.h index bd37fb2..aa4574a 100644 --- a/mwrap_httpd.h +++ b/mwrap_httpd.h @@ -487,6 +487,13 @@ static struct h1_src_loc *accumulate(unsigned long min, size_t *hslc, FILE *lp) return hslv; } +static void show_age(FILE *fp) +{ + size_t dec = uatomic_read(&total_bytes_dec); + size_t inc = uatomic_read(&total_bytes_inc); + fprintf(fp, "

Current age: %zu (live: %zu)", inc , inc - dec); +} + /* /$PID/at/$LOCATION endpoint */ static enum mw_qev each_at(struct mw_h1 *h1, struct mw_h1req *h1r) { @@ -519,9 +526,7 @@ static enum mw_qev each_at(struct mw_h1 *h1, struct mw_h1req *h1r) write_html(fp, lname.ptr, lname.len); free(lname.ptr); - size_t age = uatomic_read(&total_bytes_inc); - fprintf(fp, "

Current age: %zu (live: %zu)", - age, age - uatomic_read(&total_bytes_dec)); + show_age(fp); FPUTS("" "", fp); @@ -580,10 +585,8 @@ static enum mw_qev each_gt(struct mw_h1 *h1, struct mw_h1req *h1r, fprintf(fp, "mwrap each >%lu" "

mwrap each >%lu " "(change `%lu' in URL to adjust filtering)", min, min, min); - size_t age = uatomic_read(&total_bytes_inc); - fprintf(fp, "

Current age: %zu (live: %zu)", - age, age - uatomic_read(&total_bytes_dec)); + show_age(fp); if (bt_req_depth) /* need borders to distinguish multi-level traces */ FPUTS("

", fp); else /* save screen space if only tracing one line */ -- cgit v1.2.3-24-ge0c7
sizegenerationaddress