Back to index

lightning-sunbird  0.9+nobinonly
Classes | Functions | Variables
TestPerf.cpp File Reference
#include "TestCommon.h"
#include <stdio.h>
#include "nsCRT.h"
#include "nsNetUtil.h"
#include "nsIEventQueueService.h"
#include "nsIServiceManager.h"
#include "nsIComponentRegistrar.h"
#include "nsISupportsArray.h"

Go to the source code of this file.

Classes

class  MyListener

Functions

static PRBool load_sync_1 (nsISupports *element, void *data)
static nsresult load_sync (nsISupportsArray *urls)
static void *PR_CALLBACK ShutdownEvent_Handler (PLEvent *ev)
static void PR_CALLBACK ShutdownEvent_Cleanup (PLEvent *ev)
static PRBool load_async_1 (nsISupports *element, void *data)
static nsresult load_async (nsISupportsArray *urls)
static nsresult read_file (const char *fname, nsISupportsArray *urls)
static void print_usage ()
int main (int argc, char **argv)
 The Xalan testcases app.

Variables

static nsIIOServicegIOService = nsnull
static int gRequestCount = 0
static nsIEventQueuegEventQ = 0

Function Documentation

static nsresult load_async ( nsISupportsArray urls) [static]

Definition at line 150 of file TestPerf.cpp.

