]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: htx: Adapt htx_dump() to be used from traces
authorChristopher Faulet <cfaulet@haproxy.com>
Tue, 1 Oct 2019 20:03:49 +0000 (22:03 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Fri, 4 Oct 2019 13:48:55 +0000 (15:48 +0200)
This function now dumps info about the HTX message into a buffer, passed as
argument. In addition, it is possible to only dump meta information, without the
message content.

include/common/htx.h

index b2ab1346f82ae2e6507acca43474d02455875da4..aa0176f83721fe92688502fa2c042c79e87e8c5f 100644 (file)
@@ -805,16 +805,19 @@ static inline const char *htx_blk_type_str(enum htx_blk_type type)
 }
 
 /* For debugging purpose */
-static inline void htx_dump(struct htx *htx)
+static inline void htx_dump(struct buffer *chunk, const struct htx *htx, int full)
 {
        int32_t pos;
 
-       fprintf(stderr, "htx:%p [ size=%u - data=%u - used=%u - wrap=%s - extra=%llu]\n",
-               htx, htx->size, htx->data, htx_nbblks(htx),
-               (!htx->head_addr) ? "NO" : "YES",
-               (unsigned long long)htx->extra);
-       fprintf(stderr, "\tfirst=%d - head=%d - tail=%d - tail_addr=%d - head_addr=%d, end_addr=%d\n",
-               htx->first, htx->head, htx->tail, htx->tail_addr, htx->head_addr, htx->end_addr);
+       chunk_appendf(chunk, " htx=%p(size=%u,data=%u,used=%u,wrap=%s,flags=0x%08x,extra=%llu,"
+                     "first=%d,head=%d,tail=%d,tail_addr=%d,head_addr=%d,end_addr=%d)",
+                     htx, htx->size, htx->data, htx_nbblks(htx), (!htx->head_addr) ? "NO" : "YES",
+                     htx->flags, (unsigned long long)htx->extra, htx->first, htx->head, htx->tail,
+                     htx->tail_addr, htx->head_addr, htx->end_addr);
+
+       if (!full || !htx_nbblks(htx))
+               return;
+       chunk_memcat(chunk, "\n", 1);
 
        for (pos = htx_get_head(htx); pos != -1; pos = htx_get_next(htx, pos)) {
                struct htx_sl     *sl;
@@ -828,23 +831,22 @@ static inline void htx_dump(struct htx *htx)
 
                if (type == HTX_BLK_REQ_SL || type == HTX_BLK_RES_SL) {
                        sl = htx_get_blk_ptr(htx, blk);
-                       fprintf(stderr, "\t\t[%u] type=%-17s - size=%-6u - addr=%-6u\t%.*s %.*s %.*s\n",
-                               pos, htx_blk_type_str(type), sz, blk->addr,
-                               HTX_SL_P1_LEN(sl), HTX_SL_P1_PTR(sl),
-                               HTX_SL_P2_LEN(sl), HTX_SL_P2_PTR(sl),
-                               HTX_SL_P3_LEN(sl), HTX_SL_P3_PTR(sl));
+                       chunk_appendf(chunk, "\t\t[%u] type=%-17s - size=%-6u - addr=%-6u\t%.*s %.*s %.*s\n",
+                                     pos, htx_blk_type_str(type), sz, blk->addr,
+                                     HTX_SL_P1_LEN(sl), HTX_SL_P1_PTR(sl),
+                                     HTX_SL_P2_LEN(sl), HTX_SL_P2_PTR(sl),
+                                     HTX_SL_P3_LEN(sl), HTX_SL_P3_PTR(sl));
                }
                else if (type == HTX_BLK_HDR || type == HTX_BLK_TLR)
-                       fprintf(stderr, "\t\t[%u] type=%-17s - size=%-6u - addr=%-6u\t%.*s: %.*s\n",
-                               pos, htx_blk_type_str(type), sz, blk->addr,
-                               (int)n.len, n.ptr,
-                               (int)v.len, v.ptr);
+                       chunk_appendf(chunk, "\t\t[%u] type=%-17s - size=%-6u - addr=%-6u\t%.*s: %.*s\n",
+                                     pos, htx_blk_type_str(type), sz, blk->addr,
+                                     (int)n.len, n.ptr,
+                                     (int)v.len, v.ptr);
                else
-                       fprintf(stderr, "\t\t[%u] type=%-17s - size=%-6u - addr=%-6u%s\n",
-                               pos, htx_blk_type_str(type), sz, blk->addr,
-                               (!v.len ? "\t<empty>" : ""));
+                       chunk_appendf(chunk, "\t\t[%u] type=%-17s - size=%-6u - addr=%-6u%s\n",
+                                     pos, htx_blk_type_str(type), sz, blk->addr,
+                                     (!v.len ? "\t<empty>" : ""));
        }
-       fprintf(stderr, "\n");
 }
 
 #endif /* _COMMON_HTX_H */