From nobody Wed Dec 17 08:54:14 2025 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 2531E255E27; Mon, 12 May 2025 06:26:01 +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=1747031164; cv=none; b=PE7IBM5oQer/0axJVBFboQsExXqvqoYVzmjsCJGV+dIjLIZHXxK4Qp0ZFDQegA/DmqiS0VVLKKcW+K0Vmpv75E+8/ok4ldTQ4re93+Qn0rwhEg8gA8dFS9MeIf702AtTkhWJpQBBoujYRYlzbh2g4Ei8hjhVVpX2fBHIux89I1I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747031164; c=relaxed/simple; bh=nlRYXIexSil3us+olEQ3l6qGg05Uil0ykxfctWceppM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=XdYmCd5VGEQQP3uUntq0rYkqBKeMkPwYGmh+p4gnUbyfmXBku3KFi5/Cq4l55Y5ku6yoN9tpThQQt2hx1eJSX6WFOS75RGH11DNfrpcAQ9UZg8Uq9C/EOsm5upRnwYmO8mjfYE6enjX3dNRfTZjHaNf6ongDkKxSFWp1PCfoTiI= 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=H3nbeFz9; 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="H3nbeFz9" 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 54C5Yck2020732; Mon, 12 May 2025 06:25:51 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=QaB/di9rrLscjRxGn wPR1rtyS/LNU0MvgHfPxjHAv8k=; b=H3nbeFz9zSNATPqezN4w4F1VdenMGJITf SmfVuY54QqArT1ADKouKdl/kzBkYgVeiVrN9MQ2Oy1+ojaEadTnSqVDbNiJRsNHb zI+KgAs4C6MejODxo0ho5M200vHBQH23sV2W+bC60sLPVhrhTNQvTGeK9pzbPB0c sNEDe7RzHuHgAGyTAH3xFR43m1hWAmTvMZN2y3HtMZF7jVOt5n/awo+vKfSlVWZA 2ywhH7Wuy5VfqsIw25uvdV+jC+VgmS2rhg4yK8iqMj03A+9RpqEE87H3hrN9wvuZ Vh/sNyNhgsjFQmP7iupnfnbzi9FwM0+vINr6cCiNArF4kB1ru2unQ== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 46jrrg2x70-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 12 May 2025 06:25:50 +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 54C6E3HK020500; Mon, 12 May 2025 06:25:50 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 46jrrg2x6u-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 12 May 2025 06:25:50 +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 54C5Qa8d024452; Mon, 12 May 2025 06:25:48 GMT Received: from smtprelay06.fra02v.mail.ibm.com ([9.218.2.230]) by ppma23.wdc07v.mail.ibm.com (PPS) with ESMTPS id 46jjmkvhmj-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 12 May 2025 06:25:48 +0000 Received: from smtpav06.fra02v.mail.ibm.com (smtpav06.fra02v.mail.ibm.com [10.20.54.105]) by smtprelay06.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 54C6PiMA18481426 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 12 May 2025 06:25:45 GMT Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id A01A9200E0; Mon, 12 May 2025 05:58:03 +0000 (GMT) Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id C6868200DB; Mon, 12 May 2025 05:58:00 +0000 (GMT) Received: from li-c6426e4c-27cf-11b2-a85c-95d65bc0de0e.ibm.com.com (unknown [9.39.26.83]) by smtpav06.fra02v.mail.ibm.com (Postfix) with ESMTP; Mon, 12 May 2025 05:58:00 +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 v2 1/4] perf python: Add support for perf_counts_values to return counter data Date: Mon, 12 May 2025 11:27:42 +0530 Message-ID: <20250512055748.479786-2-gautam@linux.ibm.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250512055748.479786-1-gautam@linux.ibm.com> References: <20250512055748.479786-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-ORIG-GUID: OdvryHYZxMvEJvvOqMQRrmMZSZixWgrZ X-Proofpoint-GUID: qyzWuJFvalwHTBIqls_s8k5CP8rhA0jP X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUwNTEyMDA2MyBTYWx0ZWRfX31N19L8sXwEy EDEbddAgM5/TbC3xdSLZGr0T9xiY2uamD2Z0G3nybGnxjVeuAPi0OT28TUuKHLtxpeK8cymkmZn 6fOki1JdkUfKF3i10TkgUSIhjJqECepdBhkGiEK47loTW6vMEjPmGw7nkl7xDAjKYam7YLCgTUW sgWqmQVcfK/7eHHb2Xl8hu8luN8PtSux5XViZce+Evb+d8XmA9C4zdiRQSCpkcuCZMllkTrOabc I8vCUfrT86EDibzOtyZ2mShlYzqHAAQXBfJn7/DPWCgTP+vPslrrGdx3f2UkKap0q9HDZRfpwnV Mru72YoKrcjIpSqpbLunzjE3P+Wd8XgXW/CaPZFdWIisSw2HY9F/4zaDDWNH5Fa6+5YHrm/l/2v ZeMf0/eKLxY73iIr3nG7v4iv/poDBimN4YUklwwbixuZxqz+6aeXmFQHlV9fzkam+PYbDNdZ X-Authority-Analysis: v=2.4 cv=KPFaDEFo c=1 sm=1 tr=0 ts=6821946e cx=c_pps a=3Bg1Hr4SwmMryq2xdFQyZA==:117 a=3Bg1Hr4SwmMryq2xdFQyZA==:17 a=dt9VzEwgFbYA:10 a=VnNF1IyMAAAA:8 a=8VWMH8aeIS0OOwB8Z8wA:9 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-12_02,2025-05-09_01,2025-02-21_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 spamscore=0 mlxlogscore=999 impostorscore=0 phishscore=0 lowpriorityscore=0 clxscore=1015 malwarescore=0 bulkscore=0 suspectscore=0 priorityscore=1501 adultscore=0 classifier=spam authscore=0 authtc=n/a authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.19.0-2504070000 definitions=main-2505120063 Content-Type: text/plain; charset="utf-8" Add support for perf_counts_values struct to enable the python bindings to read and return the counter data. 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 Wed Dec 17 08:54:14 2025 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 252AF2550B0; Mon, 12 May 2025 06:26:01 +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=1747031163; cv=none; b=AosziWWlBxIi7Ffnx5NbYT42WaednGYiYprfhk3L0Cye37OE2hAsiDpOirNjijSs564gw4nkCDLqnZeW9BN+RYj3z9Ex9FzKf//RGicNCl6yTflhmwsPqbwvnnRplBLiFvfDluCxRbs4KO7kYuQ9qbq4QbyutAvDPc/wszrbXLk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747031163; c=relaxed/simple; bh=LsHWjL3dhLS8P7Kp2RQe6VT/RbytAXbMkV8qltSsWl0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=F9lcv5nHFL+Ix0VyQSecX+LJu6Tdnuq6wAQ2zZO6414oJ5BokGBns6lsYMmsu0SUWqgPEMXwUKbFco1v0dx8XBu55HcQB9xuLbA+HVA3KygshE+Zp+CEypvB2x/4RGLwxeduAsHc8/lLtldTmWcsyCArQiG9cBYNMQ9P2ItjgPo= 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=X6j/SIaa; 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="X6j/SIaa" 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 54C6IO5q024022; Mon, 12 May 2025 06:25:51 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=rBFxPBHNN9y0PykhA /DyCxQtW3JUngmmlhWQS9WGBTs=; b=X6j/SIaa5vzCqP8iV+ShpNr9aI2mcR4FG LZYt2ZjfA0fTdMboj08hAvYFV11WjY/5E6V59PS4QosX8ntON5L4MyoMJ7KmhW7T 4Qjzg0PV4Vq0d5cQczpl7Nj50kC5709Df8I83kDcrsmh9mCRIUkXyP+r4+XIEfJb EiOcXoA1FHiniGPHXv3nHxmt+gKXDgKlD9jtG6RfvFrWb10pPqH9H1/lvopUVSxR jJX6NTZivCfWWK4GzOgCWyFHzKaR7Z0nOdV7EO+T18j3quLSRnm6W/gmHuixPDsM Weu+APH87GzEUHJIrWSnKNPzTfiXCfeXVAwWYBOXqt/TtcNlqvqeA== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 46kbksr0qa-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 12 May 2025 06:25:50 +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 54C6LEsG028874; Mon, 12 May 2025 06:25:50 GMT Received: from ppma21.wdc07v.mail.ibm.com (5b.69.3da9.ip4.static.sl-reverse.com [169.61.105.91]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 46kbksr0q8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 12 May 2025 06:25:50 +0000 (GMT) Received: from pps.filterd (ppma21.wdc07v.mail.ibm.com [127.0.0.1]) by ppma21.wdc07v.mail.ibm.com (8.18.1.2/8.18.1.2) with ESMTP id 54C53rhs025907; Mon, 12 May 2025 06:25:48 GMT Received: from smtprelay06.fra02v.mail.ibm.com ([9.218.2.230]) by ppma21.wdc07v.mail.ibm.com (PPS) with ESMTPS id 46jj4nmmwu-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 12 May 2025 06:25:48 +0000 Received: from smtpav06.fra02v.mail.ibm.com (smtpav06.fra02v.mail.ibm.com [10.20.54.105]) by smtprelay06.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 54C6Pic124576636 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 12 May 2025 06:25:45 GMT Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id AAD9A200E4; Mon, 12 May 2025 05:58:10 +0000 (GMT) Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id D1FD5200E1; Mon, 12 May 2025 05:58:07 +0000 (GMT) Received: from li-c6426e4c-27cf-11b2-a85c-95d65bc0de0e.ibm.com.com (unknown [9.39.26.83]) by smtpav06.fra02v.mail.ibm.com (Postfix) with ESMTP; Mon, 12 May 2025 05:58: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 v2 2/4] perf python: Add evsel read method Date: Mon, 12 May 2025 11:27:43 +0530 Message-ID: <20250512055748.479786-3-gautam@linux.ibm.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250512055748.479786-1-gautam@linux.ibm.com> References: <20250512055748.479786-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=DrhW+H/+ c=1 sm=1 tr=0 ts=6821946e cx=c_pps a=GFwsV6G8L6GxiO2Y/PsHdQ==:117 a=GFwsV6G8L6GxiO2Y/PsHdQ==:17 a=dt9VzEwgFbYA:10 a=VnNF1IyMAAAA:8 a=mz77sXPBJAlW4eiyuogA:9 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUwNTEyMDA1OCBTYWx0ZWRfX6p8e814XSwUi t7zp7Iuw5QMAk8EhadSi1vRUufAILgk2uKvJAEoZ8o+bJuRtgyeaKtYAOTiSzDF+tbIono72xVr 3nY95pQVziV6ncQR9s6W+1IvzE6jcHDsH+LMk127bcw3KhWUbds8A3z6DvIEJudlvJksxha1Dr6 O5kz18hK0X6cHUAEIc2lPyafxUVif/ApBLVTOfFFAGMVGlellV6NNyQ64rXv38IP1D3wEGdFVnT 4R0w4zX0/xuWi37KAQRHGILuTemsb3oJ2Wozczuh32YUKX30gFSXlISu2VXLc7Ya9xpcoZJBevE UfsqfT171hp+C+yH7c9vGnc6YruIgnG41fZNcsqE2NEdyRIjOE0l04ze5hI9EXwt8Gh5YanaA84 9ZgQhNFzdF43XUsV2Y+elrUPkKFq7coadITy5BqD4DwBLQJVsqhl5bklF9GbIRU3bCtq1II3 X-Proofpoint-GUID: 5rFZEyDEEVJRJo-TUqeifVqpMYGbdKpx X-Proofpoint-ORIG-GUID: 2-HgqgO-fFsB4DV7URKYUauuhJ7g-raQ 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-12_02,2025-05-09_01,2025-02-21_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 spamscore=0 priorityscore=1501 clxscore=1015 impostorscore=0 phishscore=0 bulkscore=0 mlxscore=0 adultscore=0 lowpriorityscore=0 suspectscore=0 mlxlogscore=999 classifier=spam authscore=0 authtc=n/a authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.19.0-2504070000 definitions=main-2505120058 Content-Type: text/plain; charset="utf-8" Add the evsel read method to enable python to read counter data for the given evsel. 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 Wed Dec 17 08:54:14 2025 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 610FE2F2F; Mon, 12 May 2025 06:26:01 +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=1747031162; cv=none; b=mDy2KqomkIqi9ICadkUIs+2TlTxnNcyHUsJEIcc0T9rG8kmVPvrIBf+zVbywytDolhYZw01qWocJAp5B1+QnRVeecsupk2zGoeSaXchlOB5nNSD6ihdqBEDhmkUEj6yzC/ooYtDq290MUZ9V7S1xcGZmCkvVVGEWotNMOhFCafI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747031162; c=relaxed/simple; bh=eEy0DyOijfkBlZtvhUrSR3+1j97AsNz0adZvsul3wzY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Jo+k3jRbaaUlJx9UFpGMXMKmbocHFVnsjguY9aXQHw4OHAESZKwYDVpKRih89ud9VvApec7ufoxtdz/b81UMGgICZAYFlfAoPJywM7SoiVCJy6W0MvF3Ss2/08O/6NlSOm2Z69q5y+QHis0LuAiZ0kluGUSPcBV8vUd1AxLcjWU= 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=nVhPc9Hq; 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="nVhPc9Hq" Received: from pps.filterd (m0356517.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 54BIoXY9017202; Mon, 12 May 2025 06:25:50 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=Fo9x9GIYwNtfy8bv4 SH/aH2Q7qUDW74lxxra06E1C5o=; b=nVhPc9HqiGjMS+gnrxS5ZZkKTHpxv8p/F FC7J6GynaT4TqCxJV1FXYpqo57eFsAetk8ZOZUpJZsunJwjWLdWR5Lqf2v752XTE F9mgIOeE7fBisrnNDcVDRWGPaAXPbDeLuGjCgsPIhIXN7yJYmamZ+Wzmye6wdGJQ m56P1ZAHomIlQX7xnF3+qllkc6TZTOwE+UmJaCltId33ae1IVjN6663qncedmmi6 D5p5P0M4oyrkDQZwnVR21uEmZigjg503fiuwCEJ5kSW/n+Y+v//5JlHZrtPhL223 fhTgZEZDTcWNOZKzCIY6u4p2lcYMcCFaMBVFQNkTf37kYadVkq5Zg== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 46k1h89q60-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 12 May 2025 06:25:50 +0000 (GMT) Received: from m0356517.ppops.net (m0356517.ppops.net [127.0.0.1]) by pps.reinject (8.18.0.8/8.18.0.8) with ESMTP id 54C6Pn7W028789; Mon, 12 May 2025 06:25:49 GMT Received: from ppma11.dal12v.mail.ibm.com (db.9e.1632.ip4.static.sl-reverse.com [50.22.158.219]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 46k1h89q5u-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 12 May 2025 06:25:49 +0000 (GMT) Received: from pps.filterd (ppma11.dal12v.mail.ibm.com [127.0.0.1]) by ppma11.dal12v.mail.ibm.com (8.18.1.2/8.18.1.2) with ESMTP id 54C1YHfh011558; Mon, 12 May 2025 06:25:48 GMT Received: from smtprelay06.fra02v.mail.ibm.com ([9.218.2.230]) by ppma11.dal12v.mail.ibm.com (PPS) with ESMTPS id 46jku24b6j-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 12 May 2025 06:25:48 +0000 Received: from smtpav06.fra02v.mail.ibm.com (smtpav06.fra02v.mail.ibm.com [10.20.54.105]) by smtprelay06.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 54C6Pj9E18809158 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 12 May 2025 06:25:45 GMT Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 8A6BF200E6; Mon, 12 May 2025 05:58:17 +0000 (GMT) Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id A6FF6200E5; Mon, 12 May 2025 05:58:14 +0000 (GMT) Received: from li-c6426e4c-27cf-11b2-a85c-95d65bc0de0e.ibm.com.com (unknown [9.39.26.83]) by smtpav06.fra02v.mail.ibm.com (Postfix) with ESMTP; Mon, 12 May 2025 05:58:14 +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 v2 3/4] perf python: Add evlist close support Date: Mon, 12 May 2025 11:27:44 +0530 Message-ID: <20250512055748.479786-4-gautam@linux.ibm.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250512055748.479786-1-gautam@linux.ibm.com> References: <20250512055748.479786-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=fq3cZE4f c=1 sm=1 tr=0 ts=6821946e cx=c_pps a=aDMHemPKRhS1OARIsFnwRA==:117 a=aDMHemPKRhS1OARIsFnwRA==:17 a=dt9VzEwgFbYA:10 a=VnNF1IyMAAAA:8 a=1CJVNnU1sNpl53wobBcA:9 X-Proofpoint-GUID: j_o3YpM6a6Be1f6yQYOIMWhF6Nk9N2ax X-Proofpoint-ORIG-GUID: OPG7qsXSdOwPGr29uMKjayEIHq7cZ1_p X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUwNTEyMDA2MyBTYWx0ZWRfX8DlSFnLAfSvj SCChPyEGwiygUD16lC/z/XxtfylU4JAD7a8kRKgLBxfMtirkoBq36y9Vu5U1ZCWA46QoChqqwcY mjeQIw1hb+YfdjdTGkYtROfuZr/g8kRwah0Tz1dF1osY8He3ogR2OLsnMaRsICJrpIit3u19/zR 8lzbumGpXjc8JPyXC2FBAQ+K2g515ncALGmxJsT45CjnfK909fSf3Y/ljHqy/vzWLHLDye6vjLT y3tpIwqjdJfspU7yH+rEmI6w943/NVZNKZNcLThZjEva4VY6JpUMH5DkWCi7BDIzBD5wKj4G7pK Zl5nWsvCvR/vERWvhsRRE7fa8/UsMxAEdsSv10SD42FPyM9XwWDEIV9ztBD5EwPvBK5YjISBjkD fSSgS6ImPyYI0vdkFtld4WYY5n2VmSMkwP9cn6jsRwdineYZZ2ersD50krcIZQ/jcgFl/+3y 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-12_02,2025-05-09_01,2025-02-21_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 lowpriorityscore=0 mlxlogscore=999 phishscore=0 clxscore=1015 spamscore=0 suspectscore=0 impostorscore=0 adultscore=0 bulkscore=0 priorityscore=1501 mlxscore=0 classifier=spam authscore=0 authtc=n/a authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.19.0-2504070000 definitions=main-2505120063 Content-Type: text/plain; charset="utf-8" Add support for the evlist close function. Signed-off-by: Gautam Menghani --- v1 -> v2: 1. Drop the support for next function tools/perf/util/python.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tools/perf/util/python.c b/tools/perf/util/python.c index 5a4d2c9aaabd..245ad4a4257a 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 { @@ -1221,6 +1231,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, --=20 2.49.0 From nobody Wed Dec 17 08:54:14 2025 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 6B716255233; Mon, 12 May 2025 05:58:41 +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=1747029522; cv=none; b=KauOQuqQxHvgFtwY28QIOyzTxX0WMa9u2o4DBkmJPL7+ZM/JsJMtlNfEm7Bd6SWUUR/ISPLs+V7lvSwQeIs4wDh4BIkAW4vFXjh6vaVjSSxQymiq4iSc3q+7xLok/9B9vwCc08MkTRKSry9/OeRZmdeFlznuddlh/wllMkal7U8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747029522; c=relaxed/simple; bh=Lo3GnRfc0Ap9DHKs3wjbilSYLc2fLc9r6Rzs609IcdE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=amx+UzLN6oee97IlJT1znKfQ+WOna/pQ35BonFYRT9rIwjxQzM8Pqh9T8y/1NQsxb3IpWMrhTL/tsIXlYICP3esuXNjIP1DH5QVhGubXAce09llbWho4SGs7JeG8yUX8uVYlFo6w8G7zyseKe6b3nUil3M+r19M5QHBSGMieFbI= 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=k/ppYClM; 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="k/ppYClM" 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 54BBtDjw026345; Mon, 12 May 2025 05:58:28 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=i3pyHwr1EPnBiwUGt QyrLU15YzaSR/dxTm5nKo+84M4=; b=k/ppYClMOi4EH270SLjyvuS31vqHaTSZH A+zxjndSBawupTM5bsT9m91A67W4dbBlGmHFZPSJ8zU9zwRKwXJJckwKC2Q2zDF/ oUtLgZLbtuoKWuG2fFJwBIBFechXX62o4t9vpjQxbQ7/nzqryZIaU1VzW4HzAiYy vyQx5g2uqvxKGCI0C924HYuKp7WLAmQq/x3SVlNi4ibnKJyAeR8t07S9Ex8TjxSr QjvmfdMiSuhr55+SgxnlCZ1oHhGM8TIDWhFfWpb0naATQ67/B95hPWYhsI2OpbiA jfkECLJnsSvr0DmeSAF9HDrPQLK7/QlmD8XwyU2B+qBaWNHVP1q7w== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 46jue6aear-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 12 May 2025 05:58:28 +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 54C5rrWM026055; Mon, 12 May 2025 05:58:28 GMT Received: from ppma13.dal12v.mail.ibm.com (dd.9e.1632.ip4.static.sl-reverse.com [50.22.158.221]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 46jue6aeak-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 12 May 2025 05:58:28 +0000 (GMT) Received: from pps.filterd (ppma13.dal12v.mail.ibm.com [127.0.0.1]) by ppma13.dal12v.mail.ibm.com (8.18.1.2/8.18.1.2) with ESMTP id 54C0sLfr003815; Mon, 12 May 2025 05:58:27 GMT Received: from smtprelay01.fra02v.mail.ibm.com ([9.218.2.227]) by ppma13.dal12v.mail.ibm.com (PPS) with ESMTPS id 46jkbkcbc9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 12 May 2025 05:58:27 +0000 Received: from smtpav06.fra02v.mail.ibm.com (smtpav06.fra02v.mail.ibm.com [10.20.54.105]) by smtprelay01.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 54C5wN2m54788444 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 12 May 2025 05:58:23 GMT Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 83BC7200E2; Mon, 12 May 2025 05:58:23 +0000 (GMT) Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id ACABA200E8; Mon, 12 May 2025 05:58:20 +0000 (GMT) Received: from li-c6426e4c-27cf-11b2-a85c-95d65bc0de0e.ibm.com.com (unknown [9.39.26.83]) by smtpav06.fra02v.mail.ibm.com (Postfix) with ESMTP; Mon, 12 May 2025 05:58:20 +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 v2 4/4] perf python: Add counting.py as example for counting perf events Date: Mon, 12 May 2025 11:27:45 +0530 Message-ID: <20250512055748.479786-5-gautam@linux.ibm.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250512055748.479786-1-gautam@linux.ibm.com> References: <20250512055748.479786-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-ORIG-GUID: PnoiPDaCmddBqYYd_vKzMHJI0zpZqIqZ X-Authority-Analysis: v=2.4 cv=TbmWtQQh c=1 sm=1 tr=0 ts=68218e04 cx=c_pps a=AfN7/Ok6k8XGzOShvHwTGQ==:117 a=AfN7/Ok6k8XGzOShvHwTGQ==:17 a=dt9VzEwgFbYA:10 a=VnNF1IyMAAAA:8 a=b2wzPbE2oFXK_2wXMnoA:9 X-Proofpoint-GUID: rClI6BJapn-2IirsOtdbkpOBK7ky1XFw X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUwNTEyMDA1OCBTYWx0ZWRfXxxnjx6Iy67MS 3HZgyi6yWkMT+Ji6h1/CcBn2SdgtpZkt+5hxwL+io3tcbTmeBGOUV4m0+Y/GRGmkMwwOUFe7PeO 5J12Kuq2TPIhovQ10HUGU5gODA/nFcR27UmJ53pjlMkt59tZ9/XSb7cNKTv64w2TKiH7gwz2m+y M+7jOFS9Ro9gXatZST0Xchz96CP3rcIf8PfwKxJDYDG3RAvKDzEp/dvrgYylJYz/bftXEsGXGut sWTYbcFE8UN0KSujSOTAuJk1InrIEAfv4Rx9Ju4lG2F5I6YpvNIONxinCL4k8T1SgFlEP+frplM 5knYwA+uorgapUSHwBbhZhxvnp/WyU5+tK7Kz9wVH+4mzHQQXWzIGtHx+Nnueowdl6k3zxmqY6E M4O99EfIh0FQCc+wY/vP7BDCvKzBRWEInl3l8BZ2Jauo20zasAWCU1CKMPR/OZK9Y1jMAAsQ 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-12_02,2025-05-09_01,2025-02-21_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 clxscore=1015 malwarescore=0 phishscore=0 priorityscore=1501 impostorscore=0 adultscore=0 spamscore=0 mlxlogscore=999 bulkscore=0 suspectscore=0 lowpriorityscore=0 classifier=spam authscore=0 authtc=n/a authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.19.0-2504070000 definitions=main-2505120058 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 --- v1 -> v2: 1. Use existing iteration support instead of next 2. Read the counters on all cpus 3. Use existing helper functions tools/perf/python/counting.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 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..e535e3ae8bdf --- /dev/null +++ b/tools/perf/python/counting.py @@ -0,0 +1,34 @@ +#!/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.parse_events("cpu-clock,task-clock", cpus, thread_= map) + + for ev in evlist: + ev.read_format =3D perf.FORMAT_TOTAL_TIME_ENABLED | perf.FORMA= T_TOTAL_TIME_RUNNING + + evlist.open() + evlist.enable() + + count =3D 100000 + while count > 0: + count -=3D 1 + + evlist.disable() + + for evsel in evlist: + for cpu in cpus: + for thread in range(len(thread_map)): + counts =3D evsel.read(cpu, thread) + print(f"For {evsel} val: {counts.val} enable: {counts.= ena} run: {counts.run}") + + evlist.close() + +if __name__ =3D=3D '__main__': + main() --=20 2.49.0