Commit 28b68b4b authored by Tollef Fog Heen's avatar Tollef Fog Heen

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


git-svn-id: http://www.varnish-cache.org/svn/trunk/varnish-cache@3187 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent fc15e0d3
......@@ -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));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment