Changeset 581 for pjproject/trunk/pjsip-apps/src/samples/pjsip-perf.c
- Timestamp:
- Jul 3, 2006 2:18:17 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjsip-apps/src/samples/pjsip-perf.c
r580 r581 67 67 #include <stdio.h> 68 68 69 #define THIS_FILE "pjsip-perf.c" 70 #define DEFAULT_COUNT (PJSIP_MAX_TSX_COUNT/2>10000?10000:PJSIP_MAX_TSX_COUNT/2) 71 #define JOB_WINDOW DEFAULT_COUNT 69 #if defined(PJ_WIN32) && PJ_WIN32!=0 70 # include <windows.h> 71 #endif 72 73 #define THIS_FILE "pjsip-perf.c" 74 #define DEFAULT_COUNT (PJSIP_MAX_TSX_COUNT/2>10000?10000:PJSIP_MAX_TSX_COUNT/2) 75 #define JOB_WINDOW DEFAULT_COUNT 76 #define TERMINATE_TSX(x,c) 77 78 79 #ifndef CACHING_POOL_SIZE 80 # define CACHING_POOL_SIZE (256*1024*1024) 81 #endif 72 82 73 83 … … 139 149 job_finished, 140 150 job_window; 151 unsigned stat_max_window; 141 152 pj_time_val first_request; 142 153 pj_time_val last_completion; … … 588 599 589 600 /* Must create a pool factory before we can allocate any memory. */ 590 pj_caching_pool_init(&app.cp, &pj_pool_factory_default_policy, 0); 601 pj_caching_pool_init(&app.cp, &pj_pool_factory_default_policy, 602 CACHING_POOL_SIZE); 591 603 592 604 /* Create application pool for misc. */ … … 633 645 634 646 transport_type = "tcp"; 635 pj_sockaddr_in_init(&local_addr, 0, app.local_port);647 pj_sockaddr_in_init(&local_addr, 0, (pj_uint16_t)app.local_port); 636 648 status = pjsip_tcp_transport_start(app.sip_endpt, &local_addr, 637 649 app.thread_count, &tpfactory); … … 976 988 " --stateless, -s Set client to operate in stateless mode\n" 977 989 " (default: stateful)\n" 990 " --window=COUNT, -w Set maximum outstanding job in client (default: %d)\n" 978 991 " --real-sdp Generate real SDP from pjmedia, and also perform\n" 979 992 " proper SDP negotiation (default: dummy)\n" … … 986 999 " - sip:1@server-addr To handle requests statefully (INVITE and non-INVITE)\n" 987 1000 " - sip:2@server-addr To handle INVITE call (INVITE only)\n", 988 DEFAULT_COUNT );1001 DEFAULT_COUNT, JOB_WINDOW); 989 1002 } 990 1003 … … 1011 1024 { "verbose", 0, 0, 'v' }, 1012 1025 { "use-tcp", 0, 0, 'T' }, 1026 { "window", 1, 0, 'w' }, 1013 1027 { NULL, 0, 0, 0 }, 1014 1028 }; … … 1027 1041 /* Parse options */ 1028 1042 pj_optind = 0; 1029 while((c=pj_getopt_long(argc,argv, "p:c:m:t: hsv",1043 while((c=pj_getopt_long(argc,argv, "p:c:m:t:w:hsv", 1030 1044 long_options, &option_index))!=-1) 1031 1045 { … … 1091 1105 break; 1092 1106 1107 case 'w': 1108 app.client.job_window = my_atoi(pj_optarg); 1109 if (app.client.job_window <= 0) { 1110 PJ_LOG(3,(THIS_FILE, "Invalid --window %s", pj_optarg)); 1111 return -1; 1112 } 1113 break; 1114 1093 1115 case 'T': 1094 1116 app.use_tcp = PJ_TRUE; … … 1184 1206 tsx->mod_data[mod_test.id] = (void*)1; 1185 1207 1186 pjsip_tsx_terminate(tsx, tsx->status_code);1208 TERMINATE_TSX(tsx, tsx->status_code); 1187 1209 } 1188 1210 } … … 1220 1242 static int client_thread(void *arg) 1221 1243 { 1244 unsigned last_timeout_check = 0; 1222 1245 pj_time_val end_time, now; 1223 1246 … … 1240 1263 pj_status_t status; 1241 1264 1265 /* Calculate current outstanding job */ 1266 outstanding = app.client.job_submitted - app.client.job_finished; 1267 1268 /* Update stats on max outstanding jobs */ 1269 if (outstanding > (int)app.client.stat_max_window) 1270 app.client.stat_max_window = outstanding; 1271 1242 1272 /* Wait if there are more pending jobs than allowed in the 1243 1273 * window. 1244 1274 */ 1245 outstanding = app.client.job_submitted - app.client.job_finished; 1246 while (outstanding >= (int)app.client.job_window) { 1275 for (i=0; outstanding > (int)app.client.job_window && i<100; ++i) { 1247 1276 pjsip_endpt_handle_events(app.sip_endpt, &timeout); 1248 1277 outstanding = app.client.job_submitted - app.client.job_finished; 1249 1278 } 1250 1279 1280 1281 /* Submit one job */ 1251 1282 if (app.client.method.id == PJSIP_INVITE_METHOD) { 1252 1283 status = make_call(&app.client.dst_uri); … … 1259 1290 ++app.client.job_submitted; 1260 1291 1261 for (i=0; i<2; ++i) { 1262 unsigned cnt=0; 1263 pjsip_endpt_handle_events2(app.sip_endpt, &timeout, &cnt); 1264 if (cnt==0) 1292 /* Handle event */ 1293 pjsip_endpt_handle_events2(app.sip_endpt, &timeout, NULL); 1294 1295 /* Check for time out */ 1296 if (app.client.job_submitted - last_timeout_check >= 2000) { 1297 pj_gettimeofday(&now); 1298 if (PJ_TIME_VAL_GTE(now, end_time)) 1265 1299 break; 1300 last_timeout_check = app.client.job_submitted; 1266 1301 } 1267 1302 } … … 1272 1307 unsigned i; 1273 1308 1274 for (i=0; i<2; ++i) { 1275 unsigned cnt=0; 1276 pjsip_endpt_handle_events2(app.sip_endpt, &timeout, &cnt); 1277 if (cnt==0) 1278 break; 1309 for (i=0; i<2000; ++i) { 1310 pjsip_endpt_handle_events2(app.sip_endpt, &timeout, NULL); 1279 1311 } 1280 1312 … … 1353 1385 good_number(str_call, app.server.cur_state.call_cnt); 1354 1386 1355 printf("Total(rate): stateless:%s (%d/s), statefull:%s (%d/s), call:%s (%d/s) \r",1387 printf("Total(rate): stateless:%s (%d/s), statefull:%s (%d/s), call:%s (%d/s) \r", 1356 1388 str_stateless, stateless*1000/msec, 1357 1389 str_stateful, stateful*1000/msec, … … 1367 1399 } 1368 1400 1401 static void write_report(const char *msg) 1402 { 1403 puts(msg); 1404 1405 #if defined(PJ_WIN32) && PJ_WIN32!=0 1406 OutputDebugString(msg); 1407 OutputDebugString("\n"); 1408 #endif 1409 } 1410 1411 1369 1412 int main(int argc, char *argv[]) 1370 1413 { 1414 static char report[1024]; 1371 1415 1372 1416 if (create_app() != 0) … … 1459 1503 if (msec == 0) msec = 1; 1460 1504 1461 printf("Total %d %s sent, %d responses received in %d msec:\n" 1462 " - 2xx responses: %7d (rate=%d/sec)\n" 1463 " - 3xx responses: %7d (rate=%d/sec)\n" 1464 " - 4xx responses: %7d (rate=%d/sec)\n" 1465 " - 5xx responses: %7d (rate=%d/sec)\n" 1466 " - 6xx responses: %7d (rate=%d/sec)\n" 1467 " - 7xx responses: %7d (rate=%d/sec)\n" 1468 " ----------------\n" 1469 " TOTAL responses: %7d (rate=%d/sec)\n", 1470 app.client.job_submitted, test_type, 1471 app.client.total_responses, msec, 1472 app.client.status_class[2], app.client.status_class[2]*1000/msec, 1473 app.client.status_class[3], app.client.status_class[3]*1000/msec, 1474 app.client.status_class[4], app.client.status_class[4]*1000/msec, 1475 app.client.status_class[5], app.client.status_class[5]*1000/msec, 1476 app.client.status_class[6], app.client.status_class[6]*1000/msec, 1477 app.client.status_class[7], app.client.status_class[7]*1000/msec, 1478 app.client.total_responses, app.client.total_responses*1000/msec); 1505 pj_ansi_snprintf( 1506 report, sizeof(report), 1507 "Total %d %s sent, %d responses received in %d ms:\n" 1508 " - 2xx responses: %7d (rate=%d/sec)\n" 1509 " - 3xx responses: %7d (rate=%d/sec)\n" 1510 " - 4xx responses: %7d (rate=%d/sec)\n" 1511 " - 5xx responses: %7d (rate=%d/sec)\n" 1512 " - 6xx responses: %7d (rate=%d/sec)\n" 1513 " - 7xx responses: %7d (rate=%d/sec)\n" 1514 " ----------------\n" 1515 " TOTAL responses: %7d (rate=%d/sec)\n", 1516 app.client.job_submitted, test_type, 1517 app.client.total_responses, msec, 1518 app.client.status_class[2], app.client.status_class[2]*1000/msec, 1519 app.client.status_class[3], app.client.status_class[3]*1000/msec, 1520 app.client.status_class[4], app.client.status_class[4]*1000/msec, 1521 app.client.status_class[5], app.client.status_class[5]*1000/msec, 1522 app.client.status_class[6], app.client.status_class[6]*1000/msec, 1523 app.client.status_class[7], app.client.status_class[7]*1000/msec, 1524 app.client.total_responses, app.client.total_responses*1000/msec); 1525 1526 write_report(report); 1527 1528 pj_ansi_sprintf(report, "Maximum outstanding job: %d", 1529 app.client.stat_max_window); 1530 write_report(report); 1531 1479 1532 1480 1533 } else {
Note: See TracChangeset
for help on using the changeset viewer.