Index: extensions/dbg_interactive/queues.i
===================================================================
--- extensions/dbg_interactive/queues.i	(revision 1060)
+++ extensions/dbg_interactive/queues.i	(revision 1071)
@@ -66,10 +66,5 @@
 	/* Get the length of the queue (nb elements) */
 	int length() {
-		int l;
-		int ret = fd_fifo_length ( $self, &l, NULL );
-		if (ret != 0) {
-			DI_ERROR(ret, NULL, NULL);
-		}
-		return l;
+		return fd_fifo_length ( $self ) ;
 	}
 
Index: include/freeDiameter/libfdcore.h
===================================================================
--- include/freeDiameter/libfdcore.h	(revision 1069)
+++ include/freeDiameter/libfdcore.h	(revision 1071)
@@ -1097,6 +1097,6 @@
  *  stat	  : Which queue is being queried
  *  peer	  : (depending on the stat parameter) which peer is being queried
- *  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.
+ *  current_count : (out) The number of items in the queue currently
+ *  limit_count   : (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)
@@ -1114,5 +1114,5 @@
  */
 int fd_stat_getstats(enum fd_stat_type stat, struct peer_hdr * peer, 
-			int * len, int * max, int * highest_count, long long * total_count, 
+			int * current_count, int * limit_count, int * highest_count, long long * total_count,
 			struct timespec * total, struct timespec * blocking, struct timespec * last);
 
Index: include/freeDiameter/libfdproto.h
===================================================================
--- include/freeDiameter/libfdproto.h	(revision 1067)
+++ include/freeDiameter/libfdproto.h	(revision 1071)
@@ -3032,40 +3032,39 @@
 
 /*
+ * FUNCTION:	fd_fifo_getstats
+ *
+ * PARAMETERS:
+ *  queue	  : The queue from which to retrieve the information.
+ *  current_count : How many items in the queue at the time of execution. This changes each time an item is pushed or poped.
+ *  limit_count   : The maximum number of items allowed in this queue. This is specified during queue creation.
+ *  highest_count : The maximum number of items this queue has contained. This enables to see if limit_count count was reached.
+ *  total_count   : 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
+ *  
+ * DESCRIPTION: 
+ *  Retrieve the timing information associated with a queue, for monitoring purpose.
+ *
+ * RETURN VALUE:
+ *  0		: The statistics have been updated.
+ *  EINVAL 	: A parameter is invalid.
+ */
+int fd_fifo_getstats( struct fifo * queue, int * current_count, int * limit_count, int * highest_count, long long * total_count, 
+				           struct timespec * total, struct timespec * blocking, struct timespec * last);
+
+/*
  * FUNCTION:	fd_fifo_length
  *
  * PARAMETERS:
  *  queue	: The queue from which to retrieve the number of elements.
- *  length	: Upon success, the current number of elements in the queue is stored here.
- *  max		: the maximum number of elements as specified during creation. Can be NULL.
- *
- * DESCRIPTION: 
- *  Retrieve the number of elements in a queue.
- *
- * RETURN VALUE:
- *  0		: The length of the queue has been written.
- *  EINVAL 	: A parameter is invalid.
- */
-int fd_fifo_length ( struct fifo * queue, int * length, int * max);
-int fd_fifo_length_noerr ( struct fifo * queue ); /* no error checking version */
-
-/*
- * FUNCTION:	fd_fifo_getstats
- *
- * 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
- *  
- * DESCRIPTION: 
- *  Retrieve the timing information associated with a queue, for monitoring purpose.
- *
- * RETURN VALUE:
- *  0		: The statistics have been updated.
- *  EINVAL 	: A parameter is invalid.
- */
-int fd_fifo_getstats( struct fifo * queue, long long *items, struct timespec * total, struct timespec * blocking, struct timespec * last);
-
+ *
+ * DESCRIPTION: 
+ *  Retrieve the number of elements in a queue, without error checking.
+ *
+ * RETURN VALUE:
+ *  The number of items currently queued.
+ */
+int fd_fifo_length ( struct fifo * queue );
 
 /*
Index: libfdcore/fifo_stats.c
===================================================================
--- libfdcore/fifo_stats.c	(revision 1071)
+++ libfdcore/fifo_stats.c	(revision 1071)
@@ -0,0 +1,79 @@
+/*********************************************************************************************************
+* Software License Agreement (BSD License)                                                               *
+* Author: Sebastien Decugis <sdecugis@freediameter.net>							 *
+*													 *
+* Copyright (c) 2013, WIDE Project and NICT								 *
+* All rights reserved.											 *
+* 													 *
+* Redistribution and use of this software in source and binary forms, with or without modification, are  *
+* permitted provided that the following conditions are met:						 *
+* 													 *
+* * Redistributions of source code must retain the above 						 *
+*   copyright notice, this list of conditions and the 							 *
+*   following disclaimer.										 *
+*    													 *
+* * Redistributions in binary form must reproduce the above 						 *
+*   copyright notice, this list of conditions and the 							 *
+*   following disclaimer in the documentation and/or other						 *
+*   materials provided with the distribution.								 *
+* 													 *
+* * Neither the name of the WIDE Project or NICT nor the 						 *
+*   names of its contributors may be used to endorse or 						 *
+*   promote products derived from this software without 						 *
+*   specific prior written permission of WIDE Project and 						 *
+*   NICT.												 *
+* 													 *
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED *
+* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
+* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR *
+* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 	 *
+* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 	 *
+* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR *
+* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF   *
+* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.								 *
+*********************************************************************************************************/
+
+#include "fdcore-internal.h"
+
+/* See include/freeDiameter/libfdcore.h for more information */
+int fd_stat_getstats(enum fd_stat_type stat, struct peer_hdr * peer, 
+			int * current_count, int * limit_count, int * highest_count, long long * total_count, 
+			struct timespec * total, struct timespec * blocking, struct timespec * last)
+{
+	struct fd_peer * p = (struct fd_peer *)peer;
+	TRACE_ENTRY( "%d %p %p %p %p %p %p %p %p", stat, peer, len, max, highest_count, total_count, total, blocking, last);
+	
+	switch (stat) {
+		case STAT_G_LOCAL: {
+			CHECK_FCT( fd_fifo_getstats(fd_g_local, current_count, limit_count, highest_count, total_count, total, blocking, last) );
+		}
+		break;
+
+		case STAT_G_INCOMING: {
+			CHECK_FCT( fd_fifo_getstats(fd_g_incoming, current_count, limit_count, highest_count, total_count, total, blocking, last) );
+		}
+		break;
+
+		case STAT_G_OUTGOING: {
+			CHECK_FCT( fd_fifo_getstats(fd_g_outgoing, current_count, limit_count, highest_count, total_count, total, blocking, last) );
+		}
+		break;
+
+		case STAT_P_PSM: {
+			CHECK_PARAMS( CHECK_PEER( peer ) );
+			CHECK_FCT( fd_fifo_getstats(p->p_events, current_count, limit_count, highest_count, total_count, total, blocking, last) );
+		}
+		break;
+
+		case STAT_P_TOSEND: {
+			CHECK_PARAMS( CHECK_PEER( peer ) );
+			CHECK_FCT( fd_fifo_getstats(p->p_tosend, current_count, limit_count, highest_count, total_count, total, blocking, last) );
+		}
+		break;
+
+		default:
+			return EINVAL;
+	}
+	
+	return 0;
+}
Index: libfdproto/fifo.c
===================================================================
--- libfdproto/fifo.c	(revision 1067)
+++ libfdproto/fifo.c	(revision 1071)
@@ -284,20 +284,36 @@
 }
 
