[master] e89cffc Add -p $period to varnishtop

Tollef Fog Heen tfheen at varnish-cache.org
Thu Mar 31 14:31:40 CEST 2011


commit e89cffc006159d2dd9a42cb891225b32b03d153e
Author: Tollef Fog Heen <tfheen at varnish-software.com>
Date:   Thu Mar 31 14:30:15 2011 +0200

    Add -p $period to varnishtop
    
    Make it possible to specify the period varnishtop should integrate
    numbers over.  This makes it easier to figure out per time period
    stats.

diff --git a/bin/varnishtop/varnishtop.c b/bin/varnishtop/varnishtop.c
index d01c290..3b834a0 100644
--- a/bin/varnishtop/varnishtop.c
+++ b/bin/varnishtop/varnishtop.c
@@ -147,12 +147,13 @@ accumulate(uint32_t * const p)
 }
 
 static void
-update(const struct VSM_data *vd)
+update(const struct VSM_data *vd, int period)
 {
 	struct top *tp, *tp2;
 	int l, len;
 	double t = 0;
 	static time_t last = 0;
+	static unsigned n;
 	time_t now;
 
 	now = time(NULL);
@@ -161,6 +162,8 @@ update(const struct VSM_data *vd)
 	last = now;
 
 	l = 1;
+	if (n < period)
+		n++;
 	AC(erase());
 	AC(mvprintw(0, 0, "%*s", COLS - 1, VSM_Name(vd)));
 	AC(mvprintw(0, 0, "list length %u", ntop));
@@ -175,7 +178,7 @@ update(const struct VSM_data *vd)
 			    len, len, tp->rec_data));
 			t = tp->count;
 		}
-		tp->count *= .999;
+		tp->count += (1.0/3.0 - tp->count) / (double)n;
 		if (tp->count * 10 < t || l > LINES * 10) {
 			VTAILQ_REMOVE(&top_head, tp, list);
 			free(tp->rec_data);
@@ -211,7 +214,7 @@ accumulate_thread(void *arg)
 }
 
 static void
-do_curses(struct VSM_data *vd)
+do_curses(struct VSM_data *vd, int period)
 {
 	pthread_t thr;
 	int i;
@@ -237,7 +240,7 @@ do_curses(struct VSM_data *vd)
 	AC(erase());
 	for (;;) {
 		AZ(pthread_mutex_lock(&mtx));
-		update(vd);
+		update(vd, period);
 		AZ(pthread_mutex_unlock(&mtx));
 
 		timeout(1000);
@@ -310,11 +313,12 @@ main(int argc, char **argv)
 {
 	struct VSM_data *vd;
 	int o, once = 0;
+	float period = 60; /* seconds */
 
 	vd = VSM_New();
 	VSL_Setup(vd);
 
-	while ((o = getopt(argc, argv, VSL_ARGS "1fV")) != -1) {
+	while ((o = getopt(argc, argv, VSL_ARGS "1fVp:")) != -1) {
 		switch (o) {
 		case '1':
 			AN(VSL_Arg(vd, 'd', NULL));
@@ -323,6 +327,14 @@ main(int argc, char **argv)
 		case 'f':
 			f_flag = 1;
 			break;
+		case 'p':
+			errno = 0;
+			period = strtol(optarg, NULL, 0);
+			if (errno != 0)  {
+				fprintf(stderr, "Syntax error, %s is not a number", optarg);
+				exit(1);
+			}
+			break;
 		case 'V':
 			varnish_version("varnishtop");
 			exit(0);
@@ -340,7 +352,7 @@ main(int argc, char **argv)
 		VSL_NonBlocking(vd, 1);
 		do_once(vd);
 	} else {
-		do_curses(vd);
+		do_curses(vd, period);
 	}
 	exit(0);
 }
diff --git a/doc/sphinx/reference/varnishtop.rst b/doc/sphinx/reference/varnishtop.rst
index 4c4899a..0fe65fc 100644
--- a/doc/sphinx/reference/varnishtop.rst
+++ b/doc/sphinx/reference/varnishtop.rst
@@ -60,6 +60,10 @@ The following options are available:
 -i tag      Include log entries with the specified tag.  If neither ``-I``
    	    nor ``-i`` is specified, all log entries are included.
 
+-p period   Specifies the number of seconds to measure over, the default
+            is 60 seconds. The first number in the list is the average
+            number of requests seen over this time period.
+
 -n          Specifies the name of the varnishd instance to get logs from.  
 	    If ``-n`` is not specified, the host name is used.
 



More information about the varnish-commit mailing list