]> err.no Git - varnish/commitdiff
Add a -o argument which sorts the log into transactions before output,
authorphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Wed, 28 Jun 2006 21:18:00 +0000 (21:18 +0000)
committerphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Wed, 28 Jun 2006 21:18:00 +0000 (21:18 +0000)
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
varnish-cache/bin/varnishlog/varnishlog.c

index 2ba88928d0dda3f08e292ade400ad371bc34f59b..f69a6aa2d252ee649fecd50aeab09442224a1539 100644 (file)
@@ -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 
index f6079f68281f23dd421b80fde1fb3b56546e5529..aa2210c623c217b7a166660bc7aa6939612147c3 100644 (file)
@@ -9,6 +9,8 @@
 #include <string.h>
 #include <stdlib.h>
 #include <unistd.h>
+#include <assert.h>
+#include <sbuf.h>
 
 #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]]);