[master] 0b32af6dc panic: Optionally track miniobjs

Dridi Boukelmoune dridi.boukelmoune at gmail.com
Tue Aug 17 06:57:05 UTC 2021


commit 0b32af6dc78e422fa1fdc41033ad772f06e5e246
Author: Dridi Boukelmoune <dridi.boukelmoune at gmail.com>
Date:   Mon Jul 12 08:25:38 2021 +0200

    panic: Optionally track miniobjs
    
    PAN_dump_struct2() is now renamed to PAN__DumpStruct() following the
    guidelines from apispaces.rst in addition to growing a track argument.
    This should allow dumping structures that we know ought to be dumped
    only once, in case they would be numerous.
    
    There seems to be no good reason to expose it to VMODs yet since they
    have no integration point with the panic output, so those definitions
    can be confined in cache_varnishd.h for now.
    
    Better diff with the --ignore-all-space option.

diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h
index 7c12d7875..e65c76ea7 100644
--- a/bin/varnishd/cache/cache.h
+++ b/bin/varnishd/cache/cache.h
@@ -835,13 +835,3 @@ Tlen(const txt t)
  * extra timestamps in cache_pool.c.  Hide this detail with a macro
  */
 #define W_TIM_real(w) ((w)->lastused = VTIM_real())
-
-int PAN_dump_struct2(struct vsb *vsb, int block, const void *ptr,
-    const char *smagic, unsigned magic, const char *fmt, ...)
-    v_printflike_(6,7);
-
-#define PAN_dump_struct(vsb, ptr, magic, ...)		\
-    PAN_dump_struct2(vsb, 1, ptr, #magic, magic, __VA_ARGS__)
-
-#define PAN_dump_oneline(vsb, ptr, magic, ...)		\
-    PAN_dump_struct2(vsb, 0, ptr, #magic, magic, __VA_ARGS__)
diff --git a/bin/varnishd/cache/cache_panic.c b/bin/varnishd/cache/cache_panic.c
index 533c9e906..14de7e11b 100644
--- a/bin/varnishd/cache/cache_panic.c
+++ b/bin/varnishd/cache/cache_panic.c
@@ -110,7 +110,7 @@ static const void *already_list[N_ALREADY];
 static int already_idx;
 
 int
-PAN_dump_struct2(struct vsb *vsb, int block, const void *ptr,
+PAN__DumpStruct(struct vsb *vsb, int block, int track, const void *ptr,
     const char *smagic, unsigned magic, const char *fmt, ...)
 {
 	va_list ap;
@@ -128,17 +128,19 @@ PAN_dump_struct2(struct vsb *vsb, int block, const void *ptr,
 	VSB_printf(vsb, " = %p {", ptr);
 	if (block)
 		VSB_putc(vsb, '\n');
-	for (i = 0; i < already_idx; i++) {
-		if (already_list[i] == ptr) {
-			VSB_cat(vsb, "  [Already dumped, see above]");
-			if (block)
-				VSB_putc(vsb, '\n');
-			VSB_cat(vsb, "},\n");
-			return (-2);
+	if (track) {
+		for (i = 0; i < already_idx; i++) {
+			if (already_list[i] == ptr) {
+				VSB_cat(vsb, "  [Already dumped, see above]");
+				if (block)
+					VSB_putc(vsb, '\n');
+				VSB_cat(vsb, "},\n");
+				return (-2);
+			}
 		}
+		if (already_idx < N_ALREADY)
+			already_list[already_idx++] = ptr;
 	}
-	if (already_idx < N_ALREADY)
-		already_list[already_idx++] = ptr;
 	uptr = ptr;
 	if (*uptr != magic) {
 		VSB_printf(vsb, "  .magic = 0x%08x", *uptr);
diff --git a/bin/varnishd/cache/cache_varnishd.h b/bin/varnishd/cache/cache_varnishd.h
index 3f5d929f3..b150ea5e0 100644
--- a/bin/varnishd/cache/cache_varnishd.h
+++ b/bin/varnishd/cache/cache_varnishd.h
@@ -367,6 +367,22 @@ void ObjUnsubscribeEvents(uintptr_t *);
 
 /* cache_panic.c */
 void PAN_Init(void);
+int PAN__DumpStruct(struct vsb *vsb, int block, int track, const void *ptr,
+    const char *smagic, unsigned magic, const char *fmt, ...)
+    v_printflike_(7,8);
+
+#define PAN_dump_struct(vsb, ptr, magic, ...)		\
+    PAN__DumpStruct(vsb, 1, 1, ptr, #magic, magic, __VA_ARGS__)
+
+#define PAN_dump_oneline(vsb, ptr, magic, ...)		\
+    PAN__DumpStruct(vsb, 0, 1, ptr, #magic, magic, __VA_ARGS__)
+
+#define PAN_dump_once(vsb, ptr, magic, ...)		\
+    PAN__DumpStruct(vsb, 1, 0, ptr, #magic, magic, __VA_ARGS__)
+
+#define PAN_dump_once_oneline(vsb, ptr, magic, ...)		\
+    PAN__DumpStruct(vsb, 0, 0, ptr, #magic, magic, __VA_ARGS__)
+
 const char *sess_close_2str(enum sess_close sc, int want_desc);
 
 /* cache_pool.c */


More information about the varnish-commit mailing list