]> err.no Git - varnish/commitdiff
Include a "start_time" timestamp in the stats and teach varnishstats
authorphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Wed, 19 Jul 2006 21:14:41 +0000 (21:14 +0000)
committerphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Wed, 19 Jul 2006 21:14:41 +0000 (21:14 +0000)
to print it in curses mode.

Some polishing and cleanup.

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

varnish-cache/bin/varnishd/cache_main.c
varnish-cache/bin/varnishd/shmlog.c
varnish-cache/bin/varnishstat/varnishstat.c
varnish-cache/include/stats.h

index 4b97c48a0ad5fb29856daf3aecbde29550ddc5d7..8badc7ab2e32c0b8bde4c5d38fce5e235f803f0e 100644 (file)
@@ -130,6 +130,7 @@ child_main(void)
        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);
index 2aacd26daa1103f0ca8fe39676eaa520f0d3c9a8..05a18c48bafbb29126f4fe07b0b3e10fa141d700 100644 (file)
@@ -136,6 +136,7 @@ VSL_Init(void)
        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 @@ VSL_MgtInit(const char *fn, unsigned size)
         * management process as well.
         */
        VSL_Init();
-       memset(VSL_stats, 0, sizeof *VSL_stats);
 }
 
 /*--------------------------------------------------------------------*/
index 494323cb4671e18e523b4dc7250f770d44414099..38e678ab3996c1fb989bb50df03307b3074a68a3 100644 (file)
@@ -24,22 +24,81 @@ myexp(double *acc, double val, unsigned *n, unsigned nmax)
        (*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(&copy, 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();
 
@@ -55,41 +114,7 @@ main(int argc, char **argv)
        }
 
        if (c_flag) {
-               memset(&copy, 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) \
index 2c91a485d92b67c65bd82b07b07e4d891360377f..5dacec5365a66be67aab9ddb77b6f6bc4715a7f5 100644 (file)
@@ -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