r4897 - trunk/varnish-cache/bin/varnishstat
phk at varnish-cache.org
phk at varnish-cache.org
Sat Jun 5 13:05:06 CEST 2010
Author: phk
Date: 2010-06-05 13:05:04 +0200 (Sat, 05 Jun 2010)
New Revision: 4897
Modified:
trunk/varnish-cache/bin/varnishstat/varnishstat_curses.c
Log:
Teach varnishstat (curses mode) to reopen shmlog if varnishd master is
restarted.
Modified: trunk/varnish-cache/bin/varnishstat/varnishstat_curses.c
===================================================================
--- trunk/varnish-cache/bin/varnishstat/varnishstat_curses.c 2010-06-05 11:04:17 UTC (rev 4896)
+++ trunk/varnish-cache/bin/varnishstat/varnishstat_curses.c 2010-06-05 11:05:04 UTC (rev 4897)
@@ -60,7 +60,7 @@
uint64_t ref;
int type;
char seen;
- const char *name;
+ char *name;
};
static VTAILQ_HEAD(, pt) pthead = VTAILQ_HEAD_INITIALIZER(pthead);
@@ -116,10 +116,16 @@
}
static void
-prep_pts(struct VSL_data *vd, const char *fields)
+prep_pts(const struct VSL_data *vd, const char *fields)
{
struct curses_priv cp;
+ struct pt *pt, *pt2;
+ VTAILQ_FOREACH_SAFE(pt, &pthead, next, pt2) {
+ VTAILQ_REMOVE(&pthead, pt, next);
+ free(pt->name);
+ free(pt);
+ }
cp.fields = fields;
(void)VSL_IterStat(vd, do_curses_cb, &cp);
@@ -136,120 +142,143 @@
}
void
-do_curses(struct VSL_data *vd, const struct varnish_stats *VSL_stats, int delay, const char *fields)
+do_curses(struct VSL_data *vd, const struct varnish_stats *VSL_stats,
+ int delay, const char *fields)
{
- struct varnish_stats copy;
intmax_t ju;
struct timeval tv;
- double tt, lt, hit, miss, ratio, up;
+ double tt, lt, lhit, hit, lmiss, miss, hr, mr, ratio, up;
double a1, a2, a3;
unsigned n1, n2, n3;
time_t rt;
int ch, line;
struct pt *pt;
+ double act, lact;
- prep_pts(vd, fields);
- memset(©, 0, sizeof copy);
-
- a1 = a2 = a3 = 0.0;
- n1 = n2 = n3 = 0;
-
(void)initscr();
AC(raw());
AC(noecho());
AC(nonl());
AC(intrflush(stdscr, FALSE));
AC(curs_set(0));
- AC(erase());
- lt = 0;
while (1) {
- AZ(gettimeofday(&tv, NULL));
- tt = tv.tv_usec * 1e-6 + tv.tv_sec;
- lt = tt - lt;
+ /*
+ * Initialization goes in outher loop
+ */
+ prep_pts(vd, fields);
+ AC(erase());
+ AC(refresh());
- rt = VSL_stats->uptime;
- up = rt;
+ a1 = a2 = a3 = 0.0;
+ n1 = n2 = n3 = 0;
+ lt = 0;
+ lhit = 0;
+ lmiss = 0;
+ lact = 0;
- AC(mvprintw(0, 0, "%*s", COLS - 1, VSL_Name(vd)));
- AC(mvprintw(0, 0, "%d+%02d:%02d:%02d", rt / 86400,
- (rt % 86400) / 3600, (rt % 3600) / 60, rt % 60));
+ while (1) {
+ /*
+ * Break to outher loop if we need to re-read file.
+ * Only check if it looks like nothing is happening.
+ */
+ act = VSL_stats->cache_hit + VSL_stats->cache_miss + 1;
+ if (act == lact && VSL_ReOpen(vd))
+ break;
+ lact = act;
- hit = VSL_stats->cache_hit - copy.cache_hit;
- miss = VSL_stats->cache_miss - copy.cache_miss;
- hit /= lt;
- miss /= lt;
- if (hit + miss != 0) {
- ratio = hit / (hit + miss);
- myexp(&a1, ratio, &n1, 10);
- myexp(&a2, ratio, &n2, 100);
- myexp(&a3, ratio, &n3, 1000);
- }
- AC(mvprintw(1, 0, "Hitrate ratio: %8u %8u %8u", n1, n2, n3));
- AC(mvprintw(2, 0, "Hitrate avg: %8.4f %8.4f %8.4f", a1, a2, a3));
+ AZ(gettimeofday(&tv, NULL));
+ tt = tv.tv_usec * 1e-6 + tv.tv_sec;
+ lt = tt - lt;
- line = 3;
- VTAILQ_FOREACH(pt, &pthead, next) {
- if (line >= LINES)
+ rt = VSL_stats->uptime;
+ up = rt;
+
+ AC(mvprintw(0, 0, "%*s", COLS - 1, VSL_Name(vd)));
+ AC(mvprintw(0, 0, "%d+%02d:%02d:%02d", rt / 86400,
+ (rt % 86400) / 3600, (rt % 3600) / 60, rt % 60));
+
+ hit = VSL_stats->cache_hit;
+ miss = VSL_stats->cache_miss;
+ hr = (hit - lhit) / lt;
+ mr = (miss - lmiss) / lt;
+ lhit = hit;
+ lmiss = miss;
+ if (hr + mr != 0) {
+ ratio = hr / (hr + mr);
+ myexp(&a1, ratio, &n1, 10);
+ myexp(&a2, ratio, &n2, 100);
+ myexp(&a3, ratio, &n3, 1000);
+ }
+ AC(mvprintw(1, 0, "Hitrate ratio: %8u %8u %8u",
+ n1, n2, n3));
+ AC(mvprintw(2, 0, "Hitrate avg: %8.4f %8.4f %8.4f",
+ a1, a2, a3));
+
+ line = 3;
+ VTAILQ_FOREACH(pt, &pthead, next) {
+ if (line >= LINES)
+ break;
+ ju = *pt->ptr;
+ if (ju == 0 && !pt->seen)
+ continue;
+ pt->seen = 1;
+ line++;
+ if (pt->type == 'a') {
+ AC(mvprintw(line, 0,
+ "%12ju %12.2f %12.2f %s\n",
+ ju, (ju - (intmax_t)pt->ref)/lt,
+ ju / up, pt->name));
+ pt->ref = ju;
+ } else {
+ AC(mvprintw(line, 0,
+ "%12ju %12s %12s %s\n",
+ ju, ". ", ". ", pt->name));
+ }
+ }
+ lt = tt;
+ AC(refresh());
+ timeout(delay * 1000);
+ switch ((ch = getch())) {
+ case ERR:
break;
- ju = *pt->ptr;
- if (ju == 0 && !pt->seen)
- continue;
- pt->seen = 1;
- line++;
- if (pt->type == 'a') {
- AC(mvprintw(line, 0,
- "%12ju %12.2f %12.2f %s\n",
- ju, (ju - (intmax_t)pt->ref)/lt,
- ju / up, pt->name));
- pt->ref = ju;
- } else {
- AC(mvprintw(line, 0, "%12ju %12s %12s %s\n",
- ju, ". ", ". ", pt->name));
- }
- }
- lt = tt;
- AC(refresh());
- timeout(delay * 1000);
- switch ((ch = getch())) {
- case ERR:
- break;
#ifdef KEY_RESIZE
- case KEY_RESIZE:
- AC(erase());
- break;
+ case KEY_RESIZE:
+ AC(erase());
+ break;
#endif
- case '\014': /* Ctrl-L */
- case '\024': /* Ctrl-T */
- AC(redrawwin(stdscr));
- AC(refresh());
- break;
- case '\003': /* Ctrl-C */
- AZ(raise(SIGINT));
- break;
- case '\032': /* Ctrl-Z */
- AZ(raise(SIGTSTP));
- break;
- case '\021': /* Ctrl-Q */
- case 'Q':
- case 'q':
- AC(endwin());
- exit(0);
- case '0':
- case '1':
- case '2':
- case '3':
- case '4':
- case '5':
- case '6':
- case '7':
- case '8':
- case '9':
- delay = 1U << (ch - '0');
- break;
- default:
- AC(beep());
- break;
+ case '\014': /* Ctrl-L */
+ case '\024': /* Ctrl-T */
+ AC(redrawwin(stdscr));
+ AC(refresh());
+ break;
+ case '\003': /* Ctrl-C */
+ AZ(raise(SIGINT));
+ break;
+ case '\032': /* Ctrl-Z */
+ AZ(raise(SIGTSTP));
+ break;
+ case '\021': /* Ctrl-Q */
+ case 'Q':
+ case 'q':
+ AC(endwin());
+ exit(0);
+ case '0':
+ case '1':
+ case '2':
+ case '3':
+ case '4':
+ case '5':
+ case '6':
+ case '7':
+ case '8':
+ case '9':
+ delay = 1U << (ch - '0');
+ break;
+ default:
+ AC(beep());
+ break;
+ }
}
}
}
More information about the varnish-commit
mailing list