示例#1
0
文件: top.c 项目: 1002victor/Firmware
int
top_main(int argc, char *argv[])
{
	hrt_abstime curr_time = hrt_absolute_time();

	struct print_load_s load;
	init_print_load_s(curr_time, &load);

	/* clear screen */
	dprintf(1, "\033[2J\n");

	if (argc > 1 && !strcmp(argv[1], "once")) {
		print_load(curr_time, 1, &load);
		sleep(1);
		print_load(hrt_absolute_time(), 1, &load);
		return 0;
	}

	for (;;) {
		print_load(curr_time, 1, &load);

		/* Sleep 200 ms waiting for user input five times ~ 1s */
		for (int k = 0; k < 5; k++) {
			char c;

			struct pollfd fds;
			int ret;
			fds.fd = 0; /* stdin */
			fds.events = POLLIN;
			ret = poll(&fds, 1, 0);

			if (ret > 0) {

				read(0, &c, 1);

				switch (c) {
				case 0x03: // ctrl-c
				case 0x1b: // esc
				case 'c':
				case 'q':
					return OK;
					/* not reached */
				}
			}

			usleep(200000);
		}

		curr_time = hrt_absolute_time();
	}

	return OK;
}
示例#2
0
文件: top.c 项目: AgamAgarwal/minix
static void showtop(int cputimemode, int r)
{
#define NLOADS 3
	double loads[NLOADS];
	int nloads, lines = 0;
	struct winsize winsize;

	if(ioctl(STDIN_FILENO, TIOCGWINSZ, &winsize) != 0) {
		perror("TIOCGWINSZ");
		fprintf(stderr, "TIOCGWINSZ failed\n");
		exit(1);
	}

	get_procs();
	if (prev_proc == NULL)
		get_procs();

	if((nloads = getloadavg(loads, NLOADS)) != NLOADS) {
		fprintf(stderr, "getloadavg() failed - %d loads\n", nloads);
		exit(1);
	}


	printf("%s", Tclr_all);

	lines += print_load(loads, NLOADS);
	lines += print_proc_summary(proc);
	lines += print_memory();

	if(winsize.ws_row > 0) r = winsize.ws_row;

	print_procs(r - lines - 2, prev_proc, proc, cputimemode);
	fflush(NULL);
}
示例#3
0
void menu(){

	//Infinite loop game and menu
	while (1){
		print_menu();

		//Get the current key pressed and decide on action
		int key = _getch();
		if (key == 27){
			//Esc
			exit(0);
		}else if (key == 72 && selected > 0){
			//Up arrow key
			selected --;
		}else if (key == 80){
			//Down arrow key and check if selection is out of bounds
			if ((stage == 0 && selected < 2) || (stage == 1 && selected < 4)){
				selected ++;
			}
		}else if (key == 13){
			//Enter button and check stage and apply vars accordingly
			if (stage == 0){
				difficulty = selected;
				stage += 1;
				selected = 0;
			}else if (stage == 1){
				theme = selected;
				stage += 1;
				selected = 0;
			}	
		}

		//Check if all options have been selected and start game with config
		if (theme != -1 && difficulty != -1){
			print_load();
			Sleep(100);

			switch (difficulty){
				case 0:
					start_game(3,5,0,theme);
				break;
				case 1:
					start_game(6,8,1,theme);
				break;
				case 2:
					start_game(9,20,2,theme);
				break;
			}

			//Reset variables for new menu
			stage = 0;
			selected = 0;
			difficulty = -1;
			theme =-1;
		}
	}
}
示例#4
0
void showtop(int r)
{
#define NLOADS 3
	double loads[NLOADS];
	int nloads, i, p, lines = 0;
	static struct proc prev_proc[PROCS], proc[PROCS];
	struct winsize winsize;
        static struct pm_mem_info pmi;
	static int prev_uptime, uptime;
	static struct mproc mproc[NR_PROCS];
	struct tms tms;

	uptime = times(&tms);

	if(ioctl(STDIN_FILENO, TIOCGWINSZ, &winsize) != 0) {
		perror("TIOCGWINSZ");
		fprintf(stderr, "TIOCGWINSZ failed\n");
		exit(1);
	}

        if(getsysinfo(PM_PROC_NR, SI_MEM_ALLOC, &pmi) < 0) {
		fprintf(stderr, "getsysinfo() for SI_MEM_ALLOC failed.\n");
		exit(1);;
	}

	if(getsysinfo(PM_PROC_NR, SI_KPROC_TAB, proc) < 0) {
		fprintf(stderr, "getsysinfo() for SI_KPROC_TAB failed.\n");
		exit(1);
	}

	if(getsysinfo(PM_PROC_NR, SI_PROC_TAB, mproc) < 0) {
		fprintf(stderr, "getsysinfo() for SI_PROC_TAB failed.\n");
		exit(1);
	}

	if((nloads = getloadavg(loads, NLOADS)) != NLOADS) {
		fprintf(stderr, "getloadavg() failed - %d loads\n", nloads);
		exit(1);
	}


	printf("%s", Tclr_all);

	lines += print_load(loads, NLOADS);
	lines += print_proc_summary(proc);
	lines += print_memory(&pmi);

	if(winsize.ws_row > 0) r = winsize.ws_row;

	print_procs(r - lines - 2, prev_proc,
		proc, uptime-prev_uptime, mproc);

	memcpy(prev_proc, proc, sizeof(prev_proc));
	prev_uptime = uptime;
}
示例#5
0
void showtop(int r)
{
#define NLOADS 3
	double loads[NLOADS];
	int nloads, i, p, lines = 0;
	static struct proc prev_proc[PROCS], proc[PROCS];
	static int preheated = 0;
	struct winsize winsize;
        /*
	static struct pm_mem_info pmi;
	*/
	static struct mproc mproc[NR_PROCS];
	int mem = 0;

	if(ioctl(STDIN_FILENO, TIOCGWINSZ, &winsize) != 0) {
		perror("TIOCGWINSZ");
		fprintf(stderr, "TIOCGWINSZ failed\n");
		exit(1);
	}

#if 0
        if(getsysinfo(PM_PROC_NR, SI_MEM_ALLOC, &pmi) < 0) {
		fprintf(stderr, "getsysinfo() for SI_MEM_ALLOC failed.\n");
		mem = 0;
		exit(1);;
	} else mem = 1;
#endif

retry:
	if(getsysinfo(PM_PROC_NR, SI_KPROC_TAB, proc) < 0) {
		fprintf(stderr, "getsysinfo() for SI_KPROC_TAB failed.\n");
		exit(1);
	}
	if (!preheated) {
		preheated = 1;
		memcpy(prev_proc, proc, sizeof(prev_proc));
		goto retry;;
	}

	if(getsysinfo(PM_PROC_NR, SI_PROC_TAB, mproc) < 0) {
		fprintf(stderr, "getsysinfo() for SI_PROC_TAB failed.\n");
		exit(1);
	}

	if((nloads = getloadavg(loads, NLOADS)) != NLOADS) {
		fprintf(stderr, "getloadavg() failed - %d loads\n", nloads);
		exit(1);
	}


	printf("%s", Tclr_all);

	lines += print_load(loads, NLOADS);
	lines += print_proc_summary(proc);
#if 0
	if(mem) { lines += print_memory(&pmi); }
#endif

	if(winsize.ws_row > 0) r = winsize.ws_row;

	print_procs(r - lines - 2, prev_proc,
		proc, mproc);

	memcpy(prev_proc, proc, sizeof(prev_proc));
}
示例#6
0
文件: stats.c 项目: jvesely/helenos
int main(int argc, char *argv[])
{
	bool toggle_tasks = true;
	bool toggle_threads = false;
	bool toggle_all = false;
	bool toggle_cpus = false;
	bool toggle_load = false;
	bool toggle_uptime = false;
	
	task_id_t task_id = 0;
	
	int i;
	for (i = 1; i < argc; i++) {
		int off;
		
		/* Usage */
		if ((off = arg_parse_short_long(argv[i], "-h", "--help")) != -1) {
			usage(argv[0]);
			return 0;
		}
		
		/* All threads */
		if ((off = arg_parse_short_long(argv[i], "-a", "--all")) != -1) {
			toggle_tasks = false;
			toggle_threads = true;
			toggle_all = true;
			continue;
		}
		
		/* CPUs */
		if ((off = arg_parse_short_long(argv[i], "-c", "--cpus")) != -1) {
			toggle_tasks = false;
			toggle_cpus = true;
			continue;
		}
		
		/* Threads */
		if ((off = arg_parse_short_long(argv[i], "-t", "--task=")) != -1) {
			// TODO: Support for 64b range
			int tmp;
			int ret = arg_parse_int(argc, argv, &i, &tmp, off);
			if (ret != EOK) {
				printf("%s: Malformed task_id '%s'\n", NAME, argv[i]);
				return -1;
			}
			
			task_id = tmp;
			
			toggle_tasks = false;
			toggle_threads = true;
			continue;
		}
		
		/* Load */
		if ((off = arg_parse_short_long(argv[i], "-l", "--load")) != -1) {
			toggle_tasks = false;
			toggle_load = true;
			continue;
		}
		
		/* Uptime */
		if ((off = arg_parse_short_long(argv[i], "-u", "--uptime")) != -1) {
			toggle_tasks = false;
			toggle_uptime = true;
			continue;
		}
	}
	
	if (toggle_tasks)
		list_tasks();
	
	if (toggle_threads)
		list_threads(task_id, toggle_all);
	
	if (toggle_cpus)
		list_cpus();
	
	if (toggle_load)
		print_load();
	
	if (toggle_uptime)
		print_uptime();
	
	return 0;
}
示例#7
0
int main(int argc, char **argv) {
	int fn = 0, ch;
	int is_dir = 0;
	struct stat st;
	char src[256];
	int fileSize = 0;
	int chunk=-1;
	char *result_file_n="";
	
	char buffer[16*1024];
	char *cwd;
	
        setvbuf(stdout, buffer, _IOFBF, sizeof(buffer));

	f_result = stdout;

	while ((ch = getopt(argc, argv, "456hdDUVf:T:b:p:s:o:S:")) != -1) {
		switch (ch) {
			case 'd':
				deleted_pages_only = 1;
				break;
			case 'D':
			    deleted_records_only = 1;
			    undeleted_records_only = 0;
				break;
			case 'U':
			    undeleted_records_only = 1;
				break;
			case 'o':
				strncpy(result_file, optarg, sizeof(result_file));
				/*if(NULL == (f_result = fopen(result_file, "w"))){
					fprintf(stderr, "Can't open file %s for writing\n", result_file);
					exit(-1);
					}*/
				break;
			case 'f':
				strncpy(src, optarg, sizeof(src));
				if(stat(src, &st) == 0){
					if(S_ISDIR(st.st_mode)){
						is_dir = 1;
						}
					}
				else{
					perror("stat");
					fprintf(stderr, "Can't stat %s\n", src);
					exit(-1);
					}
				break;
			case 'V':
				debug = 1;
				break;
            		case '4':
                		process_redundant = 1;
                		break;
            		case '5':
                		process_compact = 1;
             	 		break;
            		case '6':
                		process_56 = 1;
             	 		break; 
            		case 'T':
                		set_filter_id(optarg);
                		break;
            		case 'b':
                		strncpy(blob_dir, optarg, sizeof(blob_dir));
                		break;
			case 'p':
				strncpy(dump_prefix, optarg, sizeof(dump_prefix));
				break;
			case 's':
				strncpy(schema, optarg, sizeof(schema));
				break;
			case 'S':
				chunk_size = atoi(optarg);
				break;
			default:
			case '?':
			case 'h':
				usage();
		}
	}
	char buffpath[2048 + 1];

	cwd=getcwd( buffpath, 2048 );

	if (cwd != NULL){
	   if(result_file[0] !='\0'){
	     if(result_file[0] !='/'){
	       asprintf(&result_file_n,"%s/%s",cwd,result_file);
	       strcpy(result_file,result_file_n);
	       result_file_n="";
	      // fprintf(stdout, "Current path   %s\n", result_file);
	       fflush(stdout);
	       
	    }
	  }
	}
	else{
           perror("getcwd() error");
	  exit(-1);
	}

	
	if(chunk_size > 0){
	  chunk_size = (chunk_size * 1024)*1024;
	  chunk = 0;
	}

	if(is_dir){
		DIR *src_dir;
		char src_file[256];
		struct dirent *de;
		src_dir = opendir(src);
		int file_count = 0;


/*
		while(NULL != (de = readdir(src_dir))){
			if(!strncmp(de->d_name, ".", sizeof(de->d_name))) continue;
			if(!strncmp(de->d_name, "..", sizeof(de->d_name))) continue;
            snprintf(src_file, sizeof(src_file), "%s/%s", src, de->d_name);
			if(debug) { fprintf(stderr, "Processing %s\n", src_file); }
			fprintf(stderr, "Processing %s\n", src_file);
			if(0 == (fn = open_ibfile(src_file))){
				fprintf(stderr, "Can't open %s\n", src_file);
				perror("open_ibfile");
				exit(-1);
				}
			process_ibfile(fn);
			close(fn);
			}
*/
/*The pages are NOT read from the readdir function in sorted order
 * To have them sorted we have to process them first
 *
 * Below we first identify the number of files to parse
 *
 * then we create an array with all the names and we sort it
 *
 * Then we process it.
 *
 * Process can be optimize, but at least is not presenting the pages in sparse order in the result file.
 *
 * Use debug option to enable the progress view
 */

/*
 * Start Patch \/
 */
		while(NULL != (de = readdir(src_dir))){
			if(!strncmp(de->d_name, ".", sizeof(de->d_name))) continue;
			if(!strncmp(de->d_name, "..", sizeof(de->d_name))) continue;
			file_count++;

		}
		//fprintf(stderr, "File to process %d\n", file_count); 
		char result[file_count][1024];
		int indexres = 0;

		src_dir = opendir(src);
		while(NULL != (de = readdir(src_dir))){
			if(!strncmp(de->d_name, ".", sizeof(de->d_name))) continue;
			if(!strncmp(de->d_name, "..", sizeof(de->d_name))) continue;
			
			snprintf(src_file, sizeof(src_file), "%s/%s", src, de->d_name);

			strcpy(result[indexres++], src_file) ;
		//	if(debug){ 
			//  fprintf(stderr, "Loading %s\n", src_file); 
			  
		//	}
		}

		closedir(src_dir);

		int i,j;
		char t[1024];

		for(i=0;i<file_count;i++){
		    for(j=0;j<file_count;j++)
		        {
		    	if(i == 0 && j == 0){
			  //fprintf(stderr, "First element  %d %s\n", j,result[j]);
			}
			else{
			  //fprintf(stderr, "value  %d\n", strcmp(result[j-1],result[j])>0);
			  if(strcmp(result[j-1],result[j])>0)
			      {
			      strcpy(t,result[j-1]);
			      strcpy(result[j-1],result[j]);
			      strcpy(result[j],t);
			      }
			}

			}
		    }


			indexres = 0;
			struct stat st;
			
			//if(debug){
			//fprintf(stderr, "Processing, \nTotal pages to process %d %s",file_count, ":");
			  
			//}
			
			if((result_file[0] !='\0')
			  && chunk_size > 0 ){
			  asprintf(&result_file_n,"%s_chunk_0.csv",result_file);
			  if(NULL == (f_result = fopen(result_file_n, "w"))){
				  fprintf(stderr, "Can't open file %s for writing\n", result_file);
				  exit(-1);
			    }
			  }
			  else if((result_file[0] !='\0')
			  && chunk_size == 0 ){
			  asprintf(&result_file_n,"%s.csv",result_file);
			  if(NULL == (f_result = fopen(result_file, "w"))){
				  fprintf(stderr, "Can't open file %s for writing\n", result_file);
				  exit(-1);
			    }
			}
			  
			
			
			while(indexres<file_count){
				if(debug){fprintf(stderr, "%s", ".");}
				//fprintf(stderr, "\nOpening file %s \n", result[indexres]);
				
				if(0 == (fn = open_ibfile(result[indexres]))){
					fprintf(stderr, "Can't open %s\n", result[indexres]);
					perror("open_ibfile");
					exit(-1);
					}

				process_ibfile(fn);				
				fflush(f_result);
				
				if(chunk == 0){
				  print_load(result_file_n);
				  chunk=1;
				}
				
				stat(result_file_n,&st);
				fileSize = st.st_size;
				//fprintf(stderr,"File dimension of %s = %d",result_file_n,fileSize);
				
				if(result_file_n[0] !='\0' 
				  && chunk_size > 0 
				  && fileSize > chunk_size)
				{
				    fclose(f_result);
				  
				    result_file_n="";
				    asprintf(&result_file_n,"%s_chunk_%d.csv",result_file,chunk++);
				    
				    
				    if(NULL == (f_result = fopen(result_file_n, "w"))){
					    fprintf(stderr, "Can't open file %s for writing\n", result_file);
					    exit(-1);
				    }
				    print_load(result_file_n);
				  
				  
				  
				 
				  
				}
				
				indexres++;
				close(fn);
			 }
			 if(result_file[0] =='\0'){
			   
			    print_load("");
			}
			else if(chunk_size == 0){
			  print_load(result_file_n);
			}
			if(debug){fprintf(stderr, "%s\n", "END Processing\n");}
/*
 * END Patch /\
 */


		}
	else{
		if(0 == (fn = open_ibfile(src))){
			fprintf(stderr, "Can't open %s\n", src);
			perror("open_ibfile");
			exit(-1);
			}
		process_ibfile(fn);
		close(fn);
		}

	
	
	if (!process_compact && !process_redundant) {
        printf("Error: Please, specify what format your datafile in. Use -4 for mysql 4.1 and below and -5 for 5.X+\n");
        usage();
	}
	
	
	return 0;
}