]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/libvirt.git/commitdiff
* include/libvir.h src/libvir.c src/virsh.c: tweaking of the
authorDaniel Veillard <veillard@redhat.com>
Tue, 6 Dec 2005 13:47:40 +0000 (13:47 +0000)
committerDaniel Veillard <veillard@redhat.com>
Tue, 6 Dec 2005 13:47:40 +0000 (13:47 +0000)
  GetInfo() API, returns bytes and nanoseconds, try to fix
  the scales, but time on unpriviledged interfaces doesn't work.
Daniel

ChangeLog
include/libvir.h
src/libvir.c
src/virsh.c

index 9338c76ef85b840809289212fc964cdceb05a73c..c03566953e778f5a96ca6f0fa06321f30bb3fc29 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+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:
index eb990fc96b0b6eedcf7119a8e360c030aaaa93c2..1105cf76563b19a751002eec1c70d3d18190ea7a 100644 (file)
@@ -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:
index f9ce68fce51c2dfb3f9c4e13c698e53c00c78c00..07afe836332dd81466b55d8c4968ce32e65cb244 100644 (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);
 }
index 0055a8f1954c1e06b6cfe39fd32b501d6606641d..6c9705f1c575a992fdfb53851f16c349153b9cf3 100644 (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);
     }
 
 }