Navigation


Changeset 1071:6ca6cadf209c in freeDiameter


Ignore:
Timestamp:
May 2, 2013, 12:22:31 PM (11 years ago)
Author:
Sebastien Decugis <sdecugis@freediameter.net>
Branch:
default
Phase:
public
Message:

Implement the fd_stat_getstats function; changed prototype of fd_fifo_length.

Files:
1 added
5 edited

Legend:

Unmodified
Added
Removed
  • extensions/dbg_interactive/queues.i

    r1060 r1071  
    6666        /* Get the length of the queue (nb elements) */
    6767        int length() {
    68                 int l;
    69                 int ret = fd_fifo_length ( $self, &l, NULL );
    70                 if (ret != 0) {
    71                         DI_ERROR(ret, NULL, NULL);
    72                 }
    73                 return l;
     68                return fd_fifo_length ( $self ) ;
    7469        }
    7570
  • include/freeDiameter/libfdcore.h

    r1069 r1071  
    10971097 *  stat          : Which queue is being queried
    10981098 *  peer          : (depending on the stat parameter) which peer is being queried
    1099  *  len          : (out) The number of items in the queue currently
    1100  *  max           : (out) The max number of items the queue accepts before becoming blocking -- 0 means no max.
     1099 *  current_count : (out) The number of items in the queue currently
     1100 *  limit_count   : (out) The max number of items the queue accepts before becoming blocking -- 0 means no max.
    11011101 *  highest_count : (out) The highest count the queue has reached since startup
    11021102 *  total_count   : (out) Total number of items that this queue has processed (always growing, use deltas for monitoring)
     
    11141114 */
    11151115int fd_stat_getstats(enum fd_stat_type stat, struct peer_hdr * peer,
    1116                         int * len, int * max, int * highest_count, long long * total_count,
     1116                        int * current_count, int * limit_count, int * highest_count, long long * total_count,
    11171117                        struct timespec * total, struct timespec * blocking, struct timespec * last);
    11181118
  • include/freeDiameter/libfdproto.h

    r1067 r1071  
    30323032
    30333033/*
     3034 * FUNCTION:    fd_fifo_getstats
     3035 *
     3036 * PARAMETERS:
     3037 *  queue         : The queue from which to retrieve the information.
     3038 *  current_count : How many items in the queue at the time of execution. This changes each time an item is pushed or poped.
     3039 *  limit_count   : The maximum number of items allowed in this queue. This is specified during queue creation.
     3040 *  highest_count : The maximum number of items this queue has contained. This enables to see if limit_count count was reached.
     3041 *  total_count   : the total number of items that went through the queue (already pop'd). Always increasing.
     3042 *  total         : Cumulated time all items spent in this queue, including blocking time (always growing, use deltas for monitoring)
     3043 *  blocking      : Cumulated time threads trying to post new items were blocked (queue full).
     3044 *  last          : For the last element retrieved from the queue, how long it take between posting (including blocking) and poping
     3045 * 
     3046 * DESCRIPTION:
     3047 *  Retrieve the timing information associated with a queue, for monitoring purpose.
     3048 *
     3049 * RETURN VALUE:
     3050 *  0           : The statistics have been updated.
     3051 *  EINVAL      : A parameter is invalid.
     3052 */
     3053int fd_fifo_getstats( struct fifo * queue, int * current_count, int * limit_count, int * highest_count, long long * total_count,
     3054                                           struct timespec * total, struct timespec * blocking, struct timespec * last);
     3055
     3056/*
    30343057 * FUNCTION:    fd_fifo_length
    30353058 *
    30363059 * PARAMETERS:
    30373060 *  queue       : The queue from which to retrieve the number of elements.
    3038  *  length      : Upon success, the current number of elements in the queue is stored here.
    3039  *  max         : the maximum number of elements as specified during creation. Can be NULL.
    3040  *
    3041  * DESCRIPTION:
    3042  *  Retrieve the number of elements in a queue.
    3043  *
    3044  * RETURN VALUE:
    3045  *  0           : The length of the queue has been written.
    3046  *  EINVAL      : A parameter is invalid.
    3047  */
    3048 int fd_fifo_length ( struct fifo * queue, int * length, int * max);
    3049 int fd_fifo_length_noerr ( struct fifo * queue ); /* no error checking version */
    3050 
    3051 /*
    3052  * FUNCTION:    fd_fifo_getstats
    3053  *
    3054  * PARAMETERS:
    3055  *  queue       : The queue from which to retrieve the timings information.
    3056  *  items       : the total number of items that went through the queue (already pop'd). Always increasing.
    3057  *  total       : Cumulated time all items spent in this queue, including blocking time (always growing, use deltas for monitoring)
    3058  *  blocking    : Cumulated time threads trying to post new items were blocked (queue full).
    3059  *  last        : For the last element retrieved from the queue, how long it take between posting (including blocking) and poping
    3060  * 
    3061  * DESCRIPTION:
    3062  *  Retrieve the timing information associated with a queue, for monitoring purpose.
    3063  *
    3064  * RETURN VALUE:
    3065  *  0           : The statistics have been updated.
    3066  *  EINVAL      : A parameter is invalid.
    3067  */
    3068 int fd_fifo_getstats( struct fifo * queue, long long *items, struct timespec * total, struct timespec * blocking, struct timespec * last);
    3069 
     3061 *
     3062 * DESCRIPTION:
     3063 *  Retrieve the number of elements in a queue, without error checking.
     3064 *
     3065 * RETURN VALUE:
     3066 *  The number of items currently queued.
     3067 */
     3068int fd_fifo_length ( struct fifo * queue );
    30703069
    30713070/*
  • libfdproto/fifo.c

    r1067 r1071  
    284284}
    285285
    286 /* Get the length of the queue */
    287 int fd_fifo_length ( struct fifo * queue, int * length, int * max )
    288 {
    289         TRACE_ENTRY( "%p %p %p", queue, length, max );
     286/* Get the information on the queue */
     287int fd_fifo_getstats( struct fifo * queue, int * current_count, int * limit_count, int * highest_count, long long * total_count,
     288                                           struct timespec * total, struct timespec * blocking, struct timespec * last)
     289{
     290        TRACE_ENTRY( "%p %p %p %p %p %p %p %p", queue, current_count, limit_count, highest_count, total_count, total, blocking, last);
    290291       
    291292        /* Check the parameters */
    292         CHECK_PARAMS( CHECK_FIFO( queue ) && length );
     293        CHECK_PARAMS( CHECK_FIFO( queue ) );
    293294       
    294295        /* lock the queue */
    295296        CHECK_POSIX(  pthread_mutex_lock( &queue->mtx )  );
    296297       
    297         /* Retrieve the count */
    298         *length = queue->count;
    299        
    300         if (max)
    301                 *max = queue->max;
     298        if (current_count)
     299                *current_count = queue->count;
     300       
     301        if (limit_count)
     302                *limit_count = queue->max;
     303       
     304        if (highest_count)
     305                *highest_count = queue->highest_ever;
     306       
     307        if (total_count)
     308                *total_count = queue->total_items;
     309       
     310        if (total)
     311                memcpy(total, &queue->total_time, sizeof(struct timespec));
     312       
     313        if (blocking)
     314                memcpy(blocking, &queue->blocking_time, sizeof(struct timespec));
     315       
     316        if (last)
     317                memcpy(last, &queue->last_time, sizeof(struct timespec));
    302318       
    303319        /* Unlock */
     
    308324}
    309325
    310 /* Get the timings */
    311 int fd_fifo_getstats( struct fifo * queue, long long *items, struct timespec * total, struct timespec * blocking, struct timespec * last)
    312 {
    313         TRACE_ENTRY( "%p %p %p %p %p", queue, items, total, blocking, last);
    314        
    315         /* Check the parameters */
    316         CHECK_PARAMS( CHECK_FIFO( queue ) );
    317        
    318         /* lock the queue */
    319         CHECK_POSIX(  pthread_mutex_lock( &queue->mtx )  );
    320        
    321         if (items)
    322                 *items = queue->total_items;
    323        
    324         if (total)
    325                 memcpy(total, &queue->total_time, sizeof(struct timespec));
    326        
    327         if (blocking)
    328                 memcpy(blocking, &queue->blocking_time, sizeof(struct timespec));
    329        
    330         if (last)
    331                 memcpy(last, &queue->last_time, sizeof(struct timespec));
    332        
    333         /* Unlock */
    334         CHECK_POSIX(  pthread_mutex_unlock( &queue->mtx )  );
    335        
    336         /* Done */
    337         return 0;
    338 }
    339 
    340326
    341327/* alternate version with no error checking */
    342 int fd_fifo_length_noerr ( struct fifo * queue )
     328int fd_fifo_length ( struct fifo * queue )
    343329{
    344330        if ( !CHECK_FIFO( queue ) )
  • tests/testfifo.c

    r1060 r1071  
    217217        {
    218218                struct fifo * queue = NULL;
    219                 int count, max;
    220219                struct msg * msg  = NULL;
     220                int max;
     221                long long count;
    221222               
    222223                /* Create the queue */
     
    224225               
    225226                /* Check the count is 0 */
    226                 CHECK( 0, fd_fifo_length(queue, &count, &max) );
    227                 CHECK( 0, count);
    228                 CHECK( 0, max);
     227                CHECK( 0, fd_fifo_length(queue) );
    229228               
    230229                /* Now enqueue */
     
    237236               
    238237                /* Check the count is 3 */
    239                 CHECK( 0, fd_fifo_length(queue, &count, &max) );
    240                 CHECK( 3, count);
    241                 CHECK( 0, max);
     238                CHECK( 3, fd_fifo_length(queue) );
    242239               
    243240                /* Retrieve the first message using fd_fifo_get */
    244241                CHECK( 0, fd_fifo_get(queue, &msg) );
    245242                CHECK( msg1, msg);
    246                 CHECK( 0, fd_fifo_length(queue, &count, NULL) );
    247                 CHECK( 2, count);
     243                CHECK( 2, fd_fifo_length(queue) );
    248244               
    249245                /* Retrieve the second message using fd_fifo_timedget */
     
    252248                CHECK( 0, fd_fifo_timedget(queue, &msg, &ts) );
    253249                CHECK( msg2, msg);
    254                 CHECK( 0, fd_fifo_length(queue, &count, NULL) );
    255                 CHECK( 1, count);
     250                CHECK( 1, fd_fifo_length(queue) );
    256251               
    257252                /* Retrieve the third message using meq_tryget */
    258253                CHECK( 0, fd_fifo_tryget(queue, &msg) );
    259254                CHECK( msg3, msg);
    260                 CHECK( 0, fd_fifo_length(queue, &count, NULL) );
    261                 CHECK( 0, count);
     255                CHECK( 0, fd_fifo_length(queue) );
    262256               
    263257                /* Check that another meq_tryget does not block */
    264258                CHECK( EWOULDBLOCK, fd_fifo_tryget(queue, &msg) );
    265                 CHECK( 0, fd_fifo_length(queue, &count, NULL) );
    266                 CHECK( 0, count);
     259                CHECK( 0, fd_fifo_length(queue) );
    267260               
    268261                /* Check the timedget actually timesout */
     
    274267                }
    275268                CHECK( ETIMEDOUT, fd_fifo_timedget(queue, &msg, &ts) );
    276                 CHECK( 0, fd_fifo_length(queue, &count, NULL) );
    277                 CHECK( 0, count);
     269                CHECK( 0, fd_fifo_length(queue) );
     270               
     271                /* Post & get another message */
     272                msg = msg1;
     273                CHECK( 0, fd_fifo_post(queue, &msg) );
     274                CHECK( 0, fd_fifo_timedget(queue, &msg, &ts) );
     275                CHECK( msg1, msg);             
     276               
     277                /* Check some statistics */
     278                CHECK( 0, fd_fifo_getstats(queue, NULL, NULL, &max, &count, NULL, NULL, NULL) );
     279                CHECK( 3, max );
     280                CHECK( 4, count );     
    278281               
    279282                /* We're done for basic tests */
     
    292295                pthread_t                thr [NBR_THREADS * 2];
    293296                struct dict_object      *dwr_model = NULL;
    294                 int                      count;
    295297                int                      i;
    296298                int                      nbr_threads;
     
    363365               
    364366                /* Check the count of the queue is back to 0 */
    365                 CHECK( 0, fd_fifo_length(queue, &count, NULL) );
    366                 CHECK( 0, count);
     367                CHECK( 0, fd_fifo_length(queue) );
    367368               
    368369                /* Destroy this queue and the messages */
Note: See TracChangeset for help on using the changeset viewer.