예제 #1
0
파일: main.c 프로젝트: winsky027/zimg
/**
 * @brief settings_init Init the setting with default values.
 */
static void settings_init(void) 
{
    settings.is_daemon = 0;
    strcpy(settings.root_path, "./www/index.html");
    strcpy(settings.img_path, "./img");
    strcpy(settings.log_name, "./log/zimg.log");
    strcpy(settings.version, STR(ZIMG_VERSION));
    snprintf(settings.server_name, 128, "zimg/%s", settings.version);
    settings.port = 4869;
    settings.backlog = 1024;
    settings.num_threads = get_cpu_cores();         /* N workers */
    settings.retry = 3;
    settings.up_access = NULL;
    settings.down_access = NULL;
    settings.log = false;
    settings.cache_on = false;
    strcpy(settings.cache_ip, "127.0.0.1");
    settings.cache_port = 11211;
    settings.max_keepalives = 1;
    settings.mode = 1;
    strcpy(settings.ssdb_ip, "127.0.0.1");
    settings.ssdb_port = 6379;
    strcpy(settings.beansdb_ip, "127.0.0.1");
    settings.beansdb_port = 7905;
}
/*
 * Helper function to init cpu_cores,thread_per_core,max_kthread_count and current_kthread.
 */
void init_kthread_info() {
	cpu_cores = get_cpu_cores();
	thread_per_core = get_hyperthreads();
	switch (mypthread_policy) {
	case ULONLY:
		printf("ULONLY policy selected\n");
		max_kthread_count = 1;
		printf("max_kthread_count: %d\n", max_kthread_count);
		break;
	case KLMATCHCORES:
		printf("KLMATCHCORES policy selected\n");
		max_kthread_count = cpu_cores;
		printf("max_kthread_count: %d\n", max_kthread_count);
		break;
	case KLMATCHHYPER:
		printf("KLMATCHHYPER policy selected\n");
		max_kthread_count = cpu_cores * thread_per_core;
		printf("max_kthread_count: %d\n", max_kthread_count);
		break;
	case KLALWAYS:
		printf("KLALWAYS policy selected\n");
		printf("No max_kthread_count set\n");
		break;
	}
}
예제 #3
0
파일: main.c 프로젝트: buaazp/zimg
/**
 * @brief settings_init Init the setting with default values.
 */
