* 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
This commit is contained in:
Daniel Veillard committed 2005-12-06 13:47:40 +00:00
1 parent 04130eb824
commit 6564f33fbb
4 files changed
+44 -11

No files matched your search

+21 -5
View File
@@ -13,6 +13,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <xenctrl.h>
#include <xs.h>
#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);
}
+14 -3
View File
@@ -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);
}
}