Skip to content

Commit e1cc918

Browse files
captain5050namhyung
authored andcommitted
perf stat: Drop metric-unit if unit is NULL
Avoid cases like: ``` $ perf stat -a -M topdownl1 -j -I 1000 ... {"interval" : 11.127757275, "counter-value" : "85715898.000000", "unit" : "", "event" : "IDQ.MITE_UOPS", "event-runtime" : 988376123, "pcnt-running" : 100.00, "metric-value" : "0.000000", "metric-unit" : "(null)"} ... ``` If there is no unit then drop the metric-value too as: Suggested-by: Tim Chen <[email protected]> Signed-off-by: Ian Rogers <[email protected]> Cc: Yicong Yang <[email protected]> Cc: Weilin Wang <[email protected]> Cc: Will Deacon <[email protected]> Cc: James Clark <[email protected]> Cc: Mike Leach <[email protected]> Cc: Leo Yan <[email protected]> Cc: Sumanth Korikkar <[email protected]> Cc: Thomas Richter <[email protected]> Cc: Tim Chen <[email protected]> Cc: John Garry <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Namhyung Kim <[email protected]>
1 parent 1133e7f commit e1cc918

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

tools/perf/util/stat-display.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -471,8 +471,8 @@ static void print_metric_json(struct perf_stat_config *config __maybe_unused,
471471
struct outstate *os = ctx;
472472
FILE *out = os->fh;
473473

474-
fprintf(out, "\"metric-value\" : \"%f\", ", val);
475-
fprintf(out, "\"metric-unit\" : \"%s\"", unit);
474+
if (unit)
475+
fprintf(out, "\"metric-value\" : \"%f\", \"metric-unit\" : \"%s\"", val, unit);
476476
if (!config->metric_only)
477477
fprintf(out, "}");
478478
}

0 commit comments

Comments
 (0)