perf stat: Fix multi-line metric output in JSON

Message ID 20221202190447.1588680-1-namhyung@kernel.org
State New
Headers
Series perf stat: Fix multi-line metric output in JSON |

Commit Message

Namhyung Kim Dec. 2, 2022, 7:04 p.m. UTC
  When a metric produces more than one values, it missed to print the opening
bracket.

Fixes: ab6baaae2735 ("perf stat: Fix JSON output in metric-only mode")
Reported-by: "Wang, Weilin" <weilin.wang@intel.com>
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
---
Weilin, could you please verify it fixes your problem?

 tools/perf/util/stat-display.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
  

Comments

Wang, Weilin Dec. 2, 2022, 7:31 p.m. UTC | #1
Namhyung, it works. Thanks!

-----Original Message-----
From: Namhyung Kim <namhyung@gmail.com> On Behalf Of Namhyung Kim
Sent: Friday, December 2, 2022 11:05 AM
To: Arnaldo Carvalho de Melo <acme@kernel.org>; Jiri Olsa <jolsa@kernel.org>
Cc: Ingo Molnar <mingo@kernel.org>; Peter Zijlstra <peterz@infradead.org>; LKML <linux-kernel@vger.kernel.org>; Ian Rogers <irogers@google.com>; Hunter, Adrian <adrian.hunter@intel.com>; linux-perf-users@vger.kernel.org; Kan Liang <kan.liang@linux.intel.com>; Zhengjun Xing <zhengjun.xing@linux.intel.com>; James Clark <james.clark@arm.com>; Athira Jajeev <atrajeev@linux.vnet.ibm.com>; Wang, Weilin <weilin.wang@intel.com>
Subject: [PATCH] perf stat: Fix multi-line metric output in JSON

When a metric produces more than one values, it missed to print the opening bracket.

Fixes: ab6baaae2735 ("perf stat: Fix JSON output in metric-only mode")
Reported-by: "Wang, Weilin" <weilin.wang@intel.com>
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
---
Weilin, could you please verify it fixes your problem?

 tools/perf/util/stat-display.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/perf/util/stat-display.c b/tools/perf/util/stat-display.c index f1ee4b052198..8d0bdd57163d 100644
