Changeset 259 for pjproject/trunk
- Timestamp:
- Mar 1, 2006 10:26:51 PM (19 years ago)
- Location:
- pjproject/trunk/pjsip-apps/src/pjsip-perf
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjsip-apps/src/pjsip-perf/handler_options.c
r254 r259 114 114 pjsip_tx_data *tdata; 115 115 116 PJ_LOG(5,(THIS_FILE,"Sending OPTIONS request..")); 117 116 118 status = pjsip_endpt_create_request( settings.endpt, 117 119 &pjsip_options_method, -
pjproject/trunk/pjsip-apps/src/pjsip-perf/main.c
r257 r259 46 46 settings.thread_cnt = 1; 47 47 settings.local_port = 5060; 48 settings.log_level = 3; 49 settings.app_log_level = 3; 48 50 49 51 pjsip_method_set(&settings.method, PJSIP_OPTIONS_METHOD); … … 89 91 } 90 92 93 /***************************************************************************** 94 * This is a simple module to count and log messages 95 */ 96 static void on_rx_msg(pjsip_rx_data *rdata) 97 { 98 PJ_LOG(5,(THIS_FILE, "RX %d bytes %s from %s:%d:\n" 99 "%s\n" 100 "--end msg--", 101 rdata->msg_info.len, 102 pjsip_rx_data_get_info(rdata), 103 rdata->pkt_info.src_name, 104 rdata->pkt_info.src_port, 105 rdata->msg_info.msg_buf)); 106 } 107 108 static void on_tx_msg(pjsip_tx_data *tdata) 109 { 110 PJ_LOG(5,(THIS_FILE, "TX %d bytes %s to %s:%d:\n" 111 "%s\n" 112 "--end msg--", 113 (tdata->buf.cur - tdata->buf.start), 114 pjsip_tx_data_get_info(tdata), 115 tdata->tp_info.dst_name, 116 tdata->tp_info.dst_port, 117 tdata->buf.start)); 118 } 119 120 static pj_bool_t mod_counter_on_rx_request(pjsip_rx_data *rdata) 121 { 122 settings.rx_req++; 123 on_rx_msg(rdata); 124 return PJ_FALSE; 125 } 126 127 static pj_bool_t mod_counter_on_rx_response(pjsip_rx_data *rdata) 128 { 129 settings.rx_res++; 130 on_rx_msg(rdata); 131 return PJ_FALSE; 132 } 133 134 static pj_status_t mod_counter_on_tx_request(pjsip_tx_data *tdata) 135 { 136 settings.tx_req++; 137 on_tx_msg(tdata); 138 return PJ_SUCCESS; 139 } 140 141 static pj_status_t mod_counter_on_tx_response(pjsip_tx_data *tdata) 142 { 143 settings.tx_res++; 144 on_tx_msg(tdata); 145 return PJ_SUCCESS; 146 } 147 148 static pjsip_module mod_counter = 149 { 150 NULL, NULL, /* prev, next. */ 151 { "mod-counter", 11 }, /* Name. */ 152 -1, /* Id */ 153 PJSIP_MOD_PRIORITY_TRANSPORT_LAYER-1,/* Priority */ 154 NULL, /* load() */ 155 NULL, /* start() */ 156 NULL, /* stop() */ 157 NULL, /* unload() */ 158 &mod_counter_on_rx_request, /* on_rx_request() */ 159 &mod_counter_on_rx_response, /* on_rx_response() */ 160 &mod_counter_on_tx_request, /* on_tx_request. */ 161 &mod_counter_on_tx_response, /* on_tx_response() */ 162 NULL, /* on_tsx_state() */ 163 164 }; 165 166 167 /***************************************************************************** 168 * Console application custom logging: 169 */ 170 171 172 static FILE *log_file; 173 static void app_log_writer(int level, const char *buffer, int len) 174 { 175 /* Write to both stdout and file. */ 176 if (level <= settings.app_log_level) 177 pj_log_write(level, buffer, len); 178 179 if (log_file) { 180 fwrite(buffer, len, 1, log_file); 181 fflush(log_file); 182 } 183 } 184 185 186 static pj_status_t app_logging_init(void) 187 { 188 /* Redirect log function to ours */ 189 190 pj_log_set_log_func( &app_log_writer ); 191 192 /* If output log file is desired, create the file: */ 193 194 if (settings.log_file) { 195 log_file = fopen(settings.log_file, "wt"); 196 if (log_file == NULL) { 197 PJ_LOG(1,(THIS_FILE, "Unable to open log file %s", 198 settings.log_file)); 199 return -1; 200 } 201 } 202 203 return PJ_SUCCESS; 204 } 205 206 207 void app_logging_shutdown(void) 208 { 209 /* Close logging file, if any: */ 210 if (log_file) { 211 fclose(log_file); 212 log_file = NULL; 213 } 214 } 215 216 91 217 /* Initialize */ 92 218 static pj_status_t initialize(void) … … 95 221 int i; 96 222 pj_status_t status; 223 224 /* Init logging */ 225 if (app_logging_init() != PJ_SUCCESS) 226 return -1; 97 227 98 228 /* Create UDP transport. */ … … 151 281 152 282 283 /* Register message counter module. */ 284 status = pjsip_endpt_register_module(settings.endpt, &mod_counter); 285 if (status != PJ_SUCCESS) { 286 app_perror(THIS_FILE, "Unable to register module", status); 287 return status; 288 } 289 153 290 /* Start worker thread. */ 154 291 for (i=0; i<settings.thread_cnt; ++i) { … … 161 298 } 162 299 163 pj_log_set_level( 3);300 pj_log_set_level(settings.log_level); 164 301 return PJ_SUCCESS; 165 302 } … … 221 358 puts(" --help Display this help screen"); 222 359 puts(" --version Display version info"); 360 puts(""); 361 puts("Logging options:"); 362 puts(" --log-level=N Set log verbosity (default=3)"); 363 puts(" --app-log-level=N Set screen log verbosity (default=3)"); 364 puts(" --log-file=FILE Save log to FILE"); 223 365 puts(""); 224 366 puts("SIP options:"); … … 245 387 OPT_HELP, 246 388 OPT_VERSION, 389 OPT_LOG_LEVEL, 390 OPT_APP_LOG_LEVEL, 391 OPT_LOG_FILE, 247 392 OPT_LOCAL_PORT, 248 393 OPT_STATELESS, … … 255 400 { "help", 0, 0, OPT_HELP}, 256 401 { "version", 0, 0, OPT_VERSION}, 402 { "log-level", 1, 0, OPT_LOG_LEVEL}, 403 { "app-log-level", 1, 0, OPT_APP_LOG_LEVEL}, 404 { "log-file", 1, 0, OPT_LOG_FILE}, 257 405 { "local-port", 1, 0, OPT_LOCAL_PORT}, 258 406 { "stateless", 0, 0, OPT_STATELESS}, … … 276 424 pj_dump_config(); 277 425 return PJ_EINVAL; 426 427 case OPT_LOG_LEVEL: 428 settings.log_level = atoi(optarg); 429 break; 430 431 case OPT_APP_LOG_LEVEL: 432 settings.app_log_level = atoi(optarg); 433 break; 434 435 case OPT_LOG_FILE: 436 settings.log_file = optarg; 437 break; 278 438 279 439 case OPT_LOCAL_PORT: … … 417 577 pj_status_t status = PJ_SUCCESS; 418 578 pjsip_cred_info cred_info[1]; 579 pj_time_val elapsed; 419 580 420 581 unsigned i; … … 433 594 batch->failed = 0; 434 595 pj_gettimeofday(&batch->start_time); 596 batch->spawned_time = batch->start_time; 435 597 436 598 pj_list_push_back(&sess->active_list, batch); … … 454 616 455 617 batch->started++; 618 619 elapsed.sec = elapsed.msec = 0; 620 pjsip_endpt_handle_events(settings.endpt, &elapsed); 456 621 } 457 622 458 623 pj_gettimeofday(&batch->spawned_time); 624 625 /// 626 elapsed = batch->spawned_time; 627 PJ_TIME_VAL_SUB(elapsed, batch->start_time); 628 PJ_LOG(2,(THIS_FILE, "%d requests sent in %d ms", batch->started, 629 PJ_TIME_VAL_MSEC(elapsed))); 459 630 460 631 sess->total_created += batch->started; … … 480 651 static void start_session(pj_bool_t auto_repeat) 481 652 { 482 pj_time_val interval = { 1, 0 };653 pj_time_val interval = { 0, 0 }; 483 654 pj_pool_t *pool; 484 655 session *sess; … … 501 672 settings.session = sess; 502 673 503 spawn_batch(NULL, NULL); 674 settings.timer.cb = &spawn_batch; 675 pjsip_endpt_schedule_timer( settings.endpt, &settings.timer, &interval); 504 676 } 505 677 … … 523 695 settings.duration); 524 696 697 printf("| Total tx requests: %-7u rx requests: %-7u |\n", 698 settings.tx_req, settings.rx_req); 699 printf("| tx responses: %-7u rx responses: %-7u |\n", 700 settings.tx_res, settings.rx_res); 525 701 puts ("+--------------------------------------+-------------------------------------+"); 526 702 puts ("| Test Settings | Misc Commands: |"); … … 532 708 puts ("| Test Commands |"); 533 709 puts ("| |"); 534 puts ("| s Start single test batch 710 puts ("| s Start single test batch c Clear counters |"); 535 711 puts ("| sc Start continuous test x Stop continuous tests |"); 536 712 puts ("+----------------------------------------------------------------------------+"); … … 592 768 if (settings.session) { 593 769 settings.session->stopping = 1; 770 puts("Stopping sessions..."); 594 771 } else { 595 772 PJ_LOG(3,(THIS_FILE,"Error: no sessions")); 596 773 } 774 break; 775 776 case 'c': 777 /* Clear counters */ 778 settings.rx_req = settings.rx_res = settings.tx_req = 779 settings.tx_res = 0; 780 puts("Counters cleared"); 597 781 break; 598 782 -
pjproject/trunk/pjsip-apps/src/pjsip-perf/pjsip_perf.h
r257 r259 36 36 PJ_DECL_LIST_MEMBER(struct batch); 37 37 38 unsigned rate; 39 unsigned started; 40 unsigned success; 41 unsigned failed; 42 pj_time_val start_time; 43 pj_time_val spawned_time; 44 pj_time_val end_time; 38 unsigned rate; /**< How many tasks to perform */ 39 40 unsigned started; /**< # of tasks started. */ 41 unsigned success; /**< # of tasks completed successfully. */ 42 unsigned failed; /**< # of failed tasks. */ 43 44 pj_time_val start_time; /**< Start time of the tests. */ 45 pj_time_val spawned_time; /**< Time when all tasks has been started. */ 46 pj_time_val end_time; /**< Time when all tasks has completed. */ 45 47 }; 46 48 … … 113 115 pj_mutex_t *mutex; 114 116 117 /* Misc: */ 118 int log_level; 119 int app_log_level; 120 char *log_file; 121 115 122 /* Network: */ 116 123 int local_port; … … 147 154 session *session; 148 155 pj_timer_entry timer; 156 157 /* Counters: */ 158 pj_uint32_t tx_req; 159 pj_uint32_t tx_res; 160 pj_uint32_t rx_req; 161 pj_uint32_t rx_res; 149 162 }; 150 163
Note: See TracChangeset
for help on using the changeset viewer.