예제 #1
0
파일: shared.c 프로젝트: vspetrov/fabtests
void show_perf(char *name, int tsize, int iters, struct timespec *start,
               struct timespec *end, int xfers_per_iter)
{
    static int header = 1;
    char str[FT_STR_LEN];
    int64_t elapsed = get_elapsed(start, end, MICRO);
    long long bytes = (long long) iters * tsize * xfers_per_iter;

    if (header) {
        printf("%-10s%-8s%-8s%-8s%8s %10s%13s\n",
               "name", "bytes", "iters", "total", "time", "Gb/sec", "usec/xfer");
        header = 0;
    }

    printf("%-10s", name);

    printf("%-8s", size_str(str, tsize));

    printf("%-8s", cnt_str(str, iters));

    printf("%-8s", size_str(str, bytes));

    printf("%8.2fs%10.2f%11.2f\n",
           elapsed / 1000000.0, (bytes * 8) / (1000.0 * elapsed),
           ((float)elapsed / iters / xfers_per_iter));
}
예제 #2
0
static int process_file(const char *file, int iterate_headers)
{
    Db *db;
    couchstore_error_t errcode;
    uint64_t btreesize = 0;
    const char* crc_strings[3] = {"warning crc is set to unknown",
                                  "CRC-32",
                                  "CRC-32C"};

    errcode = couchstore_open_db(file, COUCHSTORE_OPEN_FLAG_RDONLY, &db);
    if (errcode != COUCHSTORE_SUCCESS) {
        fprintf(stderr, "Failed to open \"%s\": %s\n",
                file, couchstore_strerror(errcode));
        return -1;
    }

next_header:
    printf("DB Info (%s) - header at %"PRIu64"\n", file, db->header.position);
    printf("   file format version: %"PRIu64"\n", db->header.disk_version);
    printf("   update_seq: %"PRIu64"\n", db->header.update_seq);
    printf("   purge_seq: %"PRIu64"\n", db->header.purge_seq);

    if (db->file.crc_mode < 3) {
        printf("   crc: %s\n", crc_strings[db->file.crc_mode]);
    } else {
        printf("   crc: warning crc_mode is out of range %"PRIu32"\n",  db->file.crc_mode);
    }

    print_db_info(db);
    if (db->header.by_id_root) {
        btreesize += db->header.by_id_root->subtreesize;
    }
    if (db->header.by_seq_root) {
        btreesize += db->header.by_seq_root->subtreesize;
    }
    printf("   B-tree size: %s\n", size_str(btreesize));
    printf("   total disk size: %s\n", size_str(db->file.pos));
    if (iterate_headers) {
        if (couchstore_rewind_db_header(db) == COUCHSTORE_SUCCESS) {
            printf("\n");
            goto next_header;
        }
    } else {
        couchstore_close_file(db);
        couchstore_free_db(db);
    }

    return 0;
}
예제 #3
0
static void print_db_info(Db* db)
{
    DbInfo info;
    couchstore_db_info(db, &info);
    printf("   doc count: %"PRIu64"\n", info.doc_count);
    printf("   deleted doc count: %"PRIu64"\n", info.deleted_count);
    printf("   data size: %s\n", size_str(info.space_used));
}
예제 #4
0
static void init_test(int size)
{
	char sstr[5];

	size_str(sstr, sizeof sstr, size);
	snprintf(test_name, sizeof test_name, "%s_lat", sstr);
	transfer_size = size;
	iterations = size_to_count(transfer_size);
}
예제 #5
0
파일: shared.c 프로젝트: vspetrov/fabtests
void init_test(struct cs_opts *opts, char *test_name, size_t test_name_len)
{
    char sstr[FT_STR_LEN];

    size_str(sstr, opts->transfer_size);
    snprintf(test_name, test_name_len, "%s_lat", sstr);
    if (!(opts->user_options & FT_OPT_ITER))
        opts->iterations = size_to_count(opts->transfer_size);
}
예제 #6
0
static void init_bandwidth_test(int size)
{
	char sstr[5];

	size_str(sstr, sizeof sstr, size);
	snprintf(test_name, sizeof test_name, "%s_bw", sstr);
	iterations = 1;
	transfer_size = size;
	transfer_count = size_to_count(transfer_size);
}
예제 #7
0
파일: shared.c 프로젝트: luomiao/fabtests
void init_test(int size, char *test_name, size_t test_name_len,
	int *transfer_size, int *iterations)
{
	char sstr[FI_STR_LEN];

	size_str(sstr, size);
	snprintf(test_name, test_name_len, "%s_lat", sstr);
	*transfer_size = size;
	*iterations = size_to_count(*transfer_size);
}
예제 #8
0
파일: bw.c 프로젝트: soniczhao/fabtests
static void show_perf(void)
{
	char str[32];
	float usec;
	long long bytes;

	usec = (end.tv_sec - start.tv_sec) * 1000000 + (end.tv_usec - start.tv_usec);
	bytes = (long long) iterations * transfer_size;

	/* name size transfers iterations bytes seconds Gb/sec usec/xfer */
	size_str(str, sizeof str, transfer_size);
	printf("%-8s", str);
	cnt_str(str, sizeof str, iterations);
	printf("%-8s", str);
	size_str(str, sizeof str, bytes);
	printf("%-8s", str);
	printf("%8.2fs%10.2f%11.2f\n",
		usec / 1000000., (bytes) / (usec),
		(usec / iterations));
}
예제 #9
0
int
bbsbkndoc_main()
{
	FILE *fp;
	char board[80], bkn[80], dir[160], *ptr, genbuf[STRLEN];
	struct boardmem *x1;
	struct fileheader x;
	int i, start, total;
	html_header(1);
	printf("<script src=" BBSJS "></script>\n");
	changemode(BACKNUMBER);
	//check_msg();
	getparmboard(board, sizeof(board));
	strsncpy(bkn, getparm("bkn"), 32);
	ptr = bkn;
	while (*ptr) {
		if (*ptr != 'B' && *ptr != '.' && !isdigit(*ptr))
			http_fatal("错误的过刊号");
		ptr++;
	}
	if (strlen(bkn) < 3)
		http_fatal("错误的过刊号");

	x1 = getboard(board);
	if (x1 == 0)
		nosuchboard(board, "bbsbkndoc");
	else {
		updateinboard(x1);
		strcpy(board, x1->header.filename);
		sprintf(dir, "boards/.backnumbers/%s/%s", board, bkn);
		if (!file_exist(dir))
			http_fatal("没有这卷过刊");
		sprintf(dir, "boards/.backnumbers/%s/%s/.DIR", board, bkn);
		fp = fopen(dir, "r");
		total = file_size(dir) / sizeof (struct fileheader);
		start = getdocstart(total, w_info->t_lines);
		printf("<body topmargin=0>");
		printf("<nobr><center>\n");
		sprintf(genbuf, "阅览过刊 文章数[%d]", total);
		printboardtop(x1, 5, genbuf);
		if (total <= 0)
			http_fatal("本卷过刊目前没有文章");
		printf("<table cellSpacing=0 cellPadding=2>\n");
		printf
		    ("<tr class=docbgcolor><td>序号<td>状态<td>作者<td>日期<td>标题<td>星级<td>评价</td>\n");
		if (fp) {
			fseek(fp, (start - 1) * sizeof (struct fileheader),
			      SEEK_SET);
			for (i = 0; i < w_info->t_lines; i++) {
				char filename[255];
				char *ptr;
				if (fread(&x, sizeof (x), 1, fp) <= 0)
					break;
				if (x.accessed & FH_HIDE) {
					printf
					    ("<tr><td>%d<td>&nbsp;<td>不详<td>不详<td>-本文已经被删除-<td>\n",
					     start + i);
					continue;
				}
				ptr = flag_str2(x.accessed, 1);
				sprintf(filename,
					"boards/.backnumbers/%s/%s/%s", board,
					bkn, fh2fname(&x));
				printf("<tr><td>%d<td>%s<td>%s", start + i, ptr,
				       userid_str(x.owner));
				printf("<td>%12.12s", Ctime(x.filetime) + 4);
				x.title[40] = 0;
				printf
				    ("<td><a href=bbsbkncon?B=%d&bkn=%s&file=%s&num=%d>%s%s </a>%s",
				     getbnumx(x1), bkn, fh2fname(&x), start + i - 1,
				     strncmp(x.title, "Re: ", 4) ? "○ " : "",
				     void1(titlestr(x.title)),
				     size_str(eff_size(filename)));
				printf("<td><font color=%s>%d</font>\n",
				       x.staravg50 ? "red" : "black",
				       x.staravg50 / 50);
				printf("<td><font color=%s>%d人</font>\n",
				       x.hasvoted ? "red" : "black",
				       x.hasvoted);
			}
			printf("</table>");
			printhr();
			fclose(fp);
		}
		sprintf(genbuf, "bbsbkndoc?B=%d&bkn=%s", getbnumx(x1), bkn);
		bbsdoc_helper(genbuf, start, total, w_info->t_lines);
		printf("<table><tr><td><form name=form1 action=bbsbkndoc>\n");
		printf("<input type=hidden name=B value=%d>", getbnumx(x1));
		printf("<input type=hidden name=bkn value=%s>", bkn);
		printf
		    ("<input type=submit value=跳转到> 第 <input type=text name=start size=4> 篇");
		printf("</form>\n");
		printf("</td><td><form name=form2 action=bbsdoc>\n");
		printf
		    ("<input type=submit value=跳转到><input type=text name=board size=5> 讨论区");
		printf("</form></td></tr></table>\n");
		showfile(MY_BBS_HOME "/wwwtmp/googleanalytics");
		printf("</body>");
		http_quit();
	}
	return 0;
}
예제 #10
0
int main(int argc, char *argv[]){
    int status = 0;
    struct sigaction act;
    pthread_t conn_thread, d_thread, p_thread, n_thread;
    enum conn_type d = CONN_DRIVER, p = CONN_PREV, n = CONN_NEXT;

    bool create = false;
    char *path = NULL, *next = NULL, *prev = NULL;
    unsigned long long int size = -1;

    int sig;
    act.sa_handler = handleExit;
    sigemptyset(&act.sa_mask);
    sigaddset(&act.sa_mask, SIGINT);
    sigaddset(&act.sa_mask, SIGTERM);
    sigaddset(&act.sa_mask, SIGQUIT);
    sigaddset(&act.sa_mask, SIGABRT);
    act.sa_flags = 0;

    sigaction(SIGINT, &act, NULL);
    sigaction(SIGTERM, &act, NULL);
    sigaction(SIGQUIT, &act, NULL);
    sigaction(SIGABRT, &act, NULL);

    if(argc < 3){
        printf("Usage: command [flags]\n");
        printf("-c PATH\tcreate lsvd_disk with pathname PATH\n");
        printf("-o PATH\topen existing lsvd_disk with pathname PATH\n");
        printf("-p NAME\tconnect replica to upstream host with NAME\n");
        printf("-n NAME\tconnect replica to downstream host with NAME\n");
        printf("-s SIZE\twhen -c used, initialize lsvd_disk with size SIZE Megabytes\n");
        exit(1);
    }    
    
    rmgr = new ReplicaManager();
    cmgr = new ConnectionManager();

    for (int i = 1; i < argc; i++){
        if (argv[i][0] != '-'){
            printf("Invalid flag\n");
        }
        switch(argv[i][1]){
            case 'c':
                if (i+1 < argc && path == NULL){
                    create = true;
                    printf("Path: %s\n", argv[i+1]);
                    path = argv[i+1];
                    i++;
                }
                break;
            case 'o':
                if (i+1 < argc && path == NULL){
                    create = false;
                    printf("Path: %s\n", argv[i+1]);
                    path = argv[i+1];
                    i++;
                }
                break;
            case 'p':
                if (i+1 < argc && prev == NULL){
                    printf("Previous name : %s\n", argv[i+1]);
                    prev = argv[i+1];
                    cmgr->update(CONN_PREV, prev);
                    cmgr->connect(CONN_PREV);
                    i++;
                }
                break;
            case 'n':
                if (i+1 < argc && next == NULL){
                    printf("Next name : %s\n");
                    next = argv[i+1];
                    cmgr->update(CONN_NEXT, next);
                    i++;
                }
                break;
            case 's':
                if (i+1 < argc && size == -1){
                    std::string size_str(argv[i+1]);
                    try {
                        size = stoull(size_str) * MB;
                    } catch(std::exception &e){
                        printf("Invalid size, using default\n");
                        size = DEFAULT_SIZE;
                    }
                    i++;
                }
                break;
            default:
                printf("Invalid option \n");
                exit(1);
        }
    }

    if (size == -1){
        size = DEFAULT_SIZE;
    }

    if (path != NULL){
        if (create){
            printf("Creating volume of size %lld Bytes\n", size);
            status = rmgr->create(path, size/LSVD_SECTORSIZE);
        } else {
            status = rmgr->open(path);
        }
    } else {
        printf("Invalid input parameters\n");
        exit(1);
    }

    if (status < 0){
        perror("LSVD open error\n");
        exit(1);
    }

    // Already established connection in 'p'
    if (prev != NULL && sendSyncRequest() < 0){
        perror("ERROR sync problem!");
        exit(1);
    }
   
    pthread_create(&d_thread, NULL, handleConnection, &d);
    pthread_create(&p_thread, NULL, handleConnection, &p);
    pthread_create(&n_thread, NULL, handleConnection, &n);

    pthread_join(d_thread, NULL);
    pthread_join(p_thread, NULL);
    pthread_join(n_thread, NULL);

    printf("Deleting rmgr, cmgr\n");

    delete rmgr;    // Wait for all threads to finish then delete rmgr
    delete cmgr;

    printf("Exiting main\n");
    return 0;
}