Mailing List Archive

r3187 - trunk/varnish-cache/bin/varnishtop
Author: tfheen
Date: 2008-09-16 09:30:30 +0200 (Tue, 16 Sep 2008)
New Revision: 3187

Modified:
trunk/varnish-cache/bin/varnishtop/varnishtop.c
Log:
Dynamically field widths in varnishtop

Set the second column field width in varnishtop based on the longest
field in VSL_tags rather than hard-coding a value.

Fixes: #303


Modified: trunk/varnish-cache/bin/varnishtop/varnishtop.c
===================================================================
--- trunk/varnish-cache/bin/varnishtop/varnishtop.c 2008-09-15 11:47:15 UTC (rev 3186)
+++ trunk/varnish-cache/bin/varnishtop/varnishtop.c 2008-09-16 07:30:30 UTC (rev 3187)
@@ -72,6 +72,8 @@

static int f_flag = 0;

+static unsigned maxfieldlen = 0;
+
static void
accumulate(const unsigned char *p)
{
@@ -153,8 +155,9 @@
len = SHMLOG_LEN(tp->rec);
if (len > COLS - 20)
len = COLS - 20;
- mvprintw(l, 0, "%9.2f %-9.9s %*.*s\n",
- tp->count, VSL_tags[tp->rec[SHMLOG_TAG]],
+ mvprintw(l, 0, "%9.2f %-*.*s %*.*s\n",
+ tp->count, maxfieldlen, maxfieldlen,
+ VSL_tags[tp->rec[SHMLOG_TAG]],
len, len, tp->rec + SHMLOG_DATA);
t = tp->count;
}
@@ -197,7 +200,15 @@
{
pthread_t thr;
int ch;
+ int i;

+ for (i = 0; i < 256; i++) {
+ if (VSL_tags[i] == NULL)
+ continue;
+ if (maxfieldlen < strlen(VSL_tags[i]))
+ maxfieldlen = strlen(VSL_tags[i]);
+ }
+
if (pthread_create(&thr, NULL, accumulate_thread, vd) != 0) {
fprintf(stderr, "pthread_create(): %s\n", strerror(errno));
exit(1);