Getting-Started/BB10: bb_measure_cpu.patch

File bb_measure_cpu.patch, 4.3 KB (added by bennylp, 11 years ago)
  • pjsip/include/pjsua-lib/pjsua_internal.h

     
    128128    pjsip_status_code    last_code; /**< Last status code seen.             */ 
    129129    pj_str_t             last_text; /**< Last status text seen.             */ 
    130130    pj_time_val          start_time;/**< First INVITE sent/received.        */ 
     131    pj_uint32_t          ms_utime;  /**< Starting tms.tms_utime in msec     */ 
     132    pj_uint32_t          ms_stime;  /**< Starting tms.tms_stime in msec     */ 
    131133    pj_time_val          res_time;  /**< First response sent/received.      */ 
    132134    pj_time_val          conn_time; /**< Connected/confirmed time.          */ 
    133135    pj_time_val          dis_time;  /**< Disconnect time.                   */ 
  • pjsip/src/pjsua-lib/pjsua_dump.c

     
    382382                    { 
    383383                        pjmedia_srtp_info *srtp_info = 
    384384                                    (pjmedia_srtp_info*) tp_info.spc_info[j].buffer; 
     385                        const char *policy_name = srtp_info->tx_policy.name.ptr; 
    385386 
     387                        if (!policy_name) 
     388                            policy_name = ""; 
     389 
    386390                        len = pj_ansi_snprintf(p, end-p, 
    387391                                               "   %s  SRTP status: %s Crypto-suite: %s", 
    388392                                               indent, 
    389393                                               (srtp_info->active?"Active":"Not active"), 
    390                                                srtp_info->tx_policy.name.ptr); 
     394                                               policy_name); 
    391395                        if (len > 0 && len < end-p) { 
    392396                            p += len; 
    393397                            *p++ = '\n'; 
     
    912916        buf[len] = '\0'; 
    913917} 
    914918 
     919void init_call_times(pj_uint32_t *ms_utime, pj_uint32_t *ms_stime); 
    915920 
    916921/* 
    917922 * Dump call and media statistics to string. 
     
    925930    pjsua_call *call; 
    926931    pjsip_dialog *dlg; 
    927932    pj_time_val duration, res_delay, con_delay; 
     933    unsigned cpu_user_pct, cpu_system_pct; 
    928934    char tmp[128]; 
    929935    char *p, *end; 
    930936    pj_status_t status; 
     
    970976        res_delay.sec = res_delay.msec = 0; 
    971977    } 
    972978 
     979    if (call->ms_utime) { 
     980        pj_time_val now; 
     981        pj_uint32_t ms_duration, ms_utime, ms_stime; 
     982 
     983        pj_gettimeofday(&now); 
     984        PJ_TIME_VAL_SUB(now, call->start_time); 
     985        ms_duration = PJ_TIME_VAL_MSEC(now); 
     986 
     987        if (ms_duration != 0) { 
     988            init_call_times(&ms_utime, &ms_stime); 
     989 
     990            cpu_user_pct = (ms_utime - call->ms_utime) * 100 / ms_duration; 
     991            cpu_system_pct = (ms_stime - call->ms_stime) * 100 / ms_duration; 
     992        } else { 
     993            cpu_user_pct = cpu_system_pct = 0; 
     994        } 
     995    } 
     996 
    973997    /* Print duration */ 
    974998    len = pj_ansi_snprintf(p, end-p, 
    975999                           "%s  Call time: %02dh:%02dm:%02ds, " 
    976                            "1st res in %d ms, conn in %dms", 
     1000                           "1st res in %d ms, conn in %dms, cpu (u|s|t)=%u|%u|%u%%", 
    9771001                           indent, 
    9781002                           (int)(duration.sec / 3600), 
    9791003                           (int)((duration.sec % 3600)/60), 
    9801004                           (int)(duration.sec % 60), 
    9811005                           (int)PJ_TIME_VAL_MSEC(res_delay), 
    982                            (int)PJ_TIME_VAL_MSEC(con_delay)); 
     1006                           (int)PJ_TIME_VAL_MSEC(con_delay), 
     1007                           cpu_user_pct, cpu_system_pct, 
     1008                           cpu_user_pct + cpu_system_pct); 
    9831009 
    9841010    if (len > 0 && len < end-p) { 
    9851011        p += len; 
  • pjsip/src/pjsua-lib/pjsua_call.c

     
    596596    return PJ_SUCCESS; 
    597597} 
    598598 
     599#include <sys/times.h> 
     600#include <time.h> 
     601 
     602void init_call_times(pj_uint32_t *ms_utime, pj_uint32_t *ms_stime) 
     603{ 
     604    struct tms tms; 
     605    int ret; 
     606 
     607    ret = times(&tms); 
     608 
     609    if (1) { 
     610        *ms_utime = tms.tms_utime * 1000 /  CLK_TCK; 
     611        *ms_stime = tms.tms_stime * 1000 /  CLK_TCK; 
     612    } else { 
     613        *ms_utime = *ms_stime = 0; 
     614    } 
     615} 
     616 
    599617/* 
    600618 * Make outgoing call to the specified URI using the specified account. 
    601619 */ 
     
    697715 
    698716    /* Mark call start time. */ 
    699717    pj_gettimeofday(&call->start_time); 
     718    init_call_times(&call->ms_utime, &call->ms_stime); 
    700719 
    701720    /* Reset first response time */ 
    702721    call->res_time.sec = 0; 
     
    10771096 
    10781097    /* Mark call start time. */ 
    10791098    pj_gettimeofday(&call->start_time); 
     1099    init_call_times(&call->ms_utime, &call->ms_stime); 
    10801100 
    10811101    /* Check INVITE request for Replaces header. If Replaces header is 
    10821102     * present, the function will make sure that we can handle the request.