Changeset 572:b1b56d4682d0 in freeDiameter for extensions/test_app/test_app.c
- Timestamp:
- Oct 8, 2010, 3:30:36 PM (14 years ago)
- Branch:
- default
- Phase:
- public
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
extensions/test_app/test_app.c
r258 r572 43 43 struct ta_conf * ta_conf = NULL; 44 44 static struct ta_conf _conf; 45 static pthread_t ta_stats_th = (pthread_t)NULL; 45 46 46 47 static int ta_conf_init(void) … … 59 60 ta_conf->signal = TEST_APP_DEFAULT_SIGNAL; 60 61 62 /* Initialize the mutex */ 63 CHECK_POSIX( pthread_mutex_init(&ta_conf->stats_lock, NULL) ); 64 61 65 return 0; 62 66 } … … 71 75 fd_log_debug( " Command Id ......... : %u\n", ta_conf->cmd_id); 72 76 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)" : ""); 74 78 fd_log_debug( " Destination Realm .. : %s\n", ta_conf->dest_realm ?: "- none -"); 75 79 fd_log_debug( " Destination Host ... : %s\n", ta_conf->dest_host ?: "- none -"); 76 80 fd_log_debug( " Signal ............. : %i\n", ta_conf->signal); 77 81 fd_log_debug( "------- /app_test configuration dump ---------\n"); 82 } 83 84 /* Function to display statistics every 10 seconds */ 85 static 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(©, &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 */ 78 134 } 79 135 … … 104 160 /* Start the signal handler thread */ 105 161 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 } 107 167 } 108 168 109 169 /* Advertise the support for the test application in the peer */ 110 170 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) ); 111 174 112 175 return 0; … … 120 183 if (ta_conf->mode & MODE_SERV) 121 184 ta_serv_fini(); 185 CHECK_FCT_DO( fd_thr_term(&ta_stats_th), ); 186 CHECK_POSIX_DO( pthread_mutex_destroy(&ta_conf->stats_lock), ); 122 187 } 123 188
Note: See TracChangeset
for help on using the changeset viewer.