[RFC][PATCHv1 4/5] Add a python interface for virDomainPcpuStats.

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

 



Values of all cpus are returned by a tuple of Dict as:

[{cpuTime: xxxx}, {cpuTime: yyyy}} # when the number of cpu is 2.

Signed-off-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu@xxxxxxxxxxxxxx>
---
 python/generator.py             |    1 +
 python/libvirt-override-api.xml |    5 ++++
 python/libvirt-override.c       |   42 +++++++++++++++++++++++++++++++++++++++
 3 files changed, 48 insertions(+), 0 deletions(-)

diff --git a/python/generator.py b/python/generator.py
index 4fa4f65..d2695bb 100755
--- a/python/generator.py
+++ b/python/generator.py
@@ -307,6 +307,7 @@ skip_impl = (
     'virDomainBlockStats',
     'virDomainInterfaceStats',
     'virDomainMemoryStats',
+    'virDomainPcpuStats',
     'virNodeGetCellsFreeMemory',
     'virDomainGetSchedulerType',
     'virDomainGetSchedulerParameters',
diff --git a/python/libvirt-override-api.xml b/python/libvirt-override-api.xml
index 54deeb5..5ee3881 100644
--- a/python/libvirt-override-api.xml
+++ b/python/libvirt-override-api.xml
@@ -127,6 +127,11 @@
       <return type='virDomainMemoryStats' info='a dictionary of statistics'/>
       <arg name='domain' type='virDomainPtr' info='a domain object'/>
     </function>
+    <function name='virDomainPcpuStats' file='python'>
+      <info>Extracts per cpu statistics for a domain </info>
+      <return type='virDomainPcpuStats *' info='a tuple of statistics' />
+      <arg name='domain' type='virDomainPtr' info='a domain object'/>
+    </function>
     <function name="virNodeGetCellsFreeMemory" file='python'>
       <info>Returns the available memory for a list of cells</info>
       <arg name='conn' type='virConnectPtr' info='pointer to the hypervisor connection'/>
diff --git a/python/libvirt-override.c b/python/libvirt-override.c
index 4a9b432..c2ff0aa 100644
--- a/python/libvirt-override.c
+++ b/python/libvirt-override.c
@@ -164,6 +164,47 @@ libvirt_virDomainMemoryStats(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) {
     return info;
 }
 
+static PyObject*
+libvirt_virDomainPcpuStats(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) {
+    virDomainPtr domain;
+    virNodeInfo nodeinfo;
+    PyObject *pyobj_domain;
+    PyObject *info, *info2;
+    int nr_stats, i_retval, i;
+    virDomainPcpuStatPtr stats;
+
+    if (!PyArg_ParseTuple(args, (char *)"O:virDomainPcpuStats", &pyobj_domain))
+        return (NULL);
+
+    domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
+
+    LIBVIRT_BEGIN_ALLOW_THREADS;
+    i_retval = virNodeGetInfo(virDomainGetConnect(domain), &nodeinfo);
+    LIBVIRT_END_ALLOW_THREADS;
+    if (i_retval < 0)
+        return VIR_PY_NONE;
+
+    stats = malloc(sizeof(struct _virDomainPcpuStat) * nodeinfo.cpus);
+
+    nr_stats = virDomainPcpuStats(domain, stats, nodeinfo.cpus, 0);
+
+    if (nr_stats == -1)
+        return VIR_PY_NONE;
+
+    if ((info = PyTuple_New(nodeinfo.cpus)) == NULL)
+        return VIR_PY_NONE;
+
+    for (i = 0; i < nr_stats; i++) {
+        if ((info2 = PyDict_New()) == NULL)
+            return VIR_PY_NONE;
+        PyDict_SetItem(info2, libvirt_constcharPtrWrap("cpuTime"),
+                      PyLong_FromLongLong(stats[i].cpuTime));
+        PyTuple_SetItem(info, i, info2);
+    }
+    return (info);
+}
+
+
 static PyObject *
 libvirt_virDomainGetSchedulerType(PyObject *self ATTRIBUTE_UNUSED,
                                   PyObject *args) {
@@ -3545,6 +3586,7 @@ static PyMethodDef libvirtMethods[] = {
     {(char *) "virDomainBlockStats", libvirt_virDomainBlockStats, METH_VARARGS, NULL},
     {(char *) "virDomainInterfaceStats", libvirt_virDomainInterfaceStats, METH_VARARGS, NULL},
     {(char *) "virDomainMemoryStats", libvirt_virDomainMemoryStats, METH_VARARGS, NULL},
+    {(char *) "virDomainPcpuStats", libvirt_virDomainPcpuStats, METH_VARARGS, NULL},
     {(char *) "virNodeGetCellsFreeMemory", libvirt_virNodeGetCellsFreeMemory, METH_VARARGS, NULL},
     {(char *) "virDomainGetSchedulerType", libvirt_virDomainGetSchedulerType, METH_VARARGS, NULL},
     {(char *) "virDomainGetSchedulerParameters", libvirt_virDomainGetSchedulerParameters, METH_VARARGS, NULL},
-- 
1.7.4.1


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