当前位置: 首页>>代码示例>>C++>>正文


C++ FileSystem::getCacheEfficiency方法代码示例

本文整理汇总了C++中FileSystem::getCacheEfficiency方法的典型用法代码示例。如果您正苦于以下问题:C++ FileSystem::getCacheEfficiency方法的具体用法?C++ FileSystem::getCacheEfficiency怎么用?C++ FileSystem::getCacheEfficiency使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在FileSystem的用法示例。


在下文中一共展示了FileSystem::getCacheEfficiency方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: main

int main(int argc, char **argv) {
	if (argc > 5) {
		fprintf(stderr, "Syntax:   filesystem DATA_FILE PAGE_SIZE PAGE_COUNT TEST_DATA\n\n");
		fprintf(stderr, "Creates a filesystem inside DATAFILE with given parameters and tests it using\n");
		fprintf(stderr, "Data taken from the file TEST_DATA.\n\n");
		return 1;
	}

	argv[1] = "../temp/data_file";
	argv[2] = "4096";
	argv[3] = "1024";
	argv[4] = "../temp/test_data";

	char *fileName = argv[1];
	int pageSize = atoi(argv[2]);
	int pageCount = atoi(argv[3]);
	char *testData = argv[4];
	FileSystem *fs = new FileSystem(fileName, pageSize, pageCount);
	if (!fs->isActive()) {
		fprintf(stderr, "Could not create filesystem.\n");
		return 1;
	}

	int inputFile = open(testData, O_RDONLY);

	File **f = new File*[256];
	for (int i = 0; i < TEST_FILES; i++) {
		f[i] = new File(fs);
		printf("new handle: %i. fileCount: %i\n", f[i]->getHandle(), fs->getFileCount());
	}
	f[4]->deleteFile();
	delete f[4];
	f[4] = new File(fs);
	printf("new handle: %i. fileCount: %i\n", f[4]->getHandle(), fs->getFileCount());

	int cnt = 0;
	char buffer[373];
	int inputFileSize = 0;
	while (true) {
		int size = forced_read(inputFile, buffer, sizeof(buffer));
		if (size == 0)
			break;
		for (int i = 0; i < TEST_FILES; i++)
			f[i]->write(size, buffer);
		inputFileSize += size;
	}

	char *inputData = (char*)malloc(inputFileSize);
	lseek(inputFile, 0, SEEK_SET);
	forced_read(inputFile, inputData, inputFileSize);

	printf("Total pages: %i. Used: %i.\n", fs->getPageCount(), fs->getUsedPageCount());

	int64_t a, b, c, d;
	fs->getCacheEfficiency(&a, &b, &c, &d);
	printf("Cache efficiency: %i/%i reads, %i/%i writes.\n",
			(int)b, (int)a, (int)d, (int)c);

	for (int i = 0; i < TEST_FILES; i++) {
		lseek(inputFile, 0, SEEK_SET);
		f[i]->seek(0);
		printf("f[%i]->getSize() = %i\n", i, f[i]->getSize());
		for (int j = 0; j < f[i]->getSize(); j++) {
			char c;
			f[i]->read(1, &c);
			if (c != inputData[j])
				fprintf(stderr, "ERROR!\n");
		}
		printf("  File %i ok.\n", i);
	}

	printf("Before closing: %i %i %i.\n", fs->getPageSize(), fs->getPageCount(), fs->getFileCount());
	// close files and close filesystem
	for (int i = 0; i < TEST_FILES; i++)
		delete f[i];
	delete fs;
/*
	fs = new FileSystem(fileName);
	if (fs->defrag() == FILESYSTEM_ERROR) {
		fprintf(stderr, "defrag() returns error code.\n");
		return 1;
	}
	delete fs;
*/
	for (int loop = 0; loop < 256; loop++) {
		fs = new FileSystem(fileName);
		printf("After reopening: %i %i %i.\n", fs->getPageSize(), fs->getPageCount(), fs->getFileCount());
		for (int i = 0; i < TEST_FILES; i++) {
			lseek(inputFile, 0, SEEK_SET);
			f[i] = new File(fs, i, false);
			f[i]->seek(0);
			for (int j = 0; j < f[i]->getSize(); j++) {
				char c;
				f[i]->read(1, &c);
				if (c != inputData[j])
					fprintf(stderr, "ERROR!\n");
			}
			delete f[i];
		}
		delete fs;
//.........这里部分代码省略.........
开发者ID:gmargari,项目名称:wumpus,代码行数:101,代码来源:filesystem.cpp


注:本文中的FileSystem::getCacheEfficiency方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。