[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250501093633.578010-5-gautam@linux.ibm.com>
Date: Thu, 1 May 2025 15:06:30 +0530
From: Gautam Menghani <gautam@...ux.ibm.com>
To: peterz@...radead.org, mingo@...hat.com, acme@...nel.org,
namhyung@...nel.org, mark.rutland@....com,
alexander.shishkin@...ux.intel.com, jolsa@...nel.org,
irogers@...gle.com, adrian.hunter@...el.com, kan.liang@...ux.intel.com
Cc: Gautam Menghani <gautam@...ux.ibm.com>, linux-perf-users@...r.kernel.org,
linux-kernel@...r.kernel.org, maddy@...ux.ibm.com
Subject: [PATCH 4/4] perf python: Add counting.py as example for counting perf events
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 <gautam@...ux.ibm.com>
---
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 = perf.cpu_map()
+ thread_map = perf.thread_map(-1)
+ evlist = perf.evlist(cpus, thread_map)
+
+ evsel1 = perf.evsel(type = perf.TYPE_SOFTWARE,
+ config = perf.COUNT_SW_CPU_CLOCK,
+ read_format = perf.FORMAT_TOTAL_TIME_ENABLED | perf.FORMAT_TOTAL_TIME_RUNNING,
+ disabled=1)
+ evlist.add(evsel1)
+
+ evsel2 = perf.evsel(type = perf.TYPE_SOFTWARE,
+ config = perf.COUNT_SW_TASK_CLOCK,
+ read_format = perf.FORMAT_TOTAL_TIME_ENABLED | perf.FORMAT_TOTAL_TIME_RUNNING,
+ disabled=1)
+ evlist.add(evsel2)
+
+ evlist.open()
+ evlist.enable()
+
+ count = 100000
+ while count > 0:
+ count -= 1
+
+ evlist.disable()
+ evsel = evlist.next(None)
+ while evsel != None:
+ counts = evsel.read(0, 0)
+ print(counts.val, counts.ena, counts.run)
+ evsel = evlist.next(evsel)
+ evlist.close()
+
+if __name__ == '__main__':
+ main()
--
2.49.0
Powered by blists - more mailing lists