]> err.no Git - varnish/commitdiff
Dynamically field widths in varnishtop
authortfheen <tfheen@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Tue, 16 Sep 2008 07:30:30 +0000 (07:30 +0000)
committertfheen <tfheen@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Tue, 16 Sep 2008 07:30:30 +0000 (07:30 +0000)
Set the second column field width in varnishtop based on the longest
field in VSL_tags rather than hard-coding a value.

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

varnish-cache/bin/varnishtop/varnishtop.c

index bef53a79d506547e035eb7454c86e2d1bbf0885d..db69e529b8ad42d5531617550c02c0fc08254191 100644 (file)
@@ -72,6 +72,8 @@ static pthread_mutex_t mtx = PTHREAD_MUTEX_INITIALIZER;
 
 static int f_flag = 0;
 
+static unsigned maxfieldlen = 0;
+
 static void
 accumulate(const unsigned char *p)
 {
@@ -153,8 +155,9 @@ update(void)
                        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,6 +200,14 @@ do_curses(struct VSL_data *vd)
 {
        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));