mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Gautam Menghani <gautam@linux.ibm.com>
To: peterz@infradead.org, mingo@redhat.com, acme@kernel.org,
	namhyung@kernel.org, mark.rutland@arm.com,
	alexander.shishkin@linux.intel.com, jolsa@kernel.org,
	irogers@google.com, adrian.hunter@intel.com,
	kan.liang@linux.intel.com
Cc: Gautam Menghani <gautam@linux.ibm.com>,
	linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org,
	maddy@linux.ibm.com
Subject: [PATCH 3/4] perf python: Add evlist close and next methods
Date: Thu,  1 May 2025 15:06:29 +0530	[thread overview]
Message-ID: <20250501093633.578010-4-gautam@linux.ibm.com> (raw)
In-Reply-To: <20250501093633.578010-1-gautam@linux.ibm.com>

Add support for the evlist close and next methods. The next method
enables iterating over the evsels in an evlist.

Signed-off-by: Gautam Menghani <gautam@linux.ibm.com>
---
 tools/perf/util/python.c | 47 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 47 insertions(+)

diff --git a/tools/perf/util/python.c b/tools/perf/util/python.c
index 5a4d2c9aaabd..599cb37600f1 100644
--- a/tools/perf/util/python.c
+++ b/tools/perf/util/python.c
@@ -1163,6 +1163,16 @@ static PyObject *pyrf_evlist__open(struct pyrf_evlist *pevlist,
 	return Py_None;
 }
 
+static PyObject *pyrf_evlist__close(struct pyrf_evlist *pevlist)
+{
+	struct evlist *evlist = &pevlist->evlist;
+
+	evlist__close(evlist);
+
+	Py_INCREF(Py_None);
+	return Py_None;
+}
+
 static PyObject *pyrf_evlist__config(struct pyrf_evlist *pevlist)
 {
 	struct record_opts opts = {
@@ -1202,6 +1212,31 @@ static PyObject *pyrf_evlist__enable(struct pyrf_evlist *pevlist)
 	return Py_None;
 }
 
+static PyObject *pyrf_evlist__next(struct pyrf_evlist *pevlist,
+				   PyObject *args, PyObject *kwargs)
+{
+	struct evlist *evlist = &pevlist->evlist;
+	PyObject *py_evsel;
+	struct perf_evsel *pevsel;
+	struct evsel *evsel;
+	struct pyrf_evsel *next_evsel = PyObject_New(struct pyrf_evsel, &pyrf_evsel__type);
+	static char *kwlist[] = { "evsel", NULL };
+
+	if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O", kwlist,
+					 &py_evsel))
+		return NULL;
+
+	pevsel = (py_evsel == Py_None) ? NULL : &(((struct pyrf_evsel *)py_evsel)->evsel.core);
+	pevsel = perf_evlist__next(&(evlist->core), pevsel);
+	if (pevsel != NULL) {
+		evsel = container_of(pevsel, struct evsel, core);
+		next_evsel = container_of(evsel, struct pyrf_evsel, evsel);
+		return (PyObject *) next_evsel;
+	}
+
+	return Py_None;
+}
+
 static PyMethodDef pyrf_evlist__methods[] = {
 	{
 		.ml_name  = "all_cpus",
@@ -1221,6 +1256,12 @@ static PyMethodDef pyrf_evlist__methods[] = {
 		.ml_flags = METH_VARARGS | METH_KEYWORDS,
 		.ml_doc	  = PyDoc_STR("open the file descriptors.")
 	},
+	{
+		.ml_name  = "close",
+		.ml_meth  = (PyCFunction)pyrf_evlist__close,
+		.ml_flags = METH_NOARGS,
+		.ml_doc	  = PyDoc_STR("close the file descriptors.")
+	},
 	{
 		.ml_name  = "poll",
 		.ml_meth  = (PyCFunction)pyrf_evlist__poll,
@@ -1263,6 +1304,12 @@ static PyMethodDef pyrf_evlist__methods[] = {
 		.ml_flags = METH_NOARGS,
 		.ml_doc	  = PyDoc_STR("Enable the evsels in the evlist.")
 	},
+	{
+		.ml_name  = "next",
+		.ml_meth  = (PyCFunction)pyrf_evlist__next,
+		.ml_flags = METH_VARARGS | METH_KEYWORDS,
+		.ml_doc	  = PyDoc_STR("Return next evsel")
+	},
 	{ .ml_name = NULL, }
 };
 
-- 
2.49.0


  parent reply	other threads:[~2025-05-01  9:37 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-05-01  9:36 [PATCH 0/4] perf python: Add missing infra pieces for counting perf events Gautam Menghani
2025-05-01  9:36 ` [PATCH 1/4] perf python: Add support for perf_counts_values to return counter data Gautam Menghani
2025-05-01  9:36 ` [PATCH 2/4] perf python: Add evsel read method Gautam Menghani
2025-05-01  9:36 ` Gautam Menghani [this message]
2025-05-01 15:49   ` [PATCH 3/4] perf python: Add evlist close and next methods Ian Rogers
2025-05-05 11:49     ` Gautam Menghani
2025-05-05 21:02       ` Ian Rogers
2025-05-01  9:36 ` [PATCH 4/4] perf python: Add counting.py as example for counting perf events Gautam Menghani
2025-05-01 16:04   ` Ian Rogers
2025-05-01 16:11     ` Ian Rogers
2025-05-05 11:51     ` Gautam Menghani

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250501093633.578010-4-gautam@linux.ibm.com \
    --to=gautam@linux.ibm.com \
    --cc=acme@kernel.org \
    --cc=adrian.hunter@intel.com \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=irogers@google.com \
    --cc=jolsa@kernel.org \
    --cc=kan.liang@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=maddy@linux.ibm.com \
    --cc=mark.rutland@arm.com \
    --cc=mingo@redhat.com \
    --cc=namhyung@kernel.org \
    --cc=peterz@infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®