Exemplo n.º 1
0
// Performance test.
void performance(char *fileName, fiftyoneDegreesWorksetPool *pool) {
	double totalSec, calibration, test;
	int memoryUsed;
	PERFORMANCE_STATE state;

	state.pool = pool;
	state.fileName = fileName;
#ifndef FIFTYONEDEGREES_NO_THREADING
	FIFTYONEDEGREES_MUTEX_CREATE(state.lock);
#endif

	state.test = "Caching Data";
	state.calibrate = 1;
	state.max = 0;
	state.numberOfThreads = 1;
	state.passes = 1;
	performTest(&state);

	state.numberOfThreads = THREAD_COUNT;
	state.max = state.count * state.numberOfThreads;
	state.passes = PASSES;
	state.test = "Calibrate";
	calibration = performTest(&state);
	state.test = "Detection test";
	state.calibrate = 0;
	test = performTest(&state);

	// Get the memory needed for a provider.
	memoryUsed = (int)fiftyoneDegreesGetProviderSizeWithPropertyCount(pool->dataSet->fileName, (int)pool->dataSet->requiredPropertyCount, (int)pool->size, (int)pool->cache->total);
	memoryUsed = memoryUsed / 1048576;

	// Time to complete.
	totalSec = test - calibration;
	printf("Number of records per iteration: %i s\n", state.count);
	printf("Average detection time for total data set: %.2f s\n", totalSec);
	printf("Average number of detections per second per thread: %.2f\n", (double)state.max / totalSec / (double)state.numberOfThreads);
	printf("Average milliseconds per detection: %.6f\n", (totalSec * (double)1000) / (double)state.max);
	printf("Memory used by a provider initialised with the given arguments: %d Mb\n", memoryUsed);
	if (pool->cache != NULL) {
		printf("Cache hits: %d\n", pool->cache->hits);
		printf("Cache misses: %d\n", pool->cache->misses);
		printf("Cache switches: %d\n", pool->cache->switches);
	}

#ifndef FIFTYONEDEGREES_NO_THREADING
	FIFTYONEDEGREES_MUTEX_CLOSE(state.lock);
#endif

	// Wait for a character to be pressed.
	fgetc(stdin);
}
Exemplo n.º 2
0
// Performance test.
void performance(char *fileName, fiftyoneDegreesWorksetPool *pool) {
	double totalSec, calibration, test;
	PERFORMANCE_STATE state;

	state.pool = pool;
	state.fileName = fileName;
#ifndef FIFTYONEDEGREES_NO_THREADING
	FIFTYONEDEGREES_MUTEX_CREATE(state.lock);
#endif

	state.test = "Caching Data";
	state.calibrate = 1;
	state.max = 0;
	state.numberOfThreads = 1;
	state.passes = 1;
	performTest(&state);

	state.numberOfThreads = THREAD_COUNT;
	state.max = state.count * state.numberOfThreads;
	state.passes = PASSES;
	state.test = "Calibrate";
	calibration = performTest(&state);
	state.test = "Detection test";
	state.calibrate = 0;
	test = performTest(&state);

	// Time to complete.
	totalSec = test - calibration;
	printf("Average detection time for total data set: %.2f s\n", totalSec);
	printf("Average number of detections per second per thread: %.2f\n", (double)state.max / totalSec / (double)state.numberOfThreads);
	printf("Average milliseconds per detection: %.6f\n", (totalSec * (double)1000) / (double)state.max / (double)state.numberOfThreads);
	if (pool->cache != NULL) {
		printf("Cache hits: %d\n", pool->cache->hits);
		printf("Cache misses: %d\n", pool->cache->misses);
		printf("Cache switches: %d\n", pool->cache->switches);
	}

#ifndef FIFTYONEDEGREES_NO_THREADING
	FIFTYONEDEGREES_MUTEX_CLOSE(state.lock);
#endif

	// Wait for a character to be pressed.
	fgetc(stdin);
}
Exemplo n.º 3
0
int main(int argc, char* argv[]) {

	// Required properties. Empty string initializes all properties.
	const char* requiredProperties = "IsMobile,BrowserName";

	// Path to 51Degrees data files. Or use default paths.
	const char* fileName = argc > 1 ? argv[1] :
		"../../../data/51Degrees-LiteV3.2.dat";
	// Path to file containing HTTP User-Agent strings.
	const char* inputFile = argc > 2 ? argv[2] :
		"../../../data/20000 User Agents.csv";

#ifdef _DEBUG
#ifndef _MSC_VER
	dmalloc_debug_setup("log-stats,log-non-free,check-fence,log=dmalloc.log");
#else
	_CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE);
	_CrtSetReportFile(_CRT_WARN, _CRTDBG_FILE_STDERR);
#endif
#endif

	// How many times the dataset was reloaded.
	int numberOfReloads = 0;

#ifndef FIFTYONEDEGREES_NO_THREADING
	printf("** Multi Threaded Reload Example **\r\n");
#else
	printf("** Single Threaded Reload Example **\r\n");
#endif

	// Create a pool of 4 worksets with a cache for 1000 items.
	fiftyoneDegreesDataSetInitStatus status =
		fiftyoneDegreesInitProviderWithPropertyString(
		fileName, &provider, requiredProperties, 4, 1000);
	if (status != DATA_SET_INIT_STATUS_SUCCESS) {
		reportDatasetInitStatus(status, fileName);
		fgetc(stdin);
		return 1;
	}

#ifndef FIFTYONEDEGREES_NO_THREADING
	FIFTYONEDEGREES_MUTEX_CREATE(lock);
	if (FIFTYONEDEGREES_MUTEX_VALID(&lock)) {
		startThreads(inputFile);

		char *fileInMemory;
		long currentFileSize;

		while (threadsFinished < numberOfThreads) {
			// Load file into memory.
			currentFileSize = loadFile(fileName, &fileInMemory);
			// Refresh the current dataset.
			fiftyoneDegreesProviderReloadFromMemory(&provider, (void*)fileInMemory, currentFileSize);
			fiftyoneDegreesDataSet *ds = (fiftyoneDegreesDataSet*)provider.activePool->dataSet;
			// Tell the API to free the memory occupied by the data file when the dataset is freed.
			ds->memoryToFree = (void*)fileInMemory;

			numberOfReloads++;
#ifdef _MSC_VER
			Sleep(1000); // milliseconds
#else
			sleep(1); // seconds
#endif
		}
		stopThreads();
		FIFTYONEDEGREES_MUTEX_CLOSE(lock);
	}
#else
	numberOfReloads = runRequest(inputFile);
#endif

	// Free the pool, dataset and cache.
	fiftyoneDegreesProviderFree(&provider);

	// Finish execution.
	printf("Reloaded '%i' times.\r\n", numberOfReloads);

#ifdef _DEBUG
#ifdef _MSC_VER
	_CrtDumpMemoryLeaks();
#else
	printf("Log file is %s\r\n", dmalloc_logpath);
#endif
#endif

	printf("Program execution complete. Press any Return to exit.");
	fgetc(stdin);

	return 0;
}