-/* Get the length of the queue */
-int fd_fifo_length ( struct fifo * queue, int * length, int * max )
-{
-	TRACE_ENTRY( "%p %p %p", queue, length, max );
+/* Get the information on the queue */
+int fd_fifo_getstats( struct fifo * queue, int * current_count, int * limit_count, int * highest_count, long long * total_count, 
+				           struct timespec * total, struct timespec * blocking, struct timespec * last)
+{
+	TRACE_ENTRY( "%p %p %p %p %p %p %p %p", queue, current_count, limit_count, highest_count, total_count, total, blocking, last);
 	
 	/* Check the parameters */
-	CHECK_PARAMS( CHECK_FIFO( queue ) && length );
+	CHECK_PARAMS( CHECK_FIFO( queue ) );
 	
 	/* lock the queue */
 	CHECK_POSIX(  pthread_mutex_lock( &queue->mtx )  );
 	
-	/* Retrieve the count */
-	*length = queue->count;
-	
-	if (max)
-		*max = queue->max;
+	if (current_count)
+		*current_count = queue->count;
+	
+	if (limit_count)
+		*limit_count = queue->max;
+	
+	if (highest_count)
+		*highest_count = queue->highest_ever;
+	
+	if (total_count)
+		*total_count = queue->total_items;
+	
+	if (total)
+		memcpy(total, &queue->total_time, sizeof(struct timespec));
+	
+	if (blocking)
+		memcpy(blocking, &queue->blocking_time, sizeof(struct timespec));
+	
+	if (last)
+		memcpy(last, &queue->last_time, sizeof(struct timespec));
 	
 	/* Unlock */
@@ -308,37 +324,7 @@
 }
 
-/* Get the timings */
-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 %p", queue, items, total, blocking, last);
-	
-	/* Check the parameters */
-	CHECK_PARAMS( CHECK_FIFO( queue ) );
-	
-	/* 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));
-	
-	if (blocking)
-		memcpy(blocking, &queue->blocking_time, sizeof(struct timespec));
-	
-	if (last)
-		memcpy(last, &queue->last_time, sizeof(struct timespec));
-	
-	/* Unlock */
-	CHECK_POSIX(  pthread_mutex_unlock( &queue->mtx )  );
-	
-	/* Done */
-	return 0;
-}
-
 
 /* alternate version with no error checking */
