[PATCH v2 04/11] perf python: Add evlist enable and disable methods

Ian Rogers posted 11 patches 9 months, 3 weeks ago
[PATCH v2 04/11] perf python: Add evlist enable and disable methods
Posted by Ian Rogers 9 months, 3 weeks ago
By default the evsels from parse_events will be disabled. Add access
to the evlist functions so they can be enabled/disabled.

Reviewed-by: Howard Chu <howardchu95@gmail.com>
Signed-off-by: Ian Rogers <irogers@google.com>
---
 tools/perf/util/python.c | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)

diff --git a/tools/perf/util/python.c b/tools/perf/util/python.c
index e2b9032c1311..0cf81cfcfafb 100644
--- a/tools/perf/util/python.c
+++ b/tools/perf/util/python.c
@@ -1028,6 +1028,20 @@ static PyObject *pyrf_evlist__open(struct pyrf_evlist *pevlist,
 	return Py_None;
 }
 
+static PyObject *pyrf_evlist__disable(struct pyrf_evlist *pevlist)
+{
+	evlist__disable(&pevlist->evlist);
+	Py_INCREF(Py_None);
+	return Py_None;
+}
+
+static PyObject *pyrf_evlist__enable(struct pyrf_evlist *pevlist)
+{
+	evlist__enable(&pevlist->evlist);
+	Py_INCREF(Py_None);
+	return Py_None;
+}
+
 static PyMethodDef pyrf_evlist__methods[] = {
 	{
 		.ml_name  = "mmap",
@@ -1065,6 +1079,18 @@ static PyMethodDef pyrf_evlist__methods[] = {
 		.ml_flags = METH_VARARGS | METH_KEYWORDS,
 		.ml_doc	  = PyDoc_STR("reads an event.")
 	},
+	{
+		.ml_name  = "disable",
+		.ml_meth  = (PyCFunction)pyrf_evlist__disable,
+		.ml_flags = METH_NOARGS,
+		.ml_doc	  = PyDoc_STR("Disable the evsels in the evlist.")
+	},
+	{
+		.ml_name  = "enable",
+		.ml_meth  = (PyCFunction)pyrf_evlist__enable,
+		.ml_flags = METH_NOARGS,
+		.ml_doc	  = PyDoc_STR("Enable the evsels in the evlist.")
+	},
 	{ .ml_name = NULL, }
 };
 
-- 
2.48.1.711.g2feabab25a-goog
Re: [PATCH v2 04/11] perf python: Add evlist enable and disable methods
Posted by Arnaldo Carvalho de Melo 9 months, 1 week ago
On Fri, Feb 28, 2025 at 02:23:01PM -0800, Ian Rogers wrote:
> By default the evsels from parse_events will be disabled. Add access
> to the evlist functions so they can be enabled/disabled.

Reviewed-by: Arnaldo Carvalho de Melo <acme@redhat.com>

- Arnaldo
 
> Reviewed-by: Howard Chu <howardchu95@gmail.com>
> Signed-off-by: Ian Rogers <irogers@google.com>
> ---
>  tools/perf/util/python.c | 26 ++++++++++++++++++++++++++
>  1 file changed, 26 insertions(+)
> 
> diff --git a/tools/perf/util/python.c b/tools/perf/util/python.c
> index e2b9032c1311..0cf81cfcfafb 100644
> --- a/tools/perf/util/python.c
> +++ b/tools/perf/util/python.c
> @@ -1028,6 +1028,20 @@ static PyObject *pyrf_evlist__open(struct pyrf_evlist *pevlist,
>  	return Py_None;
>  }
>  
> +static PyObject *pyrf_evlist__disable(struct pyrf_evlist *pevlist)
> +{
> +	evlist__disable(&pevlist->evlist);
> +	Py_INCREF(Py_None);
> +	return Py_None;
> +}
> +
> +static PyObject *pyrf_evlist__enable(struct pyrf_evlist *pevlist)
> +{
> +	evlist__enable(&pevlist->evlist);
> +	Py_INCREF(Py_None);
> +	return Py_None;
> +}
> +
>  static PyMethodDef pyrf_evlist__methods[] = {
>  	{
>  		.ml_name  = "mmap",
> @@ -1065,6 +1079,18 @@ static PyMethodDef pyrf_evlist__methods[] = {
>  		.ml_flags = METH_VARARGS | METH_KEYWORDS,
>  		.ml_doc	  = PyDoc_STR("reads an event.")
>  	},
> +	{
> +		.ml_name  = "disable",
> +		.ml_meth  = (PyCFunction)pyrf_evlist__disable,
> +		.ml_flags = METH_NOARGS,
> +		.ml_doc	  = PyDoc_STR("Disable the evsels in the evlist.")
> +	},
> +	{
> +		.ml_name  = "enable",
> +		.ml_meth  = (PyCFunction)pyrf_evlist__enable,
> +		.ml_flags = METH_NOARGS,
> +		.ml_doc	  = PyDoc_STR("Enable the evsels in the evlist.")
> +	},
>  	{ .ml_name = NULL, }
>  };
>  
> -- 
> 2.48.1.711.g2feabab25a-goog