summaryrefslogtreecommitdiffstats
path: root/tools/perf/util/stat-display.c
diff options
context:
space:
mode:
authorIan Rogers <irogers@google.com>2024-10-17 19:53:52 +0200
committerNamhyung Kim <namhyung@kernel.org>2024-10-17 21:44:26 +0200
commit1133e7f7dc53edcb26c0e07d345f7285c3246efa (patch)
tree57b9c65a17455b3f5ea11f2acdc06be8396dda00 /tools/perf/util/stat-display.c
parentperf stat: Fix/add parameter names for print_metric (diff)
downloadlinux-1133e7f7dc53edcb26c0e07d345f7285c3246efa.tar.xz
linux-1133e7f7dc53edcb26c0e07d345f7285c3246efa.zip
perf stat: Display "none" for NaN with metric only json
Return earlier for an empty unit case. If snprintf of the fmt doesn't produce digits between vals and ends, as happens with NaN, make the value "none" as happens in print_metric_end. Signed-off-by: Ian Rogers <irogers@google.com> Acked-by: Namhyung Kim <namhyung@kernel.org> Cc: Yicong Yang <yangyicong@hisilicon.com> Cc: Weilin Wang <weilin.wang@intel.com> Cc: Will Deacon <will@kernel.org> Cc: James Clark <james.clark@linaro.org> Cc: Mike Leach <mike.leach@linaro.org> Cc: Leo Yan <leo.yan@linux.dev> Cc: Sumanth Korikkar <sumanthk@linux.ibm.com> Cc: Thomas Richter <tmricht@linux.ibm.com> Cc: Tim Chen <tim.c.chen@linux.intel.com> Cc: John Garry <john.g.garry@oracle.com> Link: https://lore.kernel.org/r/20241017175356.783793-4-irogers@google.com Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Diffstat (limited to '')
-rw-r--r--tools/perf/util/stat-display.c11
1 files changed, 7 insertions, 4 deletions
diff --git a/tools/perf/util/stat-display.c b/tools/perf/util/stat-display.c
index ef0ca8cd802d..a137b377efa4 100644
--- a/tools/perf/util/stat-display.c
+++ b/tools/perf/util/stat-display.c
@@ -610,19 +610,22 @@ static void print_metric_only_json(struct perf_stat_config *config __maybe_unuse
{
struct outstate *os = ctx;
FILE *out = os->fh;
- char buf[64], *vals, *ends;
+ char buf[64], *ends;
char tbuf[1024];
+ const char *vals;
if (!valid_only_metric(unit))
return;
unit = fixunit(tbuf, os->evsel, unit);
+ if (!unit[0])
+ return;
snprintf(buf, sizeof(buf), fmt ?: "", val);
- ends = vals = skip_spaces(buf);
+ vals = ends = skip_spaces(buf);
while (isdigit(*ends) || *ends == '.')
ends++;
*ends = 0;
- if (!unit[0] || !vals[0])
- return;
+ if (!vals[0])
+ vals = "none";
fprintf(out, "%s\"%s\" : \"%s\"", os->first ? "" : ", ", unit, vals);
os->first = false;
}