Esempio n. 1
0
void
LOAD(const char *string, struct ZoneFileParser *parser)
{
    size_t string_length = strlen(string);
    zonefile_parse(
        parser,
        (const unsigned char *)string,
        string_length
        );

}
Esempio n. 2
0
int
perftest(int argc, char *argv[])
{
    struct PerfTest perftest[1];
	struct ZoneFileParser *parser;
    struct Catalog *db;
    size_t i;
    
    
    perftest->loop_count = 10000000;
    
    /*
     * Create a pseudo-network subsystem for generating packets
     */
    perftest->server.parent = perftest;
    perftest->server.adapter = adapter_create(
                                              perftest_alloc_packet, 
                                              perftest_server_to_client_response, 
                                              &perftest->server);
    adapter_add_ipv4(perftest->server.adapter, 0xC0A80101, 0xFFFFffff);
    
    
    /* create a catalog/database, this is where all the parsed zonefile
     * records will be put */
    perftest->db = catalog_create();
    perftest->thread->catalog = perftest->db;
    db = perftest->db;
    
    /* 
     * Parse a sample zone
     */
    parser = zonefile_begin(
                            example_origin, /* origin */
                            60,             /* TTL */
                            10000,          /* filesize */
                            "<perftest>",   /* filename */
                            zonefile_load,  /* callback */
                            db,             /* callback data */
                            0
                            );
    zonefile_set_singlestep(parser);
    for (i=0; perftest_zone[i]; i++) {
        zonefile_parse(parser,
                       (const unsigned char*)perftest_zone[i],
                       strlen(perftest_zone[i])
                       );
    }
    zonefile_end(parser);
    
    /*
     * Send packets. This creates one thread per CPU processing requests.
     */
    {
        unsigned threads_desired = pixie_cpu_get_count();
        uint64_t start, stop;
        double requests_per_second;
        
        fprintf(stderr, "running %u threads\n", threads_desired);
        
        start = pixie_gettime();
        for (i=0; i<threads_desired; i++) {
            __sync_fetch_and_add(&threads_running, 1);
            pixie_begin_thread((void(*)(void*))run_perf, 0, perftest);
        }
        while (threads_running)
            pixie_usleep(1000);
        stop = pixie_gettime();
        
        requests_per_second = 1000000.0 
                                * (1.0 * threads_desired * perftest->loop_count)
                                / (stop - start);
	fprintf(stderr, "queries = %u\n", (unsigned)(threads_desired * perftest->loop_count));
	fprintf(stderr, "seconds = %5.3f\n", (stop - start)/1000000.0);
        fprintf(stderr, "queries/second = %5.3f\n", requests_per_second);
    }
    
    exit(1);
    return 0;
}
Esempio n. 3
0
static void
conf_zonefiles_parse_thread(void *v)
{
    struct XParseThread *p = (struct XParseThread *)v;
    struct Catalog *db = p->db_load;
    struct Configuration *cfg = p->cfg;
    struct ZoneFileParser *parser;
    static const struct DomainPointer root = {(const unsigned char*)"\0",1};
    size_t directory_index;
    size_t file_index;
    size_t current_index;

    fflush(stderr);
    fflush(stdout);


    /*
     * Start the parsing
     */
    parser = zonefile_begin(
                root, 
                60, 128,
                cfg->options.directory,
                zonefile_load, 
                db,
                cfg->insertion_threads
                );

    /*
     * Find the starting point. This converts the single
     * integer number into a [directory, file] index pair.
     */
    current_index = 0;
    for (directory_index = 0; directory_index < cfg->zonedirs_length; directory_index++) {
        struct Cfg_ZoneDir *zonedir = cfg->zonedirs[directory_index];
        current_index += zonedir->file_count;
        if (current_index >= p->start_index)
            break;
    }
    file_index = current_index - p->start_index;


    
    /*
     * 'for all zonefiles in this directory...'
     */
    if (directory_index < cfg->zonedirs_length)
    while (current_index < p->end_index) {
        const char *filename;
        FILE *fp;
        int err;
        uint64_t filesize;
        struct Cfg_ZoneDir *zonedir;
        
        /* If we've gone past the end of this directory,
         * then start parsing the next directory */
        zonedir = cfg->zonedirs[directory_index];
        if (file_index >= zonedir->file_count) {
            file_index = 0;
            directory_index++;
            if (directory_index >= cfg->zonedirs_length)
                break;
            zonedir = cfg->zonedirs[directory_index];
        }

        filename = zonedir->files[file_index].filename;
        filesize = zonedir->files[file_index].size;
        current_index++;
        file_index++;

        /*
         * Open the file
         */
        fflush(stdout);
        fflush(stderr);
        err = fopen_s(&fp, filename, "rb");
        if (err || fp == NULL) {
            perror(filename);
            p->status = Failure;
            return;
        }
        p->total_bytes += filesize;

        /*
         * Set parameters
         */
        zonefile_begin_again(
            parser,
            root,   /* . domain origin */
            60,     /* one minute ttl */
            filesize, 
            filename);

        /*
         * Continue parsing the file until end, reporting progress as we
         * go along
         */
        for (;;) {
            unsigned char buf[65536];
            size_t bytes_read;

            bytes_read = fread((char*)buf, 1, sizeof(buf), fp);
            if (bytes_read == 0)
                break;

            zonefile_parse(
                parser,
                buf,
                bytes_read
                );

        }
        fclose(fp);
    }

    /* We are done parsing the directories. Now let's parse
     * the individual zonefiles */
    while (current_index < p->end_index) {
        const char *filename;
        FILE *fp;
        int err;
        uint64_t filesize;
        struct Cfg_Zone *zone;
        
        if (file_index >= cfg->zones_length)
            break;
        zone = cfg->zones[file_index];

        filename = zone->file;
        filesize = zone->file_size;
        current_index++;
        file_index++;

        /*
         * Open the file
         */
        fflush(stdout);
        fflush(stderr);
        err = fopen_s(&fp, filename, "rb");
        if (err || fp == NULL) {
            perror(filename);
            p->status = Failure;
            return;
        }
        p->total_bytes += filesize;

        /*
         * Set parameters
         */
        zonefile_begin_again(
            parser,
            root,   /* . domain origin */
            60,     /* one minute ttl */
            filesize, 
            filename);

        /*
         * Continue parsing the file until end, reporting progress as we
         * go along
         */
        for (;;) {
            unsigned char buf[65536];
            size_t bytes_read;

            bytes_read = fread((char*)buf, 1, sizeof(buf), fp);
            if (bytes_read == 0)
                break;

            zonefile_parse(
                parser,
                buf,
                bytes_read
                );

        }
        fclose(fp);
    }

    if (zonefile_end(parser) == Success) {
        p->status = Success;
    } else {
        fprintf(stderr, "%s: failure\n", "");
        p->status = Failure;
    }
}