* Log tailer for Varnish
*/
-#include <stdio.h>
+#include <curses.h>
#include <errno.h>
-#include <string.h>
+#include <limits.h>
+#include <stdio.h>
#include <stdlib.h>
-#include <unistd.h>
-#include <curses.h>
+#include <string.h>
#include <time.h>
-#include <limits.h>
+#include <unistd.h>
#ifndef HAVE_CLOCK_GETTIME
#include "compat/clock_gettime.h"
double a1, a2, a3;
unsigned n1, n2, n3;
time_t rt;
- int i;
-
+ int ch, line;
memset(©, 0, sizeof copy);
n1 = n2 = n3 = 0;
initscr();
+ raw();
+ noecho();
+ nonl();
+ intrflush(stdscr, false);
erase();
lt = 0;
rt = ts.tv_sec - VSL_stats->start_time;
up = rt;
- move(0,0);
- i = 0;
+ move(0, 0);
+ printw("%*s\n", COLS - 1, VSL_Name());
+ move(0, 0);
if (rt > 86400) {
printw("%dd+", rt / 86400);
rt %= 86400;
- i++;
}
printw("%02d:", rt / 3600);
rt %= 3600;
printw("%02d:", rt / 60);
rt %= 60;
- printw("%02d\n", rt);
+ printw("%02d", rt);
+ move(1, 0);
hit = (intmax_t)VSL_stats->cache_hit -
(intmax_t)copy.cache_hit;
miss = (intmax_t)VSL_stats->cache_miss -
printw("Hitrate avg: %8.4f %8.4f %8.4f\n", a1, a2, a3);
printw("\n");
+ line = 0;
#define MAC_STAT(n, t, f, d) \
- do { \
+ if (++line < LINES - 4) { \
ju = VSL_stats->n; \
if (f == 'a') { \
printw("%12ju %12.2f %12.2f %s\n", \
} else { \
printw("%12ju %12s %12s %s\n", ju, ". ", ". ", d); \
} \
- } while (0);
+ }
#include "stat_field.h"
#undef MAC_STAT
lt = tt;
refresh();
- sleep(delay);
+ timeout(delay * 1000);
+ switch ((ch = getch())) {
+ case ERR:
+ break;
+ case KEY_RESIZE:
+ erase();
+ break;
+ case '\014':
+ redrawwin(stdscr);
+ refresh();
+ break;
+ case '\003': /* Ctrl-C */
+ case '\021': /* Ctrl-Q */
+ case 'Q':
+ case 'q':
+ endwin();
+ return;
+ default:
+ break;
+ }
}
}