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

[libvirt] [PATCH 5/5 V3] python: implement virDomainGetPcpusUsage



Signed-off-by: Lai Jiangshan <laijs cn fujitsu com>
---
 python/generator.py             |    2 +-
 python/libvirt-override-api.xml |    6 ++++++
 python/libvirt-override.c       |   33 +++++++++++++++++++++++++++++++++
 3 files changed, 40 insertions(+), 1 deletions(-)

diff --git a/python/generator.py b/python/generator.py
index 0311004..cf75c44 100755
--- a/python/generator.py
+++ b/python/generator.py
@@ -421,7 +421,7 @@ skip_impl = (
     'virDomainGetBlockIoTune',
     'virDomainSetInterfaceParameters',
     'virDomainGetInterfaceParameters',
-    'virDomainGetPcpusUsage', # not implemented yet
+    'virDomainGetPcpusUsage',
 )
 
 qemu_skip_impl = (
diff --git a/python/libvirt-override-api.xml b/python/libvirt-override-api.xml
index 704fee9..69bb159 100644
--- a/python/libvirt-override-api.xml
+++ b/python/libvirt-override-api.xml
@@ -421,5 +421,11 @@
       <arg name='flags' type='unsigned int' info='an OR&apos;ed set of virDomainMemoryFlags'/>
       <return type='char *' info='the returned buffer or None in case of error'/>
     </function>
+    <function name='virDomainGetPcpusUsage' file='python'>
+      <info>Get the cpu usages for every physical cpu since the domain started (in nanoseconds).</info>
+      <arg name='dom' type='virDomainPtr' info='pointer to the domain'/>
+      <arg name='flags' type='unsigned int' info='an OR&apos;ed set of virDomainMemoryFlags'/>
+      <return type='unsigned long long *' info='the tuple of the cpu usages'/>
+    </function>
   </symbols>
 </api>
diff --git a/python/libvirt-override.c b/python/libvirt-override.c
index d2aad0f..ad4646d 100644
--- a/python/libvirt-override.c
+++ b/python/libvirt-override.c
@@ -5108,6 +5108,38 @@ cleanup:
     return py_retval;
 }
 
+static PyObject *
+libvirt_virDomainGetPcpusUsage(PyObject *self ATTRIBUTE_UNUSED,
+                               PyObject *args) {
+    PyObject *py_retval = NULL;
+    int c_retval;
+    virDomainPtr domain;
+    PyObject *pyobj_domain;
+    unsigned long long usages[32];
+    int i, nr_usages = sizeof(usages) / sizeof(usages[0]);
+    unsigned int flags;
+
+    if (!PyArg_ParseTuple(args, (char *)"Oi:virDomainGetPcpusUsage", &pyobj_domain,
+                          &flags))
+        return NULL;
+
+    domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
+
+    LIBVIRT_BEGIN_ALLOW_THREADS;
+    c_retval = virDomainGetPcpusUsage(domain, usages, &nr_usages, flags);
+    LIBVIRT_END_ALLOW_THREADS;
+
+    if (c_retval < 0)
+        return VIR_PY_NONE;
+
+    if ((py_retval = PyTuple_New(nr_usages)) == NULL)
+        return VIR_PY_NONE;
+    for (i = 0; i < nr_usages; i++)
+        PyTuple_SetItem(py_retval, i, PyLong_FromLongLong(usages[i]));
+
+    return py_retval;
+}
+
 /************************************************************************
  *									*
  *			The registration stuff				*
@@ -5206,6 +5238,7 @@ static PyMethodDef libvirtMethods[] = {
     {(char *) "virDomainMigrateGetMaxSpeed", libvirt_virDomainMigrateGetMaxSpeed, METH_VARARGS, NULL},
     {(char *) "virDomainBlockPeek", libvirt_virDomainBlockPeek, METH_VARARGS, NULL},
     {(char *) "virDomainMemoryPeek", libvirt_virDomainMemoryPeek, METH_VARARGS, NULL},
+    {(char *) "virDomainGetPcpusUsage", libvirt_virDomainGetPcpusUsage, METH_VARARGS, NULL},
     {NULL, NULL, 0, NULL}
 };
 
-- 
1.7.4.4


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