--- a/tools/perf/util/stat-display.c
+++ b/tools/perf/util/stat-display.c
@@ -440,7 +440,7 @@ static void new_line_json(struct perf_stat_config *config, void *ctx)  {
 	struct outstate *os = ctx;
 
-	fputc('\n', os->fh);
+	fputs("\n{", os->fh);
 	if (os->prefix)
 		fprintf(os->fh, "%s", os->prefix);
 	aggr_printout(config, os->evsel, os->id, os->nr);
--
2.39.0.rc0.267.gcb52ba06e7-goog
  
Arnaldo Carvalho de Melo Dec. 5, 2022, 1:03 p.m. UTC | #2
Em Fri, Dec 02, 2022 at 07:31:59PM +0000, Wang, Weilin escreveu:
> Namhyung, it works. Thanks!

Thanks, applied and added a Tested-by: Weilin, ok?

- Arnaldo
 
> -----Original Message-----
> From: Namhyung Kim <namhyung@gmail.com> On Behalf Of Namhyung Kim
> Sent: Friday, December 2, 2022 11:05 AM
> To: Arnaldo Carvalho de Melo <acme@kernel.org>; Jiri Olsa <jolsa@kernel.org>
> Cc: Ingo Molnar <mingo@kernel.org>; Peter Zijlstra <peterz@infradead.org>; LKML <linux-kernel@vger.kernel.org>; Ian Rogers <irogers@google.com>; Hunter, Adrian <adrian.hunter@intel.com>; linux-perf-users@vger.kernel.org; Kan Liang <kan.liang@linux.intel.com>; Zhengjun Xing <zhengjun.xing@linux.intel.com>; James Clark <james.clark@arm.com>; Athira Jajeev <atrajeev@linux.vnet.ibm.com>; Wang, Weilin <weilin.wang@intel.com>
> Subject: [PATCH] perf stat: Fix multi-line metric output in JSON
> 
> When a metric produces more than one values, it missed to print the opening bracket.
> 
> Fixes: ab6baaae2735 ("perf stat: Fix JSON output in metric-only mode")
> Reported-by: "Wang, Weilin" <weilin.wang@intel.com>
> Signed-off-by: Namhyung Kim <namhyung@kernel.org>
> ---
> Weilin, could you please verify it fixes your problem?
> 
>  tools/perf/util/stat-display.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/tools/perf/util/stat-display.c b/tools/perf/util/stat-display.c index f1ee4b052198..8d0bdd57163d 100644
> --- a/tools/perf/util/stat-display.c
> +++ b/tools/perf/util/stat-display.c
> @@ -440,7 +440,7 @@ static void new_line_json(struct perf_stat_config *config, void *ctx)  {
>  	struct outstate *os = ctx;
>  
> -	fputc('\n', os->fh);
> +	fputs("\n{", os->fh);
>  	if (os->prefix)
>  		fprintf(os->fh, "%s", os->prefix);
>  	aggr_printout(config, os->evsel, os->id, os->nr);
> --
> 2.39.0.rc0.267.gcb52ba06e7-goog
  
Wang, Weilin Dec. 5, 2022, 6:07 p.m. UTC | #3
Yes, no problem. 

Thanks, 
Weilin

-----Original Message-----
From: Arnaldo Carvalho de Melo <acme@kernel.org> 
Sent: Monday, December 5, 2022 5:04 AM
To: Wang, Weilin <weilin.wang@intel.com>
Cc: Namhyung Kim <namhyung@kernel.org>; Jiri Olsa <jolsa@kernel.org>; Ingo Molnar <mingo@kernel.org>; Peter Zijlstra <peterz@infradead.org>; LKML <linux-kernel@vger.kernel.org>; Ian Rogers <irogers@google.com>; Hunter, Adrian <adrian.hunter@intel.com>; linux-perf-users@vger.kernel.org; Kan Liang <kan.liang@linux.intel.com>; Zhengjun Xing <zhengjun.xing@linux.intel.com>; James Clark <james.clark@arm.com>; Athira Jajeev <atrajeev@linux.vnet.ibm.com>
Subject: Re: [PATCH] perf stat: Fix multi-line metric output in JSON

Em Fri, Dec 02, 2022 at 07:31:59PM +0000, Wang, Weilin escreveu:
> Namhyung, it works. Thanks!

Thanks, applied and added a Tested-by: Weilin, ok?

- Arnaldo
 
> -----Original Message-----
> From: Namhyung Kim <namhyung@gmail.com> On Behalf Of Namhyung Kim
> Sent: Friday, December 2, 2022 11:05 AM
> To: Arnaldo Carvalho de Melo <acme@kernel.org>; Jiri Olsa <jolsa@kernel.org>
> Cc: Ingo Molnar <mingo@kernel.org>; Peter Zijlstra <peterz@infradead.org>; LKML <linux-kernel@vger.kernel.org>; Ian Rogers <irogers@google.com>; Hunter, Adrian <adrian.hunter@intel.com>; linux-perf-users@vger.kernel.org; Kan Liang <kan.liang@linux.intel.com>; Zhengjun Xing <zhengjun.xing@linux.intel.com>; James Clark <james.clark@arm.com>; Athira Jajeev <atrajeev@linux.vnet.ibm.com>; Wang, Weilin <weilin.wang@intel.com>
> Subject: [PATCH] perf stat: Fix multi-line metric output in JSON
> 
> When a metric produces more than one values, it missed to print the opening bracket.
> 
> Fixes: ab6baaae2735 ("perf stat: Fix JSON output in metric-only mode")
> Reported-by: "Wang, Weilin" <weilin.wang@intel.com>
> Signed-off-by: Namhyung Kim <namhyung@kernel.org>
> ---
> Weilin, could you please verify it fixes your problem?
> 
>  tools/perf/util/stat-display.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/tools/perf/util/stat-display.c b/tools/perf/util/stat-display.c index f1ee4b052198..8d0bdd57163d 100644
> --- a/tools/perf/util/stat-display.c
> +++ b/tools/perf/util/stat-display.c
> @@ -440,7 +440,7 @@ static void new_line_json(struct perf_stat_config *config, void *ctx)  {
>  	struct outstate *os = ctx;
>  
> -	fputc('\n', os->fh);
> +	fputs("\n{", os->fh);
>  	if (os->prefix)
>  		fprintf(os->fh, "%s", os->prefix);
>  	aggr_printout(config, os->evsel, os->id, os->nr);
> --
> 2.39.0.rc0.267.gcb52ba06e7-goog
  

Patch

diff --git a/tools/perf/util/stat-display.c b/tools/perf/util/stat-display.c
index f1ee4b052198..8d0bdd57163d 100644
--- a/tools/perf/util/stat-display.c
+++ b/tools/perf/util/stat-display.c
@@ -440,7 +440,7 @@  static void new_line_json(struct perf_stat_config *config, void *ctx)
 {
 	struct outstate *os = ctx;
 
-	fputc('\n', os->fh);
+	fputs("\n{", os->fh);
 	if (os->prefix)
 		fprintf(os->fh, "%s", os->prefix);
 	aggr_printout(config, os->evsel, os->id, os->nr);