提交 6564f33f 编写于 作者: D 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.
Daniel
上级 04130eb8
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:
......
......@@ -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:
......
......@@ -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);
}
......@@ -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);
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册