Exemplo n.º 1
0
static void resetCmd(MprCmd *cmd)
{
    MprCmdFile      *files;
    int             i;

    files = cmd->files;
    for (i = 0; i < MPR_CMD_MAX_PIPE; i++) {
        if (cmd->handlers[i]) {
            mprFree(cmd->handlers[i]);
            cmd->handlers[i] = 0;
        }
        if (files[i].clientFd >= 0) {
            close(files[i].clientFd);
            files[i].clientFd = -1;
        }
        if (files[i].fd >= 0) {
            close(files[i].fd);
            files[i].fd = -1;
        }
    }
    cmd->eofCount = 0;
    cmd->status = -1;
    mprResetCond(cmd->completeCond);

    if (cmd->pid && !(cmd->flags & MPR_CMD_DETACH)) {
        mprStopCmd(cmd);
        mprReapCmd(cmd, 0);
        mprSignalCond(cmd->completeCond);
    }
}
Exemplo n.º 2
0
/*
    Do a performance benchmark
 */ 
static void doBenchmark(void *thread)
{
    MprTime         start;
    MprList         *list;
    int             count, i;
    MprMutex        *lock;
    MprSpin         *spin;

    mprPrintf("Group\t%-30s\t%13s\t%12s\n", "Benchmark", "Microsec", "Elapsed-sec");

    testMalloc();

    if (!app->testAllocOnly) {
        /*
            Locking primitives
         */
        mprPrintf("Lock Benchmarks\n");
        lock = mprCreateLock();
        count = 5000000 * app->iterations;
        start = startMark();
        for (i = 0; i < count; i++) {
            mprLock(lock);
            mprUnlock(lock);
        }
        endMark(start, count, "Mutex lock|unlock");
        
        /*
            Locking primitives
         */
        mprPrintf("Lock Benchmarks\n");
        spin = mprCreateSpinLock();
        count = 5000000 * app->iterations;
        start = startMark();
        for (i = 0; i < count; i++) {
            mprSpinLock(spin);
            mprSpinUnlock(spin);
        }
        endMark(start, count, "Spin lock|unlock");
        
        /*
            Condition signal / wait
         */
        mprPrintf("Cond Benchmarks\n");
        count = 1000000 * app->iterations;
        start = startMark();
        mprResetCond(app->complete);
        for (i = 0; i < count; i++) {
            mprSignalCond(app->complete);
            mprWaitForCond(app->complete, -1);
        }
        endMark(start, count, "Cond signal|wait");
        
        /*
            List
         */
        mprPrintf("List Benchmarks\n");
        count = 2000000 * app->iterations;
        list = mprCreateList(count, 0);
        start = startMark();
        for (i = 0; i < count; i++) {
            mprAddItem(list, (void*) (long) i);
            mprRemoveItem(list, (void*) (long) i);
        }
        endMark(start, count, "Link insert|remove");

        /*
            Events
         */
        mprPrintf("Event Benchmarks\n");
        mprResetCond(app->complete);
        count = 30000 * app->iterations;
        app->markCount = count;
        start = startMark();
        for (i = 0; i < count; i++) {
            mprCreateEvent(NULL, "eventBenchmark", 0, eventCallback, ITOP(i), MPR_EVENT_QUICK);
        }
        mprWaitForCond(app->complete, -1);
        endMark(start, count, "Event (create|run|delete)");

        /*
            Test timer creation, run and remove
            These create a new dispatcher and run a worker thread.
         */
        mprPrintf("Timer\n");
        mprResetCond(app->complete);
        count = 20000 * app->iterations;
        app->markCount = count;
        start = startMark();
        for (i = 0; i < count; i++) {
            mprCreateTimerEvent(NULL, "timerBenchmark", 0, timerCallback, (void*) (long) i, 0);
        }
        mprWaitForCond(app->complete, -1);
        endMark(start, count, "Timer (create|delete)");

        /*
            Alloc (1K)
         */
        mprPrintf("Alloc 1K Benchmarks\n");
        count = 2000000 * app->iterations;
        start = startMark();
        for (i = 0; i < count; i++) {
            mprAlloc(1024);
            if ((i % 128) == 0) {
                mprGC(0);
            }
        }
        endMark(start, count, "Alloc mprAlloc(1K)");
    }
    testComplete = 1;
}
Exemplo n.º 3
0
/*
 *  Do a performance benchmark
 */ 
