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

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

 



On 30.03.2016 04:13, Qiaowei Ren wrote:
> 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},
> 

Okay. This implementation looks reasonable. Although, after my patches gets in [1] the following needs to be squashed in:


diff --git a/libvirt-override.c b/libvirt-override.c
index 11ef15e..6053df0 100644
--- a/libvirt-override.c
+++ b/libvirt-override.c
@@ -1068,11 +1068,12 @@ libvirt_virDomainSetPerfEvents(PyObject *self ATTRIBUTE_UNUSED,
     int i_retval;
     int nparams = 0;
     Py_ssize_t size = 0;
+    unsigned int flags;
     virTypedParameterPtr params = NULL, new_params = NULL;
 
     if (!PyArg_ParseTuple(args,
-                          (char *)"OO:virDomainSetNumaParameters",
-                          &pyobj_domain, &info))
+                          (char *)"OOI:virDomainSetPerfEvents",
+                          &pyobj_domain, &info, &flags))
         return NULL;
     domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
 
@@ -1086,7 +1087,7 @@ libvirt_virDomainSetPerfEvents(PyObject *self ATTRIBUTE_UNUSED,
     }
 
     LIBVIRT_BEGIN_ALLOW_THREADS;
-    i_retval = virDomainGetPerfEvents(domain, &params, &nparams);
+    i_retval = virDomainGetPerfEvents(domain, &params, &nparams, flags);
     LIBVIRT_END_ALLOW_THREADS;
 
     if (i_retval < 0)
@@ -1103,7 +1104,7 @@ libvirt_virDomainSetPerfEvents(PyObject *self ATTRIBUTE_UNUSED,
         goto cleanup;
 
     LIBVIRT_BEGIN_ALLOW_THREADS;
-    i_retval = virDomainSetPerfEvents(domain, new_params, size);
+    i_retval = virDomainSetPerfEvents(domain, new_params, size, flags);
     LIBVIRT_END_ALLOW_THREADS;
 
     if (i_retval < 0) {
@@ -1128,15 +1129,16 @@ libvirt_virDomainGetPerfEvents(PyObject *self ATTRIBUTE_UNUSED,
     virTypedParameterPtr params = NULL;
     int nparams = 0;
     PyObject *dict = NULL;
+    unsigned int flags;
     int rc;
 
-    if (!PyArg_ParseTuple(args, (char *) "O:virDomainGetPerfEvents",
-                          &pyobj_domain))
+    if (!PyArg_ParseTuple(args, (char *) "OI:virDomainGetPerfEvents",
+                          &pyobj_domain, &flags))
         return NULL;
     domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
 
     LIBVIRT_BEGIN_ALLOW_THREADS;
-    rc = virDomainGetPerfEvents(domain, &params, &nparams);
+    rc = virDomainGetPerfEvents(domain, &params, &nparams, flags);
     LIBVIRT_END_ALLOW_THREADS;
     if (rc < 0)
         return VIR_PY_NONE;


I will do that as soon as my patches are in. ACK.

Michal


1: https://www.redhat.com/archives/libvir-list/2016-March/msg01474.html

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