Exemplo n.º 1
0
Arquivo: Driver.cpp Projeto: mw2q/dbt5
// RunTest
void CDriver::runTest(int iSleep, int iTestDuration)
{
	g_tid = (pthread_t*) malloc(sizeof(pthread_t) * iUsers);

	// before starting the test run Trade-Cleanup transaction
	cout << endl <<
			"Running Trade-Cleanup transaction before starting the test..." <<
			endl;
	m_pCDM->DoCleanupTxn();
	cout << "Trade-Cleanup transaction completed." << endl << endl;

	// time to sleep between thread creation, convert from millaseconds to
	// nanoseconds.
	struct timespec ts, rem;
	ts.tv_sec = (time_t) (iSleep / 1000);
	ts.tv_nsec = (long) (iSleep % 1000) * 1000000;

	// Caulculate when the test should stop.
	int threads_start_time =
			(int) ((double) iSleep / 1000.0 * (double) iUsers);
	stop_time = time(NULL) + iTestDuration + threads_start_time;

	CDateTime dtAux;
	dtAux.SetToCurrent();

	cout << "Test is starting at " << dtAux.ToStr(02) << endl <<
			"Estimated duration of ramp-up: " << threads_start_time <<
			" seconds" << endl;

	dtAux.AddMinutes((iTestDuration + threads_start_time)/60);
	cout << "Estimated end time " << dtAux.ToStr(02) << endl;

	logErrorMessage(">> Start of ramp-up.\n");

	// start thread that runs the Data Maintenance transaction
	entryDMWorkerThread(this);

	// parameter for the new thread
	PCustomerThreadParam pThrParam;

	for (int i = 1; i <= iUsers; i++) {
		pThrParam = new TCustomerThreadParam;
		// zero the structure
		memset(pThrParam, 0, sizeof(TCustomerThreadParam));
		pThrParam->pDriver = this;

		entryCustomerWorkerThread(reinterpret_cast<void *>(pThrParam), i);

		// Sleep for between starting terminals
		while (nanosleep(&ts, &rem) == -1) {
			if (errno == EINTR) {
				memcpy(&ts, &rem, sizeof(timespec));
			} else {
				ostringstream osErr;
				osErr << "sleep time invalid " << ts.tv_sec << " s " <<
						ts.tv_nsec << " ns" << endl;
				logErrorMessage(osErr.str());
				break;
			}
		}
	}

	// mark end of ramp-up
	m_MixLock.lock();
	m_fMix << (int) time(NULL) << ",START,,," <<
			(long long) pthread_self() << endl;
	m_MixLock.unlock();

	logErrorMessage(">> End of ramp-up.\n\n");

	// wait until all threads quit
	// 0 represents the Data-Maintenance thread
	for (int i = 0; i <= iUsers; i++) {
		if (pthread_join(g_tid[i], NULL) != 0) {
			throw new CThreadErr( CThreadErr::ERR_THREAD_JOIN,
					"Driver::RunTest" );
		}
	}
}
Exemplo n.º 2
0
/* Methods */
bool CBaseLogger::SendToLogger(const char *szPrefix, const char *szMsg)
{
    CDateTime curTime;
    return SendToLoggerImpl(szPrefix, curTime.ToStr(12), szMsg);
}