Back to index

lightning-sunbird  0.9+nobinonly
Classes | Functions | Variables
ranfile.cpp File Reference
#include <plgetopt.h>
#include <prprf.h>
#include <prio.h>
#include "rccv.h"
#include "rcthread.h"
#include "rcfileio.h"
#include "rclock.h"
#include <string.h>
#include <stdio.h>
#include <stdlib.h>

Go to the source code of this file.

Classes

class  HammerData
class  Hammer

Functions

PRIntn main (PRIntn argc, char *argv[])

Variables

static PRFileDescoutput
static PRIntn debug_mode = 0
static PRIntn failed_already = 0
static PRInt32 pageSize = 1024
static const char * baseName = "./"
static const char * programName = "Random File"
static Hammerhammer [100]

Function Documentation

PRIntn main ( PRIntn  argc,
char *  argv[] 
)

Definition at line 310 of file ranfile.cpp.

{
    RCLock ml;
       PLOptStatus os;
    RCCondition cv(&ml);
    PRUint32 writesMax = 0, durationTot = 0;
    RCThread::Scope thread_scope = RCThread::local;
    PRUint32 writes, writesMin = 0x7fffffff, writesTot = 0;
    PRIntn active, poll, limit = 0, max_virtual_procs = 0, threads = 0, virtual_procs;
    RCInterval interleave(RCInterval::FromMilliseconds(10000)), duration(0);

    const char *where[] = {"okay", "open", "close", "delete", "write", "seek"};

       PLOptState *opt = PL_CreateOptState(argc, argv, "Gdl:t:i:");
       while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
    {
              if (PL_OPT_BAD == os) continue;
        switch (opt->option)
        {
       case 0:
              baseName = opt->value;
              break;
        case 'G':  /* global threads */
              thread_scope = RCThread::global;
            break;
        case 'd':  /* debug mode */
                     debug_mode = 1;
            break;
        case 'l':  /* limiting number */
                     limit = atoi(opt->value);
            break;
        case 't':  /* number of threads */
                     threads = atoi(opt->value);
            break;
        case 'i':  /* iteration counter */
                     max_virtual_procs = atoi(opt->value);
            break;
         default:
            break;
        }
    }
       PL_DestroyOptState(opt);
    output = PR_GetSpecialFD(PR_StandardOutput);

 /* main test */
 
    cv.SetTimeout(interleave);
       
    if (max_virtual_procs == 0) max_virtual_procs = 2;
    if (limit == 0) limit = 57;
    if (threads == 0) threads = 10;

    if (debug_mode) PR_fprintf(output,
        "%s: Using %d virtual processors, %d threads, limit = %d and %s threads\n",
        programName, max_virtual_procs, threads, limit,
        (thread_scope == RCThread::local) ? "LOCAL" : "GLOBAL");

    for (virtual_procs = 0; virtual_procs < max_virtual_procs; ++virtual_procs)
    {
        if (debug_mode)
                     PR_fprintf(output,
                            "%s: Setting number of virtual processors to %d\n",
                            programName, virtual_procs + 1);
              RCPrimordialThread::SetVirtualProcessors(virtual_procs + 1);
        for (active = 0; active < threads; active++)
        {
            hammer[active] = new Hammer(thread_scope, &ml, &cv, limit);
            hammer[active]->Start();  /* then make it roll */
            RCThread::Sleep(interleave);  /* start them slowly */
        }

        /*
         * The last thread started has had the opportunity to run for
         * 'interleave' seconds. Now gather them all back in.
         */
        {
            RCEnter scope(&ml);
            for (poll = 0; poll < threads; poll++)
            {
                if (hammer[poll]->action == HammerData::sg_go)  /* don't overwrite done */
                    hammer[poll]->action = HammerData::sg_stop;  /* ask him to stop */
            }
        }

        while (active > 0)
        {
            for (poll = 0; poll < threads; poll++)
            {
                ml.Acquire();
                while (hammer[poll]->action < HammerData::sg_done) cv.Wait();
                ml.Release();

                if (hammer[poll]->problem == HammerData::sg_okay)
                {
                    duration = RCInterval(RCInterval::now) - hammer[poll]->timein;
                    writes = hammer[poll]->writes * 1000 / duration;
                    if (writes < writesMin)  writesMin = writes;
                    if (writes > writesMax) writesMax = writes;
                    writesTot += hammer[poll]->writes;
                    durationTot += duration;
                }
                else
                {
                    if (debug_mode) PR_fprintf(output,
                        "%s: test failed %s after %ld seconds\n",
                        programName, where[hammer[poll]->problem], duration);
                                   else failed_already=1;
                }
                active -= 1;  /* this is another one down */
                (void)hammer[poll]->Join();
                hammer[poll] = NULL;
            }
        }
        if (debug_mode) PR_fprintf(output,
            "%s: [%ld [%ld] %ld] writes/sec average\n",
            programName, writesMin,
            writesTot * 1000 / durationTot, writesMax);
    }

        failed_already |= (PR_FAILURE == RCPrimordialThread::Cleanup());
           PR_fprintf(output, "%s\n", (failed_already) ? "FAIL\n" : "PASS\n");
              return failed_already;
}  /* main */

Here is the call graph for this function:


Variable Documentation

const char* baseName = "./" [static]

Definition at line 114 of file ranfile.cpp.

PRIntn debug_mode = 0 [static]

Definition at line 74 of file ranfile.cpp.

PRIntn failed_already = 0 [static]

Definition at line 75 of file ranfile.cpp.

Hammer* hammer[100] [static]

Definition at line 279 of file ranfile.cpp.

PRFileDesc* output [static]

Definition at line 73 of file ranfile.cpp.

PRInt32 pageSize = 1024 [static]

Definition at line 113 of file ranfile.cpp.

const char* programName = "Random File" [static]

Definition at line 115 of file ranfile.cpp.