Exemplo n.º 1
0
void DriverSource::bootstrapThread() {
	prctl(PR_SET_NAME, (unsigned long)&"gatord-proc", 0, 0, 0);

	DynBuf printb;
	DynBuf b1;
	DynBuf b2;
	const uint64_t currTime = getTime();

	if (!readProcComms(currTime, mBuffer, &printb, &b1, &b2)) {
		logg->logError(__FILE__, __LINE__, "readProcComms failed");
		handleException();
	}

	mBuffer->commit(currTime);
	mBuffer->setDone();
}
void DriverSource::bootstrapThread() {
	prctl(PR_SET_NAME, (unsigned long)&"gatord-proc", 0, 0, 0);

	DynBuf printb;
	DynBuf b1;
	DynBuf b2;
	// MonotonicStarted may not be not assigned yet
	const uint64_t currTime = 0;//getTime() - gSessionData->mMonotonicStarted;

	if (!readProcComms(currTime, mBuffer, &printb, &b1, &b2)) {
		logg->logError("readProcComms failed");
		handleException();
	}

	mBuffer->commit(currTime);
	mBuffer->setDone();
}
Exemplo n.º 3
0
void PerfSource::run() {
	int pipefd[2];
	pthread_t procThread;
	ProcThreadArgs procThreadArgs;

	{
		DynBuf printb;
		DynBuf b1;
		DynBuf b2;

		const uint64_t currTime = getTime();

		// Start events before reading proc to avoid race conditions
		if (!mCountersGroup.start() || !mIdleGroup.start()) {
			logg->logError(__FILE__, __LINE__, "PerfGroup::start failed", __FUNCTION__, __FILE__, __LINE__);
			handleException();
		}

		if (!readProcComms(currTime, &mBuffer, &printb, &b1, &b2)) {
			logg->logError(__FILE__, __LINE__, "readProcComms failed");
			handleException();
		}
		mBuffer.commit(currTime);

		// Postpone reading kallsyms as on android adb gets too backed up and data is lost
		procThreadArgs.mBuffer = &mBuffer;
		procThreadArgs.mCurrTime = currTime;
		procThreadArgs.mIsDone = false;
		if (pthread_create(&procThread, NULL, procFunc, &procThreadArgs)) {
			logg->logError(__FILE__, __LINE__, "pthread_create failed", __FUNCTION__, __FILE__, __LINE__);
			handleException();
		}
	}

	if (pipe_cloexec(pipefd) != 0) {
		logg->logError(__FILE__, __LINE__, "pipe failed");
		handleException();
	}
	mInterruptFd = pipefd[1];

	if (!mMonitor.add(pipefd[0])) {
		logg->logError(__FILE__, __LINE__, "Monitor::add failed");
		handleException();
	}

	int timeout = -1;
	if (gSessionData->mLiveRate > 0) {
		timeout = gSessionData->mLiveRate/NS_PER_MS;
	}

	sem_post(mStartProfile);

	while (gSessionData->mSessionIsActive) {
		// +1 for uevents, +1 for pipe
		struct epoll_event events[NR_CPUS + 2];
		int ready = mMonitor.wait(events, ARRAY_LENGTH(events), timeout);
		if (ready < 0) {
			logg->logError(__FILE__, __LINE__, "Monitor::wait failed");
			handleException();
		}
		const uint64_t currTime = getTime();

		for (int i = 0; i < ready; ++i) {
			if (events[i].data.fd == mUEvent.getFd()) {
				if (!handleUEvent(currTime)) {
					logg->logError(__FILE__, __LINE__, "PerfSource::handleUEvent failed");
					handleException();
				}
				break;
			}
		}

		// send a notification that data is ready
		sem_post(mSenderSem);

		// In one shot mode, stop collection once all the buffers are filled
		// Assume timeout == 0 in this case
		if (gSessionData->mOneShot && gSessionData->mSessionIsActive) {
			logg->logMessage("%s(%s:%i): One shot", __FUNCTION__, __FILE__, __LINE__);
			child->endSession();
		}
	}

	procThreadArgs.mIsDone = true;
	pthread_join(procThread, NULL);
	mIdleGroup.stop();
	mCountersGroup.stop();
	mBuffer.setDone();
	mIsDone = true;

	// send a notification that data is ready
	sem_post(mSenderSem);

	mInterruptFd = -1;
	close(pipefd[0]);
	close(pipefd[1]);
}