-int fd_fifo_length_noerr ( struct fifo * queue )
+int fd_fifo_length ( struct fifo * queue )
 {
 	if ( !CHECK_FIFO( queue ) )
Index: tests/testfifo.c
===================================================================
--- tests/testfifo.c	(revision 1060)
+++ tests/testfifo.c	(revision 1071)
@@ -217,6 +217,7 @@
 	{
 		struct fifo * queue = NULL;
-		int count, max;
 		struct msg * msg  = NULL;
+		int max;
+		long long count;
 		
 		/* Create the queue */
@@ -224,7 +225,5 @@
 		
 		/* Check the count is 0 */
-		CHECK( 0, fd_fifo_length(queue, &count, &max) );
-		CHECK( 0, count);
-		CHECK( 0, max);
+		CHECK( 0, fd_fifo_length(queue) );
 		
 		/* Now enqueue */
@@ -237,13 +236,10 @@
 		
 		/* Check the count is 3 */
-		CHECK( 0, fd_fifo_length(queue, &count, &max) );
-		CHECK( 3, count);
-		CHECK( 0, max);
+		CHECK( 3, fd_fifo_length(queue) );
 		
 		/* Retrieve the first message using fd_fifo_get */
 		CHECK( 0, fd_fifo_get(queue, &msg) );
 		CHECK( msg1, msg);
-		CHECK( 0, fd_fifo_length(queue, &count, NULL) );
-		CHECK( 2, count);
+		CHECK( 2, fd_fifo_length(queue) );
 		
 		/* Retrieve the second message using fd_fifo_timedget */
@@ -252,17 +248,14 @@
 		CHECK( 0, fd_fifo_timedget(queue, &msg, &ts) );
 		CHECK( msg2, msg);
-		CHECK( 0, fd_fifo_length(queue, &count, NULL) );
-		CHECK( 1, count);
+		CHECK( 1, fd_fifo_length(queue) );
 		
 		/* Retrieve the third message using meq_tryget */
 		CHECK( 0, fd_fifo_tryget(queue, &msg) );
 		CHECK( msg3, msg);
-		CHECK( 0, fd_fifo_length(queue, &count, NULL) );
-		CHECK( 0, count);
+		CHECK( 0, fd_fifo_length(queue) );
 		
 		/* Check that another meq_tryget does not block */
 		CHECK( EWOULDBLOCK, fd_fifo_tryget(queue, &msg) );
-		CHECK( 0, fd_fifo_length(queue, &count, NULL) );
-		CHECK( 0, count);
+		CHECK( 0, fd_fifo_length(queue) );
 		
 		/* Check the timedget actually timesout */
@@ -274,6 +267,16 @@
 		}
 		CHECK( ETIMEDOUT, fd_fifo_timedget(queue, &msg, &ts) );
-		CHECK( 0, fd_fifo_length(queue, &count, NULL) );
-		CHECK( 0, count);
+		CHECK( 0, fd_fifo_length(queue) );
+		
+		/* Post & get another message */
+		msg = msg1;
+		CHECK( 0, fd_fifo_post(queue, &msg) );
+		CHECK( 0, fd_fifo_timedget(queue, &msg, &ts) );
+		CHECK( msg1, msg);		
+		
+		/* Check some statistics */
+		CHECK( 0, fd_fifo_getstats(queue, NULL, NULL, &max, &count, NULL, NULL, NULL) );
+		CHECK( 3, max );
+		CHECK( 4, count );	
 		
 		/* We're done for basic tests */
@@ -292,5 +295,4 @@
 		pthread_t  		 thr [NBR_THREADS * 2];
 		struct dict_object	*dwr_model = NULL;
-		int 			 count;
 		int			 i;
 		int			 nbr_threads;
@@ -363,6 +365,5 @@
 		
 		/* Check the count of the queue is back to 0 */
-		CHECK( 0, fd_fifo_length(queue, &count, NULL) );
-		CHECK( 0, count);
+		CHECK( 0, fd_fifo_length(queue) );
 		
 		/* Destroy this queue and the messages */
