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

📄 xentop.c

📁 xen 3.2.2 源码
💻 C
📖 第 1 页 / 共 3 页
字号:
			if(prompt_val_len > 0)				prompt_val[--prompt_val_len] = '\0';		default:			if((prompt_val_len+1) < PROMPT_VAL_LEN			   && isprint(ch)) {				prompt_val[prompt_val_len++] = (char)ch;				prompt_val[prompt_val_len] = '\0';			}		}	}	return 1;}/* Compares two integers, returning -1,0,1 for <,=,> */static int compare(unsigned long long i1, unsigned long long i2){	if(i1 < i2)		return -1;	if(i1 > i2)		return 1;	return 0;}/* Comparison function for use with qsort.  Compares two domains using the * current sort field. */static int compare_domains(xenstat_domain **domain1, xenstat_domain **domain2){	return fields[sort_field].compare(*domain1, *domain2);}/* Field functions *//* Compare domain names, returning -1,0,1 for <,=,> */int compare_name(xenstat_domain *domain1, xenstat_domain *domain2){	return strcasecmp(xenstat_domain_name(domain1), xenstat_domain_name(domain2));}/* Prints domain name */void print_name(xenstat_domain *domain){	print("%10s", xenstat_domain_name(domain));}struct {	unsigned int (*get)(xenstat_domain *);	char ch;} state_funcs[] = {	{ xenstat_domain_dying,    'd' },	{ xenstat_domain_shutdown, 's' },	{ xenstat_domain_blocked,  'b' },	{ xenstat_domain_crashed,  'c' },	{ xenstat_domain_paused,   'p' },	{ xenstat_domain_running,  'r' }};const unsigned int NUM_STATES = sizeof(state_funcs)/sizeof(*state_funcs);/* Compare states of two domains, returning -1,0,1 for <,=,> */static int compare_state(xenstat_domain *domain1, xenstat_domain *domain2){	unsigned int i, d1s, d2s;	for(i = 0; i < NUM_STATES; i++) {		d1s = state_funcs[i].get(domain1);		d2s = state_funcs[i].get(domain2);		if(d1s && !d2s)			return -1;		if(d2s && !d1s)			return 1;	}	return 0;}/* Prints domain state in abbreviated letter format */static void print_state(xenstat_domain *domain){	unsigned int i;	for(i = 0; i < NUM_STATES; i++)		print("%c", state_funcs[i].get(domain) ? state_funcs[i].ch		                                       : '-');}/* Compares cpu usage of two domains, returning -1,0,1 for <,=,> */static int compare_cpu(xenstat_domain *domain1, xenstat_domain *domain2){	return -compare(xenstat_domain_cpu_ns(domain1),			xenstat_domain_cpu_ns(domain2));}/* Prints domain cpu usage in seconds */static void print_cpu(xenstat_domain *domain){	print("%10llu", xenstat_domain_cpu_ns(domain)/1000000000);}/* Computes the CPU percentage used for a specified domain */static double get_cpu_pct(xenstat_domain *domain){	xenstat_domain *old_domain;	double us_elapsed;	/* Can't calculate CPU percentage without a previous sample. */	if(prev_node == NULL)		return 0.0;	old_domain = xenstat_node_domain(prev_node, xenstat_domain_id(domain));	if(old_domain == NULL)		return 0.0;	/* Calculate the time elapsed in microseconds */	us_elapsed = ((curtime.tv_sec-oldtime.tv_sec)*1000000.0		      +(curtime.tv_usec - oldtime.tv_usec));	/* In the following, nanoseconds must be multiplied by 1000.0 to	 * convert to microseconds, then divided by 100.0 to get a percentage,	 * resulting in a multiplication by 10.0 */	return ((xenstat_domain_cpu_ns(domain)		 -xenstat_domain_cpu_ns(old_domain))/10.0)/us_elapsed;}static int compare_cpu_pct(xenstat_domain *domain1, xenstat_domain *domain2){	return -compare(get_cpu_pct(domain1), get_cpu_pct(domain2));}/* Prints cpu percentage statistic */static void print_cpu_pct(xenstat_domain *domain){	print("%6.1f", get_cpu_pct(domain));}/* Compares current memory of two domains, returning -1,0,1 for <,=,> */static int compare_mem(xenstat_domain *domain1, xenstat_domain *domain2){	return -compare(xenstat_domain_cur_mem(domain1),	                xenstat_domain_cur_mem(domain2));}/* Prints current memory statistic */static void print_mem(xenstat_domain *domain){	print("%10llu", xenstat_domain_cur_mem(domain)/1024);}/* Prints memory percentage statistic, ratio of current domain memory to total * node memory */static void print_mem_pct(xenstat_domain *domain){	print("%6.1f", (double)xenstat_domain_cur_mem(domain) /	               (double)xenstat_node_tot_mem(cur_node) * 100);}/* Compares maximum memory of two domains, returning -1,0,1 for <,=,> */static int compare_maxmem(xenstat_domain *domain1, xenstat_domain *domain2){	return -compare(xenstat_domain_max_mem(domain1),	                xenstat_domain_max_mem(domain2));}/* Prints maximum domain memory statistic in KB */static void print_maxmem(xenstat_domain *domain){	unsigned long long max_mem = xenstat_domain_max_mem(domain);	if(max_mem == ((unsigned long long)-1))		print("%10s", "no limit");	else		print("%10llu", max_mem/1024);}/* Prints memory percentage statistic, ratio of current domain memory to total * node memory */static void print_max_pct(xenstat_domain *domain){	if (xenstat_domain_max_mem(domain) == (unsigned long long)-1)		print("%9s", "n/a");	else		print("%9.1f", (double)xenstat_domain_max_mem(domain) /		               (double)xenstat_node_tot_mem(cur_node) * 100);}/* Compares number of virtual CPUs of two domains, returning -1,0,1 for * <,=,> */static int compare_vcpus(xenstat_domain *domain1, xenstat_domain *domain2){	return -compare(xenstat_domain_num_vcpus(domain1),	                xenstat_domain_num_vcpus(domain2));}/* Prints number of virtual CPUs statistic */static void print_vcpus(xenstat_domain *domain){	print("%5u", xenstat_domain_num_vcpus(domain));}/* Compares number of virtual networks of two domains, returning -1,0,1 for * <,=,> */static int compare_nets(xenstat_domain *domain1, xenstat_domain *domain2){	return -compare(xenstat_domain_num_networks(domain1),	                xenstat_domain_num_networks(domain2));}/* Prints number of virtual networks statistic */static void print_nets(xenstat_domain *domain){	print("%4u", xenstat_domain_num_networks(domain));}/* Compares number of total network tx bytes of two domains, returning -1,0,1 * for <,=,> */static int compare_net_tx(xenstat_domain *domain1, xenstat_domain *domain2){	return -compare(tot_net_bytes(domain1, FALSE),	                tot_net_bytes(domain2, FALSE));}/* Prints number of total network tx bytes statistic */static void print_net_tx(xenstat_domain *domain){	print("%8llu", tot_net_bytes(domain, FALSE)/1024);}/* Compares number of total network rx bytes of two domains, returning -1,0,1 * for <,=,> */static int compare_net_rx(xenstat_domain *domain1, xenstat_domain *domain2){	return -compare(tot_net_bytes(domain1, TRUE),	                tot_net_bytes(domain2, TRUE));}/* Prints number of total network rx bytes statistic */static void print_net_rx(xenstat_domain *domain){	print("%8llu", tot_net_bytes(domain, TRUE)/1024);}/* Gets number of total network bytes statistic, if rx true, then rx bytes * otherwise tx bytes */static unsigned long long tot_net_bytes(xenstat_domain *domain, int rx_flag){	int i = 0;	xenstat_network *network;	unsigned num_networks = 0;	unsigned long long total = 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);		if (rx_flag)			total += xenstat_network_rbytes(network);		else			total += xenstat_network_tbytes(network);	}	return total;}/* Compares number of virtual block devices of two domains,   returning -1,0,1 for * <,=,> */static int compare_vbds(xenstat_domain *domain1, xenstat_domain *domain2){	return -compare(xenstat_domain_num_vbds(domain1),	                xenstat_domain_num_vbds(domain2));}/* Prints number of virtual block devices statistic */static void print_vbds(xenstat_domain *domain){	print("%4u", xenstat_domain_num_vbds(domain));}/* Compares number of total VBD OO requests of two domains,   returning -1,0,1 * for <,=,> */static int compare_vbd_oo(xenstat_domain *domain1, xenstat_domain *domain2){  return -compare(tot_vbd_reqs(domain1, FIELD_VBD_OO),		  tot_vbd_reqs(domain2, FIELD_VBD_OO));}/* Prints number of total VBD OO requests statistic */static void print_vbd_oo(xenstat_domain *domain){	print("%8llu", tot_vbd_reqs(domain, FIELD_VBD_OO));}/* Compares number of total VBD READ requests of two domains,   returning -1,0,1 * for <,=,> */static int compare_vbd_rd(xenstat_domain *domain1, xenstat_domain *domain2){	return -compare(tot_vbd_reqs(domain1, FIELD_VBD_RD),			tot_vbd_reqs(domain2, FIELD_VBD_RD));}/* Prints number of total VBD READ requests statistic */static void print_vbd_rd(xenstat_domain *domain){	print("%8llu", tot_vbd_reqs(domain, FIELD_VBD_RD));}/* Compares number of total VBD WRITE requests of two domains,   returning -1,0,1 * for <,=,> */static int compare_vbd_wr(xenstat_domain *domain1, xenstat_domain *domain2){	return -compare(tot_vbd_reqs(domain1,FIELD_VBD_WR),			tot_vbd_reqs(domain2,FIELD_VBD_WR));}/* Prints number of total VBD WRITE requests statistic */static void print_vbd_wr(xenstat_domain *domain){	print("%8llu", tot_vbd_reqs(domain,FIELD_VBD_WR));}/* Gets number of total VBD requests statistic,  *   if flag is FIELD_VBD_OO, then OO requests, *   if flag is FIELD_VBD_RD, then READ requests and *   if flag is FIELD_VBD_WR, then WRITE requests. */static unsigned long long tot_vbd_reqs(xenstat_domain *domain, int flag){	int i = 0;	xenstat_vbd *vbd;	unsigned num_vbds = 0;	unsigned long long total = 0;		num_vbds = xenstat_domain_num_vbds(domain);		for ( i=0 ; i < num_vbds ; i++) {		vbd = xenstat_domain_vbd(domain,i);		switch(flag) {		case FIELD_VBD_OO:			total += xenstat_vbd_oo_reqs(vbd);			break;		case FIELD_VBD_RD:			total += xenstat_vbd_rd_reqs(vbd);			break;		case FIELD_VBD_WR:			total += xenstat_vbd_wr_reqs(vbd);			break;		default:			break;		}	}		return total;}/* Compares security id (ssid) of two domains, returning -1,0,1 for <,=,> */static int compare_ssid(xenstat_domain *domain1, xenstat_domain *domain2){	return compare(xenstat_domain_ssid(domain1),		       xenstat_domain_ssid(domain2));}/* Prints ssid statistic */static void print_ssid(xenstat_domain *domain){	print("%4u", xenstat_domain_ssid(domain));}/* Section printing functions *//* Prints the top summary, above the domain table */void do_summary(void){#define TIME_STR_LEN 9	const char *TIME_STR_FORMAT = "%H:%M:%S";	char time_str[TIME_STR_LEN];	const char *ver_str;	unsigned run = 0, block = 0, pause = 0,	         crash = 0, dying = 0, shutdown = 0;	unsigned i, num_domains = 0;	unsigned long long used = 0;	xenstat_domain *domain;

⌨️ 快捷键说明

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