Mercurial > hg > freeDiameter
changeset 1071:6ca6cadf209c
Implement the fd_stat_getstats function; changed prototype of fd_fifo_length.
author | Sebastien Decugis <sdecugis@freediameter.net> |
---|---|
date | Thu, 02 May 2013 11:22:31 +0800 |
parents | ac5c105cbc08 |
children | 9a7d3ecbb44b |
files | extensions/dbg_interactive/queues.i include/freeDiameter/libfdcore.h include/freeDiameter/libfdproto.h libfdcore/fifo_stats.c libfdproto/fifo.c tests/testfifo.c |
diffstat | 6 files changed, 144 insertions(+), 84 deletions(-) [+] |
line wrap: on
line diff
--- a/extensions/dbg_interactive/queues.i Thu May 02 11:22:22 2013 +0800 +++ b/extensions/dbg_interactive/queues.i Thu May 02 11:22:31 2013 +0800 @@ -65,12 +65,7 @@ /* 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 ) ; } /* Is the threashold function useful here? TODO... */
--- a/include/freeDiameter/libfdcore.h Thu May 02 11:22:22 2013 +0800 +++ b/include/freeDiameter/libfdcore.h Thu May 02 11:22:31 2013 +0800 @@ -1096,8 +1096,8 @@ * PARAMETERS: * 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) * total : (out) Cumulated time all items spent in this queue, including blocking time (always growing, use deltas for monitoring) @@ -1113,7 +1113,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, 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); /*============================================================*/
--- a/include/freeDiameter/libfdproto.h Thu May 02 11:22:22 2013 +0800 +++ b/include/freeDiameter/libfdproto.h Thu May 02 11:22:31 2013 +0800 @@ -3031,32 +3031,17 @@ int fd_fifo_move ( struct fifo * oldq, struct fifo * newq, struct fifo ** loc_update ); /* - * 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 + * 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. @@ -3065,8 +3050,22 @@ * 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); - +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. + * + * 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 ); /* * FUNCTION: fd_fifo_setthrhd
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libfdcore/fifo_stats.c Thu May 02 11:22:31 2013 +0800 @@ -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; +}
--- a/libfdproto/fifo.c Thu May 02 11:22:22 2013 +0800 +++ b/libfdproto/fifo.c Thu May 02 11:22:31 2013 +0800 @@ -283,34 +283,11 @@ return 0; } -/* Get the length of the queue */ -int fd_fifo_length ( struct fifo * queue, int * length, int * 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", queue, length, max ); - - /* Check the parameters */ - CHECK_PARAMS( CHECK_FIFO( queue ) && length ); - - /* lock the queue */ - CHECK_POSIX( pthread_mutex_lock( &queue->mtx ) ); - - /* Retrieve the count */ - *length = queue->count; - - if (max) - *max = queue->max; - - /* Unlock */ - CHECK_POSIX( pthread_mutex_unlock( &queue->mtx ) ); - - /* Done */ - return 0; -} - -/* 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); + 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 ) ); @@ -318,8 +295,17 @@ /* lock the queue */ CHECK_POSIX( pthread_mutex_lock( &queue->mtx ) ); - if (items) - *items = queue->total_items; + 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)); @@ -339,7 +325,7 @@ /* 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 ) ) return 0;
--- a/tests/testfifo.c Thu May 02 11:22:22 2013 +0800 +++ b/tests/testfifo.c Thu May 02 11:22:31 2013 +0800 @@ -216,16 +216,15 @@ /* Basic operation */ { struct fifo * queue = NULL; - int count, max; struct msg * msg = NULL; + int max; + long long count; /* Create the queue */ CHECK( 0, fd_fifo_new(&queue, 0) ); /* 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 */ msg = msg1; @@ -236,34 +235,28 @@ CHECK( 0, fd_fifo_post(queue, &msg) ); /* 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 */ CHECK(0, clock_gettime(CLOCK_REALTIME, &ts)); ts.tv_sec += 1; /* Set the timeout to 1 second */ 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 */ CHECK(0, clock_gettime(CLOCK_REALTIME, &ts)); @@ -273,8 +266,18 @@ ts.tv_sec += 1; } 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 */ CHECK( 0, fd_fifo_del(&queue) ); @@ -291,7 +294,6 @@ struct msg *msgs[NBR_MSG * NBR_THREADS * 2], *msg; pthread_t thr [NBR_THREADS * 2]; struct dict_object *dwr_model = NULL; - int count; int i; int nbr_threads; #ifdef _POSIX_THREAD_THREADS_MAX @@ -362,8 +364,7 @@ } /* 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 */ CHECK( 0, fd_fifo_del(&queue) );