From: Suchit Karunakaran <suchitkarunakaran@gmail.com>
To: peterz@infradead.org, mingo@redhat.com, acme@kernel.org,
namhyung@kernel.org, mark.rutland@arm.com,
alexander.shishkin@linux.intel.com
Cc: linux-perf-users@vger.kernel.org,
linux-kernel-mentees@lists.linux.dev,
linux-kernel@vger.kernel.org, skhan@linuxfoundation.org,
Suchit Karunakaran <suchitkarunakaran@gmail.com>
Subject: [PATCH RESEND] perf stat: Fix JSON output formatting in iostat_prefix()
Date: Tue, 20 May 2025 15:15:25 +0530 [thread overview]
Message-ID: <20250520094525.97706-1-suchitkarunakaran@gmail.com> (raw)
The iostat_prefix() function previously included a TODO noting that its output
format was incorrect in JSON mode. This patch corrects that by conditionally
formatting the prefix string based on the output mode specified in
perf_stat_config.
Signed-off-by: Suchit Karunakaran <suchitkarunakaran@gmail.com>
---
tools/perf/arch/x86/util/iostat.c | 35 ++++++++++++++++++++-----------
1 file changed, 23 insertions(+), 12 deletions(-)
diff --git a/tools/perf/arch/x86/util/iostat.c b/tools/perf/arch/x86/util/iostat.c
index 7442a2cd87ed..1d9c20dab5c7 100644
--- a/tools/perf/arch/x86/util/iostat.c
+++ b/tools/perf/arch/x86/util/iostat.c
@@ -403,18 +403,29 @@ void iostat_prefix(struct evlist *evlist,
struct iio_root_port *rp = evlist->selected->priv;
if (rp) {
- /*
- * TODO: This is the incorrect format in JSON mode.
- * See prepare_timestamp()
- */
- if (ts)
- sprintf(prefix, "%6lu.%09lu%s%04x:%02x%s",
- ts->tv_sec, ts->tv_nsec,
- config->csv_sep, rp->domain, rp->bus,
- config->csv_sep);
- else
- sprintf(prefix, "%04x:%02x%s", rp->domain, rp->bus,
- config->csv_sep);
+ if (ts) {
+ if (config->json_output)
+ sprintf(prefix,
+ "\"interval\" : %lu.%09lu, \"device\" : \"%04x:%02x\"",
+ (unsigned long)ts->tv_sec, ts->tv_nsec,
+ rp->domain, rp->bus);
+ else if (config->csv_output)
+ sprintf(prefix, "%lu.%09lu%s%04x:%02x%s",
+ (unsigned long)ts->tv_sec, ts->tv_nsec,
+ config->csv_sep,
+ rp->domain, rp->bus, config->csv_sep);
+ else
+ sprintf(prefix, "%6lu.%09lu %04x:%02x%s",
+ (unsigned long)ts->tv_sec, ts->tv_nsec,
+ rp->domain, rp->bus, config->csv_sep);
+ } else {
+ if (config->json_output)
+ sprintf(prefix, "\"device\" : \"%04x:%02x\"",
+ rp->domain, rp->bus);
+ else
+ sprintf(prefix, "%04x:%02x%s", rp->domain,
+ rp->bus, config->csv_sep);
+ }
}
}
--
2.49.0
next reply other threads:[~2025-05-20 9:45 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-20 9:45 Suchit Karunakaran [this message]
2025-05-28 18:07 ` [PATCH RESEND] perf stat: Fix JSON output formatting in iostat_prefix() Arnaldo Carvalho de Melo
-- strict thread matches above, loose matches on Subject: below --
2025-06-05 18:00 Suchit Karunakaran
2025-06-06 3:57 ` Namhyung Kim
2025-06-06 4:34 ` Suchit K
2025-06-06 17:29 ` Namhyung Kim
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=20250520094525.97706-1-suchitkarunakaran@gmail.com \
--to=suchitkarunakaran@gmail.com \
--cc=acme@kernel.org \
--cc=alexander.shishkin@linux.intel.com \
--cc=linux-kernel-mentees@lists.linux.dev \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=mingo@redhat.com \
--cc=namhyung@kernel.org \
--cc=peterz@infradead.org \
--cc=skhan@linuxfoundation.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).