From: Namhyung Kim <namhyung@kernel.org>
To: Arnaldo Carvalho de Melo <acme@kernel.org>,
Ian Rogers <irogers@google.com>,
James Clark <james.clark@linaro.org>
Cc: 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: [PATCH 2/3] perf list: Get rid of json_print_state
Date: Mon, 17 Nov 2025 22:36:40 -0800 [thread overview]
Message-ID: <20251118063641.517066-2-namhyung@kernel.org> (raw)
In-Reply-To: <20251118063641.517066-1-namhyung@kernel.org>
The JSON print state has only one different field (need_sep). Let's
move it to the default print state and use it. It would waste a little
bit of more spaces but who cares? :)
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
---
tools/perf/builtin-list.c | 12 +++++-------
1 file changed, 5 insertions(+), 7 deletions(-)
diff --git a/tools/perf/builtin-list.c b/tools/perf/builtin-list.c
index 28bf1fc7f5eeff8f..1ab969ffe371c5cb 100644
--- a/tools/perf/builtin-list.c
+++ b/tools/perf/builtin-list.c
@@ -60,6 +60,8 @@ struct print_state {
bool metricgroups;
/** @exclude_abi: Exclude PMUs with types less than PERF_TYPE_MAX except PERF_TYPE_RAW. */
bool exclude_abi;
+ /** @need_sep: Should a separator be printed prior to the next item? (for JSON) */
+ bool need_sep;
/** @last_topic: The last printed event topic. */
char *last_topic;
/** @last_metricgroups: The last printed metric group. */
@@ -368,7 +370,7 @@ static void json_print_event(void *ps, const char *topic,
const char *desc, const char *long_desc,
const char *encoding_desc)
{
- struct json_print_state *print_state = ps;
+ struct print_state *print_state = ps;
bool need_sep = false;
FILE *fp = print_state->fp;
struct strbuf buf;
@@ -444,7 +446,7 @@ static void json_print_metric(void *ps __maybe_unused, const char *group,
const char *threshold, const char *unit,
const char *pmu_name)
{
- struct json_print_state *print_state = ps;
+ struct print_state *print_state = ps;
bool need_sep = false;
FILE *fp = print_state->fp;
struct strbuf buf;
@@ -521,9 +523,6 @@ int cmd_list(int argc, const char **argv)
.fp = stdout,
.desc = true,
};
- struct print_state json_ps = {
- .fp = stdout,
- };
void *ps = &default_ps;
struct print_callbacks print_cb = {
.print_start = default_print_start,
@@ -574,7 +573,6 @@ int cmd_list(int argc, const char **argv)
if (output_path) {
default_ps.fp = fopen(output_path, "w");
- json_ps.fp = default_ps.fp;
}
setup_pager();
@@ -590,7 +588,7 @@ int cmd_list(int argc, const char **argv)
.print_metric = json_print_metric,
.skip_duplicate_pmus = json_skip_duplicate_pmus,
};
- ps = &json_ps;
+ ps = &default_ps;
} else {
default_ps.last_topic = strdup("");
assert(default_ps.last_topic);
--
2.52.0.rc1.455.g30608eb744-goog
next prev parent reply other threads:[~2025-11-18 6:36 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 ` Namhyung Kim [this message]
2025-11-19 16:40 ` [PATCH 2/3] perf list: Get rid of json_print_state 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
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=20251118063641.517066-2-namhyung@kernel.org \
--to=namhyung@kernel.org \
--cc=acme@kernel.org \
--cc=adrian.hunter@intel.com \
--cc=irogers@google.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=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
all inboxes | Powered by JetHome®