From: Akinobu Mita <akinobu.mita@gmail.com>
To: damon@lists.linux.dev
Cc: linux-perf-users@vger.kernel.org, sj@kernel.org,
ravis.opensrc@gmail.com, akinobu.mita@gmail.com
Subject: [RFC PATCH 1/2] perf python: Add access to various members of evsel
Date: Mon, 22 Jun 2026 22:49:32 +0900 [thread overview]
Message-ID: <20260622134933.35773-2-akinobu.mita@gmail.com> (raw)
In-Reply-To: <20260622134933.35773-1-akinobu.mita@gmail.com>
This change is necessary to specify the same PMU event selection as the
'perf record' -e option from DAMON's userspace tools.
For example, a Python script like the following will allow you to obtain
the values to be set in the type, config, config1, and config2 members of
perf_event_attr by providing a symbolic event name.
import perf
if __name__ == '__main__':
evlist = perf.parse_events("cpu/mem-loads,ldlat=30/P")
for evsel in evlist:
print(f"{evsel}: type={evsel.type} config={evsel.config}",
f"config1={evsel.config1} config2={evsel.config2}")
Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>
---
tools/perf/util/python.c | 50 ++++++++++++++++++++++++++++++++++++++++
1 file changed, 50 insertions(+)
diff --git a/tools/perf/util/python.c b/tools/perf/util/python.c
index cc1019d29a5d..3f108b405ee3 100644
--- a/tools/perf/util/python.c
+++ b/tools/perf/util/python.c
@@ -1241,11 +1241,60 @@ static PyMemberDef pyrf_evsel__members[] = {
evsel_attr_member_def(sample_type, T_ULONGLONG, "attribute sample_type."),
evsel_attr_member_def(read_format, T_ULONGLONG, "attribute read_format."),
evsel_attr_member_def(wakeup_events, T_UINT, "attribute wakeup_events."),
+ evsel_attr_member_def(config1, T_ULONGLONG, "attribute config1."),
+ evsel_attr_member_def(config2, T_ULONGLONG, "attribute config2."),
{ .name = NULL, },
};
static const char pyrf_evsel__doc[] = PyDoc_STR("perf event selector list object.");
+static PyObject *pyrf_evsel__get_freq(struct pyrf_evsel *pevsel, void *closure)
+{
+ return PyLong_FromLong(pevsel->evsel.core.attr.freq);
+}
+
+static PyObject *pyrf_evsel__get_exclude_kernel(struct pyrf_evsel *pevsel,
+ void *closure)
+{
+ return PyLong_FromLong(pevsel->evsel.core.attr.exclude_kernel);
+}
+
+static PyObject *pyrf_evsel__get_exclude_hv(struct pyrf_evsel *pevsel,
+ void *closure)
+{
+ return PyLong_FromLong(pevsel->evsel.core.attr.exclude_hv);
+}
+
+static PyObject *pyrf_evsel__get_precise_ip(struct pyrf_evsel *pevsel,
+ void *closure)
+{
+ return PyLong_FromLong(pevsel->evsel.core.attr.precise_ip);
+}
+
+static PyGetSetDef pyrf_evsel__getset[] = {
+ {
+ .name = "freq",
+ .get = (getter)pyrf_evsel__get_freq,
+ .doc = PyDoc_STR("freq"),
+ },
+ {
+ .name = "exclude_kernel",
+ .get = (getter)pyrf_evsel__get_exclude_kernel,
+ .doc = PyDoc_STR("exclude_kernel"),
+ },
+ {
+ .name = "exclude_hv",
+ .get = (getter)pyrf_evsel__get_exclude_hv,
+ .doc = PyDoc_STR("exclude_hv"),
+ },
+ {
+ .name = "precise_ip",
+ .get = (getter)pyrf_evsel__get_precise_ip,
+ .doc = PyDoc_STR("precise_ip"),
+ },
+ { .name = NULL, },
+};
+
static PyTypeObject pyrf_evsel__type = {
PyVarObject_HEAD_INIT(NULL, 0)
.tp_name = "perf.evsel",
@@ -1255,6 +1304,7 @@ static PyTypeObject pyrf_evsel__type = {
.tp_doc = pyrf_evsel__doc,
.tp_members = pyrf_evsel__members,
.tp_methods = pyrf_evsel__methods,
+ .tp_getset = pyrf_evsel__getset,
.tp_init = (initproc)pyrf_evsel__init,
.tp_str = pyrf_evsel__str,
.tp_repr = pyrf_evsel__str,
--
2.43.0
next prev parent reply other threads:[~2026-06-22 13:50 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-22 13:49 [RFC PATCH 0/2] damo: support perf event configuration Akinobu Mita
2026-06-22 13:49 ` Akinobu Mita [this message]
2026-06-22 13:49 ` [RFC PATCH 2/2] damo: add --perf_event option Akinobu Mita
2026-06-22 15:24 ` [RFC PATCH 0/2] damo: support perf event configuration SeongJae Park
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=20260622134933.35773-2-akinobu.mita@gmail.com \
--to=akinobu.mita@gmail.com \
--cc=damon@lists.linux.dev \
--cc=linux-perf-users@vger.kernel.org \
--cc=ravis.opensrc@gmail.com \
--cc=sj@kernel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.