aboutsummaryrefslogtreecommitdiffstats
path: root/tools/xenstat
diff options
context:
space:
mode:
authorjeroney@localhost.localdomain <jeroney@localhost.localdomain>2005-10-27 10:19:58 +0100
committerjeroney@localhost.localdomain <jeroney@localhost.localdomain>2005-10-27 10:19:58 +0100
commit740401a4f848c64541f892b224d32aec56ac6946 (patch)
tree2d87f69365e7a22b0edebd898bef5d0e6ebf4d0d /tools/xenstat
parent6ee89dae792ca89399753492cac801110352f608 (diff)
downloadxen-740401a4f848c64541f892b224d32aec56ac6946.tar.gz
xen-740401a4f848c64541f892b224d32aec56ac6946.tar.bz2
xen-740401a4f848c64541f892b224d32aec56ac6946.zip
* Enable xenstat to use xenstore
* Have xentop display names instead of DomIDs as requested in Bugzilla#311 filed by Ian
Diffstat (limited to 'tools/xenstat')
-rw-r--r--tools/xenstat/libxenstat/Makefile4
-rw-r--r--tools/xenstat/libxenstat/src/xenstat.c41
-rw-r--r--tools/xenstat/libxenstat/src/xenstat.h3
-rw-r--r--tools/xenstat/xentop/Makefile2
-rw-r--r--tools/xenstat/xentop/xentop.c19
5 files changed, 65 insertions, 4 deletions
diff --git a/tools/xenstat/libxenstat/Makefile b/tools/xenstat/libxenstat/Makefile
index 750adaaa29..d874ba3af1 100644
--- a/tools/xenstat/libxenstat/Makefile
+++ b/tools/xenstat/libxenstat/Makefile
@@ -38,13 +38,13 @@ SONAME_FLAGS=-Wl,-soname -Wl,libxenstat.so.$(MAJOR)
WARN_FLAGS=-Wall -Werror
-CFLAGS+=-Isrc -I$(XEN_LIBXC)
+CFLAGS+=-Isrc -I$(XEN_LIBXC) -I$(XEN_XENSTORE)
LDFLAGS+=-Lsrc
all: $(LIB)
$(LIB): $(OBJECTS)
- $(AR) rc $@ $^
+ $(AR) rc $@ $^ $(XEN_XENSTORE)/libxenstore.so
$(RANLIB) $@
$(SHLIB): $(OBJECTS)
diff --git a/tools/xenstat/libxenstat/src/xenstat.c b/tools/xenstat/libxenstat/src/xenstat.c
index 85da72b168..22a3ec8a97 100644
--- a/tools/xenstat/libxenstat/src/xenstat.c
+++ b/tools/xenstat/libxenstat/src/xenstat.c
@@ -21,6 +21,7 @@
#include <string.h>
#include <unistd.h>
#include <xen-interface.h>
+#include <xs.h>
#include "xenstat.h"
/*
@@ -31,6 +32,7 @@
struct xenstat_handle {
xi_handle *xihandle;
+ struct xs_handle *xshandle; /* xenstore handle */
int page_size;
FILE *procnetdev;
char xen_version[VERSION_SIZE]; /* xen version running on this node */
@@ -49,6 +51,7 @@ struct xenstat_node {
struct xenstat_domain {
unsigned int id;
+ char *name;
unsigned int state;
unsigned long long cpu_ns;
unsigned int num_vcpus; /* No. vcpus configured for domain */
@@ -110,6 +113,7 @@ static void xenstat_free_xen_version(xenstat_node * node);
static void xenstat_uninit_vcpus(xenstat_handle * handle);
static void xenstat_uninit_networks(xenstat_handle * handle);
static void xenstat_uninit_xen_version(xenstat_handle * handle);
+static char *xenstat_get_domain_name(xenstat_handle * handle, unsigned int domain_id);
static xenstat_collector collectors[] = {
{ XENSTAT_VCPU, xenstat_collect_vcpus,
@@ -153,6 +157,13 @@ xenstat_handle *xenstat_init()
return NULL;
}
+ handle->xshandle = xs_daemon_open_readonly(); /* open handle to xenstore*/
+ if (handle->xshandle == NULL) {
+ perror("unable to open xenstore\n");
+ free(handle);
+ return NULL;
+ }
+
return handle;
}
@@ -163,6 +174,7 @@ void xenstat_uninit(xenstat_handle * handle)
for (i = 0; i < NUM_COLLECTORS; i++)
collectors[i].uninit(handle);
xi_uninit(handle->xihandle);
+ xs_daemon_close(handle->xshandle);
free(handle);
}
}
@@ -228,6 +240,7 @@ xenstat_node *xenstat_get_node(xenstat_handle * handle, unsigned int flags)
for (i = 0; i < new_domains; i++) {
/* Fill in domain using domaininfo[i] */
domain->id = domaininfo[i].domain;
+ domain->name = xenstat_get_domain_name(handle, domaininfo[i].domain);
domain->state = domaininfo[i].flags;
domain->cpu_ns = domaininfo[i].cpu_time;
domain->num_vcpus = (domaininfo[i].max_vcpu_id+1);
@@ -339,6 +352,12 @@ unsigned xenstat_domain_id(xenstat_domain * domain)
return domain->id;
}
+/* Get the domain name for the domain */
+char *xenstat_domain_name(xenstat_domain * domain)
+{
+ return domain->name;
+}
+
/* Get information about how much CPU time has been used */
unsigned long long xenstat_domain_cpu_ns(xenstat_domain * domain)
{
@@ -675,3 +694,25 @@ static void xenstat_free_xen_version(xenstat_node * node)
static void xenstat_uninit_xen_version(xenstat_handle * handle)
{
}
+
+static char *xenstat_get_domain_name(xenstat_handle *handle, unsigned int domain_id)
+{
+ char path[80];
+ char *name;
+ unsigned int *len;
+ struct xs_transaction_handle *xstranshandle;
+
+ snprintf(path, sizeof(path),"/local/domain/%i/name", domain_id);
+
+ xstranshandle = xs_transaction_start(handle->xshandle);
+ if (xstranshandle == NULL) {
+ perror("Unable to get transcation handle from xenstore\n");
+ exit(1); /* Change this */
+ }
+
+ name = (char *) xs_read(handle->xshandle, xstranshandle, path, len);
+
+ xs_transaction_end(handle->xshandle, xstranshandle, false);
+
+ return name;
+}
diff --git a/tools/xenstat/libxenstat/src/xenstat.h b/tools/xenstat/libxenstat/src/xenstat.h
index 286fa035bf..b9ac1d3782 100644
--- a/tools/xenstat/libxenstat/src/xenstat.h
+++ b/tools/xenstat/libxenstat/src/xenstat.h
@@ -80,6 +80,9 @@ unsigned long long xenstat_node_cpu_hz(xenstat_node * node);
/* Get the domain ID for this domain */
unsigned xenstat_domain_id(xenstat_domain * domain);
+/* Set the domain name for the domain */
+char *xenstat_domain_name(xenstat_domain * domain);
+
/* Get information about how much CPU time has been used */
unsigned long long xenstat_domain_cpu_ns(xenstat_domain * domain);
diff --git a/tools/xenstat/xentop/Makefile b/tools/xenstat/xentop/Makefile
index 633fd57064..2115e6f3cf 100644
--- a/tools/xenstat/xentop/Makefile
+++ b/tools/xenstat/xentop/Makefile
@@ -26,7 +26,7 @@ mandir=$(prefix)/share/man
man1dir=$(mandir)/man1
sbindir=$(prefix)/sbin
-CFLAGS += -DGCC_PRINTF -Wall -Werror -I$(XEN_LIBXENSTAT)
+CFLAGS += -DGCC_PRINTF -Wall -I$(XEN_LIBXENSTAT)
LDFLAGS += -L$(XEN_LIBXENSTAT)
LDLIBS += -lxenstat -lncurses
diff --git a/tools/xenstat/xentop/xentop.c b/tools/xenstat/xentop/xentop.c
index 1cb5e36829..286b037051 100644
--- a/tools/xenstat/xentop/xentop.c
+++ b/tools/xenstat/xentop/xentop.c
@@ -28,6 +28,7 @@
#include <time.h>
#include <unistd.h>
+#include <xs.h>
#include <xenstat.h>
#define XENTOP_VERSION "1.0"
@@ -91,6 +92,8 @@ static int compare_net_rx(xenstat_domain *domain1, xenstat_domain *domain2);
static void print_net_rx(xenstat_domain *domain);
static int compare_ssid(xenstat_domain *domain1, xenstat_domain *domain2);
static void print_ssid(xenstat_domain *domain);
+static int compare_name(xenstat_domain *domain1, xenstat_domain *domain2);
+static void print_name(xenstat_domain *domain);
/* Section printing functions */
static void do_summary(void);
@@ -104,6 +107,7 @@ static void top(void);
/* Field types */
typedef enum field_id {
FIELD_DOMID,
+ FIELD_NAME,
FIELD_STATE,
FIELD_CPU,
FIELD_CPU_PCT,
@@ -127,7 +131,8 @@ typedef struct field {
} field;
field fields[] = {
- { FIELD_DOMID, "DOMID", 5, compare_domid, print_domid },
+// { FIELD_DOMID, "DOMID", 5, compare_domid, print_domid },
+ { FIELD_NAME, "NAME", 10, compare_name, print_name },
{ FIELD_STATE, "STATE", 6, compare_state, print_state },
{ FIELD_CPU, "CPU(sec)", 10, compare_cpu, print_cpu },
{ FIELD_CPU_PCT, "CPU(%)", 6, compare_cpu_pct, print_cpu_pct },
@@ -356,6 +361,18 @@ void print_domid(xenstat_domain *domain)
print("%5u", xenstat_domain_id(domain));
}
+/* 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;