void FrameProfiler::processFrame() {

	std::lock_guard<std::mutex> vectorGuard(_eventsMutex);

	std::sort(_bufferedEvents.begin(), _bufferedEvents.end(), event_sorter);

	SCP_stringstream stream;

	SCP_vector<profile_sample> samples;

	bool start_found = false;
	bool end_found = false;
	uint64_t start_profile_time = 0;
	uint64_t end_profile_time = 0;

	for (auto& event : _bufferedEvents) {
		if (!start_found) {
			start_profile_time = event.timestamp;
			start_found = true;
		}
		if (!end_found) {
			end_profile_time = event.timestamp;
			end_found = true;
		}

		switch (event.type) {
			case EventType::Begin:
				process_begin(samples, event);
				break;
			case EventType::End:
				process_end(samples, event);
				break;
			default:
				break;
		}
	}
	_bufferedEvents.clear();

	dump_output(stream, start_profile_time, end_profile_time, samples);

	content = stream.str();
}
Exemple #2
0
/*
 * Executes a command from a list of args,
 * where args[0] is the command, and the rest are params.
 * 
 */
void execute(char *args[], int flag_background){

	char *command = args[0];
	if (DEBUG) printf("command: %s\n", command);

	int pid = fork();

	if (pid != 0){
		/* Parent code. */

		struct timeval start_time;
		struct rusage start_usage;

		gettimeofday(&start_time, NULL);
		getrusage(RUSAGE_CHILDREN, &start_usage);

		if (flag_background) {

			// If process is a background process

			//process is added to array of processes
			processes[num_processes].pid = pid;
			processes[num_processes].cmd = (char*) malloc(sizeof(command));
			gettimeofday(&processes[num_processes].start_time, NULL);
			strcpy(processes[num_processes].cmd, command);
			num_processes++;

			// handle background process
			process_end();

		}		

		else {

			// foreground process
			struct rusage end_usage;
			struct timeval end_time;
			wait4(pid, NULL, 0, &end_usage);

			gettimeofday(&end_time, NULL);

			double wall_time_passed = (end_time.tv_sec - start_time.tv_sec) * 1000 	+ (end_time.tv_usec - start_time.tv_usec)/1000;
			double cpu_time_user = (end_usage.ru_utime.tv_sec) * 1000 + (end_usage.ru_utime.tv_usec)/1000;
			double cpu_time_system = (end_usage.ru_stime.tv_sec) * 1000 
				+ (end_usage.ru_stime.tv_usec)/1000;
			long involuntary = end_usage.ru_nivcsw;
			long voluntary = end_usage.ru_nvcsw;
			long page_faults = end_usage.ru_majflt;
			long page_faults_sat = end_usage.ru_minflt;

			printf("\n--STATS FOR ENDED FOREGROUND PROCESS command: [%s]--\n", command);
			printf("Time passed: %f ms\n", wall_time_passed);
			printf("CPU user: %f ms\n", cpu_time_user);
			printf("CPU system: %f ms\n", cpu_time_system);
			printf("CPU user+system: %f ms\n", cpu_time_user+cpu_time_system);
			printf("Preempted CPU involuntary: %ld times\n", involuntary);
			printf("Preempted CPU voluntary: %ld times\n", voluntary);
			printf("Page faults: %ld times\n", page_faults);
			printf("Page faults (satisfiable): %ld times\n", page_faults_sat);
			printf("---------------------------------------------------------------\n");

			// handle existing background processes
			process_end();
		}
	}
	
	else {
		/* Child code. */
		if (execvp(command, &args[0]) < 0){
			printf("\nexecvp() failure\n");
		}
	}
}
Exemple #3
0
void task1(void)
{
	process_sleep(5000);
	kprintf("Ending process now!\n");
	process_end();
}