r262 - trunk/varnish-cache/bin/varnishlog
phk at projects.linpro.no
phk at projects.linpro.no
Wed Jun 28 23:18:00 CEST 2006
Author: phk
Date: 2006-06-28 23:18:00 +0200 (Wed, 28 Jun 2006)
New Revision: 262
Modified:
trunk/varnish-cache/bin/varnishlog/Makefile.am
trunk/varnish-cache/bin/varnishlog/varnishlog.c
Log:
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)
Modified: trunk/varnish-cache/bin/varnishlog/Makefile.am
===================================================================
--- trunk/varnish-cache/bin/varnishlog/Makefile.am 2006-06-28 21:03:47 UTC (rev 261)
+++ trunk/varnish-cache/bin/varnishlog/Makefile.am 2006-06-28 21:18:00 UTC (rev 262)
@@ -6,4 +6,6 @@
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
Modified: trunk/varnish-cache/bin/varnishlog/varnishlog.c
===================================================================
--- trunk/varnish-cache/bin/varnishlog/varnishlog.c 2006-06-28 21:03:47 UTC (rev 261)
+++ trunk/varnish-cache/bin/varnishlog/varnishlog.c 2006-06-28 21:18:00 UTC (rev 262)
@@ -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 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 @@
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]]);
More information about the varnish-commit
mailing list