File xentop-expand-field-sizes.patch of Package xen.openSUSE_13.1_Update

bnc#896023

Index: xen-4.2.4-testing/tools/xenstat/xentop/xentop.c
===================================================================
--- xen-4.2.4-testing.orig/tools/xenstat/xentop/xentop.c
+++ xen-4.2.4-testing/tools/xenstat/xentop/xentop.c
@@ -241,6 +241,7 @@ static void usage(const char *program)
 	       "-b, --batch	     output in batch mode, no user input accepted\n"
 	       "-i, --iterations     number of iterations before exiting\n"
 	       "-f, --full-name      output the full domain name (not truncated)\n"
+	       "-c, --column-width <COLUMN NAME>=<WIDTH>    set the column width to hold larger values\n"
 	       "\n" XENTOP_BUGSTO,
 	       program);
 	return;
@@ -444,9 +445,9 @@ int compare_name(xenstat_domain *domain1
 void print_name(xenstat_domain *domain)
 {
 	if(show_full_name)
-		print("%10s", xenstat_domain_name(domain));
+		print("%*s", fields[FIELD_NAME-1].default_width, xenstat_domain_name(domain));
 	else
-		print("%10.10s", xenstat_domain_name(domain));
+		print("%*.10s", fields[FIELD_NAME-1].default_width, xenstat_domain_name(domain));
 }
 
 struct {
@@ -481,9 +482,11 @@ static int compare_state(xenstat_domain
 static void print_state(xenstat_domain *domain)
 {
 	unsigned int i;
+	char state[8];
 	for(i = 0; i < NUM_STATES; i++)
-		print("%c", state_funcs[i].get(domain) ? state_funcs[i].ch
-		                                       : '-');
+		state[i] = (state_funcs[i].get(domain) ? state_funcs[i].ch : '-');
+	state[NUM_STATES] = '\0';
+	print("%*s", fields[FIELD_STATE-1].default_width, state);
 }
 
 /* Compares cpu usage of two domains, returning -1,0,1 for <,=,> */
@@ -496,7 +499,7 @@ static int compare_cpu(xenstat_domain *d
 /* Prints domain cpu usage in seconds */
 static void print_cpu(xenstat_domain *domain)
 {
-	print("%10llu", xenstat_domain_cpu_ns(domain)/1000000000);
+	print("%*llu", fields[FIELD_CPU-1].default_width, xenstat_domain_cpu_ns(domain)/1000000000);
 }
 
 /* Computes the CPU percentage used for a specified domain */
@@ -532,7 +535,7 @@ static int compare_cpu_pct(xenstat_domai
 /* Prints cpu percentage statistic */
 static void print_cpu_pct(xenstat_domain *domain)
 {
-	print("%6.1f", get_cpu_pct(domain));
+	print("%*.1f", fields[FIELD_CPU_PCT-1].default_width, get_cpu_pct(domain));
 }
 
 /* Compares current memory of two domains, returning -1,0,1 for <,=,> */
@@ -545,14 +548,14 @@ static int compare_mem(xenstat_domain *d
 /* Prints current memory statistic */
 static void print_mem(xenstat_domain *domain)
 {
-	print("%10llu", xenstat_domain_cur_mem(domain)/1024);
+	print("%*llu", fields[FIELD_MEM-1].default_width, 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) /
+	print("%*.1f", fields[FIELD_MEM_PCT-1].default_width, (double)xenstat_domain_cur_mem(domain) /
 	               (double)xenstat_node_tot_mem(cur_node) * 100);
 }
 
@@ -567,10 +570,11 @@ static int compare_maxmem(xenstat_domain
 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");
+		print("%*s", fields[FIELD_MAXMEM-1].default_width, "no limit");
 	else
-		print("%10llu", max_mem/1024);
+		print("%*llu", fields[FIELD_MAXMEM-1].default_width, max_mem/1024);
 }
 
 /* Prints memory percentage statistic, ratio of current domain memory to total
@@ -578,9 +582,9 @@ static void print_maxmem(xenstat_domain
 static void print_max_pct(xenstat_domain *domain)
 {
 	if (xenstat_domain_max_mem(domain) == (unsigned long long)-1)
-		print("%9s", "n/a");
+		print("%*s", fields[FIELD_MAX_PCT-1].default_width, "n/a");
 	else
-		print("%9.1f", (double)xenstat_domain_max_mem(domain) /
+		print("%*.1f", fields[FIELD_MAX_PCT-1].default_width, (double)xenstat_domain_max_mem(domain) /
 		               (double)xenstat_node_tot_mem(cur_node) * 100);
 }
 
@@ -595,7 +599,7 @@ static int compare_vcpus(xenstat_domain
 /* Prints number of virtual CPUs statistic */
 static void print_vcpus(xenstat_domain *domain)
 {
-	print("%5u", xenstat_domain_num_vcpus(domain));
+	print("%*u", fields[FIELD_VCPUS-1].default_width, xenstat_domain_num_vcpus(domain));
 }
 
 /* Compares number of virtual networks of two domains, returning -1,0,1 for
@@ -609,7 +613,7 @@ static int compare_nets(xenstat_domain *
 /* Prints number of virtual networks statistic */
 static void print_nets(xenstat_domain *domain)
 {
-	print("%4u", xenstat_domain_num_networks(domain));
+	print("%*u", fields[FIELD_NETS-1].default_width, xenstat_domain_num_networks(domain));
 }
 
 /* Compares number of total network tx bytes of two domains, returning -1,0,1
@@ -623,7 +627,7 @@ static int compare_net_tx(xenstat_domain
 /* Prints number of total network tx bytes statistic */
 static void print_net_tx(xenstat_domain *domain)
 {
-	print("%8llu", tot_net_bytes(domain, FALSE)/1024);
+	print("%*llu", fields[FIELD_NET_TX-1].default_width, tot_net_bytes(domain, FALSE)/1024);
 }
 
 /* Compares number of total network rx bytes of two domains, returning -1,0,1
@@ -637,8 +641,8 @@ static int compare_net_rx(xenstat_domain
 /* Prints number of total network rx bytes statistic */
 static void print_net_rx(xenstat_domain *domain)
 {
-	print("%8llu", tot_net_bytes(domain, TRUE)/1024);
-}
+	print("%*llu", fields[FIELD_NET_RX-1].default_width, tot_net_bytes(domain, TRUE)/1024);
+ }
 
 /* Gets number of total network bytes statistic, if rx true, then rx bytes
  * otherwise tx bytes
@@ -677,7 +681,7 @@ static int compare_vbds(xenstat_domain *
 /* Prints number of virtual block devices statistic */
 static void print_vbds(xenstat_domain *domain)
 {
-	print("%4u", xenstat_domain_num_vbds(domain));
+	print("%*u", fields[FIELD_VBDS-1].default_width, xenstat_domain_num_vbds(domain));
 }
 
 /* Compares number of total VBD OO requests of two domains,
@@ -691,7 +695,7 @@ static int compare_vbd_oo(xenstat_domain
 /* 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));
+	print("%*llu", fields[FIELD_VBD_OO-1].default_width, tot_vbd_reqs(domain, FIELD_VBD_OO));
 }
 
 /* Compares number of total VBD READ requests of two domains,
@@ -705,7 +709,7 @@ static int compare_vbd_rd(xenstat_domain
 /* 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));
+	print("%*llu", fields[FIELD_VBD_RD-1].default_width, tot_vbd_reqs(domain, FIELD_VBD_RD));
 }
 
 /* Compares number of total VBD WRITE requests of two domains,
@@ -719,7 +723,7 @@ static int compare_vbd_wr(xenstat_domain
 /* 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));
+	print("%*llu", fields[FIELD_VBD_WR-1].default_width, tot_vbd_reqs(domain, FIELD_VBD_WR));
 }
 
 /* Compares number of total VBD READ sectors of two domains,
@@ -733,7 +737,7 @@ static int compare_vbd_rsect(xenstat_dom
 /* Prints number of total VBD READ sectors statistic */
 static void print_vbd_rsect(xenstat_domain *domain)
 {
-	print("%10llu", tot_vbd_reqs(domain, FIELD_VBD_RSECT));
+	print("%*llu", fields[FIELD_VBD_RSECT-1].default_width, tot_vbd_reqs(domain, FIELD_VBD_RSECT));
 }
 
 /* Compares number of total VBD WRITE sectors of two domains,
@@ -747,7 +751,7 @@ static int compare_vbd_wsect(xenstat_dom
 /* Prints number of total VBD WRITE sectors statistic */
 static void print_vbd_wsect(xenstat_domain *domain)
 {
-	print("%10llu", tot_vbd_reqs(domain, FIELD_VBD_WSECT));
+	print("%*llu", fields[FIELD_VBD_WSECT-1].default_width, tot_vbd_reqs(domain, FIELD_VBD_WSECT));
 }
 
 
@@ -803,7 +807,7 @@ static int compare_ssid(xenstat_domain *
 /* Prints ssid statistic */
 static void print_ssid(xenstat_domain *domain)
 {
-	print("%4u", xenstat_domain_ssid(domain));
+	print("%*u", fields[FIELD_SSID-1].default_width, xenstat_domain_ssid(domain));
 }
 
 /* Section printing functions */
@@ -1119,8 +1123,9 @@ static void signal_exit_handler(int sig)
 
 int main(int argc, char **argv)
 {
-	int opt, optind = 0;
+	int opt, width, i, optind = 0;
 	int ch = ERR;
+	char *str, *column_name;
 
 	struct option lopts[] = {
 		{ "help",          no_argument,       NULL, 'h' },
@@ -1133,9 +1138,10 @@ int main(int argc, char **argv)
 		{ "batch",	   no_argument,	      NULL, 'b' },
 		{ "iterations",	   required_argument, NULL, 'i' },
 		{ "full-name",     no_argument,       NULL, 'f' },
+		{ "column-width",  required_argument, NULL, 'c' },
 		{ 0, 0, 0, 0 },
 	};
-	const char *sopts = "hVnxrvd:bi:f";
+	const char *sopts = "hVnxrvd:bi:fc:";
 
 	if (atexit(cleanup) != 0)
 		fail("Failed to install cleanup handler.\n");
@@ -1180,6 +1186,26 @@ int main(int argc, char **argv)
 		case 't':
 			show_tmem = 1;
 			break;
+		case 'c':
+			column_name = NULL;
+			str=strchr(optarg, '=');
+			if (str != NULL) {
+				*str++ = 0;
+				for(i = 0; i < NUM_FIELDS; i++) {
+					if (!strcasecmp(fields[i].header, optarg)) {
+						column_name=optarg;
+						break;
+					}
+				}
+				if (column_name) {
+					width = atoi(str);
+					if (width > strlen(column_name))
+                				fields[i].default_width = width;
+				}
+			}
+			if (column_name == NULL)
+				fail("Invalid column name specified\n");
+			break;
 		}
 	}
 
openSUSE Build Service is sponsored by