mwrap (Perl version) user+dev discussion/patches/pulls/bugs/help
 help / color / mirror / code / Atom feed
From: Eric Wong <e@80x24.org>
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	[thread overview]
Message-ID: <20221215205255.27840-7-e@80x24.org> (raw)
In-Reply-To: <20221215205255.27840-1-e@80x24.org>

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, "<p>Current age: %zu (live: %zu)", inc , inc - dec);
+	fprintf(fp, "<p>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("<table><tr><th>size</th><th>generation</th>"
 		"<th>address</th></tr>", 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, "<html><head><title>mwrap each &gt;%lu"
 		"</title></head><body><p>mwrap each &gt;%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("<table\nborder=1><tr>", 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("<html><head><title>mwrap demo"
-		"</title></head><body><p><a\n"
-		"href=\"each/" default_min "\">allocations &gt;"
-		default_min " bytes</a><p><a\nhref=\""
-		URL "\">" URL "</a></body></html>", fp);
+	FPUTS("<html><head><title>mwrap demo</title></head><body>"
+		"<p>mwrap demo", fp);
+	show_stats(fp);
+	FPUTS("<p><a\nhref=\"each/" default_min "\">allocations &gt;"
+		default_min " bytes</a>"
+		"<p><a\nhref=\"" URL "\">" URL "</a></body></html>", fp);
 	return h1_200(h1, &html);
 #undef default_min
 }

  parent reply	other threads:[~2022-12-15 20:52 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-15 20:52 [PATCH 00/19] another round of httpd improvements Eric Wong
2022-12-15 20:52 ` [PATCH 01/19] mwrap_httpd: show current bytes consistently Eric Wong
2022-12-15 20:52 ` [PATCH 02/19] introduce AUTO_FREE macro to simplify cleanup Eric Wong
2022-12-15 20:52 ` [PATCH 03/19] httpd: rework httpd to use auto-free for memstream Eric Wong
2022-12-15 20:52 ` [PATCH 04/19] httpd: avoid newline if not using bt: >= 1 Eric Wong
2022-12-15 20:52 ` [PATCH 05/19] mwrap_httpd: flesh out /$PID/ and /$PID/trim endpoints Eric Wong
2022-12-15 20:52 ` Eric Wong [this message]
2022-12-15 20:52 ` [PATCH 07/19] use uatomic_inc where appropriate Eric Wong
2022-12-15 20:52 ` [PATCH 08/19] httpd: drop unnecessary AND ops from base-64 Eric Wong
2022-12-15 20:52 ` [PATCH 09/19] mymalloc: add notes on the malloc implementation Eric Wong
2022-12-15 20:52 ` [PATCH 10/19] rproxy: link to mwrap_httpd /$PID/ root without each, too Eric Wong
2022-12-15 20:52 ` [PATCH 11/19] httpd: shrink `mean_life' field to `double' Eric Wong
2022-12-15 20:52 ` [PATCH 12/19] httpd: support CSV output Eric Wong
2022-12-15 20:52 ` [PATCH 13/19] rproxy: enable deflater by default Eric Wong
2022-12-15 20:52 ` [PATCH 14/19] mwrap_httpd: do not abort on fork if out-of-resources Eric Wong
2022-12-15 20:52 ` [PATCH 15/19] httpd: pause forking thread on resource limitations Eric Wong
2022-12-15 20:52 ` [PATCH 16/19] rename mwrap_httpd.h to httpd.h Eric Wong
2022-12-15 20:52 ` [PATCH 17/19] httpd: describe simple and naive buffering scheme Eric Wong
2022-12-15 20:52 ` [PATCH 18/19] httpd: drop TODO item for pipelining Eric Wong
2022-12-15 20:52 ` [PATCH 19/19] avoid -Warray-bounds warning, avoid stack overallocation Eric Wong

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221215205255.27840-7-e@80x24.org \
    --to=e@80x24.org \
    --cc=mwrap-perl@80x24.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mwrap-perl.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).