]> err.no Git - varnish/commitdiff
Make it possible to select which requests we want to see in
authorphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Fri, 18 Aug 2006 18:14:10 +0000 (18:14 +0000)
committerphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Fri, 18 Aug 2006 18:14:10 +0000 (18:14 +0000)
ordered mode.  For instance
./varnishlog -o rxurl foo
will only show requests that match the regexp "foo" on the rxurl field

git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@829 d4fa192b-c00b-0410-8231-f00ffab90ce4

varnish-cache/bin/varnishlog/varnishlog.c

index a079b0dd1b95479d2316e395cd39bbaeb77c7e54..dbcd366a7a647b19ea8d26b557793841d2206636 100644 (file)
@@ -9,6 +9,7 @@
 #include <string.h>
 #include <stdlib.h>
 #include <unistd.h>
+#include <regex.h>
 
 #include "compat/vis.h"
 
 
 static int     bflag, cflag;
 
+/* -------------------------------------------------------------------*/
+
+static int
+name2tag(const char *n)
+{
+       int i;
+
+       for (i = 0; i < 256; i++) {
+               if (VSL_tags[i] == NULL)
+                       continue;
+               if (!strcasecmp(n, VSL_tags[i]))
+                       return (i);
+       }
+       return (-1);
+}
+
 /* Ordering-----------------------------------------------------------*/
 
 static struct vsb      *ob[65536];
 static unsigned char   flg[65536];
 #define F_INVCL                (1 << 0)
+#define F_MATCH                (1 << 1)
+
+static int             match_tag = -1;
+static regex_t         match_re;
 
 static void
 clean_order(void)
@@ -57,6 +78,9 @@ h_order(void *priv, unsigned tag, unsigned fd, unsigned len, unsigned spec, cons
                ob[fd] = vsb_new(NULL, NULL, 0, VSB_AUTOEXTEND);
                assert(ob[fd] != NULL);
        }
+       if (tag == match_tag &&
+           !regexec(&match_re, ptr, 0, NULL, 0))
+               flg[fd] |= F_MATCH;
        switch (tag) {
        case SLT_VCL_call:
                flg[fd] |= F_INVCL;
@@ -91,7 +115,8 @@ h_order(void *priv, unsigned tag, unsigned fd, unsigned len, unsigned spec, cons
        case SLT_BackendReuse:
        case SLT_StatSess:
                vsb_finish(ob[fd]);
-               if (vsb_len(ob[fd]) > 1)
+               if (vsb_len(ob[fd]) > 1 &&
+                   (match_tag == -1 || flg[fd] & F_MATCH))
                        printf("%s\n", vsb_data(ob[fd]));
                vsb_clear(ob[fd]);
                break;
@@ -102,10 +127,24 @@ h_order(void *priv, unsigned tag, unsigned fd, unsigned len, unsigned spec, cons
 }
 
 static void
-do_order(struct VSL_data *vd)
+do_order(struct VSL_data *vd, int argc, char **argv)
 {
        int i;
 
+       if (argc == 2) {
+               match_tag = name2tag(argv[0]);
+               if (match_tag < 0) {
+                       fprintf(stderr, "Tag \"%s\" unknown\n", argv[0]);
+                       exit (2);
+               }
+               i = regcomp(&match_re, argv[1], REG_EXTENDED);
+               if (i) {
+                       char buf[BUFSIZ];
+                       regerror(i, &match_re, buf, sizeof buf);
+                       fprintf(stderr, "%s\n", buf);
+                       exit (2);
+               }
+       }
        if (!bflag) {
                VSL_Select(vd, SLT_SessionOpen);
                VSL_Select(vd, SLT_SessionClose);
@@ -226,7 +265,7 @@ main(int argc, char **argv)
                do_write(vd, w_opt);
 
        if (o_flag)
-               do_order(vd);
+               do_order(vd, argc - optind, argv + optind);
 
        while (1) {
                i = VSL_Dispatch(vd, VSL_H_Print, stdout);