]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
kvm tools: Move memory stat print to client
authorSasha Levin <levinsasha928@gmail.com>
Sun, 16 Oct 2011 19:57:55 +0000 (21:57 +0200)
committerPekka Enberg <penberg@kernel.org>
Tue, 18 Oct 2011 16:56:31 +0000 (19:56 +0300)
So far we were printing memory statistics in the terminal of the guest,
this was annoying, confusing and inneficient.

This patch moves the print to the terminal which ran 'kvm stat'

Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
tools/kvm/builtin-stat.c
tools/kvm/virtio/balloon.c

index 609a6e517db1d40a8e6549bcc5c46ee1f8c63f85..e28eb5b7d51b1f7a9568973b2ca3f758bec136c4 100644 (file)
@@ -5,10 +5,13 @@
 #include <kvm/parse-options.h>
 #include <kvm/kvm-ipc.h>
 
+#include <sys/select.h>
 #include <stdio.h>
 #include <string.h>
 #include <signal.h>
 
+#include <linux/virtio_balloon.h>
+
 struct stat_cmd {
        u32 type;
        u32 len;
@@ -51,14 +54,53 @@ void kvm_stat_help(void)
 static int do_memstat(const char *name, int sock)
 {
        struct stat_cmd cmd = {KVM_IPC_STAT, 0};
+       struct virtio_balloon_stat stats[VIRTIO_BALLOON_S_NR];
+       fd_set fdset;
+       struct timeval t = { .tv_sec = 1 };
        int r;
+       u8 i;
 
-       printf("Sending memstat command to %s, output should be on the targets' terminal.\n", name);
-
+       FD_ZERO(&fdset);
+       FD_SET(sock, &fdset);
        r = write(sock, &cmd, sizeof(cmd));
        if (r < 0)
                return r;
 
+       r = select(1, &fdset, NULL, NULL, &t);
+       if (r < 0) {
+               pr_error("Could not retrieve mem stats from %s", name);
+               return r;
+       }
+       r = read(sock, &stats, sizeof(stats));
+       if (r < 0)
+               return r;
+
+       printf("\n\n\t*** Guest memory statistics ***\n\n");
+       for (i = 0; i < VIRTIO_BALLOON_S_NR; i++) {
+               switch (stats[i].tag) {
+               case VIRTIO_BALLOON_S_SWAP_IN:
+                       printf("The amount of memory that has been swapped in (in bytes):");
+                       break;
+               case VIRTIO_BALLOON_S_SWAP_OUT:
+                       printf("The amount of memory that has been swapped out to disk (in bytes):");
+                       break;
+               case VIRTIO_BALLOON_S_MAJFLT:
+                       printf("The number of major page faults that have occurred:");
+                       break;
+               case VIRTIO_BALLOON_S_MINFLT:
+                       printf("The number of minor page faults that have occurred:");
+                       break;
+               case VIRTIO_BALLOON_S_MEMFREE:
+                       printf("The amount of memory not being used for any purpose (in bytes):");
+                       break;
+               case VIRTIO_BALLOON_S_MEMTOT:
+                       printf("The total amount of memory available (in bytes):");
+                       break;
+               }
+               printf("%llu\n", stats[i].val);
+       }
+       printf("\n");
+
        return 0;
 }
 
index 991610f99df8a7b592e26d1468c8604bbcceb820..0228686c9df5381df100cd92f33950d37e813e1c 100644 (file)
@@ -142,36 +142,14 @@ static int virtio_bln__collect_stats(void)
 
 static void virtio_bln__print_stats(int fd, u32 type, u32 len, u8 *msg)
 {
-       u16 i;
+       int r;
 
        if (virtio_bln__collect_stats() < 0)
                return;
 
-       printf("\n\n\t*** Guest memory statistics ***\n\n");
-       for (i = 0; i < bdev.stat_count; i++) {
-               switch (bdev.stats[i].tag) {
-               case VIRTIO_BALLOON_S_SWAP_IN:
-                       printf("The amount of memory that has been swapped in (in bytes):");
-                       break;
-               case VIRTIO_BALLOON_S_SWAP_OUT:
-                       printf("The amount of memory that has been swapped out to disk (in bytes):");
-                       break;
-               case VIRTIO_BALLOON_S_MAJFLT:
-                       printf("The number of major page faults that have occurred:");
-                       break;
-               case VIRTIO_BALLOON_S_MINFLT:
-                       printf("The number of minor page faults that have occurred:");
-                       break;
-               case VIRTIO_BALLOON_S_MEMFREE:
-                       printf("The amount of memory not being used for any purpose (in bytes):");
-                       break;
-               case VIRTIO_BALLOON_S_MEMTOT:
-                       printf("The total amount of memory available (in bytes):");
-                       break;
-               }
-               printf("%llu\n", bdev.stats[i].val);
-       }
-       printf("\n");
+       r = write(fd, bdev.stats, sizeof(bdev.stats));
+       if (r < 0)
+               pr_warning("Failed sending memory stats");
 }
 
 static void handle_mem(int fd, u32 type, u32 len, u8 *msg)