⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 xentop.c

📁 xen 3.2.2 源码
💻 C
📖 第 1 页 / 共 3 页
字号:
	/* Print program name, current time, and number of domains */	strftime(time_str, TIME_STR_LEN, TIME_STR_FORMAT,	         localtime((const time_t *)&curtime.tv_sec));	num_domains = xenstat_node_num_domains(cur_node);	ver_str = xenstat_node_xen_version(cur_node);	print("xentop - %s   Xen %s\n", time_str, ver_str);	/* Tabulate what states domains are in for summary */	for (i=0; i < num_domains; i++) {		domain = xenstat_node_domain_by_index(cur_node,i);		if (xenstat_domain_running(domain)) run++;		else if (xenstat_domain_blocked(domain)) block++;		else if (xenstat_domain_paused(domain)) pause++;		else if (xenstat_domain_shutdown(domain)) shutdown++;		else if (xenstat_domain_crashed(domain)) crash++;		else if (xenstat_domain_dying(domain)) dying++;	}	print("%u domains: %u running, %u blocked, %u paused, "	      "%u crashed, %u dying, %u shutdown \n",	      num_domains, run, block, pause, crash, dying, shutdown);	used = xenstat_node_tot_mem(cur_node)-xenstat_node_free_mem(cur_node);	/* Dump node memory and cpu information */	print("Mem: %lluk total, %lluk used, %lluk free    "	      "CPUs: %u @ %lluMHz\n",	      xenstat_node_tot_mem(cur_node)/1024, used/1024,	      xenstat_node_free_mem(cur_node)/1024,	      xenstat_node_num_cpus(cur_node),	      xenstat_node_cpu_hz(cur_node)/1000000);}/* Display the top header for the domain table */void do_header(void){	field_id i;	/* Turn on REVERSE highlight attribute for headings */	xentop_attron(A_REVERSE);	for(i = 0; i < NUM_FIELDS; i++) {		if (i != 0)			print(" ");		/* The BOLD attribute is turned on for the sort column */		if (i == sort_field)			xentop_attron(A_BOLD);		print("%*s", fields[i].default_width, fields[i].header);		if (i == sort_field)			xentop_attroff(A_BOLD);	}	xentop_attroff(A_REVERSE);	print("\n");}/* Displays bottom status line or current prompt */void do_bottom_line(void){	move(lines()-1, 2);	if (prompt != NULL) {		printw("%s: %s", prompt, prompt_val);	} else {		addch(A_REVERSE | 'D'); addstr("elay  ");		/* network */		addch(A_REVERSE | 'N');		attr_addstr(show_networks ? COLOR_PAIR(1) : 0, "etworks");		addstr("  ");				/* VBDs */		attr_addstr(show_vbds ? COLOR_PAIR(1) : 0, "v");		addch(A_REVERSE | 'B');		attr_addstr(show_vbds ? COLOR_PAIR(1) : 0, "ds");		addstr("  ");		/* vcpus */		addch(A_REVERSE | 'V');		attr_addstr(show_vcpus ? COLOR_PAIR(1) : 0, "CPUs");		addstr("  ");		/* repeat */		addch(A_REVERSE | 'R');		attr_addstr(repeat_header ? COLOR_PAIR(1) : 0, "epeat header");		addstr("  ");		/* sort order */		addch(A_REVERSE | 'S'); addstr("ort order  ");		addch(A_REVERSE | 'Q'); addstr("uit  ");	}}/* Prints Domain information */void do_domain(xenstat_domain *domain){	unsigned int i;	for (i = 0; i < NUM_FIELDS; i++) {		if (i != 0)			print(" ");		if (i == sort_field)			xentop_attron(A_BOLD);		fields[i].print(domain);		if (i == sort_field)			xentop_attroff(A_BOLD);	}	print("\n");}/* Output all vcpu information */void do_vcpu(xenstat_domain *domain){	int i = 0;	unsigned num_vcpus = 0;	xenstat_vcpu *vcpu;	print("VCPUs(sec): ");	num_vcpus = xenstat_domain_num_vcpus(domain);	/* for all online vcpus dump out values */	for (i=0; i< num_vcpus; i++) {		vcpu = xenstat_domain_vcpu(domain,i);		if (xenstat_vcpu_online(vcpu) > 0) {			if (i != 0 && (i%5)==0)				print("\n        ");			print(" %2u: %10llus", i, 					xenstat_vcpu_ns(vcpu)/1000000000);		}	}	print("\n");}/* Output all network information */void do_network(xenstat_domain *domain){	int i = 0;	xenstat_network *network;	unsigned num_networks = 0;	/* How many networks? */	num_networks = xenstat_domain_num_networks(domain);	/* Dump information for each network */	for (i=0; i < num_networks; i++) {		/* Next get the network information */		network = xenstat_domain_network(domain,i);		print("Net%d RX: %8llubytes %8llupkts %8lluerr %8lludrop  ",		      i,		      xenstat_network_rbytes(network),		      xenstat_network_rpackets(network),		      xenstat_network_rerrs(network),		      xenstat_network_rdrop(network));		print("TX: %8llubytes %8llupkts %8lluerr %8lludrop\n",		      xenstat_network_tbytes(network),		      xenstat_network_tpackets(network),		      xenstat_network_terrs(network),		      xenstat_network_tdrop(network));	}}/* Output all VBD information */void do_vbd(xenstat_domain *domain){	int i = 0;	xenstat_vbd *vbd;	unsigned num_vbds = 0;	const char *vbd_type[] = {		"Unidentified",           /* number 0 */		"BlkBack",           /* number 1 */		"BlkTap",            /* number 2 */	};		num_vbds = xenstat_domain_num_vbds(domain);	for (i=0 ; i< num_vbds; i++) {		char details[20];		vbd = xenstat_domain_vbd(domain,i);#if !defined(__linux__)		details[0] = '\0';#else		snprintf(details, 20, "[%2x:%2x] ",			 MAJOR(xenstat_vbd_dev(vbd)),			 MINOR(xenstat_vbd_dev(vbd)));#endif		print("VBD %s %4d %s OO: %8llu   RD: %8llu   WR: %8llu\n",		      vbd_type[xenstat_vbd_type(vbd)],		      xenstat_vbd_dev(vbd), details,		      xenstat_vbd_oo_reqs(vbd),		      xenstat_vbd_rd_reqs(vbd),		      xenstat_vbd_wr_reqs(vbd));	}}static void top(void){	xenstat_domain **domains;	unsigned int i, num_domains = 0;	/* Now get the node information */	if (prev_node != NULL)		xenstat_free_node(prev_node);	prev_node = cur_node;	cur_node = xenstat_get_node(xhandle, XENSTAT_ALL);	if (cur_node == NULL)		fail("Failed to retrieve statistics from libxenstat\n");	/* dump summary top information */	if (!batch)		do_summary();	/* Count the number of domains for which to report data */	num_domains = xenstat_node_num_domains(cur_node);	domains = malloc(num_domains*sizeof(xenstat_domain *));	if(domains == NULL)		fail("Failed to allocate memory\n");	for (i=0; i < num_domains; i++)		domains[i] = xenstat_node_domain_by_index(cur_node, i);	/* Sort */	qsort(domains, num_domains, sizeof(xenstat_domain *),	      (int(*)(const void *, const void *))compare_domains);	if(first_domain_index >= num_domains)		first_domain_index = num_domains-1;	for (i = first_domain_index; i < num_domains; i++) {		if(!batch && current_row() == lines()-1)			break;		if (i == first_domain_index || repeat_header)			do_header();		do_domain(domains[i]);		if (show_vcpus)			do_vcpu(domains[i]);		if (show_networks)			do_network(domains[i]);		if (show_vbds)			do_vbd(domains[i]);	}	if (!batch)		do_bottom_line();	free(domains);}static int signal_exit;void signal_exit_handler(int sig){	signal_exit = 1;}int main(int argc, char **argv){	int opt, optind = 0;	int ch = ERR;	struct option lopts[] = {		{ "help",          no_argument,       NULL, 'h' },		{ "version",       no_argument,       NULL, 'V' },		{ "networks",      no_argument,       NULL, 'n' },		{ "vbds",          no_argument,       NULL, 'x' },		{ "repeat-header", no_argument,       NULL, 'r' },		{ "vcpus",         no_argument,       NULL, 'v' },		{ "delay",         required_argument, NULL, 'd' },		{ "batch",	   no_argument,	      NULL, 'b' },		{ "iterations",	   required_argument, NULL, 'i' },		{ 0, 0, 0, 0 },	};	const char *sopts = "hVnxrvd:bi:";	if (atexit(cleanup) != 0)		fail("Failed to install cleanup handler.\n");	while ((opt = getopt_long(argc, argv, sopts, lopts, &optind)) != -1) {		switch (opt) {		default:			usage(argv[0]);			exit(1);		case '?':		case 'h':			usage(argv[0]);			exit(0);		case 'V':			version();			exit(0);		case 'n':			show_networks = 1;			break;		case 'x':			show_vbds = 1;			break;		case 'r':			repeat_header = 1;			break;		case 'v':			show_vcpus = 1;			break;		case 'd':			delay = atoi(optarg);			break;		case 'b':			batch = 1;			break;		case 'i':			iterations = atoi(optarg);			loop = 0;			break;		}	}	/* Get xenstat handle */	xhandle = xenstat_init();	if (xhandle == NULL)		fail("Failed to initialize xenstat library\n");	if (!batch) {		/* Begin curses stuff */		cwin = initscr();		start_color();		cbreak();		noecho();		nonl();		keypad(stdscr, TRUE);		halfdelay(5);#ifndef __sun__		use_default_colors();#endif		init_pair(1, -1, COLOR_YELLOW);		do {			gettimeofday(&curtime, NULL);			if(ch != ERR || (curtime.tv_sec - oldtime.tv_sec) >= delay) {				clear();				top();				oldtime = curtime;				refresh();				if ((!loop) && !(--iterations))					break;			}			ch = getch();		} while (handle_key(ch));	} else {		struct sigaction sa = {			.sa_handler = signal_exit_handler,			.sa_flags = 0		};		sigemptyset(&sa.sa_mask);		sigaction(SIGINT, &sa, NULL);		sigaction(SIGTERM, &sa, NULL);		do {			gettimeofday(&curtime, NULL);			top();			oldtime = curtime;			if ((!loop) && !(--iterations))				break;			sleep(delay);		} while (!signal_exit);	}	/* Cleanup occurs in cleanup(), so no work to do here. */	return 0;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -