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 2B1021FAF4 for ; Thu, 15 Dec 2022 20:52:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=80x24.org; s=selector1; t=1671137577; bh=qBJ+2E8VSQZwVWEjBuibBSc/zWVOeg6dCw5Vfa8836E=; h=From:To:Subject:Date:In-Reply-To:References:From; b=HrMoWkqn3yPR+pWv3eRZDV9ATdEkvFgSwBpiPOkda/cgxVmIZSDNXk72wW7bIQc8w 7XwrDxolqIPk5JgXskqe8QEI7v3/rIWrP7Na05wxrYbMrOT79qWkmz3j7nKYI02j2N c613KEGL6+5frjmrYSejea7hJ9u2dUHiJOogA8UA= From: Eric Wong To: mwrap-perl@80x24.org Subject: [PATCH 06/19] mwrap_httpd: add info about src_file and src_loc stats Date: Thu, 15 Dec 2022 20:52:42 +0000 Message-Id: <20221215205255.27840-7-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: This can give users some quick info about their application. We'll also show the MWRAP=bt: parameter to hint users about the backtrace depth they expect. --- mwrap_core.h | 10 +++++++--- mwrap_httpd.h | 25 +++++++++++++++---------- 2 files changed, 22 insertions(+), 13 deletions(-) diff --git a/mwrap_core.h b/mwrap_core.h index 2ef550a..4dc28d4 100644 --- a/mwrap_core.h +++ b/mwrap_core.h @@ -66,7 +66,7 @@ typedef void COP; * allocated (and we don't care about overflow on 32-bit since * hardly anybody still uses it). */ -static size_t total_bytes_inc, total_bytes_dec; +static size_t total_bytes_inc, total_bytes_dec, nr_file, nr_src_loc; static uint32_t bt_req_depth; #if MWRAP_PERL @@ -297,7 +297,9 @@ again: l->allocations = 1; CDS_INIT_LIST_HEAD(&l->allocs); cur = cds_lfht_add_unique(t, l->loc_hash, loc_eq, l, &l->hnode); - if (cur != &l->hnode) { /* lost race */ + if (cur == &l->hnode) { + uatomic_inc(&nr_src_loc); + } else { /* lost race */ rcu_read_unlock(); real_free(l); rcu_read_lock(); @@ -394,7 +396,9 @@ again: if (!f) return NULL; memcpy(f, &sf.sf, sizeof(*f) + len + 1); cur = cds_lfht_add_unique(t, f->fn_hash, fn_eq, f, &f->nd); - if (cur != &f->nd) { /* lost race */ + if (cur == &f->nd) { + uatomic_inc(&nr_file); + } else { /* lost race */ rcu_read_unlock(); real_free(f); rcu_read_lock(); diff --git a/mwrap_httpd.h b/mwrap_httpd.h index f5c3e1b..e5790aa 100644 --- a/mwrap_httpd.h +++ b/mwrap_httpd.h @@ -505,11 +505,14 @@ static struct h1_src_loc *accumulate(unsigned long min, size_t *hslc, FILE *lp) return hslv; } -static void show_age(FILE *fp) +static void show_stats(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); + fprintf(fp, "

Current age: %zu (live: %zu) " + "/ files: %zu / locations: %zu", + inc , inc - dec, + uatomic_read(&nr_file), uatomic_read(&nr_src_loc)); } /* /$PID/at/$LOCATION endpoint */ @@ -542,7 +545,7 @@ static enum mw_qev each_at(struct mw_h1 *h1, struct mw_h1req *h1r) else fputc(' ', fp); write_html(fp, lb.ptr, lb.len); - show_age(fp); + show_stats(fp); FPUTS("" "", fp); @@ -595,9 +598,10 @@ static enum mw_qev each_gt(struct mw_h1 *h1, struct mw_h1req *h1r, if (!fp) return h1_close(h1); fprintf(fp, "mwrap each >%lu" "

mwrap each >%lu " - "(change `%lu' in URL to adjust filtering)", min, min, min); + "(change `%lu' in URL to adjust filtering) - MWRAP=bt:%u", + min, min, min, (unsigned)bt_req_depth); - show_age(fp); + show_stats(fp); if (bt_req_depth) /* need borders to distinguish multi-level traces */ FPUTS("

", fp); else /* save screen space if only tracing one line */ @@ -651,11 +655,12 @@ static enum mw_qev pid_root(struct mw_h1 *h1, struct mw_h1req *h1r) if (!fp) return h1_close(h1); #define default_min "2000" - FPUTS("mwrap demo" - "

allocations >" - default_min " bytes

" URL "", fp); + FPUTS("mwrap demo" + "

mwrap demo", fp); + show_stats(fp); + FPUTS("

allocations >" + default_min " bytes" + "

" URL "", fp); return h1_200(h1, &html); #undef default_min }

sizegenerationaddress