Changeset 603
- Timestamp:
- Jul 11, 2006 12:25:45 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjsip-apps/src/samples/pjsip-perf.c
r602 r603 155 155 pj_time_val last_completion; 156 156 unsigned total_responses; 157 unsigned status_class[7];157 unsigned response_codes[800]; 158 158 } client; 159 159 … … 568 568 { 569 569 app.client.job_finished++; 570 app.client.status_class[status_code/100]++; 570 if (status_code >= 200 && status_code < 800) 571 app.client.response_codes[status_code]++; 571 572 app.client.total_responses++; 572 573 pj_gettimeofday(&app.client.last_completion); … … 1258 1259 static int client_thread(void *arg) 1259 1260 { 1260 unsigned last_timeout_check = 0;1261 1261 pj_time_val end_time, last_report, now; 1262 1262 unsigned thread_index = (unsigned)arg; 1263 unsigned cycle = 0, last_cycle = 0; 1263 1264 1264 1265 pj_thread_sleep(100); … … 1288 1289 1289 1290 /* Wait if there are more pending jobs than allowed in the 1290 * window. 1291 * window. But spawn a new job anyway if no events are happening 1292 * after we wait for some time. 1291 1293 */ 1292 for (i=0; outstanding > (int)app.client.job_window && i<100; ++i) { 1293 pjsip_endpt_handle_events(app.sip_endpt, &timeout); 1294 for (i=0; outstanding > (int)app.client.job_window && i<1000; ++i) { 1295 pj_time_val wait = { 0, 500 }; 1296 unsigned count = 0; 1297 1298 pjsip_endpt_handle_events2(app.sip_endpt, &wait, &count); 1294 1299 outstanding = app.client.job_submitted - app.client.job_finished; 1300 1301 if (count == 0) 1302 break; 1303 1304 ++cycle; 1295 1305 } 1296 1306 … … 1306 1316 1307 1317 ++app.client.job_submitted; 1318 ++cycle; 1308 1319 1309 1320 /* Handle event */ … … 1311 1322 1312 1323 /* Check for time out, also print report */ 1313 if ( app.client.job_submitted - last_timeout_check>= 500) {1324 if (cycle - last_cycle >= 500) { 1314 1325 pj_gettimeofday(&now); 1315 1326 if (PJ_TIME_VAL_GTE(now, end_time)) { 1316 1327 break; 1317 1328 } 1318 last_ timeout_check = app.client.job_submitted;1329 last_cycle = cycle; 1319 1330 1320 1331 … … 1361 1372 } 1362 1373 1363 /* Wait couple of seconds if there are still unfinished jobs*/1374 /* Wait couple of seconds to let jobs completes (e.g. ACKs to be sent) */ 1364 1375 pj_gettimeofday(&now); 1365 1376 end_time = now; 1366 1377 end_time.sec += 2; 1367 while (PJ_TIME_VAL_LT(now, end_time) && 1368 app.client.job_finished < app.client.job_submitted) 1378 while (PJ_TIME_VAL_LT(now, end_time)) 1369 1379 { 1370 1380 pj_time_val timeout = { 0, 1 }; … … 1585 1595 report, sizeof(report), 1586 1596 "Total %d %s sent in %d ms at rate of %d/sec\n" 1587 "Total %d responses receieved in %d ms:\n" 1588 " - 2xx responses: %7d (rate=%d/sec)\n" 1589 " - 3xx responses: %7d (rate=%d/sec)\n" 1590 " - 4xx responses: %7d (rate=%d/sec)\n" 1591 " - 5xx responses: %7d (rate=%d/sec)\n" 1592 " - 6xx responses: %7d (rate=%d/sec)\n" 1593 " - 7xx responses: %7d (rate=%d/sec)\n" 1594 " ----------------\n" 1595 " TOTAL responses: %7d (rate=%d/sec)\n", 1597 "Total %d responses receieved in %d ms at rate of %d/sec:", 1596 1598 app.client.job_submitted, test_type, msec_req, 1597 1599 app.client.job_submitted * 1000 / msec_req, 1598 1600 app.client.total_responses, msec_res, 1599 app.client.status_class[2], app.client.status_class[2]*1000/msec_res, 1600 app.client.status_class[3], app.client.status_class[3]*1000/msec_res, 1601 app.client.status_class[4], app.client.status_class[4]*1000/msec_res, 1602 app.client.status_class[5], app.client.status_class[5]*1000/msec_res, 1603 app.client.status_class[6], app.client.status_class[6]*1000/msec_res, 1604 app.client.status_class[7], app.client.status_class[7]*1000/msec_res, 1605 app.client.total_responses, app.client.total_responses*1000/msec_res); 1601 app.client.total_responses*1000/msec_res); 1602 write_report(report); 1603 1604 /* Print detailed response code received */ 1605 pj_ansi_sprintf(report, "\nDetailed responses received:"); 1606 write_report(report); 1607 1608 for (i=0; i<PJ_ARRAY_SIZE(app.client.response_codes); ++i) { 1609 const pj_str_t *reason; 1610 1611 if (app.client.response_codes[i] == 0) 1612 continue; 1613 1614 reason = pjsip_get_status_text(i); 1615 pj_ansi_snprintf( report, sizeof(report), 1616 " - %d responses: %7d (%.*s)", 1617 i, app.client.response_codes[i], 1618 (int)reason->slen, reason->ptr); 1619 write_report(report); 1620 } 1621 1622 /* Total responses and rate */ 1623 pj_ansi_snprintf( report, sizeof(report), 1624 " ------\n" 1625 " TOTAL responses: %7d (rate=%d/sec)\n", 1626 app.client.total_responses, 1627 app.client.total_responses*1000/msec_res); 1606 1628 1607 1629 write_report(report); … … 1618 1640 unsigned i; 1619 1641 1620 puts("");1621 1642 puts("pjsip-perf started in server-mode"); 1622 1643 1623 1644 printf("Receiving requests on the following URIs:\n" 1624 " sip:0@%.*s:%d ;transport=%s for stateless handling (non-INVITE only)\n"1625 " sip:1@%.*s:%d ;transport=%s for stateful handling (INVITE and non-INVITE)\n"1626 " sip:2@%.*s:%d ;transport=%s for call handling (INVITE only)\n",1645 " sip:0@%.*s:%d%s for stateless handling\n" 1646 " sip:1@%.*s:%d%s for stateful handling\n" 1647 " sip:2@%.*s:%d%s for call handling\n", 1627 1648 (int)app.local_addr.slen, 1628 1649 app.local_addr.ptr, 1629 1650 app.local_port, 1630 (app.use_tcp ? " tcp" : "udp"),1651 (app.use_tcp ? ";transport=tcp" : ""), 1631 1652 (int)app.local_addr.slen, 1632 1653 app.local_addr.ptr, 1633 1654 app.local_port, 1634 (app.use_tcp ? " tcp" : "udp"),1655 (app.use_tcp ? ";transport=tcp" : ""), 1635 1656 (int)app.local_addr.slen, 1636 1657 app.local_addr.ptr, 1637 1658 app.local_port, 1638 (app.use_tcp ? " tcp" : "udp"));1659 (app.use_tcp ? ";transport=tcp" : "")); 1639 1660 1640 1661 for (i=0; i<app.thread_count; ++i) { … … 1647 1668 } 1648 1669 1649 puts(" Press <ENTER> to quit");1670 puts("\nPress <ENTER> to quit\n"); 1650 1671 fflush(stdout); 1651 1672 fgets(s, sizeof(s), stdin); … … 1656 1677 app.thread[i] = NULL; 1657 1678 } 1679 1680 puts(""); 1658 1681 } 1659 1682
Note: See TracChangeset
for help on using the changeset viewer.