linux-perf-users.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Ian Rogers <irogers@google.com>
To: Namhyung Kim <namhyung@kernel.org>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>,
	James Clark <james.clark@linaro.org>,
	 Jiri Olsa <jolsa@kernel.org>,
	Adrian Hunter <adrian.hunter@intel.com>,
	 Peter Zijlstra <peterz@infradead.org>,
	Ingo Molnar <mingo@kernel.org>,
	 LKML <linux-kernel@vger.kernel.org>,
	linux-perf-users@vger.kernel.org
Subject: Re: [PATCH 3/3] perf list: Support filtering in JSON output
Date: Wed, 19 Nov 2025 08:42:50 -0800	[thread overview]
Message-ID: <CAP-5=fXBhg3M0JdE6rEF+Gh1KDBdcd=onVgGegWv4GG6Jw2U9Q@mail.gmail.com> (raw)
In-Reply-To: <20251118063641.517066-3-namhyung@kernel.org>

On Mon, Nov 17, 2025 at 10:36 PM Namhyung Kim <namhyung@kernel.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/"

The new-line '\n' here looks like another bug, the bug is coming from
reading the event from sysfs but not stripping any '\n'.

This change lgtm but we need to figure out the struct json_print_state
in patch 2.

Thanks,
Ian

>   },
>   {
>           "Unit": "cpu",
>           "Topic": "legacy hardware",
>           "EventName": "branch-misses",
>           "EventType": "Kernel PMU event",
>           "BriefDescription": "Mispredicted branch instructions",
>           "Encoding": "cpu/event=0xc5\n/"
>   },
>   ...
>
> Signed-off-by: Namhyung Kim <namhyung@kernel.org>
> ---
>  tools/perf/builtin-list.c | 20 ++++++++++++++++++++
>  1 file changed, 20 insertions(+)
>
> diff --git a/tools/perf/builtin-list.c b/tools/perf/builtin-list.c
> index 1ab969ffe371c5cb..48c799007414bf6e 100644
> --- a/tools/perf/builtin-list.c
> +++ b/tools/perf/builtin-list.c
> @@ -375,6 +375,21 @@ static void json_print_event(void *ps, const char *topic,
>         FILE *fp = print_state->fp;
>         struct strbuf buf;
>
> +       if (deprecated && !print_state->deprecated)
> +               return;
> +
> +       if (print_state->pmu_glob && (!pmu_name || !strglobmatch(pmu_name, print_state->pmu_glob)))
> +               return;
> +
> +       if (print_state->exclude_abi && pmu_type < PERF_TYPE_MAX && pmu_type != PERF_TYPE_RAW)
> +               return;
> +
> +       if (print_state->event_glob &&
> +           (!event_name || !strglobmatch(event_name, print_state->event_glob)) &&
> +           (!event_alias || !strglobmatch(event_alias, print_state->event_glob)) &&
> +           (!topic || !strglobmatch_nocase(topic, print_state->event_glob)))
> +               return;
> +
>         strbuf_init(&buf, 0);
>         fprintf(fp, "%s{\n", print_state->need_sep ? ",\n" : "");
>         print_state->need_sep = true;
> @@ -451,6 +466,11 @@ static void json_print_metric(void *ps __maybe_unused, const char *group,
>         FILE *fp = print_state->fp;
>         struct strbuf buf;
>
> +       if (print_state->event_glob &&
> +           (!print_state->metrics || !name || !strglobmatch(name, print_state->event_glob)) &&
> +           (!print_state->metricgroups || !group || !strglobmatch(group, print_state->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
>

  reply	other threads:[~2025-11-19 16:43 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-18  6:36 [PATCH 1/3] perf list: Print matching PMU events for --unit Namhyung Kim
2025-11-18  6:36 ` [PATCH 2/3] perf list: Get rid of json_print_state Namhyung Kim
2025-11-19 16:40   ` Ian Rogers
2025-11-18  6:36 ` [PATCH 3/3] perf list: Support filtering in JSON output Namhyung Kim
2025-11-19 16:42   ` Ian Rogers [this message]
2025-11-19 16:33 ` [PATCH 1/3] perf list: Print matching PMU events for --unit 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='CAP-5=fXBhg3M0JdE6rEF+Gh1KDBdcd=onVgGegWv4GG6Jw2U9Q@mail.gmail.com' \
    --to=irogers@google.com \
    --cc=acme@kernel.org \
    --cc=adrian.hunter@intel.com \
    --cc=james.clark@linaro.org \
    --cc=jolsa@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=namhyung@kernel.org \
    --cc=peterz@infradead.org \
    /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).