From 6564f33fbb1756b9c187b8502315d6d84d05825e Mon Sep 17 00:00:00 2001 From: Daniel Veillard Date: Tue, 6 Dec 2005 13:47:40 +0000 Subject: [PATCH] * 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. Daniel --- ChangeLog | 6 ++++++ include/libvir.h | 6 +++--- src/libvir.c | 26 +++++++++++++++++++++----- src/virsh.c | 17 ++++++++++++++--- 4 files changed, 44 insertions(+), 11 deletions(-) diff --git a/ChangeLog b/ChangeLog index 9338c76ef8..c03566953e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +Tue Dec 6 14:46:50 CET 2005 Daniel Veillard + + * 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 * include/libvir.h src/libvir.c src/libvir_sym.version src/virsh.c: diff --git a/include/libvir.h b/include/libvir.h index eb990fc96b..1105cf7656 100644 --- a/include/libvir.h +++ b/include/libvir.h @@ -71,14 +71,14 @@ typedef struct _virDomainInfo virDomainInfo; 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: diff --git a/src/libvir.c b/src/libvir.c index f9ce68fce5..07afe83633 100644 --- a/src/libvir.c +++ b/src/libvir.c @@ -13,6 +13,7 @@ #include #include +#include #include #include #include "internal.h" @@ -539,6 +540,7 @@ virDomainGetInfo(virDomainPtr domain, virDomainInfoPtr info) { 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; @@ -552,11 +554,19 @@ virDomainGetInfo(virDomainPtr domain, virDomainInfoPtr info) { } 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; @@ -585,9 +595,15 @@ virDomainGetInfo(virDomainPtr domain, virDomainInfoPtr info) { 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); } diff --git a/src/virsh.c b/src/virsh.c index 0055a8f195..6c9705f1c5 100644 --- a/src/virsh.c +++ b/src/virsh.c @@ -22,11 +22,13 @@ int ids[MAX_DOM]; 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 "); @@ -46,8 +48,17 @@ static void printDomain(virDomainPtr dom) { 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); } }