[PATCH 1/1] python: add python binding for Perf API

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

 



This patch adds the python binding for virDomainSetPerfEvents and
virDomainSetPerfEvents API.

Signed-off-by: Qiaowei Ren <qiaowei.ren@xxxxxxxxx>
---
 generator.py             |  2 ++
 libvirt-override-api.xml | 11 ++++++
 libvirt-override.c       | 93 ++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 106 insertions(+)

diff --git a/generator.py b/generator.py
index d9ae17e..fb6a493 100755
--- a/generator.py
+++ b/generator.py
@@ -433,6 +433,8 @@ skip_impl = (
     'virDomainGetMemoryParameters',
     'virDomainSetNumaParameters',
     'virDomainGetNumaParameters',
+    'virDomainSetPerfEvents',
+    'virDomainGetPerfEvents',
     'virDomainGetVcpus',
     'virDomainPinVcpu',
     'virDomainPinVcpuFlags',
diff --git a/libvirt-override-api.xml b/libvirt-override-api.xml
index 1a0e314..54b45f7 100644
--- a/libvirt-override-api.xml
+++ b/libvirt-override-api.xml
@@ -344,6 +344,17 @@
       <arg name='domain' type='virDomainPtr' info='pointer to domain object'/>
       <arg name='flags' type='int' info='an OR&apos;ed set of virDomainModificationImpact'/>
     </function>
+    <function name='virDomainSetPerfEvents' file='python'>
+      <info>Enable or disable the particular list of perf events</info>
+      <return type='int' info='-1 in case of error, 0 in case of success.'/>
+      <arg name='domain' type='virDomainPtr' info='pointer to domain object'/>
+      <arg name='params' type='virTypedParameterPtr' info='pointer to perf events parameter object'/>
+    </function>
+    <function name='virDomainGetPerfEvents' file='python'>
+      <info>Get all perf events setting.</info>
+      <return type='char *' info='returns a dictionary of params in case of success, None in case of error'/>
+      <arg name='domain' type='virDomainPtr' info='pointer to domain object'/>
+    </function>
     <function name='virDomainSetInterfaceParameters' file='python'>
       <info>Change the bandwidth tunables for a interface device</info>
       <arg name='dom' type='virDomainPtr' info='pointer to the domain'/>
diff --git a/libvirt-override.c b/libvirt-override.c
index ce36280..11ef15e 100644
--- a/libvirt-override.c
+++ b/libvirt-override.c
@@ -1059,6 +1059,97 @@ libvirt_virDomainGetNumaParameters(PyObject *self ATTRIBUTE_UNUSED,
 }
 
 static PyObject *
+libvirt_virDomainSetPerfEvents(PyObject *self ATTRIBUTE_UNUSED,
+                               PyObject *args)
+{
+    virDomainPtr domain;
+    PyObject *pyobj_domain, *info;
+    PyObject *ret = NULL;
+    int i_retval;
+    int nparams = 0;
+    Py_ssize_t size = 0;
+    virTypedParameterPtr params = NULL, new_params = NULL;
+
+    if (!PyArg_ParseTuple(args,
+                          (char *)"OO:virDomainSetNumaParameters",
+                          &pyobj_domain, &info))
+        return NULL;
+    domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
+
+    if ((size = PyDict_Size(info)) < 0)
+        return NULL;
+
+    if (size == 0) {
+        PyErr_Format(PyExc_LookupError,
+                     "Need non-empty dictionary to set attributes");
+        return NULL;
+    }
+
+    LIBVIRT_BEGIN_ALLOW_THREADS;
+    i_retval = virDomainGetPerfEvents(domain, &params, &nparams);
+    LIBVIRT_END_ALLOW_THREADS;
+
+    if (i_retval < 0)
+        return VIR_PY_INT_FAIL;
+
+    if (nparams == 0) {
+        PyErr_Format(PyExc_LookupError,
+                     "Domain has no settable attributes");
+        return NULL;
+    }
+
+    new_params = setPyVirTypedParameter(info, params, nparams);
+    if (!new_params)
+        goto cleanup;
+
+    LIBVIRT_BEGIN_ALLOW_THREADS;
+    i_retval = virDomainSetPerfEvents(domain, new_params, size);
+    LIBVIRT_END_ALLOW_THREADS;
+
+    if (i_retval < 0) {
+        ret = VIR_PY_INT_FAIL;
+        goto cleanup;
+    }
+
+    ret = VIR_PY_INT_SUCCESS;
+
+ cleanup:
+    virTypedParamsFree(params, nparams);
+    virTypedParamsFree(new_params, size);
+    return ret;
+}
+
+static PyObject *
+libvirt_virDomainGetPerfEvents(PyObject *self ATTRIBUTE_UNUSED,
+                               PyObject *args)
+{
+    PyObject *pyobj_domain;
+    virDomainPtr domain;
+    virTypedParameterPtr params = NULL;
+    int nparams = 0;
+    PyObject *dict = NULL;
+    int rc;
+
+    if (!PyArg_ParseTuple(args, (char *) "O:virDomainGetPerfEvents",
+                          &pyobj_domain))
+        return NULL;
+    domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
+
+    LIBVIRT_BEGIN_ALLOW_THREADS;
+    rc = virDomainGetPerfEvents(domain, &params, &nparams);
+    LIBVIRT_END_ALLOW_THREADS;
+    if (rc < 0)
+        return VIR_PY_NONE;
+
+    if (!(dict = getPyVirTypedParameter(params, nparams)))
+        goto cleanup;
+
+ cleanup:
+    virTypedParamsFree(params, nparams);
+    return dict;
+}
+
+static PyObject *
 libvirt_virDomainSetInterfaceParameters(PyObject *self ATTRIBUTE_UNUSED,
                                         PyObject *args)
 {
@@ -8686,6 +8777,8 @@ static PyMethodDef libvirtMethods[] = {
     {(char *) "virDomainGetMemoryParameters", libvirt_virDomainGetMemoryParameters, METH_VARARGS, NULL},
     {(char *) "virDomainSetNumaParameters", libvirt_virDomainSetNumaParameters, METH_VARARGS, NULL},
     {(char *) "virDomainGetNumaParameters", libvirt_virDomainGetNumaParameters, METH_VARARGS, NULL},
+    {(char *) "virDomainSetPerfEvents", libvirt_virDomainSetPerfEvents, METH_VARARGS, NULL},
+    {(char *) "virDomainGetPerfEvents", libvirt_virDomainGetPerfEvents, METH_VARARGS, NULL},
     {(char *) "virDomainSetInterfaceParameters", libvirt_virDomainSetInterfaceParameters, METH_VARARGS, NULL},
     {(char *) "virDomainGetInterfaceParameters", libvirt_virDomainGetInterfaceParameters, METH_VARARGS, NULL},
     {(char *) "virDomainGetVcpus", libvirt_virDomainGetVcpus, METH_VARARGS, NULL},
-- 
1.9.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]