]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
perf python: Add PMU argument to parse_metrics
authorIan Rogers <irogers@google.com>
Thu, 16 Oct 2025 22:22:27 +0000 (15:22 -0700)
committerNamhyung Kim <namhyung@kernel.org>
Sun, 19 Oct 2025 02:59:44 +0000 (11:59 +0900)
Add an optional PMU argument to parse_metrics to allow restriction of
the particular metrics to be opened. If no argument is provided then
all metrics with the given name/group are opened

Signed-off-by: Ian Rogers <irogers@google.com>
Acked-by: Gautam Menghani <gautam@linux.ibm.com>
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
tools/perf/util/python.c

index 779fe1280a5673207163b5da4de0d0529654c9fb..fa5e4270d182518c042c88b074a0fe80a9a8bae3 100644 (file)
@@ -2051,7 +2051,7 @@ static PyObject *pyrf__parse_events(PyObject *self, PyObject *args)
 
 static PyObject *pyrf__parse_metrics(PyObject *self, PyObject *args)
 {
-       const char *input;
+       const char *input, *pmu = NULL;
        struct evlist evlist = {};
        PyObject *result;
        PyObject *pcpus = NULL, *pthreads = NULL;
@@ -2059,14 +2059,14 @@ static PyObject *pyrf__parse_metrics(PyObject *self, PyObject *args)
        struct perf_thread_map *threads;
        int ret;
 
-       if (!PyArg_ParseTuple(args, "s|OO", &input, &pcpus, &pthreads))
+       if (!PyArg_ParseTuple(args, "s|sOO", &input, &pmu, &pcpus, &pthreads))
                return NULL;
 
        threads = pthreads ? ((struct pyrf_thread_map *)pthreads)->threads : NULL;
        cpus = pcpus ? ((struct pyrf_cpu_map *)pcpus)->cpus : NULL;
 
        evlist__init(&evlist, cpus, threads);
-       ret = metricgroup__parse_groups(&evlist, /*pmu=*/"all", input,
+       ret = metricgroup__parse_groups(&evlist, pmu ?: "all", input,
                                        /*metric_no_group=*/ false,
                                        /*metric_no_merge=*/ false,
                                        /*metric_no_threshold=*/ true,