Changeset 1060:13fc3fc9c789 in freeDiameter
- Timestamp:
- Apr 29, 2013, 6:15:34 PM (11 years ago)
- Branch:
- default
- Phase:
- public
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
extensions/dbg_interactive/queues.i
r767 r1060 67 67 int length() { 68 68 int l; 69 int ret = fd_fifo_length ( $self, &l );69 int ret = fd_fifo_length ( $self, &l, NULL ); 70 70 if (ret != 0) { 71 71 DI_ERROR(ret, NULL, NULL); -
include/freeDiameter/libfdproto.h
r1052 r1060 3037 3037 * queue : The queue from which to retrieve the number of elements. 3038 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. 3039 3040 * 3040 3041 * DESCRIPTION: … … 3045 3046 * EINVAL : A parameter is invalid. 3046 3047 */ 3047 int fd_fifo_length ( struct fifo * queue, int * length 3048 int fd_fifo_length ( struct fifo * queue, int * length, int * max); 3048 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 * total : Cumulated time all items spent in this queue, including blocking time (always growing, use deltas for monitoring) 3057 * blocking : Cumulated time threads trying to post new items were blocked (queue full). 3058 * last : For the last element retrieved from the queue, how long it take between posting (including blocking) and poping 3059 * 3060 * DESCRIPTION: 3061 * Retrieve the timing information associated with a queue, for monitoring purpose. 3062 * 3063 * RETURN VALUE: 3064 * 0 : The statistics have been updated. 3065 * EINVAL : A parameter is invalid. 3066 */ 3067 int fd_fifo_getstats( struct fifo * queue, struct timespec * total, struct timespec * blocking, struct timespec * last); 3068 3049 3069 3050 3070 /* -
libfdproto/fifo.c
r974 r1060 70 70 int highest;/* The highest count value for which h_cb has been called */ 71 71 int highest_ever; /* The max count value this queue has reached (for tweaking) */ 72 73 struct timespec total_time; /* Cumulated time all items spent in this queue, including blocking time (always growing, use deltas for monitoring) */ 74 struct timespec blocking_time; /* Cumulated time threads trying to post new items were blocked (queue full). */ 75 struct timespec last_time; /* For the last element retrieved from the queue, how long it take between posting (including blocking) and poping */ 76 77 }; 78 79 struct fifo_item { 80 struct fd_list item; 81 struct timespec posted_on; 72 82 }; 73 83 … … 130 140 queue->h_cb, queue->l_cb, queue->data, 131 141 queue->highest_ever); 142 fd_log_debug(" timings: total:%ld.%06ld, blocking:%ld.%06ld, last:%ld.%06ld", 143 (long)queue->total_time.tv_sec,(long)(queue->total_time.tv_nsec/1000), 144 (long)queue->blocking_time.tv_sec,(long)(queue->blocking_time.tv_nsec/1000), 145 (long)queue->last_time.tv_sec,(long)(queue->last_time.tv_nsec/1000) ); 132 146 133 147 if (dump_item) { … … 135 149 int i = 0; 136 150 for (li = queue->list.next; li != &queue->list; li = li->next) { 137 fd_log_debug(" [%i] item %p in fifo %p:", i++, li->o, queue); 138 (*dump_item)(level, li->o); 151 struct fifo_item * fi = (struct fifo_item *)li; 152 fd_log_debug(" [%i] item %p in fifo %p, posted:ld.%06ld", 153 i++, fi->item.o, queue, (long)fi->posted_on.tv_sec,(long)(fi->posted_on.tv_nsec/1000)); 154 (*dump_item)(level, fi->item.o); 139 155 } 140 156 } … … 251 267 252 268 /* Get the length of the queue */ 253 int fd_fifo_length ( struct fifo * queue, int * length )254 { 255 TRACE_ENTRY( "%p %p ", queue, length);269 int fd_fifo_length ( struct fifo * queue, int * length, int * max ) 270 { 271 TRACE_ENTRY( "%p %p %p", queue, length, max ); 256 272 257 273 /* Check the parameters */ … … 264 280 *length = queue->count; 265 281 282 if (max) 283 *max = queue->max; 284 266 285 /* Unlock */ 267 286 CHECK_POSIX( pthread_mutex_unlock( &queue->mtx ) ); … … 270 289 return 0; 271 290 } 291 292 /* Get the timings */ 293 int fd_fifo_getstats( struct fifo * queue, struct timespec * total, struct timespec * blocking, struct timespec * last) 294 { 295 TRACE_ENTRY( "%p %p %p %p", queue, total, blocking, last); 296 297 /* Check the parameters */ 298 CHECK_PARAMS( CHECK_FIFO( queue ) ); 299 300 /* lock the queue */ 301 CHECK_POSIX( pthread_mutex_lock( &queue->mtx ) ); 302 303 if (total) 304 memcpy(total, &queue->total_time, sizeof(struct timespec)); 305 306 if (blocking) 307 memcpy(blocking, &queue->blocking_time, sizeof(struct timespec)); 308 309 if (last) 310 memcpy(last, &queue->last_time, sizeof(struct timespec)); 311 312 /* Unlock */ 313 CHECK_POSIX( pthread_mutex_unlock( &queue->mtx ) ); 314 315 /* Done */ 316 return 0; 317 } 318 272 319 273 320 /* alternate version with no error checking */ … … 326 373 int fd_fifo_post_int ( struct fifo * queue, void ** item ) 327 374 { 328 struct f d_list* new;375 struct fifo_item * new; 329 376 int call_cb = 0; 377 struct timespec posted_on, queued_on; 330 378 331 379 TRACE_ENTRY( "%p %p", queue, item ); … … 333 381 /* Check the parameters */ 334 382 CHECK_PARAMS( CHECK_FIFO( queue ) && item && *item ); 383 384 /* Get the timing of this call */ 385 CHECK_SYS( clock_gettime(CLOCK_REALTIME, &posted_on) ); 335 386 336 387 /* lock the queue */ … … 353 404 354 405 /* Create a new list item */ 355 CHECK_MALLOC_DO( new = malloc (sizeof (struct f d_list)) , {406 CHECK_MALLOC_DO( new = malloc (sizeof (struct fifo_item)) , { 356 407 pthread_mutex_unlock( &queue->mtx ); 357 408 } ); 358 409 359 fd_list_init( new, *item);410 fd_list_init(&new->item, *item); 360 411 *item = NULL; 361 412 362 413 /* Add the new item at the end */ 363 fd_list_insert_before( &queue->list, new);414 fd_list_insert_before( &queue->list, &new->item); 364 415 queue->count++; 365 416 if (queue->highest_ever < queue->count) … … 370 421 } 371 422 423 /* store timing */ 424 memcpy(&new->posted_on, &posted_on, sizeof(struct timespec)); 425 426 /* update queue timing info "blocking time" */ 427 { 428 long long blocked_ns; 429 CHECK_SYS( clock_gettime(CLOCK_REALTIME, &queued_on) ); 430 blocked_ns = (queued_on.tv_sec - posted_on.tv_sec) * 1000000000; 431 blocked_ns += (queued_on.tv_nsec - posted_on.tv_nsec); 432 blocked_ns += queue->blocking_time.tv_nsec; 433 queue->blocking_time.tv_sec += blocked_ns / 1000000000; 434 queue->blocking_time.tv_nsec = blocked_ns % 1000000000; 435 } 436 372 437 /* Signal if threads are asleep */ 373 438 if (queue->thrs > 0) { … … 394 459 { 395 460 void * ret = NULL; 396 struct fd_list * li; 461 struct fifo_item * fi; 462 struct timespec now; 397 463 398 464 ASSERT( ! FD_IS_LIST_EMPTY(&queue->list) ); 399 465 400 fd_list_unlink(li = queue->list.next); 466 fi = (struct fifo_item *)queue->list.next; 467 fd_list_unlink(&fi->item); 401 468 queue->count--; 402 ret = li->o; 403 free(li); 469 ret = fi->item.o; 470 471 /* Update the timings */ 472 CHECK_SYS_DO( clock_gettime(CLOCK_REALTIME, &now), goto skip_timing ); 473 { 474 long long elapsed = (now.tv_sec - fi->posted_on.tv_sec) * 1000000000; 475 elapsed += now.tv_nsec - fi->posted_on.tv_nsec; 476 477 queue->last_time.tv_sec = elapsed / 1000000000; 478 queue->last_time.tv_nsec = elapsed % 1000000000; 479 480 elapsed += queue->total_time.tv_nsec; 481 queue->total_time.tv_sec += elapsed / 1000000000; 482 queue->total_time.tv_nsec = elapsed % 1000000000; 483 } 484 skip_timing: 485 free(fi); 404 486 405 487 if (queue->thrs_push) { -
tests/testfifo.c
r972 r1060 217 217 { 218 218 struct fifo * queue = NULL; 219 int count ;219 int count, max; 220 220 struct msg * msg = NULL; 221 221 … … 224 224 225 225 /* Check the count is 0 */ 226 CHECK( 0, fd_fifo_length(queue, &count ) );226 CHECK( 0, fd_fifo_length(queue, &count, &max) ); 227 227 CHECK( 0, count); 228 CHECK( 0, max); 228 229 229 230 /* Now enqueue */ … … 236 237 237 238 /* Check the count is 3 */ 238 CHECK( 0, fd_fifo_length(queue, &count ) );239 CHECK( 0, fd_fifo_length(queue, &count, &max) ); 239 240 CHECK( 3, count); 241 CHECK( 0, max); 240 242 241 243 /* Retrieve the first message using fd_fifo_get */ 242 244 CHECK( 0, fd_fifo_get(queue, &msg) ); 243 245 CHECK( msg1, msg); 244 CHECK( 0, fd_fifo_length(queue, &count ) );246 CHECK( 0, fd_fifo_length(queue, &count, NULL) ); 245 247 CHECK( 2, count); 246 248 … … 250 252 CHECK( 0, fd_fifo_timedget(queue, &msg, &ts) ); 251 253 CHECK( msg2, msg); 252 CHECK( 0, fd_fifo_length(queue, &count ) );254 CHECK( 0, fd_fifo_length(queue, &count, NULL) ); 253 255 CHECK( 1, count); 254 256 … … 256 258 CHECK( 0, fd_fifo_tryget(queue, &msg) ); 257 259 CHECK( msg3, msg); 258 CHECK( 0, fd_fifo_length(queue, &count ) );260 CHECK( 0, fd_fifo_length(queue, &count, NULL) ); 259 261 CHECK( 0, count); 260 262 261 263 /* Check that another meq_tryget does not block */ 262 264 CHECK( EWOULDBLOCK, fd_fifo_tryget(queue, &msg) ); 263 CHECK( 0, fd_fifo_length(queue, &count ) );265 CHECK( 0, fd_fifo_length(queue, &count, NULL) ); 264 266 CHECK( 0, count); 265 267 … … 272 274 } 273 275 CHECK( ETIMEDOUT, fd_fifo_timedget(queue, &msg, &ts) ); 274 CHECK( 0, fd_fifo_length(queue, &count ) );276 CHECK( 0, fd_fifo_length(queue, &count, NULL) ); 275 277 CHECK( 0, count); 276 278 … … 361 363 362 364 /* Check the count of the queue is back to 0 */ 363 CHECK( 0, fd_fifo_length(queue, &count ) );365 CHECK( 0, fd_fifo_length(queue, &count, NULL) ); 364 366 CHECK( 0, count); 365 367
Note: See TracChangeset
for help on using the changeset viewer.