static void settings_init(void) {
    settings.L = NULL;
    settings.is_daemon = 0;
    str_lcpy(settings.ip, "0.0.0.0", sizeof(settings.ip));
    settings.port = 4869;
    settings.num_threads = get_cpu_cores();         /* N workers */
    settings.backlog = 1024;
    settings.max_keepalives = 1;
    settings.retry = 3;
    str_lcpy(settings.version, STR(PROJECT_VERSION), sizeof(settings.version));
    snprintf(settings.server_name, 128, "zimg/%s", settings.version);
    settings.headers = NULL;
    settings.etag = 0;
    settings.up_access = NULL;
    settings.down_access = NULL;
    settings.admin_access = NULL;
    settings.cache_on = 0;
    str_lcpy(settings.cache_ip, "127.0.0.1", sizeof(settings.cache_ip));
    settings.cache_port = 11211;
    settings.log_level = 6;
    str_lcpy(settings.log_name, "./log/zimg.log", sizeof(settings.log_name));
    str_lcpy(settings.root_path, "./www/index.html", sizeof(settings.root_path));
    str_lcpy(settings.admin_path, "./www/admin.html", sizeof(settings.admin_path));
    settings.disable_args = 0;
    settings.disable_type = 0;
    settings.disable_zoom_up = 0;
    settings.script_on = 0;
    settings.script_name[0] = '\0';
    str_lcpy(settings.format, "none", sizeof(settings.format));
    settings.quality = 75;
    settings.mode = 1;
    settings.save_new = 1;
    settings.max_size = 10485760;
    str_lcpy(settings.img_path, "./img", sizeof(settings.img_path));
    str_lcpy(settings.beansdb_ip, "127.0.0.1", sizeof(settings.beansdb_ip));
    settings.beansdb_port = 7905;
    str_lcpy(settings.ssdb_ip, "127.0.0.1", sizeof(settings.ssdb_ip));
    settings.ssdb_port = 6379;
    multipart_parser_settings *callbacks = (multipart_parser_settings *)malloc(sizeof(multipart_parser_settings));
    memset(callbacks, 0, sizeof(multipart_parser_settings));
    //callbacks->on_header_field = on_header_field;
    callbacks->on_header_value = on_header_value;
    callbacks->on_chunk_data = on_chunk_data;
    settings.mp_set = callbacks;
    settings.get_img = NULL;
    settings.info_img = NULL;
    settings.admin_img = NULL;
}
예제 #4
0
파일: nfdumpp.c 프로젝트: Lukas955/nf-tools
int main(int argc, char **argv) {

    lnf_rec_t *recp;
    pthread_t th[MAX_THREADS];
    int i = 0;
    int numthreads = 1;
    int sortfield = 0;
    int sortbits4 = 0;
    int sortbits6 = 0;
    char c;
//	lnf_filter_t *filterp;


    flist_init(&flist);

    numthreads = get_cpu_cores() * NUM_THREADS_FACTOR;

    /* initalise one instance of memory heap (share by all threads) */
    memp = NULL;
    filterp = NULL;
    progressp = NULL;
    recp = NULL;
    filter[0] = '\0';

    /* fields in all outpusts */
    fields_add(LNF_FLD_FIRST);
    fields_add(LNF_FLD_CALC_DURATION);


    while ((c = getopt_long(argc, argv, "A:O:r:R:T:W;", longopts, NULL)) != -1) {
        switch (c) {
        case 1:
        case 'T': 	/* T option will be removed in future */
            numthreads = atoi(optarg);
            if (numthreads > MAX_THREADS) {
                fprintf(stderr, "Maximim allowed threads is %d\n", MAX_THREADS);
                exit(1);
                //	numthreads = MAX_THREADS - 1;
            }
            break;
        case 2:
            if (strcmp(optarg, "nfdump") == 0) {
                filter_type = NFDUMPP_FILTER_NFDUMP;
            } else if (strcmp(optarg, "libnf") == 0) {
                filter_type = NFDUMPP_FILTER_LIBNF;
            } else {
                fprintf(stderr, "Invalid filter type \"%s\". Allowed options nfdump or libnf. \n", optarg);
                exit(1);
            }
            break;
        case 'r':
        case 'R':
            flist_lookup_dir(&flist, optarg);
            break;
        case 'A':
            if (memp == NULL) {
                lnf_mem_init(&memp);
            }
            parse_aggreg(memp, optarg);
            break;
        case 'O':
            sortfield = lnf_fld_parse(optarg, &sortbits4, &sortbits6);
            if (sortfield == 0) {
                fprintf(stderr, "Unknow or unsupported sort field: %s\n", optarg);
                exit(1);
            }
            break;
        case '?':
            printf("Usage: %s [ -A ] [ -R -r ] [ <filter> ] \n", argv[0]);
            printf(" -r : \n");
            printf(" -R : Input file or directory  (multiple -r -R options is allowed)\n");
            printf(" -A : aggregation\n");
            printf(" -O : sort order\n");
            printf(" --num-threads = <num> : num threads (default: %.0f%% number of CPU cores, %d on this system)\n",
                   NUM_THREADS_FACTOR * 100, numthreads);
            printf(" --filter-type = nfdump|libnf : use original nfdump filter or new libnf implementation \n");
            printf("\n");
            exit(1);
        }
    }

    /* set filter */
    if (optind < argc ) {
        for ( ; optind < argc; optind++) {
            if (strlen(filter) + strlen(argv[optind]) > MAX_FILTER_LEN) {
                fprintf(stderr, "Not enough space for filter in buffer\n");
                exit(1);
            }
            strcat(filter, argv[optind]);
            strcat(filter, " ");
            printf("filter: %s \n", filter);
        }

        filterp = NULL;
        switch (filter_type) {
        case NFDUMPP_FILTER_DEFAULT:
            lnf_filter_init(&filterp, filter);
            break;
        case NFDUMPP_FILTER_NFDUMP:
            lnf_filter_init_v1(&filterp, filter);
            break;
        case NFDUMPP_FILTER_LIBNF:
            lnf_filter_init_v2(&filterp, filter);
            break;
        default:
            fprintf(stderr, "This should never hapen line: %d\n", __LINE__);
            exit(1);
            break;
        }

        if (filterp == NULL) {
            fprintf(stderr, "Can not compile filter: %s\n", filter);
            exit(1);
        }
//		lnf_filter_free(filterp);
    }


    /* init progress bar */
    if  (progress_init(&progressp, 0, NULL) != NULL) {
        progress_steps(progressp,  flist_count(&flist));
    }

    /* aggregated or not aggregated records */
    if (memp == NULL) {
        /* not aggregated, but sorted */
        if (sortfield > 0) {
            lnf_mem_init(&memp);
            /* switch memp into list mode */
            lnf_mem_setopt(memp, LNF_OPT_LISTMODE, NULL, 0);
            lnf_mem_fastaggr(memp, LNF_FAST_AGGR_BASIC);
            lnf_mem_fadd(memp, LNF_FLD_PROT, LNF_AGGR_KEY, 0, 0);
            lnf_mem_fadd(memp, LNF_FLD_SRCADDR, LNF_AGGR_KEY, 24, 128);
            lnf_mem_fadd(memp, LNF_FLD_SRCPORT, LNF_AGGR_KEY, 0, 0);
            lnf_mem_fadd(memp, LNF_FLD_DSTADDR, LNF_AGGR_KEY, 24, 128);
            lnf_mem_fadd(memp, LNF_FLD_DSTPORT, LNF_AGGR_KEY, 0, 0);
        }
        fields_add(LNF_FLD_PROT);
        fields_add(LNF_FLD_SRCADDR);
        fields_add(LNF_FLD_SRCPORT);
        fields_add(LNF_FLD_DSTADDR);
        fields_add(LNF_FLD_DSTPORT);
    }

    /* default fields on the ond of the list */
    fields_add(LNF_FLD_DPKTS);
    fields_add(LNF_FLD_DOCTETS);
    fields_add(LNF_FLD_CALC_BPS);
    fields_add(LNF_FLD_CALC_BPP);
    fields_add(LNF_FLD_AGGR_FLOWS);

    /* set sort firld */
    if (sortfield > 0) {
        int defaultaggr = 0;
        int defaultsort = 0;
        lnf_fld_info(sortfield, LNF_FLD_INFO_AGGR, &defaultaggr, sizeof(int));
        lnf_fld_info(sortfield, LNF_FLD_INFO_SORT, &defaultsort, sizeof(int));
        lnf_mem_fadd(memp, sortfield, defaultaggr|defaultsort, sortbits4, sortbits6);
    }


    print_header();

    /*  prepare and run threads */
    pthread_mutex_init(&mutex, NULL);

    for ( i = 0 ; i < numthreads ; i++ ) {
        if ( pthread_create(&th[i], NULL, process_thread, NULL) < 0) {
            fprintf(stderr, "Can not create thread for %d\n", i);
            break;
        }
    }

    /* wait for threads */
    for ( i = 0; i < numthreads; i++ ) {
        if( pthread_join(th[i], NULL) ) {
            fprintf(stderr, "Error joining thread\n");
            break;
        }
    }

    /* print the records out */
    if (memp != NULL) {
        i = 0;
        lnf_rec_init(&recp);
        while (lnf_mem_read(memp, recp) != LNF_EOF) {
            i++;
            print_row(recp);
            outputflows++;
        }
    }

    /* header */
    printf("Total input flows %d, output flows: %lu\n", totalrows, outputflows);

    lnf_mem_free(memp);
    lnf_rec_free(recp);
    if (filterp != NULL) {
        lnf_filter_free(filterp);
    }


}