[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[libvirt] [PATCH v2 2/2] Added RSS reporting



Added RSS information gathering into qemuMemoryStats into qemu driver
and the reporting into virsh dommemstat.
---
v2:
 - fixed sign for the ret variable (can be negative)

 include/libvirt/libvirt.h.in |    7 ++++++-
 src/qemu/qemu_driver.c       |   23 ++++++++++++++++++-----
 tools/virsh.c                |    2 ++
 3 files changed, 26 insertions(+), 6 deletions(-)

diff --git a/include/libvirt/libvirt.h.in b/include/libvirt/libvirt.h.in
index 958e5a6..d5ef061 100644
--- a/include/libvirt/libvirt.h.in
+++ b/include/libvirt/libvirt.h.in
@@ -884,11 +884,16 @@ typedef enum {

     /* Current balloon value (in KB). */
     VIR_DOMAIN_MEMORY_STAT_ACTUAL_BALLOON  = 6,
+
+    /* Resident Set Size of the process running the domain. This value
+     * is in kB */
+    VIR_DOMAIN_MEMORY_STAT_RSS             = 7,
+
     /*
      * The number of statistics supported by this version of the interface.
      * To add new statistics, add them to the enum and increase this value.
      */
-    VIR_DOMAIN_MEMORY_STAT_NR              = 7,
+    VIR_DOMAIN_MEMORY_STAT_NR              = 8,

 #ifdef VIR_ENUM_SENTINELS
     VIR_DOMAIN_MEMORY_STAT_LAST = VIR_DOMAIN_MEMORY_STAT_NR
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 6600afd..20d3d84 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -7978,7 +7978,7 @@ qemudDomainMemoryStats (virDomainPtr dom,
 {
     struct qemud_driver *driver = dom->conn->privateData;
     virDomainObjPtr vm;
-    unsigned int ret = -1;
+    int ret = -1;

     virCheckFlags(0, -1);

@@ -7997,14 +7997,27 @@ qemudDomainMemoryStats (virDomainPtr dom,
     if (qemuDomainObjBeginJob(driver, vm, QEMU_JOB_QUERY) < 0)
         goto cleanup;

-    if (virDomainObjIsActive(vm)) {
+    if (!virDomainObjIsActive(vm)) {
+        qemuReportError(VIR_ERR_OPERATION_INVALID,
+                        "%s", _("domain is not running"));
+    } else {
         qemuDomainObjPrivatePtr priv = vm->privateData;
         qemuDomainObjEnterMonitor(driver, vm);
         ret = qemuMonitorGetMemoryStats(priv->mon, stats, nr_stats);
         qemuDomainObjExitMonitor(driver, vm);
-    } else {
-        qemuReportError(VIR_ERR_OPERATION_INVALID,
-                        "%s", _("domain is not running"));
+
+        if (ret >= 0 && ret < nr_stats) {
+            long rss;
+            if (qemudGetProcessInfo(NULL, NULL, &rss, vm->pid, 0) < 0) {
+                qemuReportError(VIR_ERR_OPERATION_FAILED, "%s",
+                            _("cannot get RSS for domain"));
+            } else {
+                stats[ret].tag = VIR_DOMAIN_MEMORY_STAT_RSS;
+                stats[ret].val = rss;
+                ret++;
+            }
+
+        }
     }

     if (qemuDomainObjEndJob(driver, vm) == 0)
diff --git a/tools/virsh.c b/tools/virsh.c
index d635b56..d5bbabf 100644
--- a/tools/virsh.c
+++ b/tools/virsh.c
@@ -1871,6 +1871,8 @@ cmdDomMemStat(vshControl *ctl, const vshCmd *cmd)
             vshPrint (ctl, "available %llu\n", stats[i].val);
         if (stats[i].tag == VIR_DOMAIN_MEMORY_STAT_ACTUAL_BALLOON)
             vshPrint (ctl, "actual %llu\n", stats[i].val);
+        if (stats[i].tag == VIR_DOMAIN_MEMORY_STAT_RSS)
+            vshPrint (ctl, "rss %llu\n", stats[i].val);
     }

     virDomainFree(dom);
--
1.7.3.4


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]