Changeset 572:b1b56d4682d0 in freeDiameter
- Timestamp:
- Oct 8, 2010, 3:30:36 PM (14 years ago)
- Branch:
- default
- Phase:
- public
- Files:
-
- 1 added
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
doc/test_app.conf.sample
r336 r572 38 38 # mode = both; 39 39 40 # The behavior can be changed by specifying additional "benchmark;" keyword. 41 # When this keyword appears, it changes the behavior as follow: 42 # - server is silent on message reception, only the activity summary is displayed every 30 seconds 43 # - client attempts to send as many messages as possible during 10 seconds and counts them. 44 # benchmark; 45 40 46 ####################### 41 47 # Client-specific configuration -
extensions/test_app/CMakeLists.txt
r313 r572 16 16 ta_dict.c 17 17 ta_cli.c 18 ta_bench.c 18 19 ta_serv.c 19 20 ) -
extensions/test_app/ta_conf.l
r128 r572 153 153 } 154 154 155 (?i:"Benchmark") { 156 return BENCH; 157 } 158 155 159 156 160 /* Valid single characters for yyparse */ -
extensions/test_app/ta_conf.y
r127 r572 126 126 %token USER_NAME 127 127 %token SIGNAL 128 %token BENCH 128 129 129 130 /* Tokens and types for routing table definition */ … … 150 151 | conffile usrname 151 152 | conffile signal 153 | conffile bench 152 154 ; 153 155 … … 178 180 mode: MODE '=' INTEGER ';' 179 181 { 180 ta_conf->mode = $3; 182 ta_conf->mode = $3 | (ta_conf->mode & ~3); /* overwrite the 2 lsb */ 183 } 184 ; 185 186 bench: BENCH ';' 187 { 188 ta_conf->mode |= MODE_BENCH; 181 189 } 182 190 ; -
extensions/test_app/ta_serv.c
r406 r572 64 64 65 65 /* Value of Origin-Host */ 66 fprintf(stderr, "ECHO Test-Request received from "); 67 CHECK_FCT( fd_msg_search_avp ( *msg, ta_origin_host, &a) ); 68 if (a) { 69 struct avp_hdr * hdr; 70 CHECK_FCT( fd_msg_avp_hdr( a, &hdr ) ); 71 fprintf(stderr, "'%.*s'", (int)hdr->avp_value->os.len, hdr->avp_value->os.data); 72 } else { 73 fprintf(stderr, "no_Origin-Host"); 66 if (! (ta_conf->mode & MODE_BENCH)) { 67 fprintf(stderr, "ECHO Test-Request received from "); 68 CHECK_FCT( fd_msg_search_avp ( *msg, ta_origin_host, &a) ); 69 if (a) { 70 struct avp_hdr * hdr; 71 CHECK_FCT( fd_msg_avp_hdr( a, &hdr ) ); 72 fprintf(stderr, "'%.*s'", (int)hdr->avp_value->os.len, hdr->avp_value->os.data); 73 } else { 74 fprintf(stderr, "no_Origin-Host"); 75 } 76 fprintf(stderr, ", replying...\n"); 74 77 } 75 fprintf(stderr, ", replying...\n");76 78 77 79 /* Create answer header */ -
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 -
extensions/test_app/test_app.h
r258 r572 52 52 #define MODE_SERV 0x1 53 53 #define MODE_CLI 0x2 54 #define MODE_BENCH 0x4 54 55 55 56 /* The module configuration */ … … 64 65 char * user_name; /* default NULL */ 65 66 int signal; /* default TEST_APP_DEFAULT_SIGNAL */ 67 struct ta_stats { 68 unsigned long long nb_echoed; /* server */ 69 unsigned long long nb_sent; /* client */ 70 unsigned long long nb_recv; /* client */ 71 unsigned long long nb_errs; /* client */ 72 unsigned long shortest; /* fastest answer, in microseconds */ 73 unsigned long longest; /* slowest answer, in microseconds */ 74 unsigned long avg; /* average answer time, in microseconds */ 75 } stats; 76 pthread_mutex_t stats_lock; 66 77 }; 67 78 extern struct ta_conf * ta_conf; … … 77 88 int ta_cli_init(void); 78 89 void ta_cli_fini(void); 90 91 /* Benchmark flavour */ 92 int ta_bench_init(void); 93 void ta_bench_fini(void); 79 94 80 95 /* Initialize dictionary definitions */
Note: See TracChangeset
for help on using the changeset viewer.