r4299 - branches/2.0/varnish-cache/bin/varnishtop
tfheen at projects.linpro.no
tfheen at projects.linpro.no
Thu Oct 8 15:13:14 CEST 2009
Author: tfheen
Date: 2009-10-08 15:13:14 +0200 (Thu, 08 Oct 2009)
New Revision: 4299
Modified:
branches/2.0/varnish-cache/bin/varnishtop/varnishtop.c
Log:
Merge r4173: varnishtop: handle shm_reclen > 255
varnishtop used to have a hard-coded max record length of 255 bytes.
This broke with the change that allows larger record length. Use a
dynamic buffer instead.
Modified: branches/2.0/varnish-cache/bin/varnishtop/varnishtop.c
===================================================================
--- branches/2.0/varnish-cache/bin/varnishtop/varnishtop.c 2009-10-08 13:07:00 UTC (rev 4298)
+++ branches/2.0/varnish-cache/bin/varnishtop/varnishtop.c 2009-10-08 13:13:14 UTC (rev 4299)
@@ -54,7 +54,8 @@
#include "varnishapi.h"
struct top {
- unsigned char rec[4 + 255];
+ unsigned char rec[4];
+ unsigned char *rec_data;
unsigned clen;
unsigned hash;
VTAILQ_ENTRY(top) list;
@@ -99,7 +100,7 @@
continue;
if (tp->clen != q - p)
continue;
- if (memcmp(p + SHMLOG_DATA, tp->rec + SHMLOG_DATA,
+ if (memcmp(p + SHMLOG_DATA, tp->rec_data,
q - (p + SHMLOG_DATA)))
continue;
tp->count += 1.0;
@@ -109,12 +110,15 @@
ntop++;
tp = calloc(sizeof *tp, 1);
assert(tp != NULL);
+ tp->rec_data = calloc(l, 1);
+ assert(tp->rec_data != NULL);
tp->hash = u;
tp->count = 1.0;
tp->clen = q - p;
VTAILQ_INSERT_TAIL(&top_head, tp, list);
}
- memcpy(tp->rec, p, SHMLOG_DATA + l);
+ memcpy(tp->rec, p, SHMLOG_DATA - 1);
+ memcpy(tp->rec_data, p + SHMLOG_DATA, l);
while (1) {
tp2 = VTAILQ_PREV(tp, tophead, list);
if (tp2 == NULL || tp2->count >= tp->count)
@@ -157,12 +161,13 @@
mvprintw(l, 0, "%9.2f %-*.*s %*.*s\n",
tp->count, maxfieldlen, maxfieldlen,
VSL_tags[tp->rec[SHMLOG_TAG]],
- len, len, tp->rec + SHMLOG_DATA);
+ len, len, tp->rec_data);
t = tp->count;
}
tp->count *= .999;
if (tp->count * 10 < t || l > LINES * 10) {
VTAILQ_REMOVE(&top_head, tp, list);
+ free(tp->rec_data);
free(tp);
ntop--;
}
More information about the varnish-commit
mailing list