⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 b_workload.c

📁 linux 下的源代码分析阅读器 red hat公司新版
💻 C
📖 第 1 页 / 共 2 页
字号:
		}	}	TIMER_STOP;	TIMER_GET(config->tot_time);	return (0);}intrun_std_workload(dbp, config)	DB *dbp;	CONFIG *config;{	DBT key, data;	DBC *dbc;	u_int32_t i, ret;	char kbuf[10];	/* Setup a key/data pair. */	INIT_KEY(key, config);	memset(&data, 0, sizeof(data));	DB_BENCH_ASSERT(	    (data.data = malloc(data.size = config->dsize)) != NULL);	/* Store the key/data pair count times. */	TIMER_START;	for (i = 0; i < config->pcount; ++i) {		GET_KEY_NEXT(key, config, kbuf, i);		DB_BENCH_ASSERT(dbp->put(dbp, NULL, &key, &data, 0) == 0);	}	TIMER_STOP;	TIMER_GET(config->put_time);	if (is_get_workload(config->workload) == 0) {		TIMER_START;		for (i = 0; i <= config->gcount; ++i) {			DB_BENCH_ASSERT(dbp->cursor(dbp, NULL, &dbc, 0) == 0);			while ((dbc->c_get(dbc, &key, &data, DB_NEXT)) == 0);			DB_BENCH_ASSERT(dbc->c_close(dbc) == 0);		}		TIMER_STOP;		TIMER_GET(config->get_time);	}	if (is_del_workload(config->workload) == 0) {		/* reset rand to reproduce key sequence. */		srand(config->seed);		TIMER_START;		if (config->cursor_del != 0) {			DB_BENCH_ASSERT(dbp->cursor(dbp, NULL, &dbc, 0) == 0);			while (			    (ret = dbc->c_get(dbc, &key, &data, DB_NEXT)) == 0)				DB_BENCH_ASSERT(dbc->c_del(dbc, 0) == 0);			DB_BENCH_ASSERT (ret == DB_NOTFOUND);		} else {			INIT_KEY(key, config);			for (i = 0; i < config->pcount; ++i) {				GET_KEY_NEXT(key, config, kbuf, i);				ret = dbp->del(dbp, NULL, &key, 0);				/*				 * Random key generation can cause dups,				 * so NOTFOUND result is OK.				 */				if (config->ksize == 0)					DB_BENCH_ASSERT					    (ret == 0 || ret == DB_NOTFOUND);				else					DB_BENCH_ASSERT(ret == 0);			}		}		TIMER_STOP;		TIMER_GET(config->del_time);	}	return (0);}intdump_verbose_stats(dbp, config)	DB *dbp;	CONFIG *config;{/* * It would be nice to be able to define stat as _stat on * Windows, but that substitutes _stat for the db call as well. */#ifdef DB_WIN32	struct _stat fstat;#else	struct stat fstat;#endif	DB_HASH_STAT *hstat;	DB_BTREE_STAT *bstat;	double free_prop;#ifdef DB_BENCH_INCLUDE_CONFIG_SUMMARY	printf("Completed workload benchmark.\n");	printf("Configuration summary:\n");	printf("\tworkload type: %d\n", (int)config->workload);	printf("\tdatabase type: %s\n", config->ts);	if (config->cachesz != 0)		printf("\tcache size: %lu\n", (u_long)config->cachesz);	if (config->pagesz != 0)		printf("\tdatabase page size: %lu\n", (u_long)config->pagesz);	printf("\tput element count: %lu\n", (u_long)config->pcount);	if ( is_get_workload(config->workload) == 0)		printf("\tget element count: %lu\n", (u_long)config->gcount);	if (config->orderedkeys)		printf("\tInserting items in order\n");	else if (config->ksize == 0)		printf("\tInserting keys with size 10\n");	else		printf(		    "\tInserting keys with size: %lu\n", (u_long)config->ksize);	printf("\tInserting data elements size: %lu\n", (u_long)config->dsize);	if (is_del_workload(config->workload) == 0) {		if (config->cursor_del)			printf("\tDeleting items using a cursor\n");		else			printf("\tDeleting items without a cursor\n");	}#endif /* DB_BENCH_INCLUDE_CONFIG_SUMMARY */	if (is_put_workload(config->workload) == 0)		printf("%s Time spent inserting (%lu) (%s) items: %lu/%lu\n",		    config->message[0] == '\0' ? "" : config->message,		    (u_long)config->pcount, config->ts,		    (u_long)config->put_time.tv_sec, config->put_time.tv_nsec);	if (is_get_workload(config->workload) == 0)		printf("%s Time spent getting (%lu) (%s) items: %lu/%lu\n",		    config->message[0] == '\0' ? "" : config->message,		    (u_long)config->pcount * ((config->gcount == 0) ?		    1 : config->gcount), config->ts,		    (u_long)config->get_time.tv_sec, config->get_time.tv_nsec);	if (is_del_workload(config->workload) == 0)		printf("%s Time spent deleting (%lu) (%s) items: %lu/%lu\n",		    config->message[0] == '\0' ? "" : config->message,		    (u_long)config->pcount, config->ts,		    (u_long)config->del_time.tv_sec, config->del_time.tv_nsec);#ifdef DB_WIN32	if (_stat("TESTDIR/a", &fstat) == 0) {#else	if (stat("TESTDIR/a", &fstat) == 0) {#endif		printf("%s Size of db file (%s): %lu K\n",		    config->message[0] == '\0' ? "" : config->message,		    config->ts, (u_long)fstat.st_size/1024);	}	if (config->type == DB_HASH) {#if DB_VERSION_MAJOR < 3 || DB_VERSION_MAJOR == 3 && DB_VERSION_MINOR <= 2		DB_BENCH_ASSERT(dbp->stat(dbp, &hstat, NULL, 0) == 0);#elif DB_VERSION_MAJOR < 4 || DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR <= 2		DB_BENCH_ASSERT(dbp->stat(dbp, &hstat, 0) == 0);#else		DB_BENCH_ASSERT(dbp->stat(dbp, NULL, &hstat, 0) == 0);#endif		/*		 * Hash fill factor is a bit tricky. Want to include		 * both bucket and overflow buckets (not offpage).		 */		free_prop = hstat->hash_pagesize*hstat->hash_buckets;		free_prop += hstat->hash_pagesize*hstat->hash_overflows;		free_prop =		    (free_prop - hstat->hash_bfree - hstat->hash_ovfl_free)/		    free_prop;		printf("%s db fill factor (%s): %.2f%%\n",		    config->message[0] == '\0' ? "" : config->message,		    config->ts, free_prop*100);		free(hstat);	} else { /* Btree */#if DB_VERSION_MAJOR < 3 || DB_VERSION_MAJOR == 3 && DB_VERSION_MINOR <= 2		DB_BENCH_ASSERT(dbp->stat(dbp, &bstat, NULL, 0) == 0);#elif DB_VERSION_MAJOR < 4 || DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR <= 2		DB_BENCH_ASSERT(dbp->stat(dbp, &bstat, 0) == 0);#else		DB_BENCH_ASSERT(dbp->stat(dbp, NULL, &bstat, 0) == 0);#endif		free_prop = bstat->bt_pagesize*bstat->bt_leaf_pg;		free_prop = (free_prop-bstat->bt_leaf_pgfree)/free_prop;		printf("%s db fill factor (%s): %.2f%%\n",		    config->message[0] == '\0' ? "" : config->message,		    config->ts, free_prop*100);		free(bstat);	}	return (0);}char *workload_str(workload)	int workload;{	static char buf[128];	switch (workload) {	case T_PUT_GET_DELETE:		return ("PUT/GET/DELETE");		/* NOTREACHED */	case T_GET:		return ("GET");		/* NOTREACHED */	case T_PUT:		return ("PUT");		/* NOTREACHED */	case T_DELETE:		return ("DELETE");		/* NOTREACHED */	case T_PUT_GET:		return ("PUT/GET");		/* NOTREACHED */	case T_PUT_DELETE:		return ("PUT/DELETE");		/* NOTREACHED */	case T_GET_DELETE:		return ("GET/DELETE");		/* NOTREACHED */	case T_MIXED:		snprintf(buf, sizeof(buf), "MIXED (get: %d, put: %d, del: %d)",		    (int)GET_PROPORTION,		    (int)PUT_PROPORTION, (int)DEL_PROPORTION);		return (buf);	default:		break;	}	exit(usage());	/* NOTREACHED */}intis_get_workload(workload)	int workload;{	switch (workload) {	case T_GET:	case T_PUT_GET:	case T_PUT_GET_DELETE:	case T_GET_DELETE:		return 0;	}	return 1;}intis_put_workload(workload)	int workload;{	switch (workload) {	case T_PUT:	case T_PUT_GET:	case T_PUT_GET_DELETE:	case T_PUT_DELETE:		return 0;	}	return 1;}intis_del_workload(workload)	int workload;{	switch (workload) {	case T_DELETE:	case T_PUT_DELETE:	case T_PUT_GET_DELETE:	case T_GET_DELETE:		return 0;	}	return 1;}intusage(){	(void)fprintf(stderr,	    "usage: b_workload [-b cachesz] [-c count] [-d bytes] [-e]\n");	(void)fprintf(stderr,	    "\t[-g getitrs] [-i] [-k keysize] [-m message] [-o] [-p pagesz]\n");	(void)fprintf(stderr, "\t[-r dup_count] [-t type] [-w type]\n");	(void)fprintf(stderr, "Where:\n");	(void)fprintf(stderr, "\t-b the size of the DB cache.\n");	(void)fprintf(stderr, "\t-c the number of elements to be measured.\n");	(void)fprintf(stderr, "\t-d the size of each data element.\n");	(void)fprintf(stderr, "\t-e delete entries using a cursor.\n");	(void)fprintf(stderr, "\t-g number of get cursor traverses.\n");	(void)fprintf(stderr, "\t-i Pre-init hash DB bucket count.\n");	(void)fprintf(stderr, "\t-k the size of each key inserted.\n");	(void)fprintf(stderr, "\t-m message pre-pended to log output.\n");	(void)fprintf(stderr, "\t-o keys should be ordered for insert.\n");	(void)fprintf(stderr, "\t-p the page size for the database.\n");	(void)fprintf(stderr, "\t-r the number of duplicates to insert\n");	(void)fprintf(stderr, "\t-t type of the underlying database.\n");	(void)fprintf(stderr, "\t-w the workload to measure, available:\n");	(void)fprintf(stderr, "\t\tA - PUT_GET_DELETE\n");	(void)fprintf(stderr, "\t\tB - GET\n");	(void)fprintf(stderr, "\t\tC - PUT\n");	(void)fprintf(stderr, "\t\tD - DELETE\n");	(void)fprintf(stderr, "\t\tE - PUT_GET\n");	(void)fprintf(stderr, "\t\tF - PUT_DELETE\n");	(void)fprintf(stderr, "\t\tG - GET_DELETE\n");	(void)fprintf(stderr, "\t\tH - MIXED\n");	return (EXIT_FAILURE);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -