Mercurial > hg > freeDiameter
comparison extensions/test_app/ta_bench.c @ 1206:ef7c5e39badf
Show benchmark statistics until all answers are received
author | Sebastien Decugis <sdecugis@freediameter.net> |
---|---|
date | Fri, 14 Jun 2013 17:30:01 +0800 |
parents | 16f2d2f15e5b |
children | 7945c75972b0 |
comparison
equal
deleted
inserted
replaced
1205:165569e8cba8 | 1206:ef7c5e39badf |
---|---|
196 | 196 |
197 /* The function called when the signal is received */ | 197 /* The function called when the signal is received */ |
198 static void ta_bench_start() { | 198 static void ta_bench_start() { |
199 struct timespec end_time, now; | 199 struct timespec end_time, now; |
200 struct ta_stats start, end; | 200 struct ta_stats start, end; |
201 int nsec = 0; | |
201 | 202 |
202 /* Save the initial stats */ | 203 /* Save the initial stats */ |
203 CHECK_POSIX_DO( pthread_mutex_lock(&ta_conf->stats_lock), ); | 204 CHECK_POSIX_DO( pthread_mutex_lock(&ta_conf->stats_lock), ); |
204 memcpy(&start, &ta_conf->stats, sizeof(struct ta_stats)); | 205 memcpy(&start, &ta_conf->stats, sizeof(struct ta_stats)); |
205 CHECK_POSIX_DO( pthread_mutex_unlock(&ta_conf->stats_lock), ); | 206 CHECK_POSIX_DO( pthread_mutex_unlock(&ta_conf->stats_lock), ); |
210 end_time.tv_sec += ta_conf->bench_duration; | 211 end_time.tv_sec += ta_conf->bench_duration; |
211 | 212 |
212 /* Now loop until timeout is reached */ | 213 /* Now loop until timeout is reached */ |
213 do { | 214 do { |
214 /* Do not create more that NB_CONCURRENT_MESSAGES in paralel */ | 215 /* 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); |
216 if (ret == -1) { | 217 if (ret == -1) { |
217 ret = errno; | 218 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 } | |
219 break; | 222 break; |
220 } | 223 } |
221 | 224 |
222 /* Update the current time */ | 225 /* Update the current time */ |
223 CHECK_SYS_DO( clock_gettime(CLOCK_REALTIME, &now), ); | 226 CHECK_SYS_DO( clock_gettime(CLOCK_REALTIME, &now), ); |
227 | 230 |
228 /* Create and send a new test message */ | 231 /* Create and send a new test message */ |
229 ta_bench_test_message(); | 232 ta_bench_test_message(); |
230 } while (1); | 233 } while (1); |
231 | 234 |
232 /* Save the stats now */ | 235 do { |
233 CHECK_POSIX_DO( pthread_mutex_lock(&ta_conf->stats_lock), ); | 236 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 */ | 237 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)); | 238 memcpy(&end, &ta_conf->stats, sizeof(struct ta_stats)); |
236 CHECK_POSIX_DO( pthread_mutex_unlock(&ta_conf->stats_lock), ); | 239 CHECK_POSIX_DO( pthread_mutex_unlock(&ta_conf->stats_lock), ); |
237 | 240 |
238 /* Now, display the statistics */ | 241 /* Now, display the statistics */ |
239 LOG_N( "------- app_test Benchmark result ---------"); | 242 LOG_N( "------- app_test Benchmark results, end sending +%ds ---------", nsec); |
240 if (now.tv_nsec >= end_time.tv_nsec) { | 243 if (now.tv_nsec >= end_time.tv_nsec) { |
241 LOG_N( " Executing for: %d.%06ld sec", | 244 LOG_N( " Executing for: %d.%06ld sec", |
242 (int)(now.tv_sec + ta_conf->bench_duration - end_time.tv_sec), | 245 (int)(now.tv_sec + ta_conf->bench_duration - end_time.tv_sec), |
243 (long)(now.tv_nsec - end_time.tv_nsec) / 1000); | 246 (long)(now.tv_nsec - end_time.tv_nsec) / 1000); |
244 } else { | 247 } else { |
245 LOG_N( " Executing for: %d.%06ld sec", | 248 LOG_N( " Executing for: %d.%06ld sec", |
246 (int)(now.tv_sec + ta_conf->bench_duration - 1 - end_time.tv_sec), | 249 (int)(now.tv_sec + ta_conf->bench_duration - 1 - end_time.tv_sec), |
247 (long)(now.tv_nsec + 1000000000 - end_time.tv_nsec) / 1000); | 250 (long)(now.tv_nsec + 1000000000 - end_time.tv_nsec) / 1000); |
248 } | 251 } |
249 LOG_N( " %llu messages sent", end.nb_sent - start.nb_sent); | 252 LOG_N( " %llu messages sent", end.nb_sent - start.nb_sent); |
250 LOG_N( " %llu error(s) received", end.nb_errs - start.nb_errs); | 253 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); | 254 LOG_N( " %llu answer(s) received", end.nb_recv - start.nb_recv); |
252 LOG_N( " Overall:"); | 255 LOG_N( " Overall:"); |
253 LOG_N( " fastest: %ld.%06ld sec.", end.shortest / 1000000, end.shortest % 1000000); | 256 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); | 257 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); | 258 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))); | 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))); |
257 LOG_N( "-------------------------------------"); | 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 --------------"); | |
258 | 266 |
259 } | 267 } |
260 | 268 |
261 | 269 |
262 int ta_bench_init(void) | 270 int ta_bench_init(void) |