Changeset 351


Ignore:
Timestamp:
Mar 22, 2006 7:08:19 PM (18 years ago)
Author:
bennylp
Message:

Added a little more threading test and put more info in ioqueue test log

Location:
pjproject/trunk/pjlib/src/pjlib-test
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjlib/src/pjlib-test/ioq_perf.c

    r126 r351  
    8585        if (bytes_read < 0) { 
    8686            pj_status_t rc = -bytes_read; 
    87             char errmsg[128]; 
     87            char errmsg[PJ_ERR_MSG_SIZE]; 
    8888 
    8989            if (rc != last_error) { 
    9090                //last_error = rc; 
    9191                pj_strerror(rc, errmsg, sizeof(errmsg)); 
    92                 PJ_LOG(3,(THIS_FILE, "...error: read error, bytes_read=%d (%s)",  
     92                PJ_LOG(3,(THIS_FILE,"...error: read error, bytes_read=%d (%s)",  
    9393                          bytes_read, errmsg)); 
    9494                PJ_LOG(3,(THIS_FILE,  
     
    179179} 
    180180 
     181struct thread_arg 
     182{ 
     183    int           id; 
     184    pj_ioqueue_t *ioqueue; 
     185    unsigned      counter; 
     186}; 
     187 
    181188/* The worker thread. */ 
    182 static int worker_thread(void *arg) 
    183 { 
    184     pj_ioqueue_t *ioqueue = arg; 
     189static int worker_thread(void *p) 
     190{ 
     191    struct thread_arg *arg = p; 
    185192    const pj_time_val timeout = {0, 100}; 
    186193    int rc; 
    187194 
    188195    while (!thread_quit_flag) { 
    189         rc = pj_ioqueue_poll(ioqueue, &timeout); 
     196 
     197        ++arg->counter; 
     198        rc = pj_ioqueue_poll(arg->ioqueue, &timeout); 
    190199        //TRACE_((THIS_FILE, "     thread: poll returned rc=%d", rc)); 
    191200        if (rc < 0) { 
    192             app_perror("...error in pj_ioqueue_poll()", pj_get_netos_error()); 
    193             return -1; 
     201            char errmsg[PJ_ERR_MSG_SIZE]; 
     202            pj_strerror(-rc, errmsg, sizeof(errmsg)); 
     203            PJ_LOG(3, (THIS_FILE,  
     204                       "...error in pj_ioqueue_poll() in thread %d " 
     205                       "after %d loop: %s [pj_status_t=%d]",  
     206                       arg->id, arg->counter, errmsg, -rc)); 
     207            //return -1; 
    194208        } 
    195209    } 
     
    316330    /* Create the threads. */ 
    317331    for (i=0; i<thread_cnt; ++i) { 
     332        struct thread_arg *arg; 
     333 
     334        arg = pj_pool_zalloc(pool, sizeof(*arg)); 
     335        arg->id = i; 
     336        arg->ioqueue = ioqueue; 
     337        arg->counter = 0; 
     338 
    318339        rc = pj_thread_create( pool, NULL,  
    319340                               &worker_thread,  
    320                                ioqueue,  
     341                               arg,  
    321342                               PJ_THREAD_DEFAULT_STACK_SIZE,  
    322343                               PJ_THREAD_SUSPENDED, &thread[i] ); 
     
    383404    } 
    384405 
     406    /* Destroy threads */ 
     407    for (i=0; i<thread_cnt; ++i) { 
     408        pj_thread_destroy(thread[i]); 
     409    } 
     410 
    385411    /* Destroy ioqueue. */ 
    386412    TRACE_((THIS_FILE, "     destroying ioqueue..")); 
     
    403429    *p_bandwidth = (pj_uint32_t)bandwidth; 
    404430 
    405     PJ_LOG(3,(THIS_FILE, "   %.4s    %d         %d        %3d us  %8d KB/s", 
     431    PJ_LOG(3,(THIS_FILE, "   %.4s    %d         %d        %8d KB/s", 
    406432              type_name, thread_cnt, sockpair_cnt, 
    407               -1 /*total_elapsed_usec/sockpair_cnt*/, 
    408433              *p_bandwidth)); 
    409434 
     
    441466        { PJ_SOCK_DGRAM, "udp", 4, 4}, 
    442467        { PJ_SOCK_DGRAM, "udp", 4, 8}, 
     468        { PJ_SOCK_DGRAM, "udp", 4, 16}, 
    443469        { PJ_SOCK_STREAM, "tcp", 1, 1}, 
    444470        { PJ_SOCK_STREAM, "tcp", 1, 2}, 
     
    453479        { PJ_SOCK_STREAM, "tcp", 4, 4}, 
    454480        { PJ_SOCK_STREAM, "tcp", 4, 8}, 
     481        { PJ_SOCK_STREAM, "tcp", 4, 16}, 
     482/* 
     483        { PJ_SOCK_DGRAM, "udp", 32, 1}, 
     484        { PJ_SOCK_DGRAM, "udp", 32, 1}, 
     485        { PJ_SOCK_DGRAM, "udp", 32, 1}, 
     486        { PJ_SOCK_DGRAM, "udp", 32, 1}, 
     487        { PJ_SOCK_DGRAM, "udp", 1, 32}, 
     488        { PJ_SOCK_DGRAM, "udp", 1, 32}, 
     489        { PJ_SOCK_DGRAM, "udp", 1, 32}, 
     490        { PJ_SOCK_DGRAM, "udp", 1, 32}, 
     491        { PJ_SOCK_STREAM, "tcp", 32, 1}, 
     492        { PJ_SOCK_STREAM, "tcp", 32, 1}, 
     493        { PJ_SOCK_STREAM, "tcp", 32, 1}, 
     494        { PJ_SOCK_STREAM, "tcp", 32, 1}, 
     495        { PJ_SOCK_STREAM, "tcp", 1, 32}, 
     496        { PJ_SOCK_STREAM, "tcp", 1, 32}, 
     497        { PJ_SOCK_STREAM, "tcp", 1, 32}, 
     498        { PJ_SOCK_STREAM, "tcp", 1, 32}, 
     499*/ 
    455500    }; 
    456501    pj_size_t best_bandwidth; 
     
    458503 
    459504    PJ_LOG(3,(THIS_FILE, "   Benchmarking %s ioqueue:", pj_ioqueue_name())); 
    460     PJ_LOG(3,(THIS_FILE, "   ===============================================")); 
    461     PJ_LOG(3,(THIS_FILE, "   Type  Threads  Skt.Pairs  Avg.Time    Bandwidth")); 
    462     PJ_LOG(3,(THIS_FILE, "   ===============================================")); 
     505    PJ_LOG(3,(THIS_FILE, "   =======================================")); 
     506    PJ_LOG(3,(THIS_FILE, "   Type  Threads  Skt.Pairs      Bandwidth")); 
     507    PJ_LOG(3,(THIS_FILE, "   =======================================")); 
    463508 
    464509    best_bandwidth = 0; 
     
    478523            best_bandwidth = bandwidth, best_index = i; 
    479524 
    480         /* Give it a rest before next test. */ 
     525        /* Give it a rest before next test, to allow system to close the 
     526         * sockets properly.  
     527         */ 
    481528        pj_thread_sleep(500); 
    482529    } 
  • pjproject/trunk/pjlib/src/pjlib-test/thread.c

    r65 r351  
    126126    } 
    127127 
     128    pj_thread_sleep(500); 
     129 
    128130    if (flags & PJ_THREAD_SUSPENDED) { 
     131 
     132        /* Check that counter is still zero */ 
     133        if (counter != 0) { 
     134            PJ_LOG(3,(THIS_FILE, "...error: thread is not suspended")); 
     135            return -1015; 
     136        } 
     137         
    129138        rc = pj_thread_resume(thread); 
    130139        if (rc != PJ_SUCCESS) { 
     
    136145    PJ_LOG(3,(THIS_FILE, "..waiting for thread to quit..")); 
    137146 
     147    pj_thread_sleep(500); 
     148 
    138149    quit_flag = 1; 
    139150    pj_thread_join(thread); 
     
    141152    pj_pool_release(pool); 
    142153 
     154    if (counter == 0) { 
     155        PJ_LOG(3,(THIS_FILE, "...error: thread is not running")); 
     156        return -1025; 
     157    } 
     158     
    143159    PJ_LOG(3,(THIS_FILE, "...%s success", title)); 
    144160    return PJ_SUCCESS; 
Note: See TracChangeset for help on using the changeset viewer.