[PATCHv2 10/11] qemu: bulk stats: implement block group

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

 



This patch implements the VIR_DOMAIN_STATS_BLOCK
group of statistics.

Signed-off-by: Francesco Romani <fromani@xxxxxxxxxx>
---
 include/libvirt/libvirt.h.in |  1 +
 src/libvirt.c                | 13 +++++++++
 src/qemu/qemu_driver.c       | 65 ++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 79 insertions(+)

diff --git a/include/libvirt/libvirt.h.in b/include/libvirt/libvirt.h.in
index 33588d6..1d90f5e 100644
--- a/include/libvirt/libvirt.h.in
+++ b/include/libvirt/libvirt.h.in
@@ -2515,6 +2515,7 @@ typedef enum {
     VIR_DOMAIN_STATS_BALLOON = (1 << 2), /* return domain balloon info */
     VIR_DOMAIN_STATS_VCPU = (1 << 3), /* return domain virtual CPU info */
     VIR_DOMAIN_STATS_INTERFACE = (1 << 4), /* return domain interfaces info */
+    VIR_DOMAIN_STATS_BLOCK = (1 << 5), /* return domain block info */
 } virDomainStatsTypes;
 
 typedef enum {
diff --git a/src/libvirt.c b/src/libvirt.c
index 099404b..cabfb91 100644
--- a/src/libvirt.c
+++ b/src/libvirt.c
@@ -21579,6 +21579,19 @@ virConnectGetDomainCapabilities(virConnectPtr conn,
  * "net.<num>.tx.errs" - transmission errors.
  * "net.<num>.tx.drop" - transmit packets dropped.
  *
+ * VIR_DOMAIN_STATS_BLOCK: Return block devices statistics.
+ * The typed paramer keys are in this format:
+ * "block.count" - number of block devices on this domain.
+ * "block.<num>.name" - name of the block device <num>.
+ * "block.<num>.rd.reqs" - number of read requests.
+ * "block.<num>.rd.bytes" - number of read bytes.
+ * "block.<num>.rd.times" - total time (ns) spent on reads.
+ * "block.<num>.wr.reqs" - number of write requests
+ * "block.<num>.wr.bytes" - number of written bytes.
+ * "block.<num>.wr.times" - total time (ns) spent on writes.
+ * "block.<num>.fl.reqs" - total flush requests
+ * "block.<num>.fl.times" - total time (ns) spent on cache flushing
+ *
  * Using 0 for @stats returns all stats groups supported by the given
  * hypervisor.
  *
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 069a15d..977e8c7 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -17542,6 +17542,70 @@ qemuDomainGetStatsInterface(virConnectPtr conn ATTRIBUTE_UNUSED,
 
 #undef QEMU_ADD_NET_PARAM
 
+#define QEMU_ADD_BLOCK_PARAM_LL(RECORD, MAXPARAMS, NUM, NAME, VALUE) \
+do { \
+    char param_name[NAME_MAX]; \
+    snprintf(param_name, NAME_MAX, "block.%lu.%s", NUM, NAME); \
+    if (virTypedParamsAddLLong(&RECORD->params, \
+                               &RECORD->nparams, \
+                               MAXPARAMS, \
+                               param_name, \
+                               VALUE) < 0) \
+        goto cleanup; \
+} while (0)
+
+static int
+qemuDomainGetStatsBlock(virConnectPtr conn ATTRIBUTE_UNUSED,
+                        virDomainObjPtr dom,
+                        virDomainStatsRecordPtr record,
+                        int *maxparams,
+                        unsigned int privflags ATTRIBUTE_UNUSED)
+{
+    size_t i;
+    int ret = -1;
+    int nstats = dom->def->ndisks;
+    struct qemuBlockStats *stats = NULL;
+    virQEMUDriverPtr driver = conn->privateData;
+
+    if (VIR_ALLOC_N(stats, nstats) < 0)
+        return -1;
+
+    if (qemuDomainGetBlockStats(driver, dom, stats, nstats) != nstats)
+        goto cleanup;
+
+    for (i = 0; i < dom->def->ndisks; i++) {
+        QEMU_ADD_COUNT_PARAM(record, maxparams, "block", dom->def->ndisks);
+
+        QEMU_ADD_NAME_PARAM(record, maxparams,
+                            "block", i, dom->def->disks[i]->dst);
+
+        QEMU_ADD_BLOCK_PARAM_LL(record, maxparams, i,
+                                "rd.reqs", stats[i].rd_req);
+        QEMU_ADD_BLOCK_PARAM_LL(record, maxparams, i,
+                                "rd.bytes", stats[i].rd_bytes);
+        QEMU_ADD_BLOCK_PARAM_LL(record, maxparams, i,
+                                "rd.times", stats[i].rd_total_times);
+        QEMU_ADD_BLOCK_PARAM_LL(record, maxparams, i,
+                                "wr.reqs", stats[i].wr_req);
+        QEMU_ADD_BLOCK_PARAM_LL(record, maxparams, i,
+                                "wr.bytes", stats[i].wr_bytes);
+        QEMU_ADD_BLOCK_PARAM_LL(record, maxparams, i,
+                                "wr.times", stats[i].wr_total_times);
+        QEMU_ADD_BLOCK_PARAM_LL(record, maxparams, i,
+                                "fl.reqs", stats[i].flush_req);
+        QEMU_ADD_BLOCK_PARAM_LL(record, maxparams, i,
+                                "fl.times", stats[i].flush_total_times);
+    }
+
+    ret = 0;
+
+ cleanup:
+    VIR_FREE(stats);
+    return ret;
+}
+
+#undef QEMU_ADD_BLOCK_PARAM
+
 #undef QEMU_ADD_NAME_PARAM
 
 #undef QEMU_ADD_COUNT_PARAM
@@ -17564,6 +17628,7 @@ static struct qemuDomainGetStatsWorker qemuDomainGetStatsWorkers[] = {
     { qemuDomainGetStatsBalloon, VIR_DOMAIN_STATS_BALLOON },
     { qemuDomainGetStatsVcpu, VIR_DOMAIN_STATS_VCPU },
     { qemuDomainGetStatsInterface, VIR_DOMAIN_STATS_INTERFACE },
+    { qemuDomainGetStatsBlock, VIR_DOMAIN_STATS_BLOCK },
     { NULL, 0 }
 };
 
-- 
1.9.3

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]