From nobody Wed Nov 27 13:04:20 2024 Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 41B932B9D4 for ; Thu, 10 Oct 2024 01:21:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728523302; cv=none; b=MbKuph/TRKcBMajO9wKM71jg4lld6otl3FtUJLV1FPF8tNGhDDPgc18SayAbCEkUjYoHf/BY6u3n5c8WRdBNrhthys5oEyC0/HqAb7JsumFxyHYIe6WftQSi+6HjWTYBZb7unr+WPA15/mHg7C37phe60YOAzRZSTzch3WrGUgk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728523302; c=relaxed/simple; bh=3lKt0oaqmDsW092qxJwDO5cQ+pCz5Lb/SsuDsjRIV98=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=jZG8flq0w1iOfqj2bEeU7/kte+CA9h3D0UpKjMtr4E335V+PhTfBpC+1haWlAL+XugYW2oNQM6IWs+Q4IsPzKBSRP/JvjVam3fLqfA83arpphIMGqVKQRfyOsv0wlhNz8SPP/6EDFKz5cJ6VxxVyrbs3Gx3of3tKCz4ajAo2rZ0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=0epW9VXx; arc=none smtp.client-ip=209.85.128.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="0epW9VXx" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-6e2e5e376fcso10282997b3.2 for ; Wed, 09 Oct 2024 18:21:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1728523300; x=1729128100; darn=vger.kernel.org; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=fmTMc5jqBFJBcDF3mkh+k4RYYzumHew93r4OVEgMB6I=; b=0epW9VXxx4ftAm0bCxzmqIhndStQBhZHYzea2ZtM/ObEOyfz5yD951br5RdfH5riLn pUDhxiu5UJF6r84be6pbVT9YNxxZpF/Hl0WDy2HHRzFwcrGhcfhu5bEqFp82lai4or8p s0IsVdcuzcN05xr0TjcNYImFwBQcq6aFdMfq0Xw0qW/5WUkxax8RylGhys+PtSdsPASZ 3nfZaBqojNC8QFWWYH/gY8KOQ6WkpB/lT9Uv9jQCuO7Nfi7PLeAaucjAx5091dGUFSKc TTjjrrpPMymGSxFUI7y1xme3/5fXhPFRgR+N9aMRLoTc08FEZ+bUNkOggHMEZzNb1JYb X3Bg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728523300; x=1729128100; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=fmTMc5jqBFJBcDF3mkh+k4RYYzumHew93r4OVEgMB6I=; b=HHRQlriz6G5r+EZSHdLdSaLmD3C0ITOIarpEAKoY7xKDjsUqptuLtEgaNsO6uJ1GdG O2HGrzvAxjiFE9O/oBhJpOGHw0ejLYyhWPWN/1WpPsivWNem2K8Nr574bX17lY1dskXe 0zfkT5l87i5g9KNd8BNN1BOodDyEZLbMX6k93elUStNhx3Sw9wIZNl5lk9TCXFSTqpZs P0vQQXcHrBazk6YM1QHNEIyaDA2DeL+rU9/FesnUo41DKG1OqD+9gEfcP0K0eyLXMiIN 4wf8Mcy1JFoJxgHqRrt+UylkdotXkwu6RvJiOy16v+4OqnZy3shPxluS9uCVpnR2N6Fn KP4A== X-Forwarded-Encrypted: i=1; AJvYcCXxpXYYactairHc2qaCrU088fC1CjeGHACy511FxN+VX1K/P7OvHZ/sJ227ulhg5kdMY1t3X7HjuBWT8ng=@vger.kernel.org X-Gm-Message-State: AOJu0YyL0TUL01pXeomdosuaKWQPjLXsbagQ1TG3Hh0tkf7XV5erI2r8 F1eQJzgVPF1qzt/19bKGoRhtHpIoeqzARKkHnH7vgsozo5yFkAx+J+Em/tOUw1N5kWj4kM9tdlA RwvdRKA== X-Google-Smtp-Source: AGHT+IH2tGryGXwcR6Gfyf6O77ntcn+H4rPnIjlJQ3zIGUfcBK6k9krmihZyezLVDnLlFHg3Nxr8kFMzhCyA X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:6c8b:1170:a0ca:9d72]) (user=irogers job=sendgmr) by 2002:a81:b511:0:b0:62c:ea0b:a447 with SMTP id 00721157ae682-6e3221791fdmr512367b3.2.1728523300267; Wed, 09 Oct 2024 18:21:40 -0700 (PDT) Date: Wed, 9 Oct 2024 18:21:27 -0700 In-Reply-To: <20241010012135.1272535-1-irogers@google.com> Message-Id: <20241010012135.1272535-2-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241010012135.1272535-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.rc1.288.g06298d1525-goog Subject: [PATCH v2 1/8] perf color: Add printf format checking and resolve issues From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , John Garry , Will Deacon , James Clark , Mike Leach , Leo Yan , Yicong Yang , Weilin Wang , Tim Chen , Thomas Richter , Sumanth Korikkar , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add printf format checking to vararg printf routines in color.h. Resolve build errors/bugs that are found through this checking. Signed-off-by: Ian Rogers --- tools/perf/builtin-sched.c | 2 +- tools/perf/builtin-trace.c | 2 +- tools/perf/util/arm-spe.c | 2 +- tools/perf/util/color.h | 9 +++++---- tools/perf/util/intel-bts.c | 2 +- tools/perf/util/intel-pt.c | 2 +- tools/perf/util/s390-cpumsf.c | 2 +- tools/perf/util/s390-sample-raw.c | 6 +++--- 8 files changed, 14 insertions(+), 13 deletions(-) diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c index fdf979aaf275..99bfc3ad71e2 100644 --- a/tools/perf/builtin-sched.c +++ b/tools/perf/builtin-sched.c @@ -1739,7 +1739,7 @@ static int map_switch_event(struct perf_sched *sched,= struct evsel *evsel, } =20 if (sched->map.comp && new_cpu) - color_fprintf(stdout, color, " (CPU %d)", this_cpu); + color_fprintf(stdout, color, " (CPU %d)", this_cpu.cpu); =20 if (proceed !=3D 1) { color_fprintf(stdout, color, "\n"); diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c index 0b30297b4ecb..748b061f8678 100644 --- a/tools/perf/builtin-trace.c +++ b/tools/perf/builtin-trace.c @@ -1873,7 +1873,7 @@ static int trace__process_event(struct trace *trace, = struct machine *machine, switch (event->header.type) { case PERF_RECORD_LOST: color_fprintf(trace->output, PERF_COLOR_RED, - "LOST %" PRIu64 " events!\n", event->lost.lost); + "LOST %" PRIu64 " events!\n", (u64)event->lost.lost); ret =3D machine__process_lost_event(machine, event, sample); break; default: diff --git a/tools/perf/util/arm-spe.c b/tools/perf/util/arm-spe.c index 13fd2c8afebd..fd0d793ecad8 100644 --- a/tools/perf/util/arm-spe.c +++ b/tools/perf/util/arm-spe.c @@ -122,7 +122,7 @@ static void arm_spe_dump(struct arm_spe *spe __maybe_un= used, else pkt_len =3D 1; printf("."); - color_fprintf(stdout, color, " %08x: ", pos); + color_fprintf(stdout, color, " %08zx: ", pos); for (i =3D 0; i < pkt_len; i++) color_fprintf(stdout, color, " %02x", buf[i]); for (; i < 16; i++) diff --git a/tools/perf/util/color.h b/tools/perf/util/color.h index 01f7bed21c9b..72a4cf2a81a8 100644 --- a/tools/perf/util/color.h +++ b/tools/perf/util/color.h @@ -2,6 +2,7 @@ #ifndef __PERF_COLOR_H #define __PERF_COLOR_H =20 +#include #include #include =20 @@ -37,12 +38,12 @@ int perf_config_colorbool(const char *var, const char *= value, int stdout_is_tty) int color_vsnprintf(char *bf, size_t size, const char *color, const char *fmt, va_list args); int color_vfprintf(FILE *fp, const char *color, const char *fmt, va_list a= rgs); -int color_fprintf(FILE *fp, const char *color, const char *fmt, ...); -int color_snprintf(char *bf, size_t size, const char *color, const char *f= mt, ...); +int color_fprintf(FILE *fp, const char *color, const char *fmt, ...) __pri= ntf(3, 4); +int color_snprintf(char *bf, size_t size, const char *color, const char *f= mt, ...) __printf(4, 5); int color_fwrite_lines(FILE *fp, const char *color, size_t count, const ch= ar *buf); int value_color_snprintf(char *bf, size_t size, const char *fmt, double va= lue); -int percent_color_snprintf(char *bf, size_t size, const char *fmt, ...); -int percent_color_len_snprintf(char *bf, size_t size, const char *fmt, ...= ); +int percent_color_snprintf(char *bf, size_t size, const char *fmt, ...) __= printf(3, 4); +int percent_color_len_snprintf(char *bf, size_t size, const char *fmt, ...= ) __printf(3, 4); int percent_color_fprintf(FILE *fp, const char *fmt, double percent); const char *get_percent_color(double percent); =20 diff --git a/tools/perf/util/intel-bts.c b/tools/perf/util/intel-bts.c index 27d9b5c9fec8..3ea82d5e8d2e 100644 --- a/tools/perf/util/intel-bts.c +++ b/tools/perf/util/intel-bts.c @@ -100,7 +100,7 @@ static void intel_bts_dump(struct intel_bts *bts __mayb= e_unused, else sz =3D len; printf("."); - color_fprintf(stdout, color, " %08x: ", pos); + color_fprintf(stdout, color, " %08zx: ", pos); for (i =3D 0; i < sz; i++) color_fprintf(stdout, color, " %02x", buf[i]); for (; i < br_sz; i++) diff --git a/tools/perf/util/intel-pt.c b/tools/perf/util/intel-pt.c index fd2597613f3d..3fe67bf652b6 100644 --- a/tools/perf/util/intel-pt.c +++ b/tools/perf/util/intel-pt.c @@ -249,7 +249,7 @@ static void intel_pt_dump(struct intel_pt *pt __maybe_u= nused, else pkt_len =3D 1; printf("."); - color_fprintf(stdout, color, " %08x: ", pos); + color_fprintf(stdout, color, " %08zx: ", pos); for (i =3D 0; i < pkt_len; i++) color_fprintf(stdout, color, " %02x", buf[i]); for (; i < 16; i++) diff --git a/tools/perf/util/s390-cpumsf.c b/tools/perf/util/s390-cpumsf.c index 73846b73d0cf..30638653ad2d 100644 --- a/tools/perf/util/s390-cpumsf.c +++ b/tools/perf/util/s390-cpumsf.c @@ -345,7 +345,7 @@ static bool s390_cpumsf_trailer_show(const char *color,= size_t pos, } color_fprintf(stdout, color, " [%#08zx] Trailer %c%c%c bsdes:%d" " dsdes:%d Overflow:%lld Time:%#llx\n" - "\t\tC:%d TOD:%#lx\n", + "\t\tC:%d TOD:%#llx\n", pos, te->f ? 'F' : ' ', te->a ? 'A' : ' ', diff --git a/tools/perf/util/s390-sample-raw.c b/tools/perf/util/s390-sampl= e-raw.c index 53383e97ec9d..d07a94242905 100644 --- a/tools/perf/util/s390-sample-raw.c +++ b/tools/perf/util/s390-sample-raw.c @@ -98,12 +98,12 @@ static void s390_cpumcfdg_dumptrail(const char *color, = size_t offset, te.res2 =3D be32_to_cpu(tep->res2); =20 color_fprintf(stdout, color, " [%#08zx] Trailer:%c%c%c%c%c" - " Cfvn:%d Csvn:%d Speed:%d TOD:%#llx\n", + " Cfvn:%d Csvn:%d Speed:%d TOD:%#lx\n", offset, te.clock_base ? 'T' : ' ', te.speed ? 'S' : ' ', te.mtda ? 'M' : ' ', te.caca ? 'C' : ' ', te.lcda ? 'L' : ' ', te.cfvn, te.csvn, te.cpu_speed, te.timestamp); - color_fprintf(stdout, color, "\t\t1:%lx 2:%lx 3:%lx TOD-Base:%#llx" + color_fprintf(stdout, color, "\t\t1:%lx 2:%lx 3:%lx TOD-Base:%#lx" " Type:%x\n\n", te.progusage1, te.progusage2, te.progusage3, te.tod_base, te.mach_type); @@ -205,7 +205,7 @@ static void s390_cpumcfdg_dump(struct perf_pmu *pmu, st= ruct perf_sample *sample) char *ev_name =3D get_counter_name(ce.set, i, pmu); =20 color_fprintf(stdout, color, - "\tCounter:%03d %s Value:%#018lx\n", i, + "\tCounter:%03zd %s Value:%#018lx\n", i, ev_name ?: "", be64_to_cpu(*p)); free(ev_name); } --=20 2.47.0.rc1.288.g06298d1525-goog From nobody Wed Nov 27 13:04:20 2024 Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BB3C98837 for ; Thu, 10 Oct 2024 01:21:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728523305; cv=none; b=UwklNhfbAANRB8WhEchsMzvYzPG1hp7pET2AFKom5TsYbTbFUZg5Z5k5bI9mGZitG9zWLwK5+E+E9aOhGHTuySDBE+uD90Mc0kxgXXgry6s9q5fPVi/yIUw3K5HkYY1Q1tZoHCmmzmeJK8T+EgwOQ7/i/z7vPKAQqW3t/obu7PU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728523305; c=relaxed/simple; bh=9mfIJcC0HJSEWZzG9Ykal5rxE97ZbtmZRtRyHou+jpQ=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=ufLmFcL/36vm2aHMgsGKT2v95xlSgByGFEWqLnlAPQA5pTjAYGA/LzDezguw58IlEG8QpS/htpnuNA6Bke6ru/IHj632zeJJs7YT9bFTxjqEC87vEIRrxNx22WpC+2X18QVH4PFHVBsH1U36iPHRriWlJStlxCHhZ7vQDrJs7s8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=bT5QYezy; arc=none smtp.client-ip=209.85.219.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="bT5QYezy" Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-e1159fb161fso722847276.1 for ; Wed, 09 Oct 2024 18:21:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1728523302; x=1729128102; darn=vger.kernel.org; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=9vk61ddLBPHHKenKN2gCI30GmxdQHp5UrYWcIorCWcs=; b=bT5QYezyFUTWyL3EXMZFlx5BduO1zQ2iE4hnEd0vES/W94bItmbap8ZecDxnwq+BVP zo/1tEGMFFx5x1Jwu8BBiP+6sBNr6ANDdi+OgY5zy0efNcqtl5n+wezoOC1TrhoGG5Wq e10FWOdKJNXwpAlozrjvraWSWcDGHHnNxlimelbUiB4ladGX/iCpLWmeFbwhgpMmUQVM ULvBzv+Wsp2/gzBY2430GPQI+wYZ2cA1YL/T0BeveL1wKioY9UB+JAsAo5E8ckhKKqv+ txJhcIl63vmSVazpCQoXFL+37XzhwirA/YlF/u4socwArtS/x3e1DKJPVw0L5s5I9pNQ 7pVQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728523302; x=1729128102; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=9vk61ddLBPHHKenKN2gCI30GmxdQHp5UrYWcIorCWcs=; b=LjKtV6Nnu3Zwf2TCpUOgG+2bchF6W+739r43ymrNO0yUaLZr37Zr3mUUxiTtAXoVD/ 8FwGklk0h3BkKBF7Ua4wQtBqdFadDBdhjYYCB5M4Px4PuiQlg2Quu+auUwkIOCCoFxth VFqbevkwi070/e4GNK+xz9FrWll9pRpJBhrgJx/GqnSbhkvC1WocAYSfZqiIp0wDxReF nq2/S6sduI6ek6D/7CKshCY2n8ZkgIc0EQ/pDnfnn8mHDOk+t5ngm21I8itfkOrBbZWx fAJmG5vnh5J5aA/XsRfsTte1vr7469lAvBtYZTI1hLlcIAgspOXZarPfng9M+7CBM67J Lc0w== X-Forwarded-Encrypted: i=1; AJvYcCUqqzO4ADZaz+o+XrPF+dhRLar9YXmJGOesv8GtZqh2VwMGyEKab9ArxnxDV0D/Vt83QpwvRNWRA+MaafA=@vger.kernel.org X-Gm-Message-State: AOJu0Yw5JdiNQ+tZAKceiEEEzhzqyoRz+kvo+MzrwWAdv76+5RpCiKzf PnjS0dcz7186o+4hNpqZoNuq0v7S2X7ehj8CNs6HAo6dSiTaS/k0DTU16eg6UXWMfQPXmTENuwL zlwZcPA== X-Google-Smtp-Source: AGHT+IGNYW5VacBNBnZbd14bsq5eq+YibUATRXo0FoLK5s00A442U40Oj8rE+WhlaqZ+zAH+mCd7AEzQiBxN X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:6c8b:1170:a0ca:9d72]) (user=irogers job=sendgmr) by 2002:a25:c2c1:0:b0:e22:5bdf:39c1 with SMTP id 3f1490d57ef6-e28fe45b504mr2879276.10.1728523302373; Wed, 09 Oct 2024 18:21:42 -0700 (PDT) Date: Wed, 9 Oct 2024 18:21:28 -0700 In-Reply-To: <20241010012135.1272535-1-irogers@google.com> Message-Id: <20241010012135.1272535-3-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241010012135.1272535-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.rc1.288.g06298d1525-goog Subject: [PATCH v2 2/8] perf stat: Fix/add parameter names for print_metric From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , John Garry , Will Deacon , James Clark , Mike Leach , Leo Yan , Yicong Yang , Weilin Wang , Tim Chen , Thomas Richter , Sumanth Korikkar , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The print_metric parameter names were rearranged, fix and add comments in the stat-shadow callers to ensure they are correct. Signed-off-by: Ian Rogers --- tools/perf/util/stat-shadow.c | 55 ++++++++++++++++++++--------------- tools/perf/util/stat.h | 6 ++-- 2 files changed, 36 insertions(+), 25 deletions(-) diff --git a/tools/perf/util/stat-shadow.c b/tools/perf/util/stat-shadow.c index 3ce756b8ede5..1e6ba6bf244a 100644 --- a/tools/perf/util/stat-shadow.c +++ b/tools/perf/util/stat-shadow.c @@ -195,17 +195,21 @@ static void print_ratio(struct perf_stat_config *conf= ig, const struct evsel *evsel, int aggr_idx, double numerator, struct perf_stat_output_ctx *out, enum stat_type denominator_type, - const double color_ratios[3], const char *unit) + const double color_ratios[3], const char *_unit) { double denominator =3D find_stat(evsel, aggr_idx, denominator_type); + double ratio =3D 0; + const char *color =3D NULL; + const char *fmt =3D NULL; + const char *unit =3D NULL; =20 if (numerator && denominator) { - double ratio =3D numerator / denominator * 100.0; - const char *color =3D get_ratio_color(color_ratios, ratio); - - out->print_metric(config, out->ctx, color, "%7.2f%%", unit, ratio); - } else - out->print_metric(config, out->ctx, NULL, NULL, unit, 0); + ratio =3D numerator / denominator * 100.0; + color =3D get_ratio_color(color_ratios, ratio); + fmt =3D "%7.2f%%"; + unit =3D _unit; + } + out->print_metric(config, out->ctx, color, fmt, unit, ratio); } =20 static void print_stalled_cycles_front(struct perf_stat_config *config, @@ -319,14 +323,15 @@ static void print_instructions(struct perf_stat_confi= g *config, find_stat(evsel, aggr_idx, STAT_STALLED_CYCLES_BACK)); =20 if (cycles) { - print_metric(config, ctxp, NULL, "%7.2f ", "insn per cycle", - instructions / cycles); - } else - print_metric(config, ctxp, NULL, NULL, "insn per cycle", 0); + print_metric(config, ctxp, /*color=3D*/NULL, "%7.2f ", "insn per cycle", + instructions / cycles); + } else { + print_metric(config, ctxp, /*color=3D*/NULL, /*fmt=3D*/NULL, "insn per c= ycle", 0); + } =20 if (max_stalled && instructions) { out->new_line(config, ctxp); - print_metric(config, ctxp, NULL, "%7.2f ", "stalled cycles per insn", + print_metric(config, ctxp, /*color=3D*/NULL, "%7.2f ", "stalled cycles p= er insn", max_stalled / instructions); } } @@ -341,9 +346,10 @@ static void print_cycles(struct perf_stat_config *conf= ig, if (cycles && nsecs) { double ratio =3D cycles / nsecs; =20 - out->print_metric(config, out->ctx, NULL, "%8.3f", "GHz", ratio); - } else - out->print_metric(config, out->ctx, NULL, NULL, "GHz", 0); + out->print_metric(config, out->ctx, /*color=3D*/NULL, "%8.3f", "GHz", ra= tio); + } else { + out->print_metric(config, out->ctx, /*color=3D*/NULL, /*fmt=3D*/NULL, "G= Hz", 0); + } } =20 static void print_nsecs(struct perf_stat_config *config, @@ -356,10 +362,11 @@ static void print_nsecs(struct perf_stat_config *conf= ig, double wall_time =3D avg_stats(&walltime_nsecs_stats); =20 if (wall_time) { - print_metric(config, ctxp, NULL, "%8.3f", "CPUs utilized", + print_metric(config, ctxp, /*color=3D*/NULL, "%8.3f", "CPUs utilized", nsecs / (wall_time * evsel->scale)); - } else - print_metric(config, ctxp, NULL, NULL, "CPUs utilized", 0); + } else { + print_metric(config, ctxp, /*color=3D*/NULL, /*fmt=3D*/NULL, "CPUs utili= zed", 0); + } } =20 static int prepare_metric(const struct metric_expr *mexp, @@ -532,12 +539,12 @@ static void generic_metric(struct perf_stat_config *c= onfig, ratio); } } else { - print_metric(config, ctxp, color, /*unit=3D*/NULL, + print_metric(config, ctxp, color, /*fmt=3D*/NULL, out->force_header ? (metric_name ?: evsel->name) : "", 0); } } else { - print_metric(config, ctxp, color, /*unit=3D*/NULL, + print_metric(config, ctxp, color, /*fmt=3D*/NULL, out->force_header ? (metric_name ?: evsel->name) : "", 0); } @@ -708,9 +715,11 @@ void perf_stat__print_shadow_stats(struct perf_stat_co= nfig *config, =20 if (unit !=3D ' ') snprintf(unit_buf, sizeof(unit_buf), "%c/sec", unit); - print_metric(config, ctxp, NULL, "%8.3f", unit_buf, ratio); - } else + print_metric(config, ctxp, /*color=3D*/NULL, "%8.3f", + unit_buf, ratio); + } else { num =3D 0; + } } } =20 @@ -718,7 +727,7 @@ void perf_stat__print_shadow_stats(struct perf_stat_con= fig *config, &num, NULL, out, metric_events); =20 if (num =3D=3D 0) - print_metric(config, ctxp, NULL, NULL, NULL, 0); + print_metric(config, ctxp, /*color=3D*/NULL, /*fmt=3D*/NULL, /*unit=3D*/= NULL, 0); } =20 /** diff --git a/tools/perf/util/stat.h b/tools/perf/util/stat.h index fd7a187551bd..a5f3d7d00101 100644 --- a/tools/perf/util/stat.h +++ b/tools/perf/util/stat.h @@ -155,8 +155,10 @@ extern struct stats walltime_nsecs_stats; extern struct rusage_stats ru_stats; =20 typedef void (*print_metric_t)(struct perf_stat_config *config, - void *ctx, const char *color, const char *unit, - const char *fmt, double val); + void *ctx, const char *color, + const char *fmt, + const char *unit, + double val); typedef void (*new_line_t)(struct perf_stat_config *config, void *ctx); =20 /* Used to print the display name of the Default metricgroup for now. */ --=20 2.47.0.rc1.288.g06298d1525-goog From nobody Wed Nov 27 13:04:20 2024 Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 587C4139D07 for ; Thu, 10 Oct 2024 01:21:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728523307; cv=none; b=ASCq9q1eDG6BAQ7KsVe9LYw/C+nqZ/AJ2VRNKmzoF1hSW71+Gi3xdDOj5G0vPXgqnWY2ffoqUhFpxIdo1IgbFVyojMwerOWClObwDE/SpzSOYjQ7gqblWyRX2VDFdP4bbM5UxQ2aBGb0lacIwIsxwD9qUENIiK5UYrC8f1IOPAY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728523307; c=relaxed/simple; bh=K+iLRNmPq7pFFzgCwk+WDV1uDJdmXtPtLhF5jSJiB/Q=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=rtogEZ5MhyFjVjfO1+4HpBeh0yty0fgazyWbJwLvxmVXLbqOnLo9M+yNKR3JoUQ58Nkvfuza5M22halFyggHGrnId4x0RcaGJ6w7+U8UVvBUMrKTCfozf54KUo+4FPr9DBF5TcPQcpdg+UUVLk/XXssqmQtG7ByKsucWeG6TqSc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=x5xIBqVF; arc=none smtp.client-ip=209.85.128.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="x5xIBqVF" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-6e28d223794so9563997b3.0 for ; Wed, 09 Oct 2024 18:21:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1728523305; x=1729128105; darn=vger.kernel.org; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=FJ1kKijNUBB3h6Uf74qin1j8xVsGkQayF3LcGNTjFTk=; b=x5xIBqVFeBxtBJdwdHQEq+nnoA5B3ufa8P1FP9ZvPFNTVXl+b6KcLx4l4DBH4imNYk pUcmXtztjwyByctOxmWsEPHnh2u2ArBUC6lJAeGBvHw2VIE90WxFsumojuKwHQPv81hU ALrvS8gaH3zpHvo6oqwkWs6hFTfkwn2TfQhlg7+0HmN6lvNWngadZtxr6soXUXS0qJUc KOGJneq7rQC9neCi1Qvx7ohl30emiIgNfX9Y61mCoqNMJXhYSNSQg8KnFD2MAxkeWf1C oQ5r7DEvYWk2mAFPfNHXuIrjXMgaseVyJddUUoPU2h2i0aSS2WV+4yZ+mLFFuqEHy4p+ vcPw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728523305; x=1729128105; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=FJ1kKijNUBB3h6Uf74qin1j8xVsGkQayF3LcGNTjFTk=; b=eOcwCtGD/wAfdnU7dVGoi79agkBepikOmiN5m5hVyRpoD/8e96yryHAjsxmDvHggYV pjel9cXWogI99rtGJPY1uu0nYGSDVM+aW0FAFdHu0+U0hSEaspwGm80C6hpjFaQzpmin oUi4djsjuuI4QBegV4oWbyyKt4Q2k+bdAdWxZFCeiMyoHpxMRo8ogDAzZudGP3/A1JFZ KyR9FnkoMAA0ufLYQ1HhJ0uFUCAGHZJGvq72gSUZc5x8tdlayK3ZWJXZUl/RnW7Ma4pI E79FaOJJ80cvC2idQJvxTy69XkeiiecrVR3bvnR/9o/XMCxE2otnE7VEnpPo7DyhgjFG Z2Xg== X-Forwarded-Encrypted: i=1; AJvYcCWAjOOLLvoIMNl5yv7FQz4Kd0xhcI/sEWXEBwtQIJJmJDbzHLEy72awb+wc0PS1EjNBMnqfrQ+6eJjiauw=@vger.kernel.org X-Gm-Message-State: AOJu0YxT90DcPQK6hSd1qvSjASvAba0HS2qbhbCuN45wXNDYeNBkl0UI pMg7ppp8ifBbYqyImaCax89PunnZm5aXNHdGdcR99YxVQ6mFRjCTeUUsmieUuyoMcSxH3HtyxPT ulppLXg== X-Google-Smtp-Source: AGHT+IEJypg576UbQ5VaDO0MPAIHZNmppJpIj8JxQULvGLPW7W7ttj6J21OnaqDWDcmGmHFVb5umycK+sA+N X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:6c8b:1170:a0ca:9d72]) (user=irogers job=sendgmr) by 2002:a05:6902:4ac:b0:e28:fe07:e7d8 with SMTP id 3f1490d57ef6-e28fe439b20mr61632276.10.1728523304658; Wed, 09 Oct 2024 18:21:44 -0700 (PDT) Date: Wed, 9 Oct 2024 18:21:29 -0700 In-Reply-To: <20241010012135.1272535-1-irogers@google.com> Message-Id: <20241010012135.1272535-4-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241010012135.1272535-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.rc1.288.g06298d1525-goog Subject: [PATCH v2 3/8] perf stat: Display "none" for NaN with metric only json From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , John Garry , Will Deacon , James Clark , Mike Leach , Leo Yan , Yicong Yang , Weilin Wang , Tim Chen , Thomas Richter , Sumanth Korikkar , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 --- tools/perf/util/stat-display.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/tools/perf/util/stat-display.c b/tools/perf/util/stat-display.c index 5402998881c4..e392ee5efb45 100644 --- a/tools/perf/util/stat-display.c +++ b/tools/perf/util/stat-display.c @@ -609,19 +609,22 @@ static void print_metric_only_json(struct perf_stat_c= onfig *config __maybe_unuse { struct outstate *os =3D ctx; FILE *out =3D os->fh; - char buf[64], *vals, *ends; + char buf[64], *ends; char tbuf[1024]; + const char *vals; =20 if (!valid_only_metric(unit)) return; unit =3D fixunit(tbuf, os->evsel, unit); + if (!unit[0]) + return; snprintf(buf, sizeof(buf), fmt ?: "", val); - ends =3D vals =3D skip_spaces(buf); + vals =3D ends =3D skip_spaces(buf); while (isdigit(*ends) || *ends =3D=3D '.') ends++; *ends =3D 0; - if (!unit[0] || !vals[0]) - return; + if (!vals[0]) + vals =3D "none"; fprintf(out, "%s\"%s\" : \"%s\"", os->first ? "" : ", ", unit, vals); os->first =3D false; } --=20 2.47.0.rc1.288.g06298d1525-goog From nobody Wed Nov 27 13:04:20 2024 Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1E97D16A92E for ; Thu, 10 Oct 2024 01:21:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728523309; cv=none; b=JQsMtRbIIxt1HrrVo63DW67tCvtjDf3y83wa1j3NhwaaiKaup5XDTbngnIVVREkFSyXyjicunE7bNf5TKds+eBBC+cK95MRcVDcdTbgzS2xMpf0GOU675pZOinipH/C6ClmkxlnweaEtMZTcA6PUfFm01c9ddn2kotTJ/cojKhQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728523309; c=relaxed/simple; bh=1azV7E7FNm5ZgpAvEIdQ64JI8F44TJjzhA8h4p43pa4=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=P/Dls/SdVcY3a/MjX9IoCdpTNa1syv9pnxVzI0/y0e+AMsISJ9OL0A/ubJIe3PnYDquLFjjHCLRbjwRh/9eXuyL5fFz0wOU+053SwciMN7xkwKc0pAzGyyzLwbFu3QLOh7RbGD3WWi27NEr/yvA38ID5ymsEYkrROI76XN4rhIY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=hHNU6si7; arc=none smtp.client-ip=209.85.128.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="hHNU6si7" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-6e3245ed6b8so11161917b3.0 for ; Wed, 09 Oct 2024 18:21:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1728523307; x=1729128107; darn=vger.kernel.org; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=H1XFcCPRE5WoawTRbLhb/GdnJyywM9jpDE6V/JQJDp0=; b=hHNU6si7JZaoWpjrzgyWVMduBBudici6tiIky+NZGGCK4jqEKwDbks83xHRwNe6KKX DuGTk4zp4WeQeIV9lzVCjZx0fIFTL6oluhsIpXir1dahKOxOaEWD3LAeRVdEx2ZSBTS9 Y77A8jEmGS4mlbPjfDTI6RhpXePH7yRkxf5Yho2QSK35ECvVnzVU9+ZgG7kLmh3h3ya9 SDgUDstNPxSyW8G7xCzkrTh4G22floj4GqGvWsBF3jbzC3QANe12bmug4eTM/F2WbW1H 5qrIb+gePXe/nPuJG8d3ZHdjmDkC8P/39JAEkL/aWvmdEp6GBKFrlyj7292hksgFln3C tK4A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728523307; x=1729128107; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=H1XFcCPRE5WoawTRbLhb/GdnJyywM9jpDE6V/JQJDp0=; b=i5vm5idqyrhncUEK4LRUtcJ8FW/WaglmXZ9iqNRnZmxzWG4bWNLZUseia/FpGTMcip 8btreWFQ27k7rhpEW9Q+8qlXqitTar8clumWvYBKmwmKe+B8YTpQqkUZjYRserh1QFo5 Z1fSihZYyo3lRF8z2gkpY32OhLv3z4+0KDHSiXo14GTO9Lk+dwz1rcbOLvBa8zt2mQ7f kR5vZcINm5kQquBYPyjeGdJ9mhmnwIP3R6zO2KxL6UvKOe7cnHNJVRm8nDp5aTDnSPOY qwzCrGd9bNsNW0SCl2njTzeyMIQoN9jm+AuphSycWCgqBCIwmjTam/Ayelqpcaot4dX1 0UJQ== X-Forwarded-Encrypted: i=1; AJvYcCUU5rmNqKbmioqt1k8cQlNc+9tufUHG5kJcrntrfdX15okyAXwMS2guNkTeGB4HTIlJCQqwYfsdM/vmogo=@vger.kernel.org X-Gm-Message-State: AOJu0YzmlSJVuiRADnXe9LXsYw7PSQgU0zNd87MPc76EdHGPk6CMSb8t Cdk5PWEZRq/aQ1fFm32KZKcZDeg2ZQW7rLg2U9ORhCSGy5xrPa1gwYtyn58a5aSx3tHIMp7Na0n 7ZVJBZA== X-Google-Smtp-Source: AGHT+IH/Ad5uqCUblxRnAXog3BTfXT0jL5Xh0TWAOrvBEeg9poXkASqKARbLzbeTDuRshUQbzG1dEiobfRav X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:6c8b:1170:a0ca:9d72]) (user=irogers job=sendgmr) by 2002:a05:690c:2511:b0:6e2:b263:103f with SMTP id 00721157ae682-6e3220e2a8bmr549377b3.0.1728523307301; Wed, 09 Oct 2024 18:21:47 -0700 (PDT) Date: Wed, 9 Oct 2024 18:21:30 -0700 In-Reply-To: <20241010012135.1272535-1-irogers@google.com> Message-Id: <20241010012135.1272535-5-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241010012135.1272535-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.rc1.288.g06298d1525-goog Subject: [PATCH v2 4/8] perf stat: Drop metric-unit if unit is NULL From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , John Garry , Will Deacon , James Clark , Mike Leach , Leo Yan , Yicong Yang , Weilin Wang , Tim Chen , Thomas Richter , Sumanth Korikkar , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 Signed-off-by: Ian Rogers --- tools/perf/util/stat-display.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/perf/util/stat-display.c b/tools/perf/util/stat-display.c index e392ee5efb45..6bb048fefe9d 100644 --- a/tools/perf/util/stat-display.c +++ b/tools/perf/util/stat-display.c @@ -470,8 +470,8 @@ static void print_metric_json(struct perf_stat_config *= config __maybe_unused, struct outstate *os =3D ctx; FILE *out =3D os->fh; =20 - fprintf(out, "\"metric-value\" : \"%f\", ", val); - fprintf(out, "\"metric-unit\" : \"%s\"", unit); + if (unit) + fprintf(out, "\"metric-value\" : \"%f\", \"metric-unit\" : \"%s\"", val,= unit); if (!config->metric_only) fprintf(out, "}"); } --=20 2.47.0.rc1.288.g06298d1525-goog From nobody Wed Nov 27 13:04:20 2024 Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A6AB92C1B4 for ; Thu, 10 Oct 2024 01:21:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728523312; cv=none; b=nk02+jaZOtImUDLAL+W8QynrBFt0UWEfQAwCvqRQCR3Yl8sUEmpzrW+MAWwSIn6eBLToA5hxSyqovkWt2UdKdkLwiGAQsIwlmPL3+OQIHNPZOPpbVp+g9fEiIF6fA3PMYl4Ns0gpk7mJ643bOAXLImlpL+lvCB3AVf3DTjeui7M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728523312; c=relaxed/simple; bh=uiS+oLS4pffHMgCMpYDAqPQxwx7hTm/gSJ2Wy+m9tc0=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=MwEhy79tQs4ZeY4heqYSbElFO+4diqtPs3bwkIbwa6aXvvT76D+HDmg636YuSCG39hCPyOCoxmJ/7sZGmT1XANpBp+z714F7toD4/CfQV5cMR1TfWP83PSOGtnL2OYjJ/eNl4n2QrDodOqq/+FOFRHyHdCP4XCK4j9AdmMSX18Y= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=27g9JfMg; arc=none smtp.client-ip=209.85.219.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="27g9JfMg" Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-e28fdb4f35fso803906276.0 for ; Wed, 09 Oct 2024 18:21:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1728523309; x=1729128109; darn=vger.kernel.org; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=rSMf0ZciMHk1DLwXUrfHLBOPiqM+sa4aM1B7vJjuFJs=; b=27g9JfMgz+cUzRAkzA6WZWQlkQVoULC8x5rPxq45qgNo52XeftKJ6sj81B7fv3Lx/v bMHF/PNglxondqjTJlVyIONB/Ccit3N5834+PQ1/CcxSPxcH8nMByHV9uUKzbJiiP0qs D9gLlDwz8I30s9qVKYOTyE5twkcqCK0IXMODmuWIPYe5YyEdl/srROzK2q33IyhXqHr5 0rL/8ZwQREmO10H7RZ/3L5I0fA1+04sPLsbk3QX6jitjSqZ3PepKczWT5iLV2oUEBu80 sKR6crGqWAkcITvVD7jap8UFsEMRw7tAvMlgdgoq21O7MU7yjuhKEu8OBke/OBP8f8vr P+JA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728523309; x=1729128109; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=rSMf0ZciMHk1DLwXUrfHLBOPiqM+sa4aM1B7vJjuFJs=; b=Zf65cRlErp4QODTCqK2zPPKeqlcQLQuYna6AxQh1WVGzUmrMwN6ySxsxNFYPxAhWtO GKKTRWMNJuFM5DztRykKJxDdiSk+NGcivwRw5XL8WCl9JQpHBwYcDxXV3yYeHUeA+4Zc 6WlvLxWyqodGgi4Wyn4ZNvgL65iOEY0ETh9FRPlRVAXBNdEHWcpG8u77yehET5RE8lgc cvwM+v1IS32GrlehamD0LOaZTXHzn79MjWjqW7CIpfg1m/tIcLu5V8P8Ji4iD7jg3acJ PCOM4k8GTEvDj11WCjzfOGS1fVe1PecH+L1UFzmyN3s+dgLALylASLfGP5sMn7Fyeeew FIbA== X-Forwarded-Encrypted: i=1; AJvYcCWFfz6ccQbEnkBMY5wcHkiavrHDPAKN0mLNtbnWKpeUA6Dkz2O9N05Kg/sCq76eCJePeMhLucPvwfIsI7g=@vger.kernel.org X-Gm-Message-State: AOJu0Yy7v+gJmBdZng8Hay6OjBM+9ZtPLrfDIHez1O9mRPZHSoqZ2Q0o +8x+6NDLmXMJ60qTUKngjDPDOVqchvMn/euphSXJiy3DbfqmSCeoq3efaPNs0wku9SdmfsZGH+T pdeUEgw== X-Google-Smtp-Source: AGHT+IELqYJotQaSZNeZiTSaHR+QUl1mFryQRbsYcyOP2J8EBG2jxhtexX5GZXgxNG/bBBQs9No0cfVtSGsU X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:6c8b:1170:a0ca:9d72]) (user=irogers job=sendgmr) by 2002:a25:9105:0:b0:e20:25f5:a889 with SMTP id 3f1490d57ef6-e28fe4a5550mr3066276.5.1728523309358; Wed, 09 Oct 2024 18:21:49 -0700 (PDT) Date: Wed, 9 Oct 2024 18:21:31 -0700 In-Reply-To: <20241010012135.1272535-1-irogers@google.com> Message-Id: <20241010012135.1272535-6-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241010012135.1272535-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.rc1.288.g06298d1525-goog Subject: [PATCH v2 5/8] perf stat: Change color to threshold in print_metric From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , John Garry , Will Deacon , James Clark , Mike Leach , Leo Yan , Yicong Yang , Weilin Wang , Tim Chen , Thomas Richter , Sumanth Korikkar , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Colors don't mean things in CSV and JSON output, switch to a threshold enum value that the standard output can convert to a color. Updating the CSV and JSON output will be later changes. Signed-off-by: Ian Rogers --- tools/perf/arch/x86/util/iostat.c | 2 +- tools/perf/builtin-script.c | 6 +- tools/perf/util/stat-display.c | 40 ++++++++---- tools/perf/util/stat-shadow.c | 105 +++++++++++++++--------------- tools/perf/util/stat.h | 12 +++- 5 files changed, 97 insertions(+), 68 deletions(-) diff --git a/tools/perf/arch/x86/util/iostat.c b/tools/perf/arch/x86/util/i= ostat.c index df7b5dfcc26a..366b44d0bb7e 100644 --- a/tools/perf/arch/x86/util/iostat.c +++ b/tools/perf/arch/x86/util/iostat.c @@ -444,7 +444,7 @@ void iostat_print_metric(struct perf_stat_config *confi= g, struct evsel *evsel, iostat_value =3D (count->val - prev_count_val) / ((double) count->run / count->ena); } - out->print_metric(config, out->ctx, NULL, "%8.0f", iostat_metric, + out->print_metric(config, out->ctx, METRIC_THRESHOLD_UNKNOWN, "%8.0f", io= stat_metric, iostat_value / (256 * 1024)); } =20 diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c index a644787fa9e1..8c5d5cecfba4 100644 --- a/tools/perf/builtin-script.c +++ b/tools/perf/builtin-script.c @@ -2136,11 +2136,11 @@ struct metric_ctx { }; =20 static void script_print_metric(struct perf_stat_config *config __maybe_un= used, - void *ctx, const char *color, - const char *fmt, - const char *unit, double val) + void *ctx, enum metric_threshold_classify thresh, + const char *fmt, const char *unit, double val) { struct metric_ctx *mctx =3D ctx; + const char *color =3D metric_threshold_classify__color(thresh); =20 if (!fmt) return; diff --git a/tools/perf/util/stat-display.c b/tools/perf/util/stat-display.c index 6bb048fefe9d..7d42f22cd5f8 100644 --- a/tools/perf/util/stat-display.c +++ b/tools/perf/util/stat-display.c @@ -72,6 +72,19 @@ static const char *aggr_header_std[] =3D { [AGGR_GLOBAL] =3D "" }; =20 +const char *metric_threshold_classify__color(enum metric_threshold_classif= y thresh) +{ + const char * const colors[] =3D { + "", /* unknown */ + PERF_COLOR_RED, /* bad */ + PERF_COLOR_MAGENTA, /* nearly bad */ + PERF_COLOR_YELLOW, /* less good */ + PERF_COLOR_GREEN, /* good */ + }; + static_assert(ARRAY_SIZE(colors) - 1 =3D=3D METRIC_THRESHOLD_GOOD, "miss= ing enum value"); + return colors[thresh]; +} + static void print_running_std(struct perf_stat_config *config, u64 run, u6= 4 ena) { if (run !=3D ena) @@ -404,13 +417,14 @@ static void do_new_line_std(struct perf_stat_config *= config, } =20 static void print_metric_std(struct perf_stat_config *config, - void *ctx, const char *color, const char *fmt, - const char *unit, double val) + void *ctx, enum metric_threshold_classify thresh, + const char *fmt, const char *unit, double val) { struct outstate *os =3D ctx; FILE *out =3D os->fh; int n; bool newline =3D os->newline; + const char *color =3D metric_threshold_classify__color(thresh); =20 os->newline =3D false; =20 @@ -442,7 +456,7 @@ static void new_line_csv(struct perf_stat_config *confi= g, void *ctx) =20 static void print_metric_csv(struct perf_stat_config *config __maybe_unuse= d, void *ctx, - const char *color __maybe_unused, + enum metric_threshold_classify thresh __maybe_unused, const char *fmt, const char *unit, double val) { struct outstate *os =3D ctx; @@ -463,7 +477,7 @@ static void print_metric_csv(struct perf_stat_config *c= onfig __maybe_unused, =20 static void print_metric_json(struct perf_stat_config *config __maybe_unus= ed, void *ctx, - const char *color __maybe_unused, + enum metric_threshold_classify thresh __maybe_unused, const char *fmt __maybe_unused, const char *unit, double val) { @@ -558,13 +572,14 @@ static const char *fixunit(char *buf, struct evsel *e= vsel, } =20 static void print_metric_only(struct perf_stat_config *config, - void *ctx, const char *color, const char *fmt, - const char *unit, double val) + void *ctx, enum metric_threshold_classify thresh, + const char *fmt, const char *unit, double val) { struct outstate *os =3D ctx; FILE *out =3D os->fh; char buf[1024], str[1024]; unsigned mlen =3D config->metric_only_len; + const char *color =3D metric_threshold_classify__color(thresh); =20 if (!valid_only_metric(unit)) return; @@ -581,7 +596,8 @@ static void print_metric_only(struct perf_stat_config *= config, } =20 static void print_metric_only_csv(struct perf_stat_config *config __maybe_= unused, - void *ctx, const char *color __maybe_unused, + void *ctx, + enum metric_threshold_classify thresh __maybe_unused, const char *fmt, const char *unit, double val) { @@ -603,7 +619,8 @@ static void print_metric_only_csv(struct perf_stat_conf= ig *config __maybe_unused } =20 static void print_metric_only_json(struct perf_stat_config *config __maybe= _unused, - void *ctx, const char *color __maybe_unused, + void *ctx, + enum metric_threshold_classify thresh __maybe_unused, const char *fmt, const char *unit, double val) { @@ -635,7 +652,8 @@ static void new_line_metric(struct perf_stat_config *co= nfig __maybe_unused, } =20 static void print_metric_header(struct perf_stat_config *config, - void *ctx, const char *color __maybe_unused, + void *ctx, + enum metric_threshold_classify thresh __maybe_unused, const char *fmt __maybe_unused, const char *unit, double val __maybe_unused) { @@ -809,7 +827,7 @@ static void printout(struct perf_stat_config *config, s= truct outstate *os, =20 if (run =3D=3D 0 || ena =3D=3D 0 || counter->counts->scaled =3D=3D -1) { if (config->metric_only) { - pm(config, os, NULL, "", "", 0); + pm(config, os, METRIC_THRESHOLD_UNKNOWN, "", "", 0); return; } =20 @@ -864,7 +882,7 @@ static void printout(struct perf_stat_config *config, s= truct outstate *os, perf_stat__print_shadow_stats(config, counter, uval, aggr_idx, &out, &config->metric_events); } else { - pm(config, os, /*color=3D*/NULL, /*format=3D*/NULL, /*unit=3D*/"", /*val= =3D*/0); + pm(config, os, METRIC_THRESHOLD_UNKNOWN, /*format=3D*/NULL, /*unit=3D*/"= ", /*val=3D*/0); } =20 if (!config->metric_only) { diff --git a/tools/perf/util/stat-shadow.c b/tools/perf/util/stat-shadow.c index 1e6ba6bf244a..7de4e63718b9 100644 --- a/tools/perf/util/stat-shadow.c +++ b/tools/perf/util/stat-shadow.c @@ -136,18 +136,14 @@ static enum stat_type evsel__stat_type(struct evsel *= evsel) return STAT_NONE; } =20 -static const char *get_ratio_color(const double ratios[3], double val) +static enum metric_threshold_classify get_ratio_thresh(const double ratios= [3], double val) { - const char *color =3D PERF_COLOR_NORMAL; + assert(ratios[0] > ratios[1]); + assert(ratios[1] > ratios[2]); =20 - if (val > ratios[0]) - color =3D PERF_COLOR_RED; - else if (val > ratios[1]) - color =3D PERF_COLOR_MAGENTA; - else if (val > ratios[2]) - color =3D PERF_COLOR_YELLOW; - - return color; + return val > ratios[1] + ? (val > ratios[0] ? METRIC_THRESHOLD_BAD : METRIC_THRESHOLD_NEARLY_BAD) + : (val > ratios[2] ? METRIC_THRESHOLD_LESS_GOOD : METRIC_THRESHOLD_GOOD); } =20 static double find_stat(const struct evsel *evsel, int aggr_idx, enum stat= _type type) @@ -195,21 +191,21 @@ static void print_ratio(struct perf_stat_config *conf= ig, const struct evsel *evsel, int aggr_idx, double numerator, struct perf_stat_output_ctx *out, enum stat_type denominator_type, - const double color_ratios[3], const char *_unit) + const double thresh_ratios[3], const char *_unit) { double denominator =3D find_stat(evsel, aggr_idx, denominator_type); double ratio =3D 0; - const char *color =3D NULL; + enum metric_threshold_classify thresh =3D METRIC_THRESHOLD_UNKNOWN; const char *fmt =3D NULL; const char *unit =3D NULL; =20 if (numerator && denominator) { ratio =3D numerator / denominator * 100.0; - color =3D get_ratio_color(color_ratios, ratio); + thresh =3D get_ratio_thresh(thresh_ratios, ratio); fmt =3D "%7.2f%%"; unit =3D _unit; } - out->print_metric(config, out->ctx, color, fmt, unit, ratio); + out->print_metric(config, out->ctx, thresh, fmt, unit, ratio); } =20 static void print_stalled_cycles_front(struct perf_stat_config *config, @@ -217,9 +213,9 @@ static void print_stalled_cycles_front(struct perf_stat= _config *config, int aggr_idx, double stalled, struct perf_stat_output_ctx *out) { - static const double color_ratios[3] =3D {50.0, 30.0, 10.0}; + const double thresh_ratios[3] =3D {50.0, 30.0, 10.0}; =20 - print_ratio(config, evsel, aggr_idx, stalled, out, STAT_CYCLES, color_rat= ios, + print_ratio(config, evsel, aggr_idx, stalled, out, STAT_CYCLES, thresh_ra= tios, "frontend cycles idle"); } =20 @@ -228,9 +224,9 @@ static void print_stalled_cycles_back(struct perf_stat_= config *config, int aggr_idx, double stalled, struct perf_stat_output_ctx *out) { - static const double color_ratios[3] =3D {75.0, 50.0, 20.0}; + const double thresh_ratios[3] =3D {75.0, 50.0, 20.0}; =20 - print_ratio(config, evsel, aggr_idx, stalled, out, STAT_CYCLES, color_rat= ios, + print_ratio(config, evsel, aggr_idx, stalled, out, STAT_CYCLES, thresh_ra= tios, "backend cycles idle"); } =20 @@ -239,9 +235,9 @@ static void print_branch_miss(struct perf_stat_config *= config, int aggr_idx, double misses, struct perf_stat_output_ctx *out) { - static const double color_ratios[3] =3D {20.0, 10.0, 5.0}; + const double thresh_ratios[3] =3D {20.0, 10.0, 5.0}; =20 - print_ratio(config, evsel, aggr_idx, misses, out, STAT_BRANCHES, color_ra= tios, + print_ratio(config, evsel, aggr_idx, misses, out, STAT_BRANCHES, thresh_r= atios, "of all branches"); } =20 @@ -250,9 +246,9 @@ static void print_l1d_miss(struct perf_stat_config *con= fig, int aggr_idx, double misses, struct perf_stat_output_ctx *out) { - static const double color_ratios[3] =3D {20.0, 10.0, 5.0}; + const double thresh_ratios[3] =3D {20.0, 10.0, 5.0}; =20 - print_ratio(config, evsel, aggr_idx, misses, out, STAT_L1_DCACHE, color_r= atios, + print_ratio(config, evsel, aggr_idx, misses, out, STAT_L1_DCACHE, thresh_= ratios, "of all L1-dcache accesses"); } =20 @@ -261,9 +257,9 @@ static void print_l1i_miss(struct perf_stat_config *con= fig, int aggr_idx, double misses, struct perf_stat_output_ctx *out) { - static const double color_ratios[3] =3D {20.0, 10.0, 5.0}; + const double thresh_ratios[3] =3D {20.0, 10.0, 5.0}; =20 - print_ratio(config, evsel, aggr_idx, misses, out, STAT_L1_ICACHE, color_r= atios, + print_ratio(config, evsel, aggr_idx, misses, out, STAT_L1_ICACHE, thresh_= ratios, "of all L1-icache accesses"); } =20 @@ -272,9 +268,9 @@ static void print_ll_miss(struct perf_stat_config *conf= ig, int aggr_idx, double misses, struct perf_stat_output_ctx *out) { - static const double color_ratios[3] =3D {20.0, 10.0, 5.0}; + const double thresh_ratios[3] =3D {20.0, 10.0, 5.0}; =20 - print_ratio(config, evsel, aggr_idx, misses, out, STAT_LL_CACHE, color_ra= tios, + print_ratio(config, evsel, aggr_idx, misses, out, STAT_LL_CACHE, thresh_r= atios, "of all LL-cache accesses"); } =20 @@ -283,9 +279,9 @@ static void print_dtlb_miss(struct perf_stat_config *co= nfig, int aggr_idx, double misses, struct perf_stat_output_ctx *out) { - static const double color_ratios[3] =3D {20.0, 10.0, 5.0}; + const double thresh_ratios[3] =3D {20.0, 10.0, 5.0}; =20 - print_ratio(config, evsel, aggr_idx, misses, out, STAT_DTLB_CACHE, color_= ratios, + print_ratio(config, evsel, aggr_idx, misses, out, STAT_DTLB_CACHE, thresh= _ratios, "of all dTLB cache accesses"); } =20 @@ -294,9 +290,9 @@ static void print_itlb_miss(struct perf_stat_config *co= nfig, int aggr_idx, double misses, struct perf_stat_output_ctx *out) { - static const double color_ratios[3] =3D {20.0, 10.0, 5.0}; + const double thresh_ratios[3] =3D {20.0, 10.0, 5.0}; =20 - print_ratio(config, evsel, aggr_idx, misses, out, STAT_ITLB_CACHE, color_= ratios, + print_ratio(config, evsel, aggr_idx, misses, out, STAT_ITLB_CACHE, thresh= _ratios, "of all iTLB cache accesses"); } =20 @@ -305,9 +301,9 @@ static void print_cache_miss(struct perf_stat_config *c= onfig, int aggr_idx, double misses, struct perf_stat_output_ctx *out) { - static const double color_ratios[3] =3D {20.0, 10.0, 5.0}; + const double thresh_ratios[3] =3D {20.0, 10.0, 5.0}; =20 - print_ratio(config, evsel, aggr_idx, misses, out, STAT_CACHE_REFS, color_= ratios, + print_ratio(config, evsel, aggr_idx, misses, out, STAT_CACHE_REFS, thresh= _ratios, "of all cache refs"); } =20 @@ -323,16 +319,16 @@ static void print_instructions(struct perf_stat_confi= g *config, find_stat(evsel, aggr_idx, STAT_STALLED_CYCLES_BACK)); =20 if (cycles) { - print_metric(config, ctxp, /*color=3D*/NULL, "%7.2f ", "insn per cycle", - instructions / cycles); + print_metric(config, ctxp, METRIC_THRESHOLD_UNKNOWN, "%7.2f ", + "insn per cycle", instructions / cycles); } else { - print_metric(config, ctxp, /*color=3D*/NULL, /*fmt=3D*/NULL, "insn per c= ycle", 0); + print_metric(config, ctxp, METRIC_THRESHOLD_UNKNOWN, /*fmt=3D*/NULL, + "insn per cycle", 0); } - if (max_stalled && instructions) { out->new_line(config, ctxp); - print_metric(config, ctxp, /*color=3D*/NULL, "%7.2f ", "stalled cycles p= er insn", - max_stalled / instructions); + print_metric(config, ctxp, METRIC_THRESHOLD_UNKNOWN, "%7.2f ", + "stalled cycles per insn", max_stalled / instructions); } } =20 @@ -346,9 +342,11 @@ static void print_cycles(struct perf_stat_config *conf= ig, if (cycles && nsecs) { double ratio =3D cycles / nsecs; =20 - out->print_metric(config, out->ctx, /*color=3D*/NULL, "%8.3f", "GHz", ra= tio); + out->print_metric(config, out->ctx, METRIC_THRESHOLD_UNKNOWN, "%8.3f", + "GHz", ratio); } else { - out->print_metric(config, out->ctx, /*color=3D*/NULL, /*fmt=3D*/NULL, "G= Hz", 0); + out->print_metric(config, out->ctx, METRIC_THRESHOLD_UNKNOWN, /*fmt=3D*/= NULL, + "GHz", 0); } } =20 @@ -362,10 +360,11 @@ static void print_nsecs(struct perf_stat_config *conf= ig, double wall_time =3D avg_stats(&walltime_nsecs_stats); =20 if (wall_time) { - print_metric(config, ctxp, /*color=3D*/NULL, "%8.3f", "CPUs utilized", + print_metric(config, ctxp, METRIC_THRESHOLD_UNKNOWN, "%8.3f", "CPUs util= ized", nsecs / (wall_time * evsel->scale)); } else { - print_metric(config, ctxp, /*color=3D*/NULL, /*fmt=3D*/NULL, "CPUs utili= zed", 0); + print_metric(config, ctxp, METRIC_THRESHOLD_UNKNOWN, /*fmt=3D*/NULL, + "CPUs utilized", 0); } } =20 @@ -490,7 +489,7 @@ static void generic_metric(struct perf_stat_config *con= fig, double ratio, scale, threshold; int i; void *ctxp =3D out->ctx; - const char *color =3D NULL; + enum metric_threshold_classify thresh =3D METRIC_THRESHOLD_UNKNOWN; =20 pctx =3D expr__ctx_new(); if (!pctx) @@ -513,8 +512,8 @@ static void generic_metric(struct perf_stat_config *con= fig, if (metric_threshold && expr__parse(&threshold, pctx, metric_threshold) =3D=3D 0 && !isnan(threshold)) { - color =3D fpclassify(threshold) =3D=3D FP_ZERO - ? PERF_COLOR_GREEN : PERF_COLOR_RED; + thresh =3D fpclassify(threshold) =3D=3D FP_ZERO + ? METRIC_THRESHOLD_GOOD : METRIC_THRESHOLD_BAD; } =20 if (metric_unit && metric_name) { @@ -529,22 +528,22 @@ static void generic_metric(struct perf_stat_config *c= onfig, scnprintf(metric_bf, sizeof(metric_bf), "%s %s", unit, metric_name); =20 - print_metric(config, ctxp, color, "%8.1f", + print_metric(config, ctxp, thresh, "%8.1f", metric_bf, ratio); } else { - print_metric(config, ctxp, color, "%8.2f", + print_metric(config, ctxp, thresh, "%8.2f", metric_name ? metric_name : out->force_header ? evsel->name : "", ratio); } } else { - print_metric(config, ctxp, color, /*fmt=3D*/NULL, + print_metric(config, ctxp, thresh, /*fmt=3D*/NULL, out->force_header ? (metric_name ?: evsel->name) : "", 0); } } else { - print_metric(config, ctxp, color, /*fmt=3D*/NULL, + print_metric(config, ctxp, thresh, /*fmt=3D*/NULL, out->force_header ? (metric_name ?: evsel->name) : "", 0); } @@ -715,7 +714,7 @@ void perf_stat__print_shadow_stats(struct perf_stat_con= fig *config, =20 if (unit !=3D ' ') snprintf(unit_buf, sizeof(unit_buf), "%c/sec", unit); - print_metric(config, ctxp, /*color=3D*/NULL, "%8.3f", + print_metric(config, ctxp, METRIC_THRESHOLD_UNKNOWN, "%8.3f", unit_buf, ratio); } else { num =3D 0; @@ -726,8 +725,10 @@ void perf_stat__print_shadow_stats(struct perf_stat_co= nfig *config, perf_stat__print_shadow_stats_metricgroup(config, evsel, aggr_idx, &num, NULL, out, metric_events); =20 - if (num =3D=3D 0) - print_metric(config, ctxp, /*color=3D*/NULL, /*fmt=3D*/NULL, /*unit=3D*/= NULL, 0); + if (num =3D=3D 0) { + print_metric(config, ctxp, METRIC_THRESHOLD_UNKNOWN, + /*fmt=3D*/NULL, /*unit=3D*/NULL, 0); + } } =20 /** diff --git a/tools/perf/util/stat.h b/tools/perf/util/stat.h index a5f3d7d00101..6f8cff3cd39a 100644 --- a/tools/perf/util/stat.h +++ b/tools/perf/util/stat.h @@ -154,8 +154,18 @@ struct evlist; extern struct stats walltime_nsecs_stats; extern struct rusage_stats ru_stats; =20 +enum metric_threshold_classify { + METRIC_THRESHOLD_UNKNOWN, + METRIC_THRESHOLD_BAD, + METRIC_THRESHOLD_NEARLY_BAD, + METRIC_THRESHOLD_LESS_GOOD, + METRIC_THRESHOLD_GOOD, +}; +const char *metric_threshold_classify__color(enum metric_threshold_classif= y thresh); + typedef void (*print_metric_t)(struct perf_stat_config *config, - void *ctx, const char *color, + void *ctx, + enum metric_threshold_classify thresh, const char *fmt, const char *unit, double val); --=20 2.47.0.rc1.288.g06298d1525-goog From nobody Wed Nov 27 13:04:20 2024 Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 93BFB18D622 for ; Thu, 10 Oct 2024 01:21:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728523314; cv=none; b=ZcOLDFvfYZ9JPDQw4oREiSQxnttVhsTWrW3wrsgrUa9qLbq1OEc9lHM8MbkRFYbot80vrL2XfPv+qerJJ5sjKMLQ7i9W8bgoA5RZb1rOfjYp1X8OCnuElAtRcfAEARtukn+CLL1LZ3jAuIfNB3Asu1KpWoLg2YlpneLS9hSAqYk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728523314; c=relaxed/simple; bh=i2P8XZ8C8+KW3cQpvcq8swJ4pl42rq2Dmo38yCruSj4=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=BFus9VleCSk5WmvRKpGH/gnOTnot8Y0uJRP0uovZoRFBJXFKIuBychVQyw05cNKOtlE9Ena6NSOxap/6d4yLZlHGTAPbCYMp8hgv+Dxr7Ow+R7LqZwTRJf5C1JQNmmXPrURNTaKX1nVa4EUawYrA461S5r4TNJIqaYsUXsqB6+s= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=2MqcNIIv; arc=none smtp.client-ip=209.85.128.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="2MqcNIIv" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-6e32f43c797so4411087b3.1 for ; Wed, 09 Oct 2024 18:21:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1728523311; x=1729128111; darn=vger.kernel.org; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=SY35F8wtXf7s51KAxRJvlRRZZ0EtgMGdYbZDGjNC5K4=; b=2MqcNIIvcaOaQY4s01zoYGqfyN2PCWclfuRgcVDYk+tEVZSbV+5PgSw8ukd+v5LKrI NIVwZUKs9JQz+R/dZpi9JvPdWI32mW1+27LgCK7rRpr1BhvkxVfc62Su3Y66gL1yn6b5 OIz84H5QZj6GtDtXYMSeYCL74q7mm02xonDPodE+oDJyL/BV+FA+1q3qU2SQt/So/ipw bjbYDw3zetdptbi132+0G9cfEgGEQCBRQbyNz1v83C7/nVk3qMwHZAwMkmhjLtj61d8N GFIyZgvPTvnsgNORKIdKwOnxTjqfsa634fMBReNkUzUeP0ALJzJlA/PF4lu00nfl7Z6I +XqQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728523311; x=1729128111; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=SY35F8wtXf7s51KAxRJvlRRZZ0EtgMGdYbZDGjNC5K4=; b=ePKO4ERsxNe5l474Cha6nD1YYFrdFc295Mk76PLvN2As1WaMFJrrOjSjb/JpbbhgJ2 MFBuZEbPOjqEi8SRSyW////4W757uk8PQz51QcMZ/01YGqa8/IVE8hKoiBp34/lKi6gU oWjp3bG0S+r4BJcsPAs16WZbWTi+esIJrKd/8anUF5/ekLEJ5f9Q/xTwB3IVIYX88IMA nj2fdP2JI8UfLdhooKoxS51qJo8XwluGJX7D+SP531NPEsGtFpPMMFMxY4uAyOoQb7YH AP+G2/JcCRbj6Z4hNEMiwywCjzr1RzPjq7mCbVgDn2ozs4n7kdXQ/j2XHnO6s0GLCJIj Oa/g== X-Forwarded-Encrypted: i=1; AJvYcCWlsRfvvW6P0mrIus3y38wFszJg6IhNGXqivDuqQtqIuo4kmptFLbHMQImdcRKF1ZehNzMdFPk8opk+0tQ=@vger.kernel.org X-Gm-Message-State: AOJu0Ywe+noKK/pgmdLFa5jpLLX8lbAlAJKIOmvngoC5hBUfuev0PqL3 eE9EBtubIMk9BOxz4Xu2mIvuoceWh3z/kYL72GH0jKeChKHNEgMZ6h5rcAvlcfWtEs4C1Hx7DS0 hwooCEw== X-Google-Smtp-Source: AGHT+IEo+AhmVuRPXxAJrGcC75p7O4MsBrjj0rLuyL4dmA0Lwz++Jrcl9Ca9RTVSl405V6qIiOQYsSFnikKX X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:6c8b:1170:a0ca:9d72]) (user=irogers job=sendgmr) by 2002:a05:690c:20a0:b0:6da:3596:21b8 with SMTP id 00721157ae682-6e32f32d904mr310327b3.4.1728523311622; Wed, 09 Oct 2024 18:21:51 -0700 (PDT) Date: Wed, 9 Oct 2024 18:21:32 -0700 In-Reply-To: <20241010012135.1272535-1-irogers@google.com> Message-Id: <20241010012135.1272535-7-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241010012135.1272535-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.rc1.288.g06298d1525-goog Subject: [PATCH v2 6/8] perf stat: Display metric threshold value in CSV output From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , John Garry , Will Deacon , James Clark , Mike Leach , Leo Yan , Yicong Yang , Weilin Wang , Tim Chen , Thomas Richter , Sumanth Korikkar , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add a column with a metric threshold value. For example, the bad/good in the last column below: ``` $ perf stat -a -M topdownl1 -x, -I 1000 1.000103288,4677067630,,TOPDOWN.SLOTS,16029302700,100.00,31.1,% tma_backen= d_bound,bad 1.000103288,,,,,,51.0,% tma_frontend_bound,bad 1.000103288,,,,,,7.6,% tma_bad_speculation,good 1.000103288,,,,,,10.2,% tma_retiring,good 1.000103288,476781750,,topdown-retiring,16029302700,100.00,, 1.000103288,2389693619,,topdown-fe-bound,16029302700,100.00,, 1.000103288,1431602465,,topdown-be-bound,16029302700,100.00,, 1.000103288,378991388,,topdown-bad-spec,16029302700,100.00,, 1.000103288,4934535,,INT_MISC.CLEARS_COUNT,16029339890,100.00,, 1.000103288,56474476,,IDQ.MS_UOPS,16029292873,100.00,, 1.000103288,3188888,,INT_MISC.UOP_DROPPING,16029239908,100.00,, 1.000103288,484429099,,UOPS_RETIRED.SLOTS,16029176080,100.00,, 1.000103288,49066178,,UOPS_DECODED.DEC0,16029100912,100.00,, 1.000103288,26472844,,cpu/UOPS_DECODED.DEC0,cmask=3D1/,16029009707,100.00,, 1.000103288,709313662,,UOPS_ISSUED.ANY,16028914990,100.00,, 1.000103288,346833383,,IDQ.MITE_UOPS,16028820330,100.00,, ``` Signed-off-by: Ian Rogers --- tools/perf/Documentation/perf-stat.txt | 1 + tools/perf/tests/shell/stat+csv_output.sh | 24 ++++++++++---------- tools/perf/util/stat-display.c | 27 +++++++++++++++++++---- 3 files changed, 36 insertions(+), 16 deletions(-) diff --git a/tools/perf/Documentation/perf-stat.txt b/tools/perf/Documentat= ion/perf-stat.txt index 2bc063672486..9bfa1a085e98 100644 --- a/tools/perf/Documentation/perf-stat.txt +++ b/tools/perf/Documentation/perf-stat.txt @@ -622,6 +622,7 @@ The fields are in this order: - optional variance if multiple values are collected with -r - optional metric value - optional unit of metric + - optional how the value relates to a metric threshold =20 Additional metrics may be printed with all earlier fields being empty. =20 diff --git a/tools/perf/tests/shell/stat+csv_output.sh b/tools/perf/tests/s= hell/stat+csv_output.sh index fc2d8cc6e5e0..a3bc3c99b534 100755 --- a/tools/perf/tests/shell/stat+csv_output.sh +++ b/tools/perf/tests/shell/stat+csv_output.sh @@ -31,19 +31,19 @@ function commachecker() local exp=3D0 =20 case "$1" - in "--no-args") exp=3D6 - ;; "--system-wide") exp=3D6 - ;; "--event") exp=3D6 - ;; "--interval") exp=3D7 + in "--no-args") exp=3D7 + ;; "--system-wide") exp=3D7 + ;; "--event") exp=3D7 + ;; "--interval") exp=3D8 ;; "--per-thread") exp=3D7 - ;; "--system-wide-no-aggr") exp=3D7 - [ "$(uname -m)" =3D "s390x" ] && exp=3D'^[6-7]$' - ;; "--per-core") exp=3D8 - ;; "--per-socket") exp=3D8 - ;; "--per-node") exp=3D8 - ;; "--per-die") exp=3D8 - ;; "--per-cluster") exp=3D8 - ;; "--per-cache") exp=3D8 + ;; "--system-wide-no-aggr") exp=3D8 + [ "$(uname -m)" =3D "s390x" ] && exp=3D'^[7-8]$' + ;; "--per-core") exp=3D9 + ;; "--per-socket") exp=3D9 + ;; "--per-node") exp=3D9 + ;; "--per-die") exp=3D9 + ;; "--per-cluster") exp=3D9 + ;; "--per-cache") exp=3D9 esac =20 while read line diff --git a/tools/perf/util/stat-display.c b/tools/perf/util/stat-display.c index 7d42f22cd5f8..5b5923730a7b 100644 --- a/tools/perf/util/stat-display.c +++ b/tools/perf/util/stat-display.c @@ -85,6 +85,19 @@ const char *metric_threshold_classify__color(enum metric= _threshold_classify thre return colors[thresh]; } =20 +static const char *metric_threshold_classify__str(enum metric_threshold_cl= assify thresh) +{ + const char * const strs[] =3D { + "unknown", + "bad", + "nearly bad", + "less good", + "good", + }; + static_assert(ARRAY_SIZE(strs) - 1 =3D=3D METRIC_THRESHOLD_GOOD, "missin= g enum value"); + return strs[thresh]; +} + static void print_running_std(struct perf_stat_config *config, u64 run, u6= 4 ena) { if (run !=3D ena) @@ -454,14 +467,15 @@ static void new_line_csv(struct perf_stat_config *con= fig, void *ctx) fputs(config->csv_sep, os->fh); } =20 -static void print_metric_csv(struct perf_stat_config *config __maybe_unuse= d, +static void print_metric_csv(struct perf_stat_config *config, void *ctx, - enum metric_threshold_classify thresh __maybe_unused, + enum metric_threshold_classify thresh, const char *fmt, const char *unit, double val) { struct outstate *os =3D ctx; FILE *out =3D os->fh; char buf[64], *vals, *ends; + const char *thresh_str =3D ""; =20 if (unit =3D=3D NULL || fmt =3D=3D NULL) { fprintf(out, "%s%s", config->csv_sep, config->csv_sep); @@ -472,7 +486,12 @@ static void print_metric_csv(struct perf_stat_config *= config __maybe_unused, while (isdigit(*ends) || *ends =3D=3D '.') ends++; *ends =3D 0; - fprintf(out, "%s%s%s%s", config->csv_sep, vals, config->csv_sep, skip_spa= ces(unit)); + if (thresh !=3D METRIC_THRESHOLD_UNKNOWN || !rblist__empty(&config->metri= c_events)) + thresh_str =3D metric_threshold_classify__str(thresh); + fprintf(out, "%s%s%s%s%s%s", + config->csv_sep, vals, + config->csv_sep, skip_spaces(unit), + config->csv_sep, thresh_str); } =20 static void print_metric_json(struct perf_stat_config *config __maybe_unus= ed, @@ -527,7 +546,7 @@ static void print_metricgroup_header_csv(struct perf_st= at_config *config, =20 for (i =3D 0; i < os->nfields; i++) fputs(config->csv_sep, os->fh); - fprintf(config->output, "%s", metricgroup_name); + fprintf(config->output, "%s%s", metricgroup_name, config->csv_sep); new_line_csv(config, ctx); } =20 --=20 2.47.0.rc1.288.g06298d1525-goog From nobody Wed Nov 27 13:04:20 2024 Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DCD2F191473 for ; Thu, 10 Oct 2024 01:21:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728523316; cv=none; b=P2w/1uw6La22r4GxqWomI+P4RYneGv39q1F3eusjs1A7embzJtkOmsZ65asbe66IB/LJ3A+F2V/Ylhjz2ffBKCOArDQfgusoVkGBVQhNrl/HQdON4koqj33LrYbIb9uVqXSnIp80r1RWu0gLzXYsT1EBq5MnCoR2fbu1Rv2X13Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728523316; c=relaxed/simple; bh=y9oDWwclikRMV44veYy4NteJ9B9046N9/nsDDXlj3AY=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=iJdFvy4eKwRypqOiT0xaNHVRKZIrDWeXQz53ZREpcYcW7u1RnQpcb24l8FkCr/LvOhUkPQG5TGjT1IBetG0LGo0A5XO/sTYDMdZ6wwjfl61Z+ncP+hFhnQZIA44bWDKjgitiTodg1v+1t8lmEYSiKOyLs6ax12DWkE+gtndzFjE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=Uk3mws3k; arc=none smtp.client-ip=209.85.219.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="Uk3mws3k" Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-e26046ed465so580575276.3 for ; Wed, 09 Oct 2024 18:21:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1728523314; x=1729128114; darn=vger.kernel.org; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=n7UO+Jwq3ZdJxz6tultIv+LNJVzpQeU7Lfk7TZbknkQ=; b=Uk3mws3kJ6xntS0O/DN++jqMvV6P5B02JOlGsWi3rXfoEpk4MN2m3ArOsNYdUJRVnN yQv6KzlTJk5aK2x7FmChIcWWfWsTjKzPTEjm76C+HlKdN7ZAzqZsJG2BMMMU4wZisVx7 hM6Oi5IL2fSGQ3bX8BmXS20wf3g2vmMW2YUFwy4omQSVCpLaLsvJ3SFVND47kibTB41n EtP11WgP1hqoLbu7GI0rVZP8pF+YqK6bDi+V6yOSrrk3OgXhaB24VxDgYW3FNFw5p9UN 7L/OQOUKEImeXN+JuYvI9IvAXtpaIODpEkq0DVCRTWoGp5ju7r0pGReyT1VeYkUrfp7L T0Uw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728523314; x=1729128114; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=n7UO+Jwq3ZdJxz6tultIv+LNJVzpQeU7Lfk7TZbknkQ=; b=k72XiH5VH/1fsTvghLtl2hYdNqYHxZS9unzjo0Q5L3WRc/8EJAhwazT7phtxzfawoq kII/Yr8c+7Y3x8rzkxCG08Hylz8J1WUMlCmxRBnHdwd8EDYXgV476PMKRI7MRdmU5BEa Ku2ZU0VdFc8gtupWVSNfgrCph0yj2jp1ugKycy9MnrADVYBL09wkd/RRFUAQNHQZEWPs cBl2f4R389csz7dEMZikuWs4abujaI+RRYtW2L7bzxmReouoBnKMJB2qMKnqGWYItpQI DBxNeBCivA3SPdsUiCy/ubRZIvVsqcZB9Fpss2Pirf6jMHccgIG6RGJJ4GGlzCyN7Jcg ZWIw== X-Forwarded-Encrypted: i=1; AJvYcCW84Lz810gzip3ZEdXD+EJjmEGwdK/rb7OUrB4aVLwXEfjtTXCXbc6EshW1lCxPf9FB+YQFIeP2ojsfCIQ=@vger.kernel.org X-Gm-Message-State: AOJu0YyufoCRQosLHshZTRwDMdLDeHsevRvuJgLDsD0nc3ibaDBy7MQM zaew+VjDrFaXFoTsY+jzHa2FUUlERukuhepjjGtleaZQB81S2hHxqvnALt5bvt3RhamGBOTfhWS 2+GRkaA== X-Google-Smtp-Source: AGHT+IH94d/FgOnQJGUCJA7UrSbuAGJUXY9x6cU/dfPnHY26ynRvGlw4Kx879HTPfkURmk14BaQfQXrnHOdX X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:6c8b:1170:a0ca:9d72]) (user=irogers job=sendgmr) by 2002:a5b:948:0:b0:e0b:958a:3344 with SMTP id 3f1490d57ef6-e28fe44cd86mr79440276.10.1728523313861; Wed, 09 Oct 2024 18:21:53 -0700 (PDT) Date: Wed, 9 Oct 2024 18:21:33 -0700 In-Reply-To: <20241010012135.1272535-1-irogers@google.com> Message-Id: <20241010012135.1272535-8-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241010012135.1272535-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.rc1.288.g06298d1525-goog Subject: [PATCH v2 7/8] perf stat: Add metric-threshold to json output From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , John Garry , Will Deacon , James Clark , Mike Leach , Leo Yan , Yicong Yang , Weilin Wang , Tim Chen , Thomas Richter , Sumanth Korikkar , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" When the threshold isn't unknown add a value to the json like: "metric-threshold" : "good" A more complete example: ``` $ perf stat -a -j -I 1000 {"interval" : 1.001089747, "counter-value" : "16045.281449", "unit" : "msec= ", "event" : "cpu-clock", "event-runtime" : 16045355135, "pcnt-running" : 1= 00.00, "metric-value" : "16.045281", "metric-unit" : "CPUs utilized"} {"interval" : 1.001089747, "counter-value" : "10003.000000", "unit" : "", "= event" : "context-switches", "event-runtime" : 16045314844, "pcnt-running" = : 100.00, "metric-value" : "623.423156", "metric-unit" : "/sec"} {"interval" : 1.001089747, "counter-value" : "328.000000", "unit" : "", "ev= ent" : "cpu-migrations", "event-runtime" : 16045321403, "pcnt-running" : 10= 0.00, "metric-value" : "20.442147", "metric-unit" : "/sec"} {"interval" : 1.001089747, "counter-value" : "20114.000000", "unit" : "", "= event" : "page-faults", "event-runtime" : 16045355927, "pcnt-running" : 100= .00, "metric-value" : "1.253577", "metric-unit" : "K/sec"} {"interval" : 1.001089747, "counter-value" : "4066679471.000000", "unit" : = "", "event" : "instructions", "event-runtime" : 16045369123, "pcnt-running"= : 100.00, "metric-value" : "1.628330", "metric-unit" : "insn per cycle"} {"interval" : 1.001089747, "counter-value" : "2497454658.000000", "unit" : = "", "event" : "cycles", "event-runtime" : 16045374810, "pcnt-running" : 100= .00, "metric-value" : "0.155650", "metric-unit" : "GHz"} {"interval" : 1.001089747, "counter-value" : "914974294.000000", "unit" : "= ", "event" : "branches", "event-runtime" : 16045379877, "pcnt-running" : 10= 0.00, "metric-value" : "57.024509", "metric-unit" : "M/sec"} {"interval" : 1.001089747, "counter-value" : "9237201.000000", "unit" : "",= "event" : "branch-misses", "event-runtime" : 16045375017, "pcnt-running" := 100.00, "metric-value" : "1.009559", "metric-unit" : "of all branches", "m= etric-threshold" : "good"} {"interval" : 1.001089747, "event-runtime" : 16045397172, "pcnt-running" : = 100.00, "metricgroup" : "TopdownL1"} {"interval" : 1.001089747, "metric-value" : "22.036686", "metric-unit" : "%= tma_backend_bound", "metric-threshold" : "bad"} {"interval" : 1.001089747, "metric-value" : "7.610161", "metric-unit" : "% = tma_bad_speculation", "metric-threshold" : "good"} {"interval" : 1.001089747, "metric-value" : "36.729687", "metric-unit" : "%= tma_frontend_bound", "metric-threshold" : "bad"} {"interval" : 1.001089747, "metric-value" : "33.623465", "metric-unit" : "%= tma_retiring"} ... ``` Signed-off-by: Ian Rogers --- tools/perf/tests/shell/lib/perf_json_output_lint.py | 5 ++++- tools/perf/util/stat-display.c | 9 +++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/tools/perf/tests/shell/lib/perf_json_output_lint.py b/tools/pe= rf/tests/shell/lib/perf_json_output_lint.py index abc1fd737782..8ddb85586131 100644 --- a/tools/perf/tests/shell/lib/perf_json_output_lint.py +++ b/tools/perf/tests/shell/lib/perf_json_output_lint.py @@ -57,6 +57,7 @@ def check_json_output(expected_items): 'interval': lambda x: isfloat(x), 'metric-unit': lambda x: True, 'metric-value': lambda x: isfloat(x), + 'metric-threshold': lambda x: x in ['unknown', 'good', 'less good', = 'nearly bad', 'bad'], 'metricgroup': lambda x: True, 'node': lambda x: True, 'pcnt-running': lambda x: isfloat(x), @@ -68,13 +69,15 @@ def check_json_output(expected_items): for item in json.loads(input): if expected_items !=3D -1: count =3D len(item) - if count !=3D expected_items and count >=3D 1 and count <=3D 6 and '= metric-value' in item: + if count !=3D expected_items and count >=3D 1 and count <=3D 7 and '= metric-value' in item: # Events that generate >1 metric may have isolated metric # values and possibly other prefixes like interval, core, # aggregate-number, or event-runtime/pcnt-running from multiplexin= g. pass elif count !=3D expected_items and count >=3D 1 and count <=3D 5 and= 'metricgroup' in item: pass + elif count =3D=3D expected_items + 1 and 'metric-threshold' in item: + pass elif count !=3D expected_items: raise RuntimeError(f'wrong number of fields. counted {count} expec= ted {expected_items}' f' in \'{item}\'') diff --git a/tools/perf/util/stat-display.c b/tools/perf/util/stat-display.c index 5b5923730a7b..f699e39abcd8 100644 --- a/tools/perf/util/stat-display.c +++ b/tools/perf/util/stat-display.c @@ -496,15 +496,20 @@ static void print_metric_csv(struct perf_stat_config = *config, =20 static void print_metric_json(struct perf_stat_config *config __maybe_unus= ed, void *ctx, - enum metric_threshold_classify thresh __maybe_unused, + enum metric_threshold_classify thresh, const char *fmt __maybe_unused, const char *unit, double val) { struct outstate *os =3D ctx; FILE *out =3D os->fh; =20 - if (unit) + if (unit) { fprintf(out, "\"metric-value\" : \"%f\", \"metric-unit\" : \"%s\"", val,= unit); + if (thresh !=3D METRIC_THRESHOLD_UNKNOWN) { + fprintf(out, ", \"metric-threshold\" : \"%s\"", + metric_threshold_classify__str(thresh)); + } + } if (!config->metric_only) fprintf(out, "}"); } --=20 2.47.0.rc1.288.g06298d1525-goog From nobody Wed Nov 27 13:04:20 2024 Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EC08A1925A3 for ; Thu, 10 Oct 2024 01:21:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728523318; cv=none; b=tCCZUwHMDQ7DfoJXsOZ4Qo01yGP1E3hQD3IKhC2baJUnICHgwP1N+1kXmh/2astd0LFKYmfkOYR/vnb4qb+lW0tsKJaPmzMuZ3MTTnZCPWzY14cuZf2Ueow2PiJce51WC3Gq2IRE0NaOVSP/9vc9YSHhXPR0+19a2ZvhQR5cvQ0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728523318; c=relaxed/simple; bh=FQo9E02Bn3mdVTp4UYBsHwuKn5WnsZDVjaQO28W85H4=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=qK3mtIMlS1Kn8uxcZLmPR/BEGeWbLau9odTCIUqGnTBEOqHJQhmFEu+xTvhureJ981NFLYGPWazITcUQmK3+1IB5AlkR2ZRyFLCqS3L+jYFNkpEp0jVZGDkTZA91FOZTiVVtBZqR2CyP52iGTbA2koV5NgRFLvc3gyw8DimfFGM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=m3b9umA4; arc=none smtp.client-ip=209.85.128.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="m3b9umA4" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-6e32e920cf6so10460267b3.2 for ; Wed, 09 Oct 2024 18:21:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1728523316; x=1729128116; darn=vger.kernel.org; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=6prvQ0QcTA2Zgvk0fmsEl8IIT0Zop3+WO9YOOT65awI=; b=m3b9umA4c7dXW/HDJs46hRd+fZvwOAru6mQiloIe5/KyFvdr/Za/fs4ntsIwoFwYgM jpP6dWSDFNFBWvArKMY0hHJuAMSTTUnvx56y6PfEhDzWesl9brhMKXu7tWuHSxFNeUkp bAnymIR/sddr5EF1GilLuHu+ZsTQTS2nCnHbqHfv3HsDORPapdNEb3Vdxu/uvYKZOcnF PeHfX2autZaEWwO8R8HnCUURM3ga5S5iFoysvjoSk0HZyRVzNWl+4KpjGmYGFjPsau3U TLtuSL0PWicXRLYRzmEY23AqGY+HzWldicnYiJ1jGCKoRiCJISFLTqYSQNLiwc+WupNO z4Mg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728523316; x=1729128116; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=6prvQ0QcTA2Zgvk0fmsEl8IIT0Zop3+WO9YOOT65awI=; b=jOylngeo8yfh1AcF3oxRjcP656JjW6Zi8FyhT2fI0L2QI8gskVhB1CFtJv3LspNI5s DG2iAM49znBupY5qmPKLMOzvZYUK+ohCLrjlxOEJBSJajbYm/LZ7BZL4FSplVi32iR18 NQay3aHz1NxEB6nA0Ow0bVGpq4oqRwOHm5KICaOrpKr4BimGNcbrV5aPZQ5S60UEKc6f p9LKINmMLZAVsoX8Qf2kpm7RQv521iE0xLrUuEr2Ni7C6cAncLd8kvGlJQ/gxMseKV1r wcAdrsvzpBiOerChF8Kl8WlEFETrZ800JkMC+ldL251ijpNaZAJGkvY11e5wP7O1lUph gjVw== X-Forwarded-Encrypted: i=1; AJvYcCXAT42IBZodiVyIEPtoIbrfne38BU96Ck0hr1mDNNA2RTrfwyIO42nC77pIEBW02a2VZTVdlWmc98foxLc=@vger.kernel.org X-Gm-Message-State: AOJu0Yz8b1AIhsR+TpOk2V19u9O2B5EexjTap3kCoUPT6Jo5qKqGO45c 3kx7szeY5G4/2jQhgPnCZlJOx3tS2qUMSsXByxuyaAV5qC7z0z8R/r8wdNiNxcThLPfIHd9hjju uzSb4xQ== X-Google-Smtp-Source: AGHT+IGl02iKtMag4kCRH9LX8ownm1gRPRF7Oeo1w0LTYkYyH4dDmIB6/0LxgIS9tAg9HLgfNYcTC1WETIps X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:6c8b:1170:a0ca:9d72]) (user=irogers job=sendgmr) by 2002:a05:690c:6681:b0:6e2:12e5:356f with SMTP id 00721157ae682-6e32215bd01mr1195137b3.3.1728523316141; Wed, 09 Oct 2024 18:21:56 -0700 (PDT) Date: Wed, 9 Oct 2024 18:21:34 -0700 In-Reply-To: <20241010012135.1272535-1-irogers@google.com> Message-Id: <20241010012135.1272535-9-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241010012135.1272535-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.rc1.288.g06298d1525-goog Subject: [PATCH v2 8/8] perf stat: Disable metric thresholds for CSV/JSON metric-only mode From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , John Garry , Will Deacon , James Clark , Mike Leach , Leo Yan , Yicong Yang , Weilin Wang , Tim Chen , Thomas Richter , Sumanth Korikkar , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" These modes don't use the threshold, so don't compute it saving time and potentially reducing events. Signed-off-by: Ian Rogers --- tools/perf/builtin-stat.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c index 3e6b9f216e80..936800c01c72 100644 --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c @@ -2560,6 +2560,14 @@ int cmd_stat(int argc, const char **argv) goto out; } =20 + if (stat_config.metric_only && (stat_config.csv_output || stat_config.jso= n_output)) { + /* + * Current metric-only CSV and JSON output doesn't display the + * metric threshold so don't compute it. + */ + stat_config.metric_no_threshold =3D true; + } + if (stat_config.walltime_run_table && stat_config.run_count <=3D 1) { fprintf(stderr, "--table is only supported with -r\n"); parse_options_usage(stat_usage, stat_options, "r", 1); --=20 2.47.0.rc1.288.g06298d1525-goog