[PATCHv3 3/6] virNodeGetCPUTime: Implement public API

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

 



virNodeGetCPUTime: Implement public API

Signed-off-by: Minoru Usui <usui@xxxxxxxxxxxxxxxxx>
---
 src/libvirt.c |   79 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 79 insertions(+), 0 deletions(-)

diff --git a/src/libvirt.c b/src/libvirt.c
index 0da9885..12d666d 100644
--- a/src/libvirt.c
+++ b/src/libvirt.c
@@ -14,6 +14,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <strings.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <unistd.h>
@@ -4229,6 +4230,84 @@ error:
 }
 
 /**
+ * virNodeGetCpuTime:
+ * @stats: nr_stats-sized array of unsigned long long (returned)
+ * @nr_stats: number of cpu time statistics requested of the node.
+ * @flags: an OR'ed set of virNodeGetCpuTimeFlags
+ *
+ * This function provides cpu time statistics of the node.
+ *
+ * Up to 'nr_stats' elements of 'stats' will be populated with cpu
+ * time statistics of the node. Only statistics requested by the user
+ * will be returned.
+ * -1 will be returned, if requested statistics isn't supported by
+ * the driver or this version of libvirt.
+ *
+ * Cpu time Statistics(@flags):
+ *
+ * VIR_NODE_CPU_TIME_KERNEL:
+ *     The cumulative CPU time which spends by kernel,
+ *     when the node booting up.(nanoseconds)
+ * VIR_NODE_CPU_TIME_USER:
+ *     The cumulative CPU time which spends by user processes,
+ *     when the node booting up.(nanoseconds)
+ * VIR_NODE_CPU_TIME_IDLE:
+ *     The cumulative idle CPU time, when the node booting up.(nanoseconds)
+ * VIR_NODE_CPU_TIME_IOWAIT:
+ *     The cumulative I/O wait CPU time, when the node booting up.(nanoseconds)
+ * VIR_NODE_CPU_TIME_UTILIZATION:
+ *     The CPU utilization. The usage value is in percent and 100%
+ *     represents all CPUs on the server.
+ *
+ * Returns: The number of stats provided or -1 in case of failure.
+ */
+int virNodeGetCpuTime (virConnectPtr conn, unsigned long long *stats,
+                          unsigned int nr_stats, unsigned int flags)
+{
+    unsigned long nr_stats_ret = 0;
+    unsigned int req_type;
+    int req_count = 0;
+
+    VIR_DEBUG("conn=%p, stats=%p, nr_stats=%u", conn, stats, nr_stats);
+
+    virResetLastError();
+
+    if (!VIR_IS_CONNECT (conn)) {
+        virLibConnError(VIR_ERR_INVALID_CONN, __FUNCTION__);
+        virDispatchError(NULL);
+        return 0;
+    }
+
+    if (!stats || nr_stats == 0)
+        return 0;
+
+    req_type = flags & VIR_NODE_CPU_TIME_MASK;
+    while (req_type) {
+        int bit_index;
+
+        req_count++;
+        bit_index = ffs(req_type);
+        req_type &= ~(1 << (bit_index - 1));
+    }
+
+    if (nr_stats > req_count)
+        nr_stats = req_count;
+
+    if (conn->driver->nodeGetCpuTime) {
+        nr_stats_ret = conn->driver->nodeGetCpuTime (conn, stats, nr_stats, flags);
+        if (nr_stats_ret == -1)
+            goto error;
+        return nr_stats_ret;
+    }
+
+    virLibConnError(VIR_ERR_NO_SUPPORT, __FUNCTION__);
+
+error:
+    virDispatchError(conn);
+    return -1;
+}
+
+/**
  * virNodeGetFreeMemory:
  * @conn: pointer to the hypervisor connection
  *
-- 
1.7.1

-- 
Minoru Usui <usui@xxxxxxxxxxxxxxxxx>

--
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]