changeset 1067:23989d6c8390

Add total count in the statistics of the queues, thanks for the feedback :)
author Sebastien Decugis <sdecugis@freediameter.net>
date Tue, 30 Apr 2013 09:51:09 +0800
parents a455dbb7527c
children 54f06e95c2ee
files include/freeDiameter/libfdcore.h include/freeDiameter/libfdproto.h libfdproto/fifo.c
diffstat 3 files changed, 30 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/include/freeDiameter/libfdcore.h	Mon Apr 29 13:31:31 2013 +0200
+++ b/include/freeDiameter/libfdcore.h	Tue Apr 30 09:51:09 2013 +0800
@@ -1025,6 +1025,7 @@
  *  len	  	  : (out) The number of items in the queue currently
  *  max	  	  : (out) The max number of items the queue accepts before becoming blocking -- 0 means no max.
  *  highest_count : (out) The highest count the queue has reached since startup
+ *  total_count	  : (out) Total number of items that this queue has processed (always growing, use deltas for monitoring)
  *  total	  : (out) Cumulated time all items spent in this queue, including blocking time (always growing, use deltas for monitoring)
  *  blocking      : (out) Cumulated time threads trying to post new items were blocked (queue full).
  *  last          : (out) For the last element retrieved from the queue, how long it took between posting (including blocking) and poping
@@ -1038,7 +1039,7 @@
  *  EINVAL 	: A parameter is invalid.
  */
 int fd_stat_getstats(enum fd_stat_type stat, struct peer_hdr * peer, 
-			int * len, int * max, int * highest_count, 
+			int * len, int * max, int * highest_count, long long * total_count, 
 			struct timespec * total, struct timespec * blocking, struct timespec * last);
 
 #ifdef __cplusplus
--- a/include/freeDiameter/libfdproto.h	Mon Apr 29 13:31:31 2013 +0200
+++ b/include/freeDiameter/libfdproto.h	Tue Apr 30 09:51:09 2013 +0800
@@ -3053,6 +3053,7 @@
  *
  * PARAMETERS:
  *  queue	: The queue from which to retrieve the timings information.
+ *  items       : the total number of items that went through the queue (already pop'd). Always increasing.
  *  total	: Cumulated time all items spent in this queue, including blocking time (always growing, use deltas for monitoring)
  *  blocking    : Cumulated time threads trying to post new items were blocked (queue full).
  *  last        : For the last element retrieved from the queue, how long it take between posting (including blocking) and poping
@@ -3064,7 +3065,7 @@
  *  0		: The statistics have been updated.
  *  EINVAL 	: A parameter is invalid.
  */
-int fd_fifo_getstats( struct fifo * queue, struct timespec * total, struct timespec * blocking, struct timespec * last);
+int fd_fifo_getstats( struct fifo * queue, long long *items, struct timespec * total, struct timespec * blocking, struct timespec * last);
 
 
 /*
--- a/libfdproto/fifo.c	Mon Apr 29 13:31:31 2013 +0200
+++ b/libfdproto/fifo.c	Tue Apr 30 09:51:09 2013 +0800
@@ -70,6 +70,7 @@
 	int 		highest;/* The highest count value for which h_cb has been called */
 	int		highest_ever; /* The max count value this queue has reached (for tweaking) */
 	
+	long long	total_items;   /* Cumulated number of items that went through this fifo (excluding current count), always increasing. */
 	struct timespec total_time;    /* Cumulated time all items spent in this queue, including blocking time (always growing, use deltas for monitoring) */
 	struct timespec blocking_time; /* Cumulated time threads trying to post new items were blocked (queue full). */
 	struct timespec last_time;     /* For the last element retrieved from the queue, how long it take between posting (including blocking) and poping */
@@ -139,8 +140,9 @@
 			queue->high, queue->low, queue->highest, 
 			queue->h_cb, queue->l_cb, queue->data,
 			queue->highest_ever);
-	fd_log_debug("   timings: total:%ld.%06ld, blocking:%ld.%06ld, last:%ld.%06ld",
-			(long)queue->total_time.tv_sec,(long)(queue->total_time.tv_nsec/1000),
+	fd_log_debug("   stats: total:%lld in %ld.%06ld, blocking:%ld.%06ld, last:%ld.%06ld",
+			queue->total_items,
+	                (long)queue->total_time.tv_sec,(long)(queue->total_time.tv_nsec/1000), 
 			(long)queue->blocking_time.tv_sec,(long)(queue->blocking_time.tv_nsec/1000),
 			(long)queue->last_time.tv_sec,(long)(queue->last_time.tv_nsec/1000) );
 	
@@ -258,6 +260,22 @@
 	old->count = 0;
 	old->eyec = FIFO_EYEC;
 	
+	/* Merge the stats in the new queue */
+	new->total_items += old->total_items;
+	old->total_items = 0;
+	
+	new->total_time.tv_nsec += old->total_time.tv_nsec;
+	new->total_time.tv_sec += old->total_time.tv_sec + (new->total_time.tv_nsec / 1000000000);
+	new->total_time.tv_nsec %= 1000000000;
+	old->total_time.tv_nsec = 0;
+	old->total_time.tv_sec = 0;
+	
+	new->blocking_time.tv_nsec += old->blocking_time.tv_nsec;
+	new->blocking_time.tv_sec += old->blocking_time.tv_sec + (new->blocking_time.tv_nsec / 1000000000);
+	new->blocking_time.tv_nsec %= 1000000000;
+	old->blocking_time.tv_nsec = 0;
+	old->blocking_time.tv_sec = 0;
+	
 	/* Unlock, we're done */
 	CHECK_POSIX(  pthread_mutex_unlock( &new->mtx )  );
 	CHECK_POSIX(  pthread_mutex_unlock( &old->mtx )  );
@@ -290,9 +308,9 @@
 }
 
 /* Get the timings */
-int fd_fifo_getstats( struct fifo * queue, struct timespec * total, struct timespec * blocking, struct timespec * last)
+int fd_fifo_getstats( struct fifo * queue, long long *items, struct timespec * total, struct timespec * blocking, struct timespec * last)
 {
-	TRACE_ENTRY( "%p %p %p %p", queue, total, blocking, last);
+	TRACE_ENTRY( "%p %p %p %p %p", queue, items, total, blocking, last);
 	
 	/* Check the parameters */
 	CHECK_PARAMS( CHECK_FIFO( queue ) );
@@ -300,6 +318,9 @@
 	/* lock the queue */
 	CHECK_POSIX(  pthread_mutex_lock( &queue->mtx )  );
 	
+	if (items)
+		*items = queue->total_items;
+	
 	if (total)
 		memcpy(total, &queue->total_time, sizeof(struct timespec));
 	
@@ -466,6 +487,7 @@
 	fi = (struct fifo_item *)queue->list.next;
 	fd_list_unlink(&fi->item);
 	queue->count--;
+	queue->total_items++;
 	ret = fi->item.o;
 	
 	/* Update the timings */
"Welcome to our mercurial repository"