r509 - in trunk/varnish-cache: bin/varnishd bin/varnishstat include
phk at projects.linpro.no
phk at projects.linpro.no
Wed Jul 19 23:14:41 CEST 2006
Author: phk
Date: 2006-07-19 23:14:41 +0200 (Wed, 19 Jul 2006)
New Revision: 509
Modified:
trunk/varnish-cache/bin/varnishd/cache_main.c
trunk/varnish-cache/bin/varnishd/shmlog.c
trunk/varnish-cache/bin/varnishstat/varnishstat.c
trunk/varnish-cache/include/stats.h
Log:
Include a "start_time" timestamp in the stats and teach varnishstats
to print it in curses mode.
Some polishing and cleanup.
Modified: trunk/varnish-cache/bin/varnishd/cache_main.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_main.c 2006-07-19 20:07:16 UTC (rev 508)
+++ trunk/varnish-cache/bin/varnishd/cache_main.c 2006-07-19 21:14:41 UTC (rev 509)
@@ -130,6 +130,7 @@
arm_keepalive();
printf("Ready\n");
+ VSL_stats->start_time = time(NULL);
i = event_base_loop(eb, 0);
if (i != 0)
printf("event_dispatch() = %d\n", i);
Modified: trunk/varnish-cache/bin/varnishd/shmlog.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/shmlog.c 2006-07-19 20:07:16 UTC (rev 508)
+++ trunk/varnish-cache/bin/varnishd/shmlog.c 2006-07-19 21:14:41 UTC (rev 509)
@@ -136,6 +136,7 @@
AZ(pthread_mutex_init(&vsl_mutex, NULL));
loghead->starttime = time(NULL);
VSL_stats = &loghead->stats;
+ memset(VSL_stats, 0, sizeof *VSL_stats);
}
/*--------------------------------------------------------------------*/
@@ -184,7 +185,6 @@
* management process as well.
*/
VSL_Init();
- memset(VSL_stats, 0, sizeof *VSL_stats);
}
/*--------------------------------------------------------------------*/
Modified: trunk/varnish-cache/bin/varnishstat/varnishstat.c
===================================================================
--- trunk/varnish-cache/bin/varnishstat/varnishstat.c 2006-07-19 20:07:16 UTC (rev 508)
+++ trunk/varnish-cache/bin/varnishstat/varnishstat.c 2006-07-19 21:14:41 UTC (rev 509)
@@ -24,23 +24,82 @@
(*acc) += (val - *acc) / (double)*n;
}
-int
-main(int argc, char **argv)
+static void
+do_curses(struct varnish_stats *VSL_stats)
{
- int c;
- struct varnish_stats *VSL_stats, copy;
- int c_flag = 0;
+ struct varnish_stats copy;
intmax_t ju;
struct timespec ts;
double tt, lt, hit, miss, ratio;
double a1, a2, a3;
unsigned n1, n2, n3;
+ time_t rt;
+ int i;
- a1 = a2 = a3 = 0;
+
+ memset(©, 0, sizeof copy);
+
+ a1 = a2 = a3 = 0.0;
n1 = n2 = n3 = 0;
+ initscr();
+ erase();
+
lt = 0;
+ while (1) {
+ clock_gettime(CLOCK_REALTIME, &ts);
+ tt = ts.tv_nsec * 1e-9 + ts.tv_sec;
+ lt = tt - lt;
+ rt = ts.tv_sec - VSL_stats->start_time;
+
+ move(0,0);
+ i = 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);
+ hit = (intmax_t)VSL_stats->cache_hit -
+ (intmax_t)copy.cache_hit;
+ miss = (intmax_t)VSL_stats->cache_miss -
+ (intmax_t)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);
+ }
+ printw("Hitrate ratio: %8u %8u %8u\n", n1, n2, n3);
+ printw("Hitrate avg: %8.4f %8.4f %8.4f\n", a1, a2, a3);
+ printw("\n");
+
+#define MAC_STAT(n,t,f,d) \
+ ju = VSL_stats->n; \
+ printw("%12ju %10.2f " d "\n", ju, (ju - (intmax_t)copy.n)/lt); \
+ copy.n = ju;
+#include "stat_field.h"
+#undef MAC_STAT
+ lt = tt;
+ refresh();
+ sleep(1);
+ }
+}
+
+int
+main(int argc, char **argv)
+{
+ int c;
+ struct varnish_stats *VSL_stats;
+ int c_flag = 0;
+
VSL_stats = VSL_OpenStats();
while ((c = getopt(argc, argv, "c")) != -1) {
@@ -55,41 +114,7 @@
}
if (c_flag) {
- memset(©, 0, sizeof copy);
- initscr();
- erase();
-
- while (1) {
- clock_gettime(CLOCK_MONOTONIC, &ts);
- tt = ts.tv_nsec * 1e-9 + ts.tv_sec;
- lt = tt - lt;
- move(0,0);
- hit = (intmax_t)VSL_stats->cache_hit -
- (intmax_t)copy.cache_hit;
- miss = (intmax_t)VSL_stats->cache_miss -
- (intmax_t)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);
- }
- printw("Hitrate ratio: %8u %8u %8u\n", n1, n2, n3);
- printw("Hitrate avg: %8.4f %8.4f %8.4f\n", a1, a2, a3);
- printw("\n");
-
-#define MAC_STAT(n,t,f,d) \
- ju = VSL_stats->n; \
- printw("%12ju %10.2f " d "\n", ju, (ju - (intmax_t)copy.n)/lt); \
- copy.n = ju;
-#include "stat_field.h"
-#undef MAC_STAT
- lt = tt;
- refresh();
- sleep(1);
- }
+ do_curses(VSL_stats);
} else {
#define MAC_STAT(n,t,f,d) \
Modified: trunk/varnish-cache/include/stats.h
===================================================================
--- trunk/varnish-cache/include/stats.h 2006-07-19 20:07:16 UTC (rev 508)
+++ trunk/varnish-cache/include/stats.h 2006-07-19 21:14:41 UTC (rev 509)
@@ -3,6 +3,7 @@
#include <stdint.h>
struct varnish_stats {
+ time_t start_time;
#define MAC_STAT(n,t,f,e) t n;
#include "stat_field.h"
#undef MAC_STAT
More information about the varnish-commit
mailing list