From nobody Sun Feb 8 07:07:26 2026 Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AF7011F4199; Thu, 1 May 2025 09:37:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=148.163.158.5 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746092235; cv=none; b=EVdQRyNVCoSjeH5L7nrfc+XggPwWX2oHlDHtChmAA0wjpHh9NDqEEbYHUjsMw+S5ziKR22hdW4S2a7e2MwH8g8Hk08cJTiyn2WCXxsyQEw9M2AxwSbhWEqVmmLS/4voC7cnWK2kYhfpwYm68DK8O6ugdpSEov7gwnUe3EaMFJks= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746092235; c=relaxed/simple; bh=w+9HjyX3jPytKMeWfq0Zv6KPNKkcA/I3EyFlCmydQcI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hy5Cp1wPwijucWLCVx5Bq/JpOSXGKUGARUGcMZeuJdL53NXv+GcMdv4CG68N7S6/5LLwrD2eIk9tmVekmHAOWoY6t2gl0zdZYH/pcghCIXuiO4I5ogVhx1grv8GeEJF0ZIocE3t4XWpKVcd0f3Suszm4ZTkMo5SaYfXzImw5s6E= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com; spf=pass smtp.mailfrom=linux.ibm.com; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b=TyuCINKD; arc=none smtp.client-ip=148.163.158.5 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.ibm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b="TyuCINKD" Received: from pps.filterd (m0360072.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 53ULggQp011435; Thu, 1 May 2025 09:36:59 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=cc :content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=pp1; bh=G0uv3MPU+9SsFN0ap vvs3jxDMqDztLFz4hlXpCOMI2o=; b=TyuCINKDSu0CmfmrzlsjTL8JdVYAZs8m2 2jYE6kbCvfQHet69McEfTSe3JRvvXMSMbXOIO2rdSQRK9b++uKuwvcn7dinXVx5f BBJEnFEqU5qD1FlKzFsJMxpeIt9/zk9KuQnWps3KqjPK+93pkKhnj3hlK01bN+yt EkV0e7C527BqFjSJv39fxz8m2OmB022/Rz/MiFYGd599TrLrYAD5+CapoxP1zAmT /BaB4gBSGMzZBidvK7EzzmzCnxf5h0CpM9q4AgocmOpXPEq6c9Dd492msu+xOjZL TElkEcW5xuxxyNDG1GVGgP1RmnJGfWJc56wEK2gGcNF6Q0a5Uhh4w== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 46bv0vt5mt-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 01 May 2025 09:36:59 +0000 (GMT) Received: from m0360072.ppops.net (m0360072.ppops.net [127.0.0.1]) by pps.reinject (8.18.0.8/8.18.0.8) with ESMTP id 5419awpR024834; Thu, 1 May 2025 09:36:59 GMT Received: from ppma12.dal12v.mail.ibm.com (dc.9e.1632.ip4.static.sl-reverse.com [50.22.158.220]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 46bv0vt5mp-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 01 May 2025 09:36:58 +0000 (GMT) Received: from pps.filterd (ppma12.dal12v.mail.ibm.com [127.0.0.1]) by ppma12.dal12v.mail.ibm.com (8.18.1.2/8.18.1.2) with ESMTP id 5418nqtc031665; Thu, 1 May 2025 09:36:58 GMT Received: from smtprelay04.fra02v.mail.ibm.com ([9.218.2.228]) by ppma12.dal12v.mail.ibm.com (PPS) with ESMTPS id 4699tucc4r-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 01 May 2025 09:36:57 +0000 Received: from smtpav04.fra02v.mail.ibm.com (smtpav04.fra02v.mail.ibm.com [10.20.54.103]) by smtprelay04.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 5419asMU18743792 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 1 May 2025 09:36:54 GMT Received: from smtpav04.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 3BA842004B; Thu, 1 May 2025 09:36:54 +0000 (GMT) Received: from smtpav04.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id E080F20040; Thu, 1 May 2025 09:36:50 +0000 (GMT) Received: from li-c6426e4c-27cf-11b2-a85c-95d65bc0de0e.ibm.com.com (unknown [9.124.221.47]) by smtpav04.fra02v.mail.ibm.com (Postfix) with ESMTP; Thu, 1 May 2025 09:36:50 +0000 (GMT) From: Gautam Menghani 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 , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, maddy@linux.ibm.com Subject: [PATCH 1/4] perf python: Add support for perf_counts_values to return counter data Date: Thu, 1 May 2025 15:06:27 +0530 Message-ID: <20250501093633.578010-2-gautam@linux.ibm.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250501093633.578010-1-gautam@linux.ibm.com> References: <20250501093633.578010-1-gautam@linux.ibm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-TM-AS-GCONF: 00 X-Authority-Analysis: v=2.4 cv=LJlmQIW9 c=1 sm=1 tr=0 ts=681340bb cx=c_pps a=bLidbwmWQ0KltjZqbj+ezA==:117 a=bLidbwmWQ0KltjZqbj+ezA==:17 a=dt9VzEwgFbYA:10 a=VnNF1IyMAAAA:8 a=8VWMH8aeIS0OOwB8Z8wA:9 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUwNTAxMDA3MiBTYWx0ZWRfX5PeIBK9KqqB5 IjYoJfuj3RJcj/XY2otskDMMED4YTgVL9evfgodi9pmQq12JcSDAF1peEuaE6ZAEa1vd2aC1v3h P6IY/64N6D4SxU6y55NJGXk3uWqay8WP/laFdT6KYH/ay17I7etnanyuJKCNx2/or/CrjSGESaq rVwF5ZYD3WygyFM6PUhouYsGjeyr23314ll5uHOUYcWF0XOlWmFA0af4HZKZK83oQYiupQ95d3q RDtezXD3M3uefDpvRr/dIrgbWRzFg7fEQYE5wdVxO6v69UpOufKMn8c+xn8FYzSi/ETuPIBgwWo jNaMQS+Umq+BX7zO+lcbxwEqlX86HUztWeN1h0KGF2yhLM53SWim58BbdlslupyDwpc4Bc0185V FmTcLPoZstIe8wne5g64ZmyKAkLkjzssFC7wbdEkfrIwTowUZKLkUredTkkj2KS1mJwLQKi3 X-Proofpoint-ORIG-GUID: -_FF04ZLKwMEccwEQ0emCbQDJXfXrrcp X-Proofpoint-GUID: hWvZSAkf00Bp70cZzY-quS6vtMt-yiQJ X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1099,Hydra:6.0.736,FMLib:17.12.80.40 definitions=2025-05-01_03,2025-04-24_02,2025-02-21_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 suspectscore=0 mlxlogscore=999 malwarescore=0 bulkscore=0 lowpriorityscore=0 mlxscore=0 priorityscore=1501 adultscore=0 phishscore=0 clxscore=1015 spamscore=0 classifier=spam authscore=0 authtc=n/a authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.19.0-2504070000 definitions=main-2505010072 Content-Type: text/plain; charset="utf-8" Add bindings for perf_counts_values struct to enable the python scripts to read the counter data for an event. Signed-off-by: Gautam Menghani --- tools/perf/util/python.c | 92 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 91 insertions(+), 1 deletion(-) diff --git a/tools/perf/util/python.c b/tools/perf/util/python.c index f3c05da25b4a..011ee2e27797 100644 --- a/tools/perf/util/python.c +++ b/tools/perf/util/python.c @@ -626,6 +626,92 @@ static int pyrf_thread_map__setup_types(void) return PyType_Ready(&pyrf_thread_map__type); } =20 +struct pyrf_counts_values { + PyObject_HEAD + + struct perf_counts_values values; +}; + +static const char pyrf_counts_values__doc[] =3D PyDoc_STR("perf counts val= ues object."); + +static void pyrf_counts_values__delete(struct pyrf_counts_values *pcounts_= values) +{ + Py_TYPE(pcounts_values)->tp_free((PyObject *)pcounts_values); +} + +#define counts_values_member_def(member, ptype, help) \ + { #member, ptype, \ + offsetof(struct pyrf_counts_values, values.member), \ + 0, help } + +static PyMemberDef pyrf_counts_values_members[] =3D { + counts_values_member_def(val, Py_T_ULONG, "Value of event"), + counts_values_member_def(ena, Py_T_ULONG, "Time for which enabled"), + counts_values_member_def(run, Py_T_ULONG, "Time for which running"), + counts_values_member_def(id, Py_T_ULONG, "Unique ID for an event"), + counts_values_member_def(lost, Py_T_ULONG, "Num of lost samples"), + {NULL} +}; + +static PyObject *pyrf_counts_values_get_values(struct pyrf_counts_values *= self, void *closure) +{ + PyObject *vals =3D PyList_New(5); + + if (!vals) + return NULL; + for (int i =3D 0; i < 5; i++) + PyList_SetItem(vals, i, PyLong_FromLong(self->values.values[i])); + + return vals; +} + +static int pyrf_counts_values_set_values(struct pyrf_counts_values *self, = PyObject *list, + void *closure) +{ + Py_ssize_t size; + PyObject *item =3D NULL; + + if (!PyList_Check(list)) { + PyErr_SetString(PyExc_TypeError, "Value assigned must be a list"); + return -1; + } + + size =3D PyList_Size(list); + for (Py_ssize_t i =3D 0; i < size; i++) { + item =3D PyList_GetItem(list, i); + if (!PyLong_Check(item)) { + PyErr_SetString(PyExc_TypeError, "List members should be numbers"); + return -1; + } + self->values.values[i] =3D PyLong_AsLong(item); + } + + return 0; +} + +static PyGetSetDef pyrf_counts_values_getset[] =3D { + {"values", (getter)pyrf_counts_values_get_values, (setter)pyrf_counts_val= ues_set_values, + "Name field", NULL}, + {NULL} +}; + +static PyTypeObject pyrf_counts_values__type =3D { + PyVarObject_HEAD_INIT(NULL, 0) + .tp_name =3D "perf.counts_values", + .tp_basicsize =3D sizeof(struct pyrf_counts_values), + .tp_dealloc =3D (destructor)pyrf_counts_values__delete, + .tp_flags =3D Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE, + .tp_doc =3D pyrf_counts_values__doc, + .tp_members =3D pyrf_counts_values_members, + .tp_getset =3D pyrf_counts_values_getset, +}; + +static int pyrf_counts_values__setup_types(void) +{ + pyrf_counts_values__type.tp_new =3D PyType_GenericNew; + return PyType_Ready(&pyrf_counts_values__type); +} + struct pyrf_evsel { PyObject_HEAD =20 @@ -1442,7 +1528,8 @@ PyMODINIT_FUNC PyInit_perf(void) pyrf_evlist__setup_types() < 0 || pyrf_evsel__setup_types() < 0 || pyrf_thread_map__setup_types() < 0 || - pyrf_cpu_map__setup_types() < 0) + pyrf_cpu_map__setup_types() < 0 || + pyrf_counts_values__setup_types() < 0) return module; =20 /* The page_size is placed in util object. */ @@ -1487,6 +1574,9 @@ PyMODINIT_FUNC PyInit_perf(void) Py_INCREF(&pyrf_cpu_map__type); PyModule_AddObject(module, "cpu_map", (PyObject*)&pyrf_cpu_map__type); =20 + Py_INCREF(&pyrf_counts_values__type); + PyModule_AddObject(module, "counts_values", (PyObject *)&pyrf_counts_valu= es__type); + dict =3D PyModule_GetDict(module); if (dict =3D=3D NULL) goto error; --=20 2.49.0 From nobody Sun Feb 8 07:07:26 2026 Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 172A225A623; Thu, 1 May 2025 09:37:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=148.163.156.1 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746092241; cv=none; b=JSamMCa578K519b1fA9LLPey+Alx6kbdOz6fGAbXmYXN7M2yaHyZ9CX1FHQBaJ7o5NJWDpD4VpPTiSSn4COUzFx/zfj34X2ZiH0YyWWOuSMPMtBIgbWzyNAESZD89aEEXl4GGTeZxHOCWAnEmrtwShnssiHSOzlD/IHbyRtk9oE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746092241; c=relaxed/simple; bh=bbBhhl4DNZvNM0i/8eTCvJERerffvAeyCojBFgOwd1A=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=r0iKQHbyarx0NcAVf7JwsTWm/jP0tnfVvm8DhKWdueRWvu5RXQ6aoG0LkXPANzUkRj8SxWT1AicR6XGmnoYC7APaRkA1lBgL05G+yh8KJpdg7goCv8Y0jhzkOS5Q7bG8zJeloDyVC/H+/fo5QPaPnYS2cArd246B2FnTpsBhHf8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com; spf=pass smtp.mailfrom=linux.ibm.com; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b=GtiEwDTP; arc=none smtp.client-ip=148.163.156.1 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.ibm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b="GtiEwDTP" Received: from pps.filterd (m0360083.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 5416RHAr006425; Thu, 1 May 2025 09:37:08 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=cc :content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=pp1; bh=/zbH5yG2+qt9ridWK zgS1saNGmlvuCWVCOT2OJatMvA=; b=GtiEwDTPD6W0sMXCtmK0T68tLiZ2l1aO6 IntIOZ1OZwcy2tZiRWKM9TjL8syvzwzLNJgns3IaRxttzfkBxsKF776teQaa+oq4 WdmXgK1cTLd7L12sJy0dy0gbq30zTud4BCcjcsDUzFJM6fYJhASb19B2WuDiFPMK IgrNrcvycnh2M1uC7OJUNo/f+ZxSCyv9tvnFJilpoc73ek4xoNCZQAg6IM4mLvXH 1eglRBJjgmuIb50puaiXGh3U4u6zTCbi27VA6JVmIISNATChR3iVsvdhkC969rJZ G6gxDpRsrORNWfsZrtiOCiAyqQKc81G7ozNbkvW+fwd4Dpx4l0PSw== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 46bhsjwh2m-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 01 May 2025 09:37:08 +0000 (GMT) Received: from m0360083.ppops.net (m0360083.ppops.net [127.0.0.1]) by pps.reinject (8.18.0.8/8.18.0.8) with ESMTP id 5419b7Z5008331; Thu, 1 May 2025 09:37:07 GMT Received: from ppma23.wdc07v.mail.ibm.com (5d.69.3da9.ip4.static.sl-reverse.com [169.61.105.93]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 46bhsjwh2f-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 01 May 2025 09:37:07 +0000 (GMT) Received: from pps.filterd (ppma23.wdc07v.mail.ibm.com [127.0.0.1]) by ppma23.wdc07v.mail.ibm.com (8.18.1.2/8.18.1.2) with ESMTP id 54161E2v001803; Thu, 1 May 2025 09:37:06 GMT Received: from smtprelay02.fra02v.mail.ibm.com ([9.218.2.226]) by ppma23.wdc07v.mail.ibm.com (PPS) with ESMTPS id 469bamv4tv-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 01 May 2025 09:37:06 +0000 Received: from smtpav04.fra02v.mail.ibm.com (smtpav04.fra02v.mail.ibm.com [10.20.54.103]) by smtprelay02.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 5419b27A33161596 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 1 May 2025 09:37:02 GMT Received: from smtpav04.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 7B5F120043; Thu, 1 May 2025 09:37:02 +0000 (GMT) Received: from smtpav04.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 292EB20040; Thu, 1 May 2025 09:36:59 +0000 (GMT) Received: from li-c6426e4c-27cf-11b2-a85c-95d65bc0de0e.ibm.com.com (unknown [9.124.221.47]) by smtpav04.fra02v.mail.ibm.com (Postfix) with ESMTP; Thu, 1 May 2025 09:36:58 +0000 (GMT) From: Gautam Menghani 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 , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, maddy@linux.ibm.com Subject: [PATCH 2/4] perf python: Add evsel read method Date: Thu, 1 May 2025 15:06:28 +0530 Message-ID: <20250501093633.578010-3-gautam@linux.ibm.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250501093633.578010-1-gautam@linux.ibm.com> References: <20250501093633.578010-1-gautam@linux.ibm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-TM-AS-GCONF: 00 X-Authority-Analysis: v=2.4 cv=dcuA3WXe c=1 sm=1 tr=0 ts=681340c4 cx=c_pps a=3Bg1Hr4SwmMryq2xdFQyZA==:117 a=3Bg1Hr4SwmMryq2xdFQyZA==:17 a=dt9VzEwgFbYA:10 a=VnNF1IyMAAAA:8 a=X_mIwdbuNq69S7QoM7cA:9 X-Proofpoint-GUID: h4ru7CCXZwuzE6Uftp_WzlM9p-KAp_cg X-Proofpoint-ORIG-GUID: TpC0e04OfMIYWfWtF1xK0WcZ3AB4qi7A X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUwNTAxMDA3MiBTYWx0ZWRfX5vgj7UUC3geP DMVRSI7Hw6V5xZwH16Hct5UoRRDHsumgnU695E6988wfSjUnz2C5CXfCZobxOyXe9qml+tTOA4Y IvBZ1jh85vMO7J6UykpSIc9g6bzdh8N9lDd8ufnGss2XTu+NKtmJql51+4MDlujCQq3wCndSYFd fdTiV5qOOBigOAC7OflBJfzF6eDO45wVsiO+VlKcr7VRGCfz4JGuD1OGqcAg1D2POtQpad14tac Jh7nS0SRV6X4CXL2m1wED8rTSlrwSNmr3sBPdMGD8uwSVoXwUT7anvvYTPpwv1oK5mI6ntfXD3K x1GfEqjTSvvN4Y/jvM3LDc8GFrPJIlyA66e7+PRmwQgbRtNkuSrYR6+Qjwn+SaXSMyYbanf2PEl V3TspllsJCfaAfS2kQaHsOxptAKipJVzbdPvobkEfS4IyRNsR1N0Na5TvM4TOVhiG0F5H+wt X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1099,Hydra:6.0.736,FMLib:17.12.80.40 definitions=2025-05-01_03,2025-04-24_02,2025-02-21_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 suspectscore=0 spamscore=0 impostorscore=0 bulkscore=0 adultscore=0 mlxscore=0 malwarescore=0 mlxlogscore=999 priorityscore=1501 lowpriorityscore=0 clxscore=1015 classifier=spam authscore=0 authtc=n/a authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.19.0-2504070000 definitions=main-2505010072 Content-Type: text/plain; charset="utf-8" Add the evsel read method to enable reading counter data for the given evsel from python. Signed-off-by: Gautam Menghani --- tools/perf/util/python.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/tools/perf/util/python.c b/tools/perf/util/python.c index 011ee2e27797..5a4d2c9aaabd 100644 --- a/tools/perf/util/python.c +++ b/tools/perf/util/python.c @@ -867,6 +867,23 @@ static PyObject *pyrf_evsel__open(struct pyrf_evsel *p= evsel, return Py_None; } =20 +static PyObject *pyrf_evsel__read(struct pyrf_evsel *pevsel, + PyObject *args, PyObject *kwargs) +{ + struct evsel *evsel =3D &pevsel->evsel; + int cpu_map_idx =3D 0, thread =3D 0; + struct perf_counts_values counts; + struct pyrf_counts_values *count_values =3D PyObject_New(struct pyrf_coun= ts_values, + &pyrf_counts_values__type); + + if (!PyArg_ParseTuple(args, "ii", &cpu_map_idx, &thread)) + return NULL; + + perf_evsel__read(&(evsel->core), cpu_map_idx, thread, &counts); + count_values->values =3D counts; + return (PyObject *)count_values; +} + static PyObject *pyrf_evsel__str(PyObject *self) { struct pyrf_evsel *pevsel =3D (void *)self; @@ -885,6 +902,12 @@ static PyMethodDef pyrf_evsel__methods[] =3D { .ml_flags =3D METH_VARARGS | METH_KEYWORDS, .ml_doc =3D PyDoc_STR("open the event selector file descriptor table.") }, + { + .ml_name =3D "read", + .ml_meth =3D (PyCFunction)pyrf_evsel__read, + .ml_flags =3D METH_VARARGS | METH_KEYWORDS, + .ml_doc =3D PyDoc_STR("read counters") + }, { .ml_name =3D NULL, } }; =20 --=20 2.49.0 From nobody Sun Feb 8 07:07:26 2026 Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E996A22CBD5; Thu, 1 May 2025 09:37:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=148.163.158.5 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746092248; cv=none; b=V+2o3LmBoKthQhG0zSEkyZK3rmRtu8KXceV0v9Qvn7IfOWadNRG/basxvSoxNxZKKaMi3W5gdvI0jNDYR2X3+1giXGWPrPGgqkxbWwUUhqkm5Er8B/9wGrAmXSTqTuqk2rjQsoUxC/j+rC6E+RZV2l/he4ybt/eUp5yPd7n6M0I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746092248; c=relaxed/simple; bh=oFt16kgUKdcj33X/bx1wFeNI8gWedSulniZ0udiW7pA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=CEN9Z7zsztgU1L/pV7/PuEe1ocENItNE7I+tmkLEffniz0qd22ho+8sB/IvrOJ8lKESw1D/V4/leUZhRog++oBMA7qiePZ8NRFUKig9m6onZcPAc9Ln4wsJ5TshZkvx/iFGhmqtAl686tCyupW34FmTOmt2rPuKB5mVKlVrC9Uw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com; spf=pass smtp.mailfrom=linux.ibm.com; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b=eZn7dODM; arc=none smtp.client-ip=148.163.158.5 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.ibm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b="eZn7dODM" Received: from pps.filterd (m0356516.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 5414PmKH012575; Thu, 1 May 2025 09:37:16 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=cc :content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=pp1; bh=IQ5UwL7a/qlNX/AYu nSCEk7/ZRMUEI71r/DO7zPY7Fw=; b=eZn7dODM4+j0qf7f9tL01uHPuveugiAj5 oVm6QX+D/37r55QcmwKmhgJhu2Kgdo39JsaUZ4Mbw8c3Rirs4gMx/z2cJOy3xHxq APmD1ogrbUXBxpyDUexot1suVcXnPklXmfZN1JzVFR2RGcTzuibpUZ21vz4RBdsC p5+7tKjuxm31YS68Q5UhDoYGSqha+mbisbxXnFthZaUPXbxgsWZmsGwzCqzmlZ2J EdhWctxljWtXMDuyOb2c3C69nNf7HnvSOo7w79K9QBye+AHnasj91pUZS4nDnnQ3 Qtnj35aIgUQ+1Lwjy6vggBTSs4micdH7z1mlYnA13n8GCPitjFe1A== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 46bjas592m-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 01 May 2025 09:37:16 +0000 (GMT) Received: from m0356516.ppops.net (m0356516.ppops.net [127.0.0.1]) by pps.reinject (8.18.0.8/8.18.0.8) with ESMTP id 5419bFLq001185; Thu, 1 May 2025 09:37:15 GMT Received: from ppma22.wdc07v.mail.ibm.com (5c.69.3da9.ip4.static.sl-reverse.com [169.61.105.92]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 46bjas592h-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 01 May 2025 09:37:15 +0000 (GMT) Received: from pps.filterd (ppma22.wdc07v.mail.ibm.com [127.0.0.1]) by ppma22.wdc07v.mail.ibm.com (8.18.1.2/8.18.1.2) with ESMTP id 5418aUGg016584; Thu, 1 May 2025 09:37:15 GMT Received: from smtprelay05.fra02v.mail.ibm.com ([9.218.2.225]) by ppma22.wdc07v.mail.ibm.com (PPS) with ESMTPS id 469a70mbre-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 01 May 2025 09:37:14 +0000 Received: from smtpav04.fra02v.mail.ibm.com (smtpav04.fra02v.mail.ibm.com [10.20.54.103]) by smtprelay05.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 5419bBN041091572 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 1 May 2025 09:37:11 GMT Received: from smtpav04.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 1AF2820043; Thu, 1 May 2025 09:37:11 +0000 (GMT) Received: from smtpav04.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id CA08A20040; Thu, 1 May 2025 09:37:07 +0000 (GMT) Received: from li-c6426e4c-27cf-11b2-a85c-95d65bc0de0e.ibm.com.com (unknown [9.124.221.47]) by smtpav04.fra02v.mail.ibm.com (Postfix) with ESMTP; Thu, 1 May 2025 09:37:07 +0000 (GMT) From: Gautam Menghani 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 , 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 Message-ID: <20250501093633.578010-4-gautam@linux.ibm.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250501093633.578010-1-gautam@linux.ibm.com> References: <20250501093633.578010-1-gautam@linux.ibm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-TM-AS-GCONF: 00 X-Proofpoint-GUID: yyBUwlojeB4xEITTnv8pARp8CkFrYMXf X-Proofpoint-ORIG-GUID: mTS9J_dvBiI8nrm5vqITQ2Qlb91nc3ds X-Authority-Analysis: v=2.4 cv=LKNmQIW9 c=1 sm=1 tr=0 ts=681340cc cx=c_pps a=5BHTudwdYE3Te8bg5FgnPg==:117 a=5BHTudwdYE3Te8bg5FgnPg==:17 a=dt9VzEwgFbYA:10 a=VnNF1IyMAAAA:8 a=Mu-R3_ysuym7pKtYsCYA:9 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUwNTAxMDA3MiBTYWx0ZWRfXwt7Ohp+kVF3k BQL4hf4trUWiAl4VTyzblWJiLP5p6DcbKhr+2orDlhu3XdFrCfxI7+QIavyS/yCb0+4X/+KNPZ+ JibQF14OG5WLLJrRKwTf1nKhYYAmYCGLva52A2ndYRxHKg4aVapHXYsbrPCC33NuTNGzm8UP+g0 93CrNU60CLBgmzbK2sWD8CMBC+y5n7Z2CtzTF87wypWC3N70W9/u0Sysz/iksNevVuizjbMQRfE dP1mNsOOArRofAeZVpA7sRWLX1UWFh9pxopvG4/+rE+Tv32Ttig4V1lgjo+R06NL0f/WrDb2sWq 8ipiX4nsSQBpR1ezE71oJaFggfo43HtnOcb9Z3ScEFkTjBEGzgQXhpXM0OrsFX997gZtXEGiGrd uXFCHKR+ENs2NTwjaarQ/rHlyOAH4Q4Pfbp8qn/qoCJ92CaLrpcv/YLvZ8wy4xE1CiQKMWaZ X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1099,Hydra:6.0.736,FMLib:17.12.80.40 definitions=2025-05-01_03,2025-04-24_02,2025-02-21_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 priorityscore=1501 malwarescore=0 suspectscore=0 spamscore=0 mlxscore=0 impostorscore=0 adultscore=0 bulkscore=0 mlxlogscore=950 clxscore=1015 phishscore=0 classifier=spam authscore=0 authtc=n/a authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.19.0-2504070000 definitions=main-2505010072 Content-Type: text/plain; charset="utf-8" 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 --- 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_evlis= t *pevlist, return Py_None; } =20 +static PyObject *pyrf_evlist__close(struct pyrf_evlist *pevlist) +{ + struct evlist *evlist =3D &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 =3D { @@ -1202,6 +1212,31 @@ static PyObject *pyrf_evlist__enable(struct pyrf_evl= ist *pevlist) return Py_None; } =20 +static PyObject *pyrf_evlist__next(struct pyrf_evlist *pevlist, + PyObject *args, PyObject *kwargs) +{ + struct evlist *evlist =3D &pevlist->evlist; + PyObject *py_evsel; + struct perf_evsel *pevsel; + struct evsel *evsel; + struct pyrf_evsel *next_evsel =3D PyObject_New(struct pyrf_evsel, &pyrf_e= vsel__type); + static char *kwlist[] =3D { "evsel", NULL }; + + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O", kwlist, + &py_evsel)) + return NULL; + + pevsel =3D (py_evsel =3D=3D Py_None) ? NULL : &(((struct pyrf_evsel *)py_= evsel)->evsel.core); + pevsel =3D perf_evlist__next(&(evlist->core), pevsel); + if (pevsel !=3D NULL) { + evsel =3D container_of(pevsel, struct evsel, core); + next_evsel =3D container_of(evsel, struct pyrf_evsel, evsel); + return (PyObject *) next_evsel; + } + + return Py_None; +} + static PyMethodDef pyrf_evlist__methods[] =3D { { .ml_name =3D "all_cpus", @@ -1221,6 +1256,12 @@ static PyMethodDef pyrf_evlist__methods[] =3D { .ml_flags =3D METH_VARARGS | METH_KEYWORDS, .ml_doc =3D PyDoc_STR("open the file descriptors.") }, + { + .ml_name =3D "close", + .ml_meth =3D (PyCFunction)pyrf_evlist__close, + .ml_flags =3D METH_NOARGS, + .ml_doc =3D PyDoc_STR("close the file descriptors.") + }, { .ml_name =3D "poll", .ml_meth =3D (PyCFunction)pyrf_evlist__poll, @@ -1263,6 +1304,12 @@ static PyMethodDef pyrf_evlist__methods[] =3D { .ml_flags =3D METH_NOARGS, .ml_doc =3D PyDoc_STR("Enable the evsels in the evlist.") }, + { + .ml_name =3D "next", + .ml_meth =3D (PyCFunction)pyrf_evlist__next, + .ml_flags =3D METH_VARARGS | METH_KEYWORDS, + .ml_doc =3D PyDoc_STR("Return next evsel") + }, { .ml_name =3D NULL, } }; =20 --=20 2.49.0 From nobody Sun Feb 8 07:07:26 2026 Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1A65822D4F0; Thu, 1 May 2025 09:37:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=148.163.156.1 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746092255; cv=none; b=dYjzWyomLcZu9uYnjrNjUAXwx6J8jMlH30tH4zlZc1KxtXGEx6Zpj6RPziQP/XfbbWZ6wHAFLGfORF/rpHnRX056YXsAOLGmbAYd4cFH5+tU8qn/YGgmP/NrA8cuTDTdixOLMdVpwt7FJQHzyTSyUFgwJXNIKUt9wuxZGftsV84= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746092255; c=relaxed/simple; bh=hc7NgoslmUG4t3a9ZjQNuHyS58KdErQYl4ZgInZTw4A=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=DD1ohpy1aGvk9jxwXgqpULJhrbNLJeg5TS4iIEEeOjXxLoBU31/24TN9rmvDw7xdeGabP61LrmsFgXzc7Wu5Gyq85Atxb9cH++CoinBPGRozZwHR7wM+qoUMkezQeiVCc1v8anAxp+T9MJUXQKjEH6UrMJFtCBhASSewoWfYyyo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com; spf=pass smtp.mailfrom=linux.ibm.com; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b=RK2iU0jp; arc=none smtp.client-ip=148.163.156.1 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.ibm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b="RK2iU0jp" Received: from pps.filterd (m0353729.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 53UL3EHd021977; Thu, 1 May 2025 09:37:25 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=cc :content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=pp1; bh=AquKFxP8l67OoaM9Z z0xrfQap9EJ2IiwDoc+9rWGBDo=; b=RK2iU0jp/lWTs9uSJrZgOyHwhAmVvPwNS hHzICziJ43LfzZ9u9APfbhBwMFJ+z8nRZOp4WOHGkVVleQb28L0S71uJNzB4n/Zo 9gv3Kss7p+Y/ai1mugpJ8ROeR6cZchy59lrS5fw2b/HlEoODr+L0kWoiFwXdRPp9 Q6vTcB15Bgr62ANYgEpVyEEJQaeLmJfMnaxbFGGz9a6fPlkQbJA/pBjXZgD1hmx6 RHK2QPVp0J/ankLG22q35kGuQXWKHSPAmHP3WSsUnJiri7oFxbytIDarGWuE8K3a 61ULi1cdJ/0TInphvP//YRzu3AOdTz0uBdzgM2OrSZg9/JVPOuDcQ== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 46buekjbk9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 01 May 2025 09:37:25 +0000 (GMT) Received: from m0353729.ppops.net (m0353729.ppops.net [127.0.0.1]) by pps.reinject (8.18.0.8/8.18.0.8) with ESMTP id 5419bOhb005184; Thu, 1 May 2025 09:37:24 GMT Received: from ppma22.wdc07v.mail.ibm.com (5c.69.3da9.ip4.static.sl-reverse.com [169.61.105.92]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 46buekjbk5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 01 May 2025 09:37:24 +0000 (GMT) Received: from pps.filterd (ppma22.wdc07v.mail.ibm.com [127.0.0.1]) by ppma22.wdc07v.mail.ibm.com (8.18.1.2/8.18.1.2) with ESMTP id 5419EBFk016145; Thu, 1 May 2025 09:37:23 GMT Received: from smtprelay06.fra02v.mail.ibm.com ([9.218.2.230]) by ppma22.wdc07v.mail.ibm.com (PPS) with ESMTPS id 469a70mbrn-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 01 May 2025 09:37:23 +0000 Received: from smtpav04.fra02v.mail.ibm.com (smtpav04.fra02v.mail.ibm.com [10.20.54.103]) by smtprelay06.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 5419bJaw21954850 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 1 May 2025 09:37:19 GMT Received: from smtpav04.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 7B51220043; Thu, 1 May 2025 09:37:19 +0000 (GMT) Received: from smtpav04.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 1DAF320040; Thu, 1 May 2025 09:37:16 +0000 (GMT) Received: from li-c6426e4c-27cf-11b2-a85c-95d65bc0de0e.ibm.com.com (unknown [9.124.221.47]) by smtpav04.fra02v.mail.ibm.com (Postfix) with ESMTP; Thu, 1 May 2025 09:37:15 +0000 (GMT) From: Gautam Menghani 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 , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, maddy@linux.ibm.com Subject: [PATCH 4/4] perf python: Add counting.py as example for counting perf events Date: Thu, 1 May 2025 15:06:30 +0530 Message-ID: <20250501093633.578010-5-gautam@linux.ibm.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250501093633.578010-1-gautam@linux.ibm.com> References: <20250501093633.578010-1-gautam@linux.ibm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-TM-AS-GCONF: 00 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUwNTAxMDA3MiBTYWx0ZWRfX4ep+RS1nkGDH iQwwqG7jrir52dpfBhi2LBia4vZ2jGBSiF+B0fyNFECfwjm3JYrceivvkLS6OXVts0m0LZODuH6 r5MCMCGRA6sj1NOj9outZjj1tMKChCf28lm/jIPbfNL0TecblMR6Qy7wSP+uQFNKkRPssbLWbr/ 6gBXzoGdSD7fGwwYxpSseb2vDBObCTxIbjXQyoPvZNCYCAyJph8CO5m9nu/gtC75ER6Jx2zgv7u N/XKfXOBzQymSNjk/1VxV4in+zePqoID11SOB77uHcDpp1ETG+rHCJvltfAHnpLaeJUjbe9kKt5 bgrDBnIDqYHYElGP8RA8kmYL9as5KVwrH+37bJQowT7JplzA+USzdJ4aMhpSUqGegJT4M2GHlUy 5VJl2IiHvYr7OKZBd5fCCOlxV1tHdMn1omm0JJsmiGU1RqLy7lOdxex+CaPYQyrBL4ybQ8Qh X-Authority-Analysis: v=2.4 cv=Io0ecK/g c=1 sm=1 tr=0 ts=681340d5 cx=c_pps a=5BHTudwdYE3Te8bg5FgnPg==:117 a=5BHTudwdYE3Te8bg5FgnPg==:17 a=dt9VzEwgFbYA:10 a=VnNF1IyMAAAA:8 a=YI06EguIVAnxD8KhfcAA:9 X-Proofpoint-ORIG-GUID: HZXWosbrsR__hhjxEQHClb4BplyKzekZ X-Proofpoint-GUID: Awrz7UgddSuikCZ4ScTR0SFfKhng096F X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1099,Hydra:6.0.736,FMLib:17.12.80.40 definitions=2025-05-01_03,2025-04-24_02,2025-02-21_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 clxscore=1015 malwarescore=0 suspectscore=0 mlxlogscore=999 impostorscore=0 mlxscore=0 adultscore=0 bulkscore=0 phishscore=0 lowpriorityscore=0 spamscore=0 classifier=spam authscore=0 authtc=n/a authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.19.0-2504070000 definitions=main-2505010072 Content-Type: text/plain; charset="utf-8" Add counting.py - a python version of counting.c to demonstrate measuring and reading of counts for given perf events. Signed-off-by: Gautam Menghani --- tools/perf/python/counting.py | 41 +++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100755 tools/perf/python/counting.py diff --git a/tools/perf/python/counting.py b/tools/perf/python/counting.py new file mode 100755 index 000000000000..0c58907bd8bf --- /dev/null +++ b/tools/perf/python/counting.py @@ -0,0 +1,41 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: GPL-2.0 +# -*- python -*- +# -*- coding: utf-8 -*- + +import perf + +def main(): + cpus =3D perf.cpu_map() + thread_map =3D perf.thread_map(-1) + evlist =3D perf.evlist(cpus, thread_map) + + evsel1 =3D perf.evsel(type =3D perf.TYPE_SOFTWARE, + config =3D perf.COUNT_SW_CPU_CLOCK, + read_format =3D perf.FORMAT_TOTAL_TIME_ENABLED | perf.FOR= MAT_TOTAL_TIME_RUNNING, + disabled=3D1) + evlist.add(evsel1) + + evsel2 =3D perf.evsel(type =3D perf.TYPE_SOFTWARE, + config =3D perf.COUNT_SW_TASK_CLOCK, + read_format =3D perf.FORMAT_TOTAL_TIME_ENABLED | perf.FOR= MAT_TOTAL_TIME_RUNNING, + disabled=3D1) + evlist.add(evsel2) + + evlist.open() + evlist.enable() + + count =3D 100000 + while count > 0: + count -=3D 1 + + evlist.disable() + evsel =3D evlist.next(None) + while evsel !=3D None: + counts =3D evsel.read(0, 0) + print(counts.val, counts.ena, counts.run) + evsel =3D evlist.next(evsel) + evlist.close() + +if __name__ =3D=3D '__main__': + main() --=20 2.49.0