r3795 - trunk/varnish-cache/bin/varnishd

phk at projects.linpro.no phk at projects.linpro.no
Fri Feb 20 16:18:46 CET 2009


Author: phk
Date: 2009-02-20 16:18:46 +0100 (Fri, 20 Feb 2009)
New Revision: 3795

Modified:
   trunk/varnish-cache/bin/varnishd/hash_critbit.c
Log:
Make "hcb.dump" a CLI command



Modified: trunk/varnish-cache/bin/varnishd/hash_critbit.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/hash_critbit.c	2009-02-20 14:00:16 UTC (rev 3794)
+++ trunk/varnish-cache/bin/varnishd/hash_critbit.c	2009-02-20 15:18:46 UTC (rev 3795)
@@ -41,6 +41,7 @@
 #include "shmlog.h"
 #include "cache.h"
 #include "hash_slinger.h"
+#include "cli_priv.h"
 
 static struct lock hcb_mtx;
 
@@ -282,9 +283,9 @@
 }
 
 /**********************************************************************/
-#ifdef PHK
+
 static void
-dumptree(uintptr_t p, int indent, FILE *fd)
+dumptree(struct cli *cli, uintptr_t p, int indent)
 {
 	int i;
 	const struct objhead *oh;
@@ -294,7 +295,7 @@
 		return;
 	if (hcb_is_node(p)) {
 		oh = hcb_l_node(p);
-		fprintf(fd, "%*.*sN %d r%u <%02x%02x%02x...> <%s>\n",
+		cli_out(cli, "%*.*sN %d r%u <%02x%02x%02x...> <%s>\n",
 		    indent, indent, "", indent / 2, oh->refcnt,
 		    oh->digest[0], oh->digest[1], oh->digest[2],
 		    oh->hash);
@@ -302,24 +303,38 @@
 	}
 	assert(hcb_is_y(p));
 	y = hcb_l_y(p);
-	fprintf(fd, "%*.*sY c %u p %u b %02x i %d\n",
+	cli_out(cli, "%*.*sY c %u p %u b %02x i %d\n",
 	    indent, indent, "",
 	    y->critbit, y->ptr, y->bitmask, indent / 2);
 	indent += 2;
 	for (i = 0; i < 2; i++)
-		dumptree(y->leaf[i], indent, fd);
+		dumptree(cli, y->leaf[i], indent);
 }
 
 static void
-dump(const struct hcb_root *root, FILE *fd)
+hcb_dump(struct cli *cli, const char * const *av, void *priv)
 {
-	fprintf(fd, "-------------\n");
-	dumptree(root->origo, 0, fd);
-	fprintf(fd, "-------------\n");
-	(void)fflush(fd);
+	struct objhead *oh, *oh2;
+	struct hcb_y *y;
+
+	(void)priv;
+	(void)av;
+	cli_out(cli, "HCB dump:\n");
+	dumptree(cli, hcb_root.origo, 0);
+	cli_out(cli, "Coollist:\n");
+	Lck_Lock(&hcb_mtx);
+	VTAILQ_FOREACH_SAFE(oh, &laylow, coollist, oh2) {
+		y = (void *)&oh->u;
+		cli_out(cli, "%p ref %d, y{%u, %u}\n", oh,
+			oh->refcnt, y->leaf[0], y->leaf[1]);
+	}
+	Lck_Unlock(&hcb_mtx);
 }
-#endif
 
+static struct cli_proto hcb_cmds[] = {
+	{ "hcb.dump", "hcb.dump", "dump HCB tree\n", 0, 0, hcb_dump },
+	{ NULL }
+};
 
 /**********************************************************************/
 
@@ -362,6 +377,7 @@
 	pthread_t tp;
 
 	(void)oh;
+	CLI_AddFuncs(DEBUG_CLI, hcb_cmds);
 	AZ(pthread_create(&tp, NULL, hcb_cleaner, NULL));
 	assert(sizeof(struct hcb_y) <= sizeof(oh->u));
 	memset(&hcb_root, 0, sizeof hcb_root);
@@ -387,7 +403,6 @@
 	Lck_Unlock(&oh->mtx);
 #ifdef PHK
 	fprintf(stderr, "hcb_defef %d %d <%s>\n", __LINE__, r, oh->hash);
-	dump(&hcb_root, stderr);
 #endif
 	return (r);
 }
@@ -424,7 +439,6 @@
 		VSL_stats->hcb_insert++;
 #ifdef PHK
 		fprintf(stderr, "hcb_lookup %d\n", __LINE__);
-		dump(&hcb_root, stderr);
 #endif
 	} else {
 		free(noh->hash);
@@ -432,7 +446,6 @@
 		VSL_stats->hcb_lock++;
 #ifdef PHK
 		fprintf(stderr, "hcb_lookup %d\n", __LINE__);
-		dump(&hcb_root, stderr);
 #endif
 	}
 	Lck_Unlock(&hcb_mtx);



More information about the varnish-commit mailing list