Navigation


Changeset 1206:ef7c5e39badf in freeDiameter for extensions


Ignore:
Timestamp:
Jun 14, 2013, 6:30:01 PM (11 years ago)
Author:
Sebastien Decugis <sdecugis@freediameter.net>
Branch:
default
Phase:
public
Message:

Show benchmark statistics until all answers are received

File:
1 edited

Legend:

Unmodified
Added
Removed
  • extensions/test_app/ta_bench.c

    r1195 r1206  
    199199        struct timespec end_time, now;
    200200        struct ta_stats start, end;
     201        int nsec = 0;
    201202       
    202203        /* Save the initial stats */
     
    213214        do {
    214215                /* Do not create more that NB_CONCURRENT_MESSAGES in paralel */
    215                 int ret = sem_wait(&ta_sem);
     216                int ret = sem_timedwait(&ta_sem, &end_time);
    216217                if (ret == -1) {
    217218                        ret = errno;
    218                         CHECK_POSIX_DO(ret, ); /* Just to log it */
     219                        if (ret != ETIMEDOUT) {
     220                                CHECK_POSIX_DO(ret, ); /* Just to log it */
     221                        }
    219222                        break;
    220223                }
     
    230233        } while (1);
    231234       
    232         /* Save the stats now */
    233         CHECK_POSIX_DO( pthread_mutex_lock(&ta_conf->stats_lock), );
    234         CHECK_SYS_DO( clock_gettime(CLOCK_REALTIME, &now), ); /* Re-read the time because we might have spent some time wiating for the mutex */
    235         memcpy(&end, &ta_conf->stats, sizeof(struct ta_stats));
    236         CHECK_POSIX_DO( pthread_mutex_unlock(&ta_conf->stats_lock), );
    237        
    238         /* Now, display the statistics */
    239         LOG_N( "------- app_test Benchmark result ---------");
    240         if (now.tv_nsec >= end_time.tv_nsec) {
    241                 LOG_N( " Executing for: %d.%06ld sec",
    242                                 (int)(now.tv_sec + ta_conf->bench_duration - end_time.tv_sec),
    243                                 (long)(now.tv_nsec - end_time.tv_nsec) / 1000);
    244         } else {
    245                 LOG_N( " Executing for: %d.%06ld sec",
    246                                 (int)(now.tv_sec + ta_conf->bench_duration - 1 - end_time.tv_sec),
    247                                 (long)(now.tv_nsec + 1000000000 - end_time.tv_nsec) / 1000);
    248         }
    249         LOG_N( "   %llu messages sent", end.nb_sent - start.nb_sent);
    250         LOG_N( "   %llu error(s) received", end.nb_errs - start.nb_errs);
    251         LOG_N( "   %llu answer(s) received", end.nb_recv - start.nb_recv);
    252         LOG_N( "   Overall:");
    253         LOG_N( "     fastest: %ld.%06ld sec.", end.shortest / 1000000, end.shortest % 1000000);
    254         LOG_N( "     slowest: %ld.%06ld sec.", end.longest / 1000000, end.longest % 1000000);
    255         LOG_N( "     Average: %ld.%06ld sec.", end.avg / 1000000, end.avg % 1000000);
    256         LOG_N( "   Throughput: %llu messages / sec", (end.nb_recv - start.nb_recv) / (( now.tv_sec + ta_conf->bench_duration - end_time.tv_sec ) + ((now.tv_nsec - end_time.tv_nsec) / 1000000000)));
    257         LOG_N( "-------------------------------------");
     235        do {
     236                CHECK_POSIX_DO( pthread_mutex_lock(&ta_conf->stats_lock), );
     237                CHECK_SYS_DO( clock_gettime(CLOCK_REALTIME, &now), ); /* Re-read the time because we might have spent some time wiating for the mutex */
     238                memcpy(&end, &ta_conf->stats, sizeof(struct ta_stats));
     239                CHECK_POSIX_DO( pthread_mutex_unlock(&ta_conf->stats_lock), );
     240               
     241                /* Now, display the statistics */
     242                LOG_N( "------- app_test Benchmark results, end sending +%ds ---------", nsec);
     243                if (now.tv_nsec >= end_time.tv_nsec) {
     244                        LOG_N( " Executing for: %d.%06ld sec",
     245                                        (int)(now.tv_sec + ta_conf->bench_duration - end_time.tv_sec),
     246                                        (long)(now.tv_nsec - end_time.tv_nsec) / 1000);
     247                } else {
     248                        LOG_N( " Executing for: %d.%06ld sec",
     249                                        (int)(now.tv_sec + ta_conf->bench_duration - 1 - end_time.tv_sec),
     250                                        (long)(now.tv_nsec + 1000000000 - end_time.tv_nsec) / 1000);
     251                }
     252                LOG_N( "   %llu messages sent", end.nb_sent - start.nb_sent);
     253                LOG_N( "   %llu error(s) received", end.nb_errs - start.nb_errs);
     254                LOG_N( "   %llu answer(s) received", end.nb_recv - start.nb_recv);
     255                LOG_N( "   Overall:");
     256                LOG_N( "     fastest: %ld.%06ld sec.", end.shortest / 1000000, end.shortest % 1000000);
     257                LOG_N( "     slowest: %ld.%06ld sec.", end.longest / 1000000, end.longest % 1000000);
     258                LOG_N( "     Average: %ld.%06ld sec.", end.avg / 1000000, end.avg % 1000000);
     259                LOG_N( "   Throughput: %llu messages / sec", (end.nb_recv - start.nb_recv) / (( now.tv_sec + ta_conf->bench_duration - end_time.tv_sec ) + ((now.tv_nsec - end_time.tv_nsec) / 1000000000)));
     260                LOG_N( "-------------------------------------");
     261               
     262                nsec ++;
     263                sleep(1);
     264        } while ( (end.nb_sent - start.nb_sent) > (end.nb_errs - start.nb_errs) + (end.nb_recv - start.nb_recv) );
     265        LOG_N( "--------------- Test Complete --------------");
    258266
    259267}
Note: See TracChangeset for help on using the changeset viewer.