{
    nsresult rv;

    // Create the Event Queue for this thread...
    nsCOMPtr<nsIEventQueueService> eqs(
            do_GetService("@mozilla.org/event-queue-service;1", &rv) );
    if (NS_FAILED(rv)) return rv;

    rv = eqs->CreateMonitoredThreadEventQueue();
    if (NS_FAILED(rv)) return rv;

    rv = eqs->GetThreadEventQueue(NS_CURRENT_THREAD, &gEventQ);
    if (NS_FAILED(rv)) return rv;

    urls->EnumerateForwards(load_async_1, nsnull);

    while (1) {
        PLEvent *ev;
        gEventQ->WaitForEvent(&ev);
        if (gRequestCount == 0)
            break;
        gEventQ->HandleEvent(ev);
    }
    NS_RELEASE(gEventQ);
    return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static PRBool load_async_1 ( nsISupports *  element,
void data 
) [static]

Definition at line 130 of file TestPerf.cpp.

{
    nsCOMPtr<nsIURI> uri( do_QueryInterface(element) );
    if (!uri)
        return PR_TRUE;

    MyListener *listener = new MyListener();
    if (!listener)
        return PR_TRUE;
    NS_ADDREF(listener);
    nsresult rv = NS_OpenURI(listener, nsnull, uri, gIOService);
    NS_RELEASE(listener);
    if (NS_SUCCEEDED(rv))
        gRequestCount++;
    else 
        printf(">> NS_OpenURI failed [rv=%x]\n", rv);
    return PR_TRUE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static nsresult load_sync ( nsISupportsArray urls) [static]

Definition at line 47 of file TestPerf.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

static PRBool load_sync_1 ( nsISupports *  element,
void data 
) [static]

Definition at line 15 of file TestPerf.cpp.

{
    nsCOMPtr<nsIInputStream> stream;
    nsCOMPtr<nsIURI> uri( do_QueryInterface(element) );
    nsCAutoString spec;
    nsresult rv;

    rv = NS_OpenURI(getter_AddRefs(stream), uri, gIOService);
    if (NS_FAILED(rv)) {
        uri->GetAsciiSpec(spec);
        fprintf(stderr, "*** failed opening %s [rv=%x]\n", spec.get(), rv);
        return PR_TRUE;
    }

    char buf[4096];
    PRUint32 bytesRead;

    while (1) {
        rv = stream->Read(buf, sizeof(buf), &bytesRead);
        if (NS_FAILED(rv) || bytesRead == 0) {
            if (NS_FAILED(rv)) {
                uri->GetAsciiSpec(spec);
                fprintf(stderr, "*** failed reading %s [rv=%x]\n", spec.get(), rv);
            }
            break;
        }
    }

    return PR_TRUE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int main ( int  argc,
char **  argv 
)

The Xalan testcases app.

Definition at line 219 of file TestPerf.cpp.

{
    if (test_common_init(&argc, &argv) != 0)
        return -1;

    nsresult rv;
    PRBool sync;

    if (argc < 3) {
        print_usage();
        return -1;
    }

    if (PL_strcasecmp(argv[1], "-sync") == 0)
        sync = PR_TRUE;
    else if (PL_strcasecmp(argv[1], "-async") == 0)
        sync = PR_FALSE;
    else {
        print_usage();
        return -1;
    }

    nsCOMPtr<nsIServiceManager> servMan;
    NS_InitXPCOM2(getter_AddRefs(servMan), nsnull, nsnull);
    nsCOMPtr<nsIComponentRegistrar> registrar = do_QueryInterface(servMan);
    NS_ASSERTION(registrar, "Null nsIComponentRegistrar");
    registrar->AutoRegister(nsnull);

    // cache the io service
    {
        nsCOMPtr<nsIIOService> ioserv( do_GetIOService() );
        NS_ADDREF(gIOService = ioserv);
    }

    nsCOMPtr<nsISupportsArray> urls;
    rv = NS_NewISupportsArray(getter_AddRefs(urls));
    if (NS_FAILED(rv)) return -1;

    rv = read_file(argv[2], urls);
    if (NS_FAILED(rv)) {
        printf("failed reading file-of-urls\n");
        return -1;
    }

    PRUint32 urlCount;
    urls->Count(&urlCount);

    PRIntervalTime start = PR_IntervalNow();

    if (sync)
        rv = load_sync(urls);
    else
        rv = load_async(urls);

    if (NS_FAILED(rv)) {
        printf("load failed\n");
        return -1;
    }

    PRIntervalTime end = PR_IntervalNow();
    fprintf(stderr, "read: %u urls; total time: %u milliseconds\n",
            urlCount,
            PR_IntervalToMilliseconds(end - start));

    NS_RELEASE(gIOService);
    return 0;
}

Here is the call graph for this function:

static void print_usage ( void  ) [static]

Definition at line 213 of file TestPerf.cpp.

{
    printf("usage: TestPerf [-sync|-async] <file-of-urls>\n");
}

Here is the caller graph for this function:

static nsresult read_file ( const char *  fname,
nsISupportsArray urls 
) [static]

Definition at line 181 of file TestPerf.cpp.

{
    FILE *fp = fopen(fname, "r");
    if (!fp) {
        printf("failed opening file: %s\n", fname);
        return NS_ERROR_FAILURE;
    }

    nsCOMPtr<nsIURI> uri;
    nsresult rv;
    char buf[512];
    while (fgets(buf, sizeof(buf), fp)) {
        // remove trailing newline
        buf[strlen(buf) - 1] = 0;
        rv = NS_NewURI(getter_AddRefs(uri), buf, nsnull, gIOService); 
        if (NS_FAILED(rv))
            printf("*** ignoring malformed uri: %s\n", buf);
        else {
            //nsXPIDLCString spec;
            //uri->GetSpec(getter_Copies(spec));
            //printf("read url: %s\n", spec.get());
            urls->AppendElement(uri);
        }
    }

    fclose(fp);
    return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void PR_CALLBACK ShutdownEvent_Cleanup ( PLEvent ev) [static]

Definition at line 105 of file TestPerf.cpp.

{
    delete ev;
}
static void* PR_CALLBACK ShutdownEvent_Handler ( PLEvent ev) [static]

Definition at line 99 of file TestPerf.cpp.

{
    return nsnull;
}

Variable Documentation

nsIEventQueue* gEventQ = 0 [static]

Definition at line 56 of file TestPerf.cpp.

Definition at line 10 of file TestPerf.cpp.

int gRequestCount = 0 [static]

Definition at line 55 of file TestPerf.cpp.