[PATCH v1 10/11] perf python: Add evlist.config to set up record options

Ian Rogers posted 11 patches 11 months, 2 weeks ago
There is a newer version of this series
[PATCH v1 10/11] perf python: Add evlist.config to set up record options
Posted by Ian Rogers 11 months, 2 weeks ago
Add access to evlist__config that is used to configure an evlist with
record options.

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

diff --git a/tools/perf/util/python.c b/tools/perf/util/python.c
index 1e8ab5291637..38a7e16e09c9 100644
--- a/tools/perf/util/python.c
+++ b/tools/perf/util/python.c
@@ -9,10 +9,12 @@
 #include <event-parse.h>
 #endif
 #include <perf/mmap.h>
+#include "callchain.h"
 #include "evlist.h"
 #include "evsel.h"
 #include "event.h"
 #include "print_binary.h"
+#include "record.h"
 #include "strbuf.h"
 #include "thread_map.h"
 #include "trace-event.h"
@@ -1043,6 +1045,31 @@ static PyObject *pyrf_evlist__open(struct pyrf_evlist *pevlist,
 	return Py_None;
 }
 
+static PyObject *pyrf_evlist__config(struct pyrf_evlist *pevlist)
+{
+	struct record_opts opts = {
+		.sample_time	     = true,
+		.mmap_pages	     = UINT_MAX,
+		.user_freq	     = UINT_MAX,
+		.user_interval	     = ULLONG_MAX,
+		.freq		     = 4000,
+		.target		     = {
+			.uses_mmap   = true,
+			.default_per_cpu = true,
+		},
+		.nr_threads_synthesize = 1,
+		.ctl_fd              = -1,
+		.ctl_fd_ack          = -1,
+			.no_buffering = true,
+			.no_inherit = true,
+	};
+	struct evlist *evlist = &pevlist->evlist;
+
+	evlist__config(evlist, &opts, &callchain_param);
+	Py_INCREF(Py_None);
+	return Py_None;
+}
+
 static PyObject *pyrf_evlist__disable(struct pyrf_evlist *pevlist)
 {
 	evlist__disable(&pevlist->evlist);
@@ -1100,6 +1127,12 @@ static PyMethodDef pyrf_evlist__methods[] = {
 		.ml_flags = METH_VARARGS | METH_KEYWORDS,
 		.ml_doc	  = PyDoc_STR("reads an event.")
 	},
+	{
+		.ml_name  = "config",
+		.ml_meth  = (PyCFunction)pyrf_evlist__config,
+		.ml_flags = METH_NOARGS,
+		.ml_doc	  = PyDoc_STR("Apply default record options to the evlist.")
+	},
 	{
 		.ml_name  = "disable",
 		.ml_meth  = (PyCFunction)pyrf_evlist__disable,
-- 
2.47.1.613.gc27f4b7a9f-goog
Re: [PATCH v1 10/11] perf python: Add evlist.config to set up record options
Posted by Howard Chu 9 months, 4 weeks ago
Hello,

On Wed, Jan 8, 2025 at 11:51 PM Ian Rogers <irogers@google.com> wrote:
>
> Add access to evlist__config that is used to configure an evlist with
> record options.
>
> Signed-off-by: Ian Rogers <irogers@google.com>
> ---
>  tools/perf/util/python.c | 33 +++++++++++++++++++++++++++++++++
>  1 file changed, 33 insertions(+)
>

<SNIP>

> +               .user_interval       = ULLONG_MAX,
> +               .freq                = 4000,
> +               .target              = {
> +                       .uses_mmap   = true,
> +                       .default_per_cpu = true,
> +               },
> +               .nr_threads_synthesize = 1,
> +               .ctl_fd              = -1,
> +               .ctl_fd_ack          = -1,
> +                       .no_buffering = true,
> +                       .no_inherit = true,

Are these indentations intentional?

Thanks,
Howard
Re: [PATCH v1 10/11] perf python: Add evlist.config to set up record options
Posted by Ian Rogers 9 months, 4 weeks ago
On Wed, Feb 26, 2025 at 9:46 PM Howard Chu <howardchu95@gmail.com> wrote:
>
> Hello,
>
> On Wed, Jan 8, 2025 at 11:51 PM Ian Rogers <irogers@google.com> wrote:
> >
> > Add access to evlist__config that is used to configure an evlist with
> > record options.
> >
> > Signed-off-by: Ian Rogers <irogers@google.com>
> > ---
> >  tools/perf/util/python.c | 33 +++++++++++++++++++++++++++++++++
> >  1 file changed, 33 insertions(+)
> >
>
> <SNIP>
>
> > +               .user_interval       = ULLONG_MAX,
> > +               .freq                = 4000,
> > +               .target              = {
> > +                       .uses_mmap   = true,
> > +                       .default_per_cpu = true,
> > +               },
> > +               .nr_threads_synthesize = 1,
> > +               .ctl_fd              = -1,
> > +               .ctl_fd_ack          = -1,
> > +                       .no_buffering = true,
> > +                       .no_inherit = true,
>
> Are these indentations intentional?

Nope, not sure what happened. I'll fix it in v2.

Thanks and thanks for the tags!
Ian

>
> Thanks,
> Howard