[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <aR9n5qgwryvJaexY@google.com>
Date: Thu, 20 Nov 2025 11:11:34 -0800
From: Namhyung Kim <namhyung@...nel.org>
To: Ian Rogers <irogers@...gle.com>
Cc: Arnaldo Carvalho de Melo <acme@...nel.org>,
James Clark <james.clark@...aro.org>, Jiri Olsa <jolsa@...nel.org>,
Adrian Hunter <adrian.hunter@...el.com>,
Peter Zijlstra <peterz@...radead.org>,
Ingo Molnar <mingo@...nel.org>, LKML <linux-kernel@...r.kernel.org>,
linux-perf-users@...r.kernel.org
Subject: Re: [PATCH v2 3/3] perf list: Support filtering in JSON output
On Wed, Nov 19, 2025 at 09:42:51PM -0800, Ian Rogers wrote:
> On Wed, Nov 19, 2025 at 4:47 PM Namhyung Kim <namhyung@...nel.org> wrote:
> >
> > Like regular output mode, it should honor command line arguments to
> > limit to a certain type of PMUs or events.
> >
> > $ perf list -j hw
> > [
> > {
> > "Unit": "cpu",
> > "Topic": "legacy hardware",
> > "EventName": "branch-instructions",
> > "EventType": "Kernel PMU event",
> > "BriefDescription": "Retired branch instructions [This event is an alias of branches]",
> > "Encoding": "cpu/event=0xc4\n/"
> > },
> > {
> > "Unit": "cpu",
> > "Topic": "legacy hardware",
> > "EventName": "branch-misses",
> > "EventType": "Kernel PMU event",
> > "BriefDescription": "Mispredicted branch instructions",
> > "Encoding": "cpu/event=0xc5\n/"
>
> I think these newlines can be fixed by changing:
> https://web.git.kernel.org/pub/scm/linux/kernel/git/perf/perf-tools-next.git/tree/tools/perf/util/pmu.c?h=perf-tools-next#n643
> ```
> ret = io__getline(&io, &alias->terms, &line_len) < 0 ? -errno : 0;
> if (ret) {
> ...
> }
> ```
> to something like:
> ```
> ret = io__getline(&io, &alias->terms, &line_len) < 0 ? -errno : 0;
> if (ret) {
> ...
> }
> if (alias->terms[line_len - 1] == '\n')
> alias->terms[line_len - 1] = '\0';
> ```
Yep, will do in a separate patch.
>
> > },
> > ...
> >
> > Signed-off-by: Namhyung Kim <namhyung@...nel.org>
>
> Reviewed-by: Ian Rogers <irogers@...gle.com>
Thanks for your review!
Namhyung
> > ---
> > tools/perf/builtin-list.c | 24 ++++++++++++++++++++++++
> > 1 file changed, 24 insertions(+)
> >
> > diff --git a/tools/perf/builtin-list.c b/tools/perf/builtin-list.c
> > index 6c5913f129f39c94..5cbca0bacd35237e 100644
> > --- a/tools/perf/builtin-list.c
> > +++ b/tools/perf/builtin-list.c
> > @@ -373,6 +373,23 @@ static void json_print_event(void *ps, const char *topic,
> > FILE *fp = print_state->common.fp;
> > struct strbuf buf;
> >
> > + if (deprecated && !print_state->common.deprecated)
> > + return;
> > +
> > + if (print_state->common.pmu_glob &&
> > + (!pmu_name || !strglobmatch(pmu_name, print_state->common.pmu_glob)))
> > + return;
> > +
> > + if (print_state->common.exclude_abi && pmu_type < PERF_TYPE_MAX &&
> > + pmu_type != PERF_TYPE_RAW)
> > + return;
> > +
> > + if (print_state->common.event_glob &&
> > + (!event_name || !strglobmatch(event_name, print_state->common.event_glob)) &&
> > + (!event_alias || !strglobmatch(event_alias, print_state->common.event_glob)) &&
> > + (!topic || !strglobmatch_nocase(topic, print_state->common.event_glob)))
> > + return;
> > +
> > strbuf_init(&buf, 0);
> > fprintf(fp, "%s{\n", print_state->need_sep ? ",\n" : "");
> > print_state->need_sep = true;
> > @@ -449,6 +466,13 @@ static void json_print_metric(void *ps __maybe_unused, const char *group,
> > FILE *fp = print_state->common.fp;
> > struct strbuf buf;
> >
> > + if (print_state->common.event_glob &&
> > + (!print_state->common.metrics || !name ||
> > + !strglobmatch(name, print_state->common.event_glob)) &&
> > + (!print_state->common.metricgroups || !group ||
> > + !strglobmatch(group, print_state->common.event_glob)))
> > + return;
> > +
> > strbuf_init(&buf, 0);
> > fprintf(fp, "%s{\n", print_state->need_sep ? ",\n" : "");
> > print_state->need_sep = true;
> > --
> > 2.52.0.rc1.455.g30608eb744-goog
> >
Powered by blists - more mailing lists