Re: [PATCH RESEND] perf stat: Fix JSON output formatting in iostat_prefix()
From: Namhyung Kim
Date: Fri Jun 06 2025 - 13:29:32 EST
On Fri, Jun 06, 2025 at 10:04:17AM +0530, Suchit K wrote:
> On Fri, 6 Jun 2025 at 09:27, Namhyung Kim <namhyung@xxxxxxxxxx> wrote:
> >
> > Hello,
> >
> > On Thu, Jun 05, 2025 at 11:30:11PM +0530, Suchit Karunakaran wrote:
> > > 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.
> >
> > I've tested this. It doesn't work well.
> >
> > Before:
> > # ./perf iostat -j -I 1000 true
> > # time port 0.000517525 0000:00 "Inbound Read(MB)" : "0", "Inbound Write(MB)" : "0", "Outbound Read(MB)" : "0", "Outbound Write(MB)" : "0"
> > 0.000517525 0000:80
> > 0.000517525 0000:17 , "Inbound Read(MB)" : "0", "Inbound Write(MB)" : "0", "Outbound Read(MB)" : "0", "Outbound Write(MB)" : "0"
> > 0.000517525 0000:85
> > 0.000517525 0000:3a , "Inbound Read(MB)" : "0", "Inbound Write(MB)" : "0", "Outbound Read(MB)" : "0", "Outbound Write(MB)" : "0"
> > 0.000517525 0000:ae
> > 0.000517525 0000:5d , "Inbound Read(MB)" : "0", "Inbound Write(MB)" : "0", "Outbound Read(MB)" : "0", "Outbound Write(MB)" : "0"
> > 0.000517525 0000:d7
> >
> >
> > After:
> > # ./perf iostat -j -I 1000 true
> > # time port "interval" : 0.000463559, "device" : "0000:00""Inbound Read(MB)" : "0", "Inbound Write(MB)" : "0", "Outbound Read(MB)" : "0", "Outbound Write(MB)" : "0"
> > "interval" : 0.000463559, "device" : "0000:80"
> > "interval" : 0.000463559, "device" : "0000:17", "Inbound Read(MB)" : "0", "Inbound Write(MB)" : "0", "Outbound Read(MB)" : "0", "Outbound Write(MB)" : "0"
> > "interval" : 0.000463559, "device" : "0000:85"
> > "interval" : 0.000463559, "device" : "0000:3a", "Inbound Read(MB)" : "0", "Inbound Write(MB)" : "0", "Outbound Read(MB)" : "0", "Outbound Write(MB)" : "0"
> > "interval" : 0.000463559, "device" : "0000:ae"
> > "interval" : 0.000463559, "device" : "0000:5d", "Inbound Read(MB)" : "0", "Inbound Write(MB)" : "0", "Outbound Read(MB)" : "0", "Outbound Write(MB)" : "0"
> > "interval" : 0.000463559, "device" : "0000:d7"
>
> Hi Namhyung,
> Thanks for testing it. Could you please tell what could be improved?
I think it should show a valid JSON. Something like this?
# ./perf iostat -j -I 1000 true
{"interval" : 0.000463559, "device" : "0000:00", "Inbound Read(MB)" : "0", ...}
{"interval" : 0.000463559, "device" : "0000:80", "Inbound Read(MB)" : "0", ...}
{"interval" : 0.000463559, "device" : "0000:17", "Inbound Read(MB)" : "0", ...}
{"interval" : 0.000463559, "device" : "0000:85", "Inbound Read(MB)" : "0", ...}
...
Thanks,
Namhyung