From 4ce65c57f9f3932bb31a4cbe9c9c46722cd55677 Mon Sep 17 00:00:00 2001 From: phk Date: Wed, 28 Jun 2006 21:18:00 +0000 Subject: [PATCH] Add a -o argument which sorts the log into transactions before output, this is a fair bit easier to chew through than the raw log (the default) git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@262 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- varnish-cache/bin/varnishlog/Makefile.am | 4 +- varnish-cache/bin/varnishlog/varnishlog.c | 67 ++++++++++++++++++++++- 2 files changed, 68 insertions(+), 3 deletions(-) diff --git a/varnish-cache/bin/varnishlog/Makefile.am b/varnish-cache/bin/varnishlog/Makefile.am index 2ba88928..f69a6aa2 100644 --- a/varnish-cache/bin/varnishlog/Makefile.am +++ b/varnish-cache/bin/varnishlog/Makefile.am @@ -6,4 +6,6 @@ bin_PROGRAMS = varnishlog varnishlog_SOURCES = varnishlog.c -varnishlog_LDADD = $(top_builddir)/lib/libvarnishapi/libvarnishapi.la +varnishlog_LDADD = \ + $(top_builddir)/lib/libvarnishapi/libvarnishapi.la \ + $(top_builddir)/lib/libsbuf/libsbuf.a diff --git a/varnish-cache/bin/varnishlog/varnishlog.c b/varnish-cache/bin/varnishlog/varnishlog.c index f6079f68..aa2210c6 100644 --- a/varnish-cache/bin/varnishlog/varnishlog.c +++ b/varnish-cache/bin/varnishlog/varnishlog.c @@ -9,6 +9,8 @@ #include #include #include +#include +#include #include "shmlog.h" #include "varnishapi.h" @@ -30,20 +32,77 @@ static struct tagnames { static const char *tagnames[256]; -static struct shmloghead *loghead; +/* Ordering-----------------------------------------------------------*/ + +static struct sbuf *ob[65536]; + +static void +order(unsigned char *p) +{ + unsigned u; + + u = (p[2] << 8) | p[3]; + if (ob[u] == NULL) { + ob[u] = sbuf_new(NULL, NULL, 0, SBUF_AUTOEXTEND); + assert(ob[u] != NULL); + } + sbuf_printf(ob[u], "%02x %3d %4d %-12s", + p[0], p[1], u, tagnames[p[0]]); + if (p[1] > 0) { + sbuf_cat(ob[u], " <"); + sbuf_bcat(ob[u], p + 4, p[1]); + sbuf_cat(ob[u], ">"); + } + sbuf_cat(ob[u], "\n"); + if (u == 0) { + sbuf_finish(ob[u]); + printf("%s", sbuf_data(ob[u])); + sbuf_clear(ob[u]); + return; + } + switch (p[0]) { + case SLT_SessionClose: + case SLT_SessionReuse: + case SLT_BackendClose: + sbuf_finish(ob[u]); + printf("%s\n", sbuf_data(ob[u])); + sbuf_clear(ob[u]); + break; + default: + break; + } +} + + + +/*--------------------------------------------------------------------*/ + int main(int argc, char **argv) { - int i; + int i, c; unsigned u; unsigned char *p, *q; + int o_flag = 0; + struct shmloghead *loghead; loghead = VSL_OpenLog(); for (i = 0; stagnames[i].tag != SLT_ENDMARKER; i++) tagnames[stagnames[i].tag] = stagnames[i].name; + while ((c = getopt(argc, argv, "o")) != -1) { + switch (c) { + case 'o': + o_flag = 1; + break; + default: + fprintf(stderr, "Usage: varnishlog [-o]\n"); + exit (2); + } + } + q = NULL; while (VSL_NextLog(loghead, &q) != NULL) ; @@ -54,6 +113,10 @@ main(int argc, char **argv) sleep(1); continue; } + if (o_flag) { + order(p); + continue; + } u = (p[2] << 8) | p[3]; printf("%02x %3d %4d %-12s <", p[0], p[1], u, tagnames[p[0]]); -- 2.39.5