Navigation


Changeset 572:b1b56d4682d0 in freeDiameter for extensions/test_app/test_app.c


Ignore:
Timestamp:
Oct 8, 2010, 3:30:36 PM (14 years ago)
Author:
Sebastien Decugis <sdecugis@nict.go.jp>
Branch:
default
Phase:
public
Message:

Added benchmark mode in test_app

File:
1 edited

Legend:

Unmodified
Added
Removed
  • extensions/test_app/test_app.c

    r258 r572  
    4343struct ta_conf * ta_conf = NULL;
    4444static struct ta_conf _conf;
     45static pthread_t ta_stats_th = (pthread_t)NULL;
    4546
    4647static int ta_conf_init(void)
     
    5960        ta_conf->signal     = TEST_APP_DEFAULT_SIGNAL;
    6061       
     62        /* Initialize the mutex */
     63        CHECK_POSIX( pthread_mutex_init(&ta_conf->stats_lock, NULL) );
     64       
    6165        return 0;
    6266}
     
    7175        fd_log_debug( " Command Id ......... : %u\n", ta_conf->cmd_id);
    7276        fd_log_debug( " AVP Id ............. : %u\n", ta_conf->avp_id);
    73         fd_log_debug( " Mode ............... : %s%s\n", ta_conf->mode & MODE_SERV ? "Serv" : "", ta_conf->mode & MODE_CLI ? "Cli" : "" );
     77        fd_log_debug( " Mode ............... : %s%s%s\n", ta_conf->mode & MODE_SERV ? "Serv" : "", ta_conf->mode & MODE_CLI ? "Cli" : "",  ta_conf->mode & MODE_BENCH ? " (Benchmark)" : "");
    7478        fd_log_debug( " Destination Realm .. : %s\n", ta_conf->dest_realm ?: "- none -");
    7579        fd_log_debug( " Destination Host ... : %s\n", ta_conf->dest_host ?: "- none -");
    7680        fd_log_debug( " Signal ............. : %i\n", ta_conf->signal);
    7781        fd_log_debug( "------- /app_test configuration dump ---------\n");
     82}
     83
     84/* Function to display statistics every 10 seconds */
     85static void * ta_stats(void * arg) {
     86
     87        struct timespec start, now;
     88        struct ta_stats copy;
     89       
     90        /* Get the start time */
     91        CHECK_SYS_DO( clock_gettime(CLOCK_REALTIME, &start), );
     92       
     93        /* Now, loop until canceled */
     94        while (1) {
     95                /* Display statistics every 30 seconds */
     96                sleep(30);
     97               
     98                /* Now, get the current stats */
     99                CHECK_POSIX_DO( pthread_mutex_lock(&ta_conf->stats_lock), );
     100                memcpy(&copy, &ta_conf->stats, sizeof(struct ta_stats));
     101                CHECK_POSIX_DO( pthread_mutex_unlock(&ta_conf->stats_lock), );
     102               
     103                /* Get the current execution time */
     104                CHECK_SYS_DO( clock_gettime(CLOCK_REALTIME, &now), );
     105               
     106                /* Now, display everything */
     107                fd_log_debug( "------- app_test statistics ---------\n");
     108                if (now.tv_nsec >= start.tv_nsec) {
     109                        fd_log_debug( " Executing for: %d.%06ld sec\n",
     110                                        (int)(now.tv_sec - start.tv_sec),
     111                                        (long)(now.tv_nsec - start.tv_nsec) / 1000);
     112                } else {
     113                        fd_log_debug( " Executing for: %d.%06ld sec\n",
     114                                        (int)(now.tv_sec - 1 - start.tv_sec),
     115                                        (long)(now.tv_nsec + 1000000000 - start.tv_nsec) / 1000);
     116                }
     117               
     118                if (ta_conf->mode & MODE_SERV) {
     119                        fd_log_debug( " Server: %llu messages echoed\n", copy.nb_echoed);
     120                }
     121                if (ta_conf->mode & MODE_CLI) {
     122                        fd_log_debug( " Client:\n");
     123                        fd_log_debug( "   %llu messages sent\n", copy.nb_sent);
     124                        fd_log_debug( "   %llu errors received\n", copy.nb_errs);
     125                        fd_log_debug( "   %llu answers received\n", copy.nb_recv);
     126                        fd_log_debug( "     fastest: %ld.%06ld sec.\n", copy.shortest / 1000000, copy.shortest % 1000000);
     127                        fd_log_debug( "     slowest: %ld.%06ld sec.\n", copy.longest / 1000000, copy.longest % 1000000);
     128                        fd_log_debug( "     Average: %ld.%06ld sec.\n", copy.avg / 1000000, copy.avg % 1000000);
     129                }
     130                fd_log_debug( "-------------------------------------\n");
     131        }
     132       
     133        return NULL; /* never called */
    78134}
    79135
     
    104160        /* Start the signal handler thread */
    105161        if (ta_conf->mode & MODE_CLI) {
    106                 CHECK_FCT( ta_cli_init() );
     162                if (ta_conf->mode & MODE_BENCH) {
     163                        CHECK_FCT( ta_bench_init() );
     164                } else {
     165                        CHECK_FCT( ta_cli_init() );
     166                }
    107167        }
    108168       
    109169        /* Advertise the support for the test application in the peer */
    110170        CHECK_FCT( fd_disp_app_support ( ta_appli, ta_vendor, 1, 0 ) );
     171       
     172        /* Start the statistics thread */
     173        CHECK_POSIX( pthread_create(&ta_stats_th, NULL, ta_stats, NULL) );
    111174       
    112175        return 0;
     
    120183        if (ta_conf->mode & MODE_SERV)
    121184                ta_serv_fini();
     185        CHECK_FCT_DO( fd_thr_term(&ta_stats_th), );
     186        CHECK_POSIX_DO( pthread_mutex_destroy(&ta_conf->stats_lock), );
    122187}
    123188
Note: See TracChangeset for help on using the changeset viewer.