vmod_debug: Add a utility function to log the origin of strands

This is implemented as a logging function to not use workspace itself.
parent ae6a9b16
varnishtest "Test VRT STRANDS functions"
varnishtest "Test VRT STRANDS related functions"
varnish v1 -arg "-i foobar" -vcl {
import debug;
......@@ -85,6 +85,11 @@ varnish v1 -arg "-i foobar" -vcl {
req.url + "<-->" + req.url
)
);
debug.log_strands("return_strands",
debug.return_strands(
req.url + "<-->" + req.url
)
);
}
} -start
......
......@@ -1288,3 +1288,77 @@ xyzzy_use_reembarking_http1(VRT_CTX)
{
debug_transport_reembarking_http1_use(ctx);
}
static int
in_oc(struct worker *wrk, struct objcore *oc, const char *p)
{
const char *hdrs;
ssize_t len = 0;
if (oc == NULL)
return (0);
hdrs = ObjGetAttr(wrk, oc, OA_HEADERS, &len);
if (hdrs == NULL)
return (0);
if (p < hdrs)
return (0);
if (p > hdrs + len)
return (0);
return (1);
}
static const char *
ptr_where(VRT_CTX, const char *p)
{
struct ws *ws = ctx->ws;
struct ws *aws;
struct worker *wrk;
struct objcore *oc, *stale_oc;
if (ctx->req != NULL) {
wrk = ctx->req->wrk;
oc = ctx->req->objcore;
stale_oc = ctx->req->stale_oc;
}
else if (ctx->bo != NULL) {
wrk = ctx->bo->wrk;
oc = ctx->bo->fetch_objcore;
stale_oc = ctx->bo->stale_oc;
}
else
WRONG("ctx");
AN(wrk);
aws = ctx->req->wrk->aws;
if (WS_Allocated(ws, p, -1))
return ("ws");
if (WS_Allocated(aws, p, -1))
return ("aws");
if (in_oc(wrk, oc, p))
return ("oc");
if (in_oc(wrk, stale_oc, p))
return ("stale_oc");
return ("?");
}
VCL_VOID
xyzzy_log_strands(VRT_CTX, VCL_STRING prefix, VCL_STRANDS subject, VCL_INT nn)
{
int i, n;
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
if (prefix == NULL)
prefix = "";
AN(subject);
if (nn > INT_MAX)
n = INT_MAX;
else
n = nn;
for (i = 0; i < subject->n; i++) {
const char *p = subject->p[i];
mylog(ctx->vsl, SLT_Debug, "%s[%d]: (%s) %p %.*s%s", prefix, i,
ptr_where(ctx, p), p, n, p, strlen(p) > n ? "..." : "");
}
}
......@@ -447,6 +447,25 @@ $Restrict vcl_deliver
Switch to the reembarking http1 debug transport. Calling it from any other
transport than http1 results in VCL failure.
$Function VOID log_strands(STRING prefix, STRANDS subject, INT n=4)
For each strands member, emit one ``Debug`` log line as formatted using
``printf()`` with prefix as ``%s``, the strands member index as ``[%d]:``, the
*origin* as ``(%s)``, addresses of each strands as ``%p`` and at most the first
*n* characters of each strand, with truncations marked by "...".
*origin* can be one of:
* ``ws`` if from ``ctx->ws``
* ``aws`` if from ``wrk->aws``
* ``oc`` if from ``OA_HEADERS`` of ``req->objcore`` or ``bo->fetch_objcore``
* ``stale_oc`` if from ``OA_HEADERS`` of ``req->stale_oc`` or bo->stale_oc``
* ``?`` otherwise
Example::
Debug c prefix[0]: (ws) 0x7fe69ef80420 abcd...
DEPRECATED
==========
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment