[master] 399aab7 Cast to integer to prevent negative values messing the statistics

Martin Blix Grydeland martin at varnish-software.com
Thu Sep 10 15:35:10 CEST 2015


commit 399aab778dec87bae5212e1ef65c9f48bf692c23
Author: Martin Blix Grydeland <martin at varnish-software.com>
Date:   Thu Sep 10 15:31:14 2015 +0200

    Cast to integer to prevent negative values messing the statistics
    
    Negative values can occur intermittently due to per worker caching of
    changes to counters.
    
    Fixes: #1778

diff --git a/bin/varnishstat/varnishstat_curses.c b/bin/varnishstat/varnishstat_curses.c
index 4637b61..3dd4230 100644
--- a/bin/varnishstat/varnishstat_curses.c
+++ b/bin/varnishstat/varnishstat_curses.c
@@ -384,14 +384,14 @@ sample_points(void)
 		pt->t_cur = VTIM_mono();
 
 		if (pt->t_last)
-			pt->chg = ((intmax_t)pt->cur - (intmax_t)pt->last) /
+			pt->chg = ((int64_t)pt->cur - (int64_t)pt->last) /
 			    (pt->t_cur - pt->t_last);
 
 		if (pt->semantics == 'g') {
 			pt->avg = 0.;
-			update_ma(&pt->ma_10, pt->cur);
-			update_ma(&pt->ma_100, pt->cur);
-			update_ma(&pt->ma_1000, pt->cur);
+			update_ma(&pt->ma_10, (int64_t)pt->cur);
+			update_ma(&pt->ma_100, (int64_t)pt->cur);
+			update_ma(&pt->ma_1000, (int64_t)pt->cur);
 		} else if (pt->semantics == 'c') {
 			if (VSC_C_main != NULL && VSC_C_main->uptime)
 				pt->avg = pt->cur / VSC_C_main->uptime;



More information about the varnish-commit mailing list