+Tue Dec 6 14:46:50 CET 2005 Daniel Veillard <veillard@redhat.com>
+
+ * include/libvir.h src/libvir.c src/virsh.c: tweaking of the
+ GetInfo() API, returns bytes and nanoseconds, try to fix
+ the scales, but time on unpriviledged interfaces doesn't work.
+
Mon Dec 5 19:14:05 CET 2005 Daniel Veillard <veillard@redhat.com>
* include/libvir.h src/libvir.c src/libvir_sym.version src/virsh.c:
struct _virDomainInfo {
unsigned char state; /* the running state, a virDomainFlags */
+ unsigned long maxMem; /* the maximum number of bytes allowed */
+ unsigned long memory; /* the number of bytes used by the domain */
/*
* Informations below are only available to clients with a connection
* with full access to the hypervisor
*/
- unsigned long long cpuTime; /* the CPU time used */
- unsigned long pages; /* the number of pages used by the domain */
- unsigned long maxPages; /* the maximum number of pages allowed */
+ unsigned long long cpuTime; /* the CPU time used in nanoseconds */
/*
* TODO:
#include <stdio.h>
#include <stdlib.h>
+#include <string.h>
#include <xenctrl.h>
#include <xs.h>
#include "internal.h"
if ((domain == NULL) || (domain->magic != VIR_DOMAIN_MAGIC) ||
(info == NULL))
return(-1);
+ memset(info, 0, sizeof(virDomainInfo));
if (domain->conn->flags & VIR_CONNECT_RO) {
char *tmp;
}
tmp = virDomainDoStoreQuery(domain, "memory/target");
if (tmp != NULL) {
- info->pages = atol(tmp) / 4096;
+ info->memory = atol(tmp) * 1024;
+ info->maxMem = atol(tmp) * 1024;
free(tmp);
} else {
- info->pages = 0;
- info->maxPages = 0;
+ info->memory = 0;
+ info->maxMem = 0;
+ }
+ tmp = virDomainDoStoreQuery(domain, "cpu_time");
+ if (tmp != NULL) {
+ info->cpuTime = atol(tmp);
+ free(tmp);
+ } else {
+ info->cpuTime = 0;
}
} else {
xc_domaininfo_t dominfo;
default:
info->state = VIR_DOMAIN_NONE;
}
+
+ /*
+ * the API brings back the cpu time in nanoseconds,
+ * convert to microseconds, same thing convert to
+
+ */
info->cpuTime = dominfo.cpu_time;
- info->pages = dominfo.tot_pages;
- info->maxPages = dominfo.max_pages;
+ info->memory = dominfo.tot_pages * 4096;
+ info->maxMem = dominfo.max_pages * 4096;
}
return(0);
}
static void printDomain(virDomainPtr dom) {
virDomainInfo info;
- printf("id %d: name %s ", virDomainGetID(dom), virDomainGetName(dom));
+ printf("id %d: name %s, ", virDomainGetID(dom), virDomainGetName(dom));
virDomainGetInfo(dom, &info);
if (virDomainGetInfo(dom, &info) < 0) {
printf("failed to get informations\n");
} else {
+ float mem, maxMem;
+
switch (info.state) {
case VIR_DOMAIN_RUNNING:
printf("running ");
default:
break;
}
- printf("%lu CPU time, %lu mem used, %lu max_mem\n",
- info.cpuTime, info.pages * 4096, info.maxPages * 4096);
+ if (info.cpuTime != 0) {
+ float cpuUsed = info.cpuTime;
+
+ cpuUsed /= 1000000000;
+ printf("%.1f s CPU time, ", cpuUsed);
+ }
+ mem = info.memory;
+ mem /= 1024 * 1024;
+ maxMem = info.maxMem;
+ maxMem /= 1024 * 1024;
+ printf("%.0f MB mem used, %.0f MB max_mem\n", mem, maxMem);
}
}