From: Ian Rogers <irogers@google.com>
To: Peter Zijlstra <peterz@infradead.org>,
Ingo Molnar <mingo@redhat.com>,
Arnaldo Carvalho de Melo <acme@kernel.org>,
Namhyung Kim <namhyung@kernel.org>,
Mark Rutland <mark.rutland@arm.com>,
Alexander Shishkin <alexander.shishkin@linux.intel.com>,
Jiri Olsa <jolsa@kernel.org>, Ian Rogers <irogers@google.com>,
Adrian Hunter <adrian.hunter@intel.com>,
Kan Liang <kan.liang@linux.intel.com>,
James Clark <james.clark@linaro.org>,
Xu Yang <xu.yang_2@nxp.com>,
"Masami Hiramatsu (Google)" <mhiramat@kernel.org>,
Collin Funk <collin.funk1@gmail.com>,
Howard Chu <howardchu95@gmail.com>,
Weilin Wang <weilin.wang@intel.com>,
Andi Kleen <ak@linux.intel.com>,
"Dr. David Alan Gilbert" <linux@treblig.org>,
Thomas Richter <tmricht@linux.ibm.com>,
Tiezhu Yang <yangtiezhu@loongson.cn>,
Gautam Menghani <gautam@linux.ibm.com>,
Thomas Falcon <thomas.falcon@intel.com>,
Chun-Tse Shao <ctshao@google.com>,
linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org
Subject: [PATCH v5 11/14] perf python: Add evlist metrics function
Date: Thu, 10 Jul 2025 13:36:53 -0700 [thread overview]
Message-ID: <20250710203656.1963075-12-irogers@google.com> (raw)
In-Reply-To: <20250710203656.1963075-1-irogers@google.com>
The function returns a list of the names of metrics within the
evlist. For example:
```
>>> import perf
>>> perf.parse_metrics("TopdownL1").metrics()
['tma_bad_speculation', 'tma_frontend_bound', 'tma_backend_bound', 'tma_retiring']
```
Signed-off-by: Ian Rogers <irogers@google.com>
---
tools/perf/util/python.c | 33 +++++++++++++++++++++++++++++++++
1 file changed, 33 insertions(+)
diff --git a/tools/perf/util/python.c b/tools/perf/util/python.c
index 2a8026a261ce..9377b64d73af 100644
--- a/tools/perf/util/python.c
+++ b/tools/perf/util/python.c
@@ -1278,6 +1278,33 @@ static PyObject *pyrf_evlist__all_cpus(struct pyrf_evlist *pevlist)
return (PyObject *)pcpu_map;
}
+static PyObject *pyrf_evlist__metrics(struct pyrf_evlist *pevlist)
+{
+ PyObject *list = PyList_New(/*len=*/0);
+ struct rb_node *node;
+
+ if (!list)
+ return NULL;
+
+ for (node = rb_first_cached(&pevlist->evlist.metric_events.entries); node;
+ node = rb_next(node)) {
+ struct metric_event *me = container_of(node, struct metric_event, nd);
+ struct list_head *pos;
+
+ list_for_each(pos, &me->head) {
+ struct metric_expr *expr = container_of(pos, struct metric_expr, nd);
+ PyObject *str = PyUnicode_FromString(expr->metric_name);
+
+ if (!str || PyList_Append(list, str) != 0) {
+ Py_DECREF(list);
+ return NULL;
+ }
+ Py_DECREF(str);
+ }
+ }
+ return list;
+}
+
static PyObject *pyrf_evlist__mmap(struct pyrf_evlist *pevlist,
PyObject *args, PyObject *kwargs)
{
@@ -1504,6 +1531,12 @@ static PyMethodDef pyrf_evlist__methods[] = {
.ml_flags = METH_NOARGS,
.ml_doc = PyDoc_STR("CPU map union of all evsel CPU maps.")
},
+ {
+ .ml_name = "metrics",
+ .ml_meth = (PyCFunction)pyrf_evlist__metrics,
+ .ml_flags = METH_NOARGS,
+ .ml_doc = PyDoc_STR("List of metric names within the evlist.")
+ },
{
.ml_name = "mmap",
.ml_meth = (PyCFunction)pyrf_evlist__mmap,
--
2.50.0.727.gbf7dc18ff4-goog
next prev parent reply other threads:[~2025-07-10 20:37 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-10 20:36 [PATCH v5 00/14] New perf ilist app Ian Rogers
2025-07-10 20:36 ` [PATCH v5 01/14] perf jevents: Add common software event json Ian Rogers
2025-07-10 20:36 ` [PATCH v5 02/14] perf parse-events: Remove non-json software events Ian Rogers
2025-07-10 20:36 ` [PATCH v5 03/14] perf tp_pmu: Factor existing tracepoint logic to new file Ian Rogers
2025-07-10 20:36 ` [PATCH v5 04/14] perf tp_pmu: Add event APIs Ian Rogers
2025-07-10 20:36 ` [PATCH v5 05/14] perf list: Remove tracepoint printing code Ian Rogers
2025-07-10 20:36 ` [PATCH v5 06/14] perf list: Skip ABI PMUs when printing pmu values Ian Rogers
2025-07-10 20:36 ` [PATCH v5 07/14] perf python: Add basic PMU abstraction and pmus sequence Ian Rogers
2025-07-10 20:36 ` [PATCH v5 08/14] perf python: Add function returning dictionary of all events on a PMU Ian Rogers
2025-07-10 20:36 ` [PATCH v5 09/14] perf ilist: Add new python ilist command Ian Rogers
2025-07-10 20:36 ` [PATCH v5 10/14] perf python: Add parse_metrics function Ian Rogers
2025-07-10 20:36 ` Ian Rogers [this message]
2025-07-10 20:36 ` [PATCH v5 12/14] perf python: Add evlist compute_metric Ian Rogers
2025-07-10 20:36 ` [PATCH v5 13/14] perf python: Add metrics function Ian Rogers
2025-07-10 20:36 ` [PATCH v5 14/14] perf ilist: Add support for metrics Ian Rogers
-- strict thread matches above, loose matches on Subject: below --
2025-07-10 20:24 [PATCH v5 00/14] New perf ilist app Ian Rogers
2025-07-10 20:24 ` [PATCH v5 11/14] perf python: Add evlist metrics function Ian Rogers
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=20250710203656.1963075-12-irogers@google.com \
--to=irogers@google.com \
--cc=acme@kernel.org \
--cc=adrian.hunter@intel.com \
--cc=ak@linux.intel.com \
--cc=alexander.shishkin@linux.intel.com \
--cc=collin.funk1@gmail.com \
--cc=ctshao@google.com \
--cc=gautam@linux.ibm.com \
--cc=howardchu95@gmail.com \
--cc=james.clark@linaro.org \
--cc=jolsa@kernel.org \
--cc=kan.liang@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=linux@treblig.org \
--cc=mark.rutland@arm.com \
--cc=mhiramat@kernel.org \
--cc=mingo@redhat.com \
--cc=namhyung@kernel.org \
--cc=peterz@infradead.org \
--cc=thomas.falcon@intel.com \
--cc=tmricht@linux.ibm.com \
--cc=weilin.wang@intel.com \
--cc=xu.yang_2@nxp.com \
--cc=yangtiezhu@loongson.cn \
/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;
as well as URLs for NNTP newsgroup(s).