From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.1 required=3.0 tests=ALL_TRUSTED,AWL,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 184821F61A for ; Thu, 15 Dec 2022 20:52:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=80x24.org; s=selector1; t=1671137576; bh=GSUkmxVE61k9XXo5F1Q3iBdoykEVmx8iOZ8bujPDdOU=; h=From:To:Subject:Date:In-Reply-To:References:From; b=V7a9i2vuesbTEH/g1Vnf0/082yPCmdYQ0eg8wkYhdsFkuuuq8+mOB9ty8CFTMA9XR rJ6enYjEvzJhKsR/lhpfgqJt5nbvIDX4hiNsOR2M5EIreyMx9KU6+6k6PpANPzgFS7 YyNCs+KZqROsOFZhu8CNZEm3pOsxN5I2WXOwpqFQ= From: Eric Wong To: mwrap-perl@80x24.org Subject: [PATCH 01/19] mwrap_httpd: show current bytes consistently Date: Thu, 15 Dec 2022 20:52:37 +0000 Message-Id: <20221215205255.27840-2-e@80x24.org> In-Reply-To: <20221215205255.27840-1-e@80x24.org> References: <20221215205255.27840-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: 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 */
sizegenerationaddress