static void doBenchmark(Mpr *mpr, void *thread)
{
    MprTime     start;
    MprList     *list;
    void        *mp;
    int         count, i;
#if BLD_FEATURE_MULTITHREAD
    MprMutex    *lock;
#endif

    complete = mprCreateCond(mpr);

    mprPrintf(mpr, "Group\t%-30s\t%13s\t%12s\n", "Benchmark", "Microsec", "Elapsed-sec");

    /*
     *  Alloc (1K)
     */
    mprPrintf(mpr, "Alloc Benchmarks\n");
    count = 2000000 * iterations;
    start = startMark(mpr);
    for (i = 0; i < count; i++) {
        mp = mprAlloc(mpr, 1024);
        memset(mp, 0, 1024);
        mprFree(mp);
    }
    endMark(mpr, start, count, "Alloc mprAlloc(1K)|mprFree");
    start = startMark(mpr);

#if BLD_FEATURE_MULTITHREAD
    /*
     *  Locking primitives
     */
    mprPrintf(mpr, "Lock Benchmarks\n");
    lock = mprCreateLock(mpr);
    count = 5000000 * iterations;
    start = startMark(mpr);
    for (i = 0; i < count; i++) {
        mprLock(lock);
        mprUnlock(lock);
    }
    endMark(mpr, start, count, "Mutex lock|unlock");
    mprFree(lock);

    /*
     *  Condition signal / wait
     */
    mprPrintf(mpr, "Cond Benchmarks\n");
    count = 1000000 * iterations;
    start = startMark(mpr);
    mprResetCond(complete);
    for (i = 0; i < count; i++) {
        mprSignalCond(complete);
        mprWaitForCond(complete, -1);
    }
    endMark(mpr, start, count, "Cond signal|wait");
#endif

    /*
     *  List
     */
    mprPrintf(mpr, "List Benchmarks\n");
    count = 500000 * iterations;
    list = mprCreateList(mpr);
    start = startMark(mpr);
    for (i = 0; i < count; i++) {
        mprAddItem(list, (void*) (long) i);
        mprRemoveItem(list, (void*) (long) i);
    }
    endMark(mpr, start, count, "Link insert|remove");
    mprFree(list);;

    /*
     *  Events
     */
    mprPrintf(mpr, "Event Benchmarks\n");
    mprResetCond(complete);
    count = 200000 * iterations;
    markCount = count;
    start = startMark(mpr);
    for (i = 0; i < count; i++) {
        mprCreateEvent(mprGetDispatcher(mpr), eventCallback, 0, 0, (void*) (long) i, 0);
    }
    endMark(mpr, start, count, "Event (create)");
    mprWaitForCondWithService(complete, -1);
    endMark(mpr, start, count, "Event (run|delete)");


    /*
     *  Test timer creation, run and delete (make a million timers!)
     */
    mprPrintf(mpr, "Timer\n");
    mprResetCond(complete);
    count = 50000 * iterations;
    markCount = count;
    start = startMark(mpr);
    for (i = 0; i < count; i++) {
        mprCreateTimerEvent(mprGetDispatcher(mpr), timerCallback, 0, 0, (void*) (long) i, 0);
    }
    endMark(mpr, start, count, "Timer (create)");
    mprWaitForCondWithService(complete, -1);
    endMark(mpr, start, count, "Timer (delete)");

    testComplete = 1;
}