direct-io.hg
changeset 7501:a793b7a53605
* Enable xenstat to use xenstore
* Have xentop display names instead of DomIDs
as requested in Bugzilla#311 filed by Ian
* Have xentop display names instead of DomIDs
as requested in Bugzilla#311 filed by Ian
author | jeroney@localhost.localdomain |
---|---|
date | Thu Oct 27 10:19:58 2005 +0100 (2005-10-27) |
parents | 20d1a79ebe31 |
children | e70ea9465b31 |
files | tools/xenstat/libxenstat/Makefile tools/xenstat/libxenstat/src/xenstat.c tools/xenstat/libxenstat/src/xenstat.h tools/xenstat/xentop/Makefile tools/xenstat/xentop/xentop.c |
line diff
1.1 --- a/tools/xenstat/libxenstat/Makefile Wed Oct 26 16:59:13 2005 +0100 1.2 +++ b/tools/xenstat/libxenstat/Makefile Thu Oct 27 10:19:58 2005 +0100 1.3 @@ -38,13 +38,13 @@ SONAME_FLAGS=-Wl,-soname -Wl,libxenstat. 1.4 1.5 WARN_FLAGS=-Wall -Werror 1.6 1.7 -CFLAGS+=-Isrc -I$(XEN_LIBXC) 1.8 +CFLAGS+=-Isrc -I$(XEN_LIBXC) -I$(XEN_XENSTORE) 1.9 LDFLAGS+=-Lsrc 1.10 1.11 all: $(LIB) 1.12 1.13 $(LIB): $(OBJECTS) 1.14 - $(AR) rc $@ $^ 1.15 + $(AR) rc $@ $^ $(XEN_XENSTORE)/libxenstore.so 1.16 $(RANLIB) $@ 1.17 1.18 $(SHLIB): $(OBJECTS)
2.1 --- a/tools/xenstat/libxenstat/src/xenstat.c Wed Oct 26 16:59:13 2005 +0100 2.2 +++ b/tools/xenstat/libxenstat/src/xenstat.c Thu Oct 27 10:19:58 2005 +0100 2.3 @@ -21,6 +21,7 @@ 2.4 #include <string.h> 2.5 #include <unistd.h> 2.6 #include <xen-interface.h> 2.7 +#include <xs.h> 2.8 #include "xenstat.h" 2.9 2.10 /* 2.11 @@ -31,6 +32,7 @@ 2.12 2.13 struct xenstat_handle { 2.14 xi_handle *xihandle; 2.15 + struct xs_handle *xshandle; /* xenstore handle */ 2.16 int page_size; 2.17 FILE *procnetdev; 2.18 char xen_version[VERSION_SIZE]; /* xen version running on this node */ 2.19 @@ -49,6 +51,7 @@ struct xenstat_node { 2.20 2.21 struct xenstat_domain { 2.22 unsigned int id; 2.23 + char *name; 2.24 unsigned int state; 2.25 unsigned long long cpu_ns; 2.26 unsigned int num_vcpus; /* No. vcpus configured for domain */ 2.27 @@ -110,6 +113,7 @@ static void xenstat_free_xen_version(xen 2.28 static void xenstat_uninit_vcpus(xenstat_handle * handle); 2.29 static void xenstat_uninit_networks(xenstat_handle * handle); 2.30 static void xenstat_uninit_xen_version(xenstat_handle * handle); 2.31 +static char *xenstat_get_domain_name(xenstat_handle * handle, unsigned int domain_id); 2.32 2.33 static xenstat_collector collectors[] = { 2.34 { XENSTAT_VCPU, xenstat_collect_vcpus, 2.35 @@ -153,6 +157,13 @@ xenstat_handle *xenstat_init() 2.36 return NULL; 2.37 } 2.38 2.39 + handle->xshandle = xs_daemon_open_readonly(); /* open handle to xenstore*/ 2.40 + if (handle->xshandle == NULL) { 2.41 + perror("unable to open xenstore\n"); 2.42 + free(handle); 2.43 + return NULL; 2.44 + } 2.45 + 2.46 return handle; 2.47 } 2.48 2.49 @@ -163,6 +174,7 @@ void xenstat_uninit(xenstat_handle * han 2.50 for (i = 0; i < NUM_COLLECTORS; i++) 2.51 collectors[i].uninit(handle); 2.52 xi_uninit(handle->xihandle); 2.53 + xs_daemon_close(handle->xshandle); 2.54 free(handle); 2.55 } 2.56 } 2.57 @@ -228,6 +240,7 @@ xenstat_node *xenstat_get_node(xenstat_h 2.58 for (i = 0; i < new_domains; i++) { 2.59 /* Fill in domain using domaininfo[i] */ 2.60 domain->id = domaininfo[i].domain; 2.61 + domain->name = xenstat_get_domain_name(handle, domaininfo[i].domain); 2.62 domain->state = domaininfo[i].flags; 2.63 domain->cpu_ns = domaininfo[i].cpu_time; 2.64 domain->num_vcpus = (domaininfo[i].max_vcpu_id+1); 2.65 @@ -339,6 +352,12 @@ unsigned xenstat_domain_id(xenstat_domai 2.66 return domain->id; 2.67 } 2.68 2.69 +/* Get the domain name for the domain */ 2.70 +char *xenstat_domain_name(xenstat_domain * domain) 2.71 +{ 2.72 + return domain->name; 2.73 +} 2.74 + 2.75 /* Get information about how much CPU time has been used */ 2.76 unsigned long long xenstat_domain_cpu_ns(xenstat_domain * domain) 2.77 { 2.78 @@ -675,3 +694,25 @@ static void xenstat_free_xen_version(xen 2.79 static void xenstat_uninit_xen_version(xenstat_handle * handle) 2.80 { 2.81 } 2.82 + 2.83 +static char *xenstat_get_domain_name(xenstat_handle *handle, unsigned int domain_id) 2.84 +{ 2.85 + char path[80]; 2.86 + char *name; 2.87 + unsigned int *len; 2.88 + struct xs_transaction_handle *xstranshandle; 2.89 + 2.90 + snprintf(path, sizeof(path),"/local/domain/%i/name", domain_id); 2.91 + 2.92 + xstranshandle = xs_transaction_start(handle->xshandle); 2.93 + if (xstranshandle == NULL) { 2.94 + perror("Unable to get transcation handle from xenstore\n"); 2.95 + exit(1); /* Change this */ 2.96 + } 2.97 + 2.98 + name = (char *) xs_read(handle->xshandle, xstranshandle, path, len); 2.99 + 2.100 + xs_transaction_end(handle->xshandle, xstranshandle, false); 2.101 + 2.102 + return name; 2.103 +}
3.1 --- a/tools/xenstat/libxenstat/src/xenstat.h Wed Oct 26 16:59:13 2005 +0100 3.2 +++ b/tools/xenstat/libxenstat/src/xenstat.h Thu Oct 27 10:19:58 2005 +0100 3.3 @@ -80,6 +80,9 @@ unsigned long long xenstat_node_cpu_hz(x 3.4 /* Get the domain ID for this domain */ 3.5 unsigned xenstat_domain_id(xenstat_domain * domain); 3.6 3.7 +/* Set the domain name for the domain */ 3.8 +char *xenstat_domain_name(xenstat_domain * domain); 3.9 + 3.10 /* Get information about how much CPU time has been used */ 3.11 unsigned long long xenstat_domain_cpu_ns(xenstat_domain * domain); 3.12
4.1 --- a/tools/xenstat/xentop/Makefile Wed Oct 26 16:59:13 2005 +0100 4.2 +++ b/tools/xenstat/xentop/Makefile Thu Oct 27 10:19:58 2005 +0100 4.3 @@ -26,7 +26,7 @@ mandir=$(prefix)/share/man 4.4 man1dir=$(mandir)/man1 4.5 sbindir=$(prefix)/sbin 4.6 4.7 -CFLAGS += -DGCC_PRINTF -Wall -Werror -I$(XEN_LIBXENSTAT) 4.8 +CFLAGS += -DGCC_PRINTF -Wall -I$(XEN_LIBXENSTAT) 4.9 LDFLAGS += -L$(XEN_LIBXENSTAT) 4.10 LDLIBS += -lxenstat -lncurses 4.11
5.1 --- a/tools/xenstat/xentop/xentop.c Wed Oct 26 16:59:13 2005 +0100 5.2 +++ b/tools/xenstat/xentop/xentop.c Thu Oct 27 10:19:58 2005 +0100 5.3 @@ -28,6 +28,7 @@ 5.4 #include <time.h> 5.5 #include <unistd.h> 5.6 5.7 +#include <xs.h> 5.8 #include <xenstat.h> 5.9 5.10 #define XENTOP_VERSION "1.0" 5.11 @@ -91,6 +92,8 @@ static int compare_net_rx(xenstat_domain 5.12 static void print_net_rx(xenstat_domain *domain); 5.13 static int compare_ssid(xenstat_domain *domain1, xenstat_domain *domain2); 5.14 static void print_ssid(xenstat_domain *domain); 5.15 +static int compare_name(xenstat_domain *domain1, xenstat_domain *domain2); 5.16 +static void print_name(xenstat_domain *domain); 5.17 5.18 /* Section printing functions */ 5.19 static void do_summary(void); 5.20 @@ -104,6 +107,7 @@ static void top(void); 5.21 /* Field types */ 5.22 typedef enum field_id { 5.23 FIELD_DOMID, 5.24 + FIELD_NAME, 5.25 FIELD_STATE, 5.26 FIELD_CPU, 5.27 FIELD_CPU_PCT, 5.28 @@ -127,7 +131,8 @@ typedef struct field { 5.29 } field; 5.30 5.31 field fields[] = { 5.32 - { FIELD_DOMID, "DOMID", 5, compare_domid, print_domid }, 5.33 +// { FIELD_DOMID, "DOMID", 5, compare_domid, print_domid }, 5.34 + { FIELD_NAME, "NAME", 10, compare_name, print_name }, 5.35 { FIELD_STATE, "STATE", 6, compare_state, print_state }, 5.36 { FIELD_CPU, "CPU(sec)", 10, compare_cpu, print_cpu }, 5.37 { FIELD_CPU_PCT, "CPU(%)", 6, compare_cpu_pct, print_cpu_pct }, 5.38 @@ -356,6 +361,18 @@ void print_domid(xenstat_domain *domain) 5.39 print("%5u", xenstat_domain_id(domain)); 5.40 } 5.41 5.42 +/* Compare domain names, returning -1,0,1 for <,=,> */ 5.43 +int compare_name(xenstat_domain *domain1, xenstat_domain *domain2) 5.44 +{ 5.45 + return strcasecmp(xenstat_domain_name(domain1), xenstat_domain_name(domain2)); 5.46 +} 5.47 + 5.48 +/* Prints domain name */ 5.49 +void print_name(xenstat_domain *domain) 5.50 +{ 5.51 + print("%10s", xenstat_domain_name(domain)); 5.52 +} 5.53 + 5.54 struct { 5.55 unsigned int (*get)(xenstat_domain *); 5.56 char ch;