From nobody Thu Nov 28 02:34:27 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 ABF0D1547EF for ; Fri, 4 Oct 2024 23:41:26 +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=1728085288; cv=none; b=JtXqrH1CSwU1JAwpPM0P2jcZuWsBH4pKQt0Sv66G44CiEgNDLodzQSZymrMvyMBwNPofpbz7Kq/HorUALtjkKOOu49uxJV0r0mOLq4sn3eUgPgomKNp7RqTsOU6C/g3/Z4LXCaoZk0xbzfS2ylXzvJMHy7dL4skAc3xNWee0O3I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728085288; c=relaxed/simple; bh=7YzPNdfRKmQE5AyBfLbiel6HIbKbkuhCRQOwkDiYmMs=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=S5LQrfIPmGezg5MMbrA7npeNk9RcSxlpbmSfMSk0h1YVJCrTb0MWKR6qod9bHxcpvcSZKTjfSydhvCkbif/U9yt5Kyh3+Y2bgG9msp3QNlFx2PKPc5Ld1BnFsD8ixj9slEgAqroJCmDpCfNqwYJWsqzluoS6P7Cml+E0m+QUhvk= 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=1ZY1j/ot; 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="1ZY1j/ot" Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-e0b8fa94718so3991085276.0 for ; Fri, 04 Oct 2024 16:41:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1728085286; x=1728690086; 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=OQkv9fq9wprz1BlFu3d+/+F0yxiSVkXzoaXCWnFh2GM=; b=1ZY1j/othi3Vs86Fmq0id5DA7kwh+ExOXu5og8Z35iFiSsm/gaSY2bDXv4nZjgQGZq AyTv5SfsYY+Xd8GryVV0fgcZKgeTMd76PQl2JLeNe/meYt+E9QOLvpx47+Lmk08G6zEl lzIVsYV0Jk02RYogEfuHaPFwYA8jBNHy9G8mxbYcTjwqnNikU7cnG7l/mOfNW4nlAZzv trnO+yBUj29A6S3QaUoF6REkmOLpFgPDh4FERXwczJX+SExWUP7GoiEJHKZ9fmzO4evQ i1TxbHrXhtjThjWZ9UhFV3sZm9C5FpOmCqS1t7xnYPbExry1vwJk4+sQ0fnvHwl/E2Mk fQfA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728085286; x=1728690086; 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=OQkv9fq9wprz1BlFu3d+/+F0yxiSVkXzoaXCWnFh2GM=; b=XtN4OS7eTmqpmfClFbPgn7NfP2isMFnql610YWfHmHQqSONMKLM5Sedzw5xsFEvrCk pMxoq2Az7zWqTLtNYEHi1lpBw4GgOfD89XmshsIj9zlA3kxXE999nguRQqeTzQOYpteU Xc2L9kLHqS/+GpWpTE1U+xMBS9rjGqrwckYUXcd0v8g1fo/KNsEojeD0oBRStSKnT9Sj 47dVpzF0A6VRYLfWNg/TQ8UgYwnCXwDe93TmA4vguE8sD8hnbTlvdyNyMDrVu3udXUSf PfITu6P9JTpBociYbyTp3NA/NWKS3/dSzTglHnnJxUQPp2wc1zMn+iXEaBi3/dVh/Lv6 KpcQ== X-Forwarded-Encrypted: i=1; AJvYcCVis5ifgaXjnQLBN7tXqd2DCx7fA1vW3sgGe5h3V20eA9WkpmXmhFUXOQ3NEQpF742lSifaX4bJZjp/+NM=@vger.kernel.org X-Gm-Message-State: AOJu0YzGwa9HFOGckBk2kJBg7iakQwBCgYmNEl72YB7OvahogApipHfb rk1ftxUINrxxpIktZTgaIowQ7uDE9HXbOzeRAu4AwuHtKm8NhlTaKKAvd3mHPnY7M1XKEIIMgxq lrefX7g== X-Google-Smtp-Source: AGHT+IGlEKle8bj4uC7Fk9+NrqsNKgHk2R6etU8mknZVSWapNMofmaSq9gzdVRDfZrk08YvvCqAearFgxaDA X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:8d23:e3c7:679f:19df]) (user=irogers job=sendgmr) by 2002:a25:aa72:0:b0:e17:8e4f:981a with SMTP id 3f1490d57ef6-e289395e704mr8524276.11.1728085285646; Fri, 04 Oct 2024 16:41:25 -0700 (PDT) Date: Fri, 4 Oct 2024 16:41:13 -0700 In-Reply-To: <20241004234120.1495209-1-irogers@google.com> Message-Id: <20241004234120.1495209-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: <20241004234120.1495209-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.rc0.187.ge670bccf7e-goog Subject: [PATCH v1 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 Acked-by: Namhyung Kim --- 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 f6e847529073..c16023bc5553 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 138ffc71b32d..edd93450cafd 100644 --- a/tools/perf/util/arm-spe.c +++ b/tools/perf/util/arm-spe.c @@ -118,7 +118,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.rc0.187.ge670bccf7e-goog From nobody Thu Nov 28 02:34:27 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 0AEDA1553AB for ; Fri, 4 Oct 2024 23:41:28 +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=1728085290; cv=none; b=nghzZXg0CWM2O5lXs7d7NYMqlEwfEhMBl0JjZ0eCFuMku6DTjYm4wja2DYvUjJE8oVKGdXSuOY+XFj1qLXc/OixMbd0Kxvs+DfcWJzYTayvlzkR+MqthD3/aajVh/kLJOEu+STvKO5n+vKpphgrJIT7XiwKWxOMOJf17iY6+7qo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728085290; c=relaxed/simple; bh=LvLeqWxdA2TeKOaDt4auOtFHYmifqW5hHzjxgLb+wnk=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=fvLVFLGcaLmA+YL4yUJW2VY8bMOxRwVtS4GZfJ1ojFo/s/avAUzQ8dKDQb+NzFyWoul2VQInBqcBBEKgcdKXPlayfbwf9S9cw/hB1dIv0X5Yi0ZpE+yqCWODBNUVsg0E348jqs4wMVkoyBZM9qnWKc5dBFI/DzotOi5MNC+sks0= 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=D8cCcljZ; 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="D8cCcljZ" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-6e26ba37314so41994687b3.0 for ; Fri, 04 Oct 2024 16:41:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1728085288; x=1728690088; 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=A6CcUNAGP79XtjWuaAPJ4OrijNFqcGuc6YFaoXPXPNs=; b=D8cCcljZtKRLLHmas+tud6Ndo+kDepmj+wMKt05ZgcUA2BLD/R5ks/Y5tHkplX9sEU viIJ4X/KNCnNe0/c5b3oFbe0RwAL/k5AOZjg82uuKFOM+8l8Jl1EE7GBeLBWeawViqV7 R/YQWPIiiGAQ5nCaF6iXLO/fjSyJt3T35fO9ybrGooFtMK2Ew/J1DzcK+IlZMzjSfQxG z4F/nyczaaFkhStKgs3Wcy/ForEKv2NObqbygXqRthxnbUelXWBSuFOaoPz2UpR1iFWf MiyKuWbe4+yf28PB/3Ep2DY7Aq9anVzXSJ5l5Rz0stkyVDNIwyxUuJOp/6pk7/HiVkjT 6wYw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728085288; x=1728690088; 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=A6CcUNAGP79XtjWuaAPJ4OrijNFqcGuc6YFaoXPXPNs=; b=Nzolv4AVJxYrCfPA9mvBt7QSdR3+VLm4hxXlmxc0IOi9r0nIYfOgjHNW8hYruwadEW VTRpIoqpz8yh2uF9kDbJVQXHnW1HIVHr2qmoygx62ho9BlDaYHufSnF7hlIa1Pxup2d4 raQhFj++Moj17hQLjm4JUyCBhFbB623c7o3EKnANvCkWzWjzofqb7w2xTRSBIc1JY0AZ P8Evt5g1S03sjnQBDxfbv+wP/ZcInmPyR1uj275sqomNv0yT83miCWRuif67siyrscc5 TtSFUqjEGamYUA62+9gftFmPwuYf0Wof7xL+LSs4byopmMZMB0figBR7PWxUlHRmgpCu EDpA== X-Forwarded-Encrypted: i=1; AJvYcCUssaQ6xLzHenzUc4uooSleO0fU/A0f1hgaZIoZUbyBYCHq+ZG6OTd2HfOrcoU8crIAt+NDXVMQcVpBU7E=@vger.kernel.org X-Gm-Message-State: AOJu0YzO7gTDXV1EWNoJ0Cw4jHocDum5ZjZ4roqqMeJejjc+Xt2otypN 5YRn9G9/WxKaXiP3YCe8TXuZ8mpkgqFzLI1BPH3/yM7J3WOmCsWHNfFh2ife2tyYB1ecEiLWpD8 wL/EOvQ== X-Google-Smtp-Source: AGHT+IFqw6htDoHPrP52f8AD6FsGc60YnuQl8LA6+s9ft64QucdGHglRTtYEDtHIDvGu9pa6YkRbuCsaTeHC X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:8d23:e3c7:679f:19df]) (user=irogers job=sendgmr) by 2002:a05:690c:6686:b0:6db:da20:fa12 with SMTP id 00721157ae682-6e2c6e90bb5mr215817b3.0.1728085287901; Fri, 04 Oct 2024 16:41:27 -0700 (PDT) Date: Fri, 4 Oct 2024 16:41:14 -0700 In-Reply-To: <20241004234120.1495209-1-irogers@google.com> Message-Id: <20241004234120.1495209-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: <20241004234120.1495209-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.rc0.187.ge670bccf7e-goog Subject: [PATCH v1 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 Acked-by: Namhyung Kim --- 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.rc0.187.ge670bccf7e-goog From nobody Thu Nov 28 02:34:27 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 1569215572E for ; Fri, 4 Oct 2024 23:41:31 +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=1728085292; cv=none; b=mAGo7qj2KBphqEScqpz83fDieeijvbzDUJEO5GfNtgaXQV7xgtCCvVCcrd8YqVWZv26xCqLaTe2l1vftBDMyF+vQ3DUT/sc4O5xuC5toB9VwH8k3vYrZkuA3q2NEjPO2YF0KGJRhUbVznyWyk0+CGWYIP9MDF0vaFKZMRQDr2gs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728085292; c=relaxed/simple; bh=582DRnB5Pp2nT0TmmUs1PKu6Q4ckzT+k5c03nxLaKLU=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=kbnDusnuhDwNlsnqR9j3gZ61WgByEFfAN+WIwQMPoNhWka17ywFLAWrdD3/LqplcJsxCFVdtEP9GuYOxqGvPGs5Dw4/js2+dJFaXRibUOhXG0R6Y5OWXm2DWv4xMNE5urzGh72BTNA97eTuaSSjI5kNjU3iX4mKeA+61HT68xPs= 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=KsUjdMx7; 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="KsUjdMx7" Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-e288a73e967so3028264276.1 for ; Fri, 04 Oct 2024 16:41:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1728085290; x=1728690090; 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=FKmYAtBHo12nlkSZDOvO0LdX2ud+8CKD/pmfUApXbfo=; b=KsUjdMx7fWtf4NOksTLfaumdkjdkiS2dIxKe6zQmKfMbSyc0EnLR4Q/h7ZBB5oQijs zeVVnluVzDRv8Pa8Yby6jy9tNs1+5+35UisgJQ9dbAnpeVteoQdqjL14RnvQqa5vx1lt TFW8FbZwXIFLWRJHbJIZ2dGIiZ5f8W5JHMcYlRmBO9v3bcRcVJqmIea32GceEanCLSas PPSPQszjuRjJ1qwv0F3lzmPYFgC9SzeBcxceGbnN9l/QrfRfyt0ym2NJpexElfd4Yv1T 7ceZsOBv36ryjdd8esy8iDdTxOwox3cvhOiwNs19k8Ax6RHzSDuepMxmMk4Abr/DWzTd jsnw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728085290; x=1728690090; 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=FKmYAtBHo12nlkSZDOvO0LdX2ud+8CKD/pmfUApXbfo=; b=NDrqGpefdCy+CCRV0Mv6oMsmkJTQarzzUv8VcWJGPT4U8zbuPlRG3Dokf107PW2j3q 8RgCU+WNQ2Rjq8AFq7fciaD56E6vRLL4OnwVeShXncBFPSVvbrDDZu09dBRR+bQ5RPyI g/vKl3UYU0lUXZmMXEOwmgXhr+muGLv06ewOm1br/0aUoUYS9oaopG8aedBB711s4U/O oDHxHWm38L8XerIOtm1vBn1SQakGSQr6egxksMIaZFg1DZ1sA7fVudjAhbsqpnWLDr99 /9ZDOhYR/dfyG1P+CKvd4kDlIWrMv0u5ddBIvBbvbHyOVIXKZ/UNu06+GrSimWaR2r96 awPw== X-Forwarded-Encrypted: i=1; AJvYcCWzr75qdymvtWF6ECKi/FvA6YIHvdGlvuwEbxjT5xyeWBVwMEZDS28yLoOwW/53pvnDwC8D0y/Hgz0V7C4=@vger.kernel.org X-Gm-Message-State: AOJu0YxbYyw9yopDflR7X9ZXK0MT3lMr0ZZU3AGU1DGRh342qEjeJnwf 65NHrZXckifvjM1kYVUpRLjntJF8QCEWh5gj8VxfK3gtwb2rwbVvldlyI4DlX+N7WUChr92zgRb R6wUjGA== X-Google-Smtp-Source: AGHT+IFIP1vxomIUR1izckKXkT0KBqdFIx8rKTHDFttFm5UhBt8Cz3r+IBAR/Uuku6pVTLADgrA8Md0dEdz5 X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:8d23:e3c7:679f:19df]) (user=irogers job=sendgmr) by 2002:a25:ce88:0:b0:e25:d596:4847 with SMTP id 3f1490d57ef6-e28939190b5mr10441276.6.1728085290158; Fri, 04 Oct 2024 16:41:30 -0700 (PDT) Date: Fri, 4 Oct 2024 16:41:15 -0700 In-Reply-To: <20241004234120.1495209-1-irogers@google.com> Message-Id: <20241004234120.1495209-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: <20241004234120.1495209-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.rc0.187.ge670bccf7e-goog Subject: [PATCH v1 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 Acked-by: Namhyung Kim --- 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.rc0.187.ge670bccf7e-goog From nobody Thu Nov 28 02:34:27 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 86F33158A30 for ; Fri, 4 Oct 2024 23:41:33 +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=1728085295; cv=none; b=uCPousA49OiWZ1gOL/+nzWuwuHC/7aeebZAPLTQwsrjMJgD9eAmPLxilugJzV68I7z/iiHUPc9S/eOqUROlokfU7cqwHG2iWRUGF0VImQqqjdCGvkLj9ncjMDCuBNfhtHBiqkSLITwxjprMtmf8Dv+kqFfohPy2oTXlWA7d+W9M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728085295; c=relaxed/simple; bh=WH6U5UKcSxKz080nFhPzA6BhGHtiiakcmSbMwKhmscg=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=cEf73c1Nqr9dK8Iu7eBmG7EgrCuTxX6UVW49q20/0UVuzNFiAxN/Mk1L0kgiRmiYz1vFVst4eqqg0pEFn5mjtIqpQNPzFPA6w5Hk8ZBmJsA7P1FCshyTHdSl/VqE2ovRNzpofSQOZX6Eu9ip5aiVEFaPJxZEYMWcdl//lD97dFE= 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=vPrmzqT0; 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="vPrmzqT0" Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-e25ea440729so4118362276.0 for ; Fri, 04 Oct 2024 16:41:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1728085293; x=1728690093; 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=JbHvBR/EzAqjLypHxbH5hOAD+Tff2Cbq3GElgEXpZ6I=; b=vPrmzqT0DMXQTv2hokqIuAxiwMTUWb3vr1SsUTyRyZgBti4/SiEv1rg9BAn2cOUPLn pE3QQaNWr+gRBzaj8xlBPfWSQpRieXD5ygKYrQwjaZ9Jd/6wmCHAtaRSEfJh9+t10SJ+ tm2hiCatqyYgOF3Swa4/HPAxkxgtJh5b8Vkzku2VFkYp7YajWZJw0x6VqHSfWijGt0RJ P07kiUxvWTesmQS8EGMYFDwLT8oekUB/ZKOB/E70jHVRkE5qicM7TG+Ap7HMTF6lWMGN FvksCBc9IrhoolzEe8YN9sG/DWxg4AeTR443pun/HubifWOhSO2MFhr+bhAdTKoSkmkd 4nLg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728085293; x=1728690093; 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=JbHvBR/EzAqjLypHxbH5hOAD+Tff2Cbq3GElgEXpZ6I=; b=lSMHU1i++w3dFFvwXCC/xUHjxcQD4N+Oc0iuTKPG7duCiMSj0ziUiQNSJGkD+8NQOh eupHxX/45YLR1TjGVpXnFiqksYVKuP6nsyfSQrE4oEXTRb3FQS3m/uzNRNrYkHmd/sH8 MNZKKVcKMyCs5/MYIS0SvMPVOfVthP39M3CljMtw0LMy3+WMqSM2AyMmPJCqz0fWj9le lYaw0UwRSU6h+7GwDlu5uc2KeqpZuu7OmViQyE98J+YeDvu11QrJaxc9VBNLsjzHbfP0 mVXs+Hjl2Il01X46fKqPrLc9MN9Lh37ZqileCfeyXNdbwYycZveqiaxKBvqpcY75AAt7 RoNw== X-Forwarded-Encrypted: i=1; AJvYcCWelfj0LochiumOcVQJxUHb94njbKOcoRMOigpRODw3koXYk1y0C/8zcClvODS0OPez9KQ0q3wzgqARyu4=@vger.kernel.org X-Gm-Message-State: AOJu0Yx+aw0XwDBb6EDNxJ0jjCycvgVak4LTmh0HXvMxJTPHOEw2+WR4 QToeQ7lkcN6yhmSsJL62OFvsucsMehRPZsH59v/RPG/6K6U0hEt4WRVACgcd5XmrBMTXkKc+Sym X76QtMg== X-Google-Smtp-Source: AGHT+IH22Jbpim2TnHZNa9RN1uITcqq/n+FuZ5urdZ2d5c5YMlnYHZNc5wFzlIOwE/NB2tBENvRcUrdAHqAL X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:8d23:e3c7:679f:19df]) (user=irogers job=sendgmr) by 2002:a25:6908:0:b0:e22:624b:aea2 with SMTP id 3f1490d57ef6-e28934fc7a7mr3438276.0.1728085292542; Fri, 04 Oct 2024 16:41:32 -0700 (PDT) Date: Fri, 4 Oct 2024 16:41:16 -0700 In-Reply-To: <20241004234120.1495209-1-irogers@google.com> Message-Id: <20241004234120.1495209-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: <20241004234120.1495209-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.rc0.187.ge670bccf7e-goog Subject: [PATCH v1 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)"} ... ``` Signed-off-by: Ian Rogers Acked-by: Namhyung Kim --- tools/perf/util/stat-display.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tools/perf/util/stat-display.c b/tools/perf/util/stat-display.c index e392ee5efb45..9b65968e37d1 100644 --- a/tools/perf/util/stat-display.c +++ b/tools/perf/util/stat-display.c @@ -470,8 +470,9 @@ 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); + fprintf(out, "\"metric-value\" : \"%f\"", val); + if (unit) + fprintf(out, ", \"metric-unit\" : \"%s\"", unit); if (!config->metric_only) fprintf(out, "}"); } --=20 2.47.0.rc0.187.ge670bccf7e-goog From nobody Thu Nov 28 02:34:27 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 5504E15956C for ; Fri, 4 Oct 2024 23:41:36 +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=1728085298; cv=none; b=DGJHNl8ZUMOWFQ24dL68jHUd+/T9ZkTXF5Uy/DW34SOIAbmV25Uis0bH0NWRCtv+x/1rwcYNp8Cw11sB10j1e1V5kq045Enz5zGYNvzm7edAsS/UxMjXiUR0iCoOVOZgwg92AYnVBOnnnnmvGUgmkyn6ASMZRmL7/aog0VgoP5E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728085298; c=relaxed/simple; bh=eAeWj+dfa09lZhT7LmiGlH7KRUiexZ7z7VtbZvIM64Y=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=MRzXd4ssLF1udX3ml9VSwA67BJDeqGVAxAR2fUNFBoj/oLEpHiaDYKFIYh7N3HsOmeCk6qYGq+OlSCs2veWNraO/vVdwAmSvaTpZFeuPxLvBHFGtT545IJYF/b1nOT260NuCWYKFE+Ighd6L/1u3y3F5I0Pw0mfo0aHxR1AZOOk= 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=PSgu/vwC; 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="PSgu/vwC" Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-e288a73e967so3028316276.1 for ; Fri, 04 Oct 2024 16:41:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1728085295; x=1728690095; 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=gCnY8Lk9xKf0rzzmE4bkdPpj0hlyaDEDE7XtDK4a/8I=; b=PSgu/vwCESTA+BUaA6FqPxtYVcNAakX8rQiUDN2HFz7kW7gCReK6HBZJ55aw/Iaupm nGAsh/7wo9MYNkEIlk9XOIG5EcPTLREHAywqcvSGR+ZaSeq7863NDvjbjaFLRpBbFiqn S5FN+qfslN47hvin2pe+n3J+KoOl5xNMexJSJ+Tv8uOTZ+DP4BepPpfzWj3w4+RNrjKt wUXpg2EeDHhR6CsLyujPvsjB8/jAAVc5p8G4PnyBDVsGVImC28CZQtIhl88gSvNzG0NJ d2k0cbl7dcRkseZpCDPuKQQDwBXZXrUaNbERpIGDhlRq7gdhhdIPrP7hKuCFGCMuZr7L VCrg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728085295; x=1728690095; 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=gCnY8Lk9xKf0rzzmE4bkdPpj0hlyaDEDE7XtDK4a/8I=; b=pTVXPHwz3TC7aojAQxbIZPGrLnuQ/bY3P7JD93ddvSeKtSIwFLwdY0Ljgp8yZ7eJud Ypg7mw6UgmVkjIcnGT9PwRYKi5p15haU6k57Tdsz0kpdgrZvPea6z8dKGtBHMUD95veH W1wf9qxfGHXzPClhKeOgXDKo8JYRRkY2i5p59gPeWqHF0pEHCpRov+kZ7XSOzG8VLV+y MzAEm7DdzJgrhUqSctyTJ3u8hX/sA+4xDA3Hx/og99Yg5cz81TUlmfbyg93wD5/urIx3 1ZGAZklEc4EKk/WFoWdNSZbBjWRZ6yMFQkjbvt894YW2MBU+S6Ji1659kpWpC93ZEfi2 hYew== X-Forwarded-Encrypted: i=1; AJvYcCXI5aD2VTZESuymJr578ApO7w1wn3R7KcvF7sVHJUjq0ETxmGBpMT9fPrut6sgrB5uGx4DR1OjEiS1vr2M=@vger.kernel.org X-Gm-Message-State: AOJu0YzwnvQnt/NhvxV3hhN/0Xdj5sIujgTytJgGjVEijIceAQ/wHq8h 2aFQjt+paiooux8GY/B7RxU4nLEhBjZEVY1qdbyFqnuphp6m6lrp/VM8FyZl7orrd2Qv4H8P2yP O2S13jw== X-Google-Smtp-Source: AGHT+IF/D1lzdKPwnfFKYHfMx8s/tVQly+6TaIflIAubFNFwvIxoIC1Khb87YvYmWJyNFDg+i72eoDzxmcl5 X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:8d23:e3c7:679f:19df]) (user=irogers job=sendgmr) by 2002:a25:ec09:0:b0:e25:cf7f:a065 with SMTP id 3f1490d57ef6-e289392aee3mr10575276.8.1728085294844; Fri, 04 Oct 2024 16:41:34 -0700 (PDT) Date: Fri, 4 Oct 2024 16:41:17 -0700 In-Reply-To: <20241004234120.1495209-1-irogers@google.com> Message-Id: <20241004234120.1495209-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: <20241004234120.1495209-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.rc0.187.ge670bccf7e-goog Subject: [PATCH v1 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 Acked-by: Namhyung Kim --- 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 9b65968e37d1..0035f92274bc 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) { @@ -559,13 +573,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; @@ -582,7 +597,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) { @@ -604,7 +620,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) { @@ -636,7 +653,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) { @@ -810,7 +828,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 @@ -865,7 +883,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.rc0.187.ge670bccf7e-goog From nobody Thu Nov 28 02:34:27 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 EBCA815ADA0 for ; Fri, 4 Oct 2024 23:41:38 +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=1728085300; cv=none; b=GpkDsiBCUWFV4T/OULVEH+EtCngYZhh0fp63R6TXU1cR+xixauiETY2QQSuyANkcO4qIei6z33LyuD0xDSVWf2jg3dx0zfRS02sStyJMd+XQk6nTNFFmLPdubhghnEkdenoiHSQOMoCpczc98DT6Yiumq1hTggMXi5WyNEIy88Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728085300; c=relaxed/simple; bh=VYOEnKfmchbdQvIZhzYMlhvDYwIaS/hGm1bHBvMut24=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=DE3UAo1ZbEas6pKD4eG6S6Ze8ZUji0N8OsMeh7K5A1kKw2IiLu8fD71fsvX8GSLXYkrb8f64DRgxJ/VrJB+W2L1P48TE9sdPNbI1fY4G55adDSBRfmtJlF/7k+OeEDn4MWcHA7bZt+Gbournuae2hrp5zz/Ts9I1ZEvUFCC3sk0= 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=4Dd1LTcl; 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="4Dd1LTcl" Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-e249fafe1ebso4488073276.2 for ; Fri, 04 Oct 2024 16:41:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1728085298; x=1728690098; 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=LSvLD9+3HnLPwJR0vN/rx0jFBJk20ekbsLHeC8gntB8=; b=4Dd1LTclqDmkQekcPalcKO10GOdY83WAknxl5QEzwiWFVyb5Vkv6iTgu29lqiteBfz 23f6iIu9ZgQ1raywhyGVAzDQtN8Cmj1FM+MH8t0dQDCsIognEKsWmUNSaMgAtAoweDwO u7ij24sDOc7rWGJHBcNkyDBY+AvVyP6OJiuHbp4m64+IPxb8IPXZvMjdjxVl/CVuYDYE vW7aLYhn80YGkPXWwsBt+pZCHeWUaDvamNB5G9XRWad768tIssmhXH72sPDTKAa0H5hY dQLIT5///ug1R3BKb/5uBhjVwhQNIhoC7wU4xGe2N4bb9/aqL5yn4xXY0OfFS+AlCzvx TP0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728085298; x=1728690098; 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=LSvLD9+3HnLPwJR0vN/rx0jFBJk20ekbsLHeC8gntB8=; b=e0667OKaXCzd7kYGdtNu9XXS84Jg1KIzRxyII/tnVjCcsjV/iVN8mLgauhHfEaJy4Y DJ4+IXG1e0eYX5Y7w0QMdWSlVo7Hkpkf2GHajQN2tk5QTkT3C5mQAjlTQQG6xqZiIv50 z/HAMiC1hDZyNQgwIcqIkDJi+88v6jDZm+7Ze4KPVN1PV5wBPXQlVQwGgkLFzV7Nq0ti 2j9EZ0mivNN78y4WDuXU0DYbQb4VkrCaohT8vHLm+8FnvgMRzoPxvzCyWodsA/U5oUqL 1Uo+9aaZ4FnfXmRoSf/XBZE/4IUsgjDsD8cF63VrnCYUpEWVQIBnpTbvhG+R/jk6sHNU zg4w== X-Forwarded-Encrypted: i=1; AJvYcCX0nsTjkgV0am1r8p/bMuV+qnr5tBuh7m3DWN+hHJ1JYj5I7VXTJ6RzUtKD30fKovYJq/DQmyZYXTd6CXg=@vger.kernel.org X-Gm-Message-State: AOJu0YyNFeGUmKvX5fsHYFWheAE+dsjfSAg1la43zbSDccRr11A0mCOv cW/U8bv46+KArvwgu62sREhGC0uwn8Ew5HSP2qdoNOh71bkLdq/qrxH7gSoLX1HceFrWJp34eqf AF0h+Og== X-Google-Smtp-Source: AGHT+IH3gdeXXLyDJ0ui/URozvG0oh/yTYpW4MAsjjReRBWr0v0dFMIrdEMOin3ucnFMSCSh1cah+fMHg2Zu X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:8d23:e3c7:679f:19df]) (user=irogers job=sendgmr) by 2002:a25:c7d2:0:b0:e20:298c:541 with SMTP id 3f1490d57ef6-e2893945553mr3027276.9.1728085297577; Fri, 04 Oct 2024 16:41:37 -0700 (PDT) Date: Fri, 4 Oct 2024 16:41:18 -0700 In-Reply-To: <20241004234120.1495209-1-irogers@google.com> Message-Id: <20241004234120.1495209-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: <20241004234120.1495209-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.rc0.187.ge670bccf7e-goog Subject: [PATCH v1 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 Acked-by: Namhyung Kim --- 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 0035f92274bc..c8f3f5a30542 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, @@ -528,7 +547,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.rc0.187.ge670bccf7e-goog From nobody Thu Nov 28 02:34:27 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 6EDDB1AAE12 for ; Fri, 4 Oct 2024 23:41:41 +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=1728085303; cv=none; b=qWGyAA9KY4odTzCvvPR9NxvyS4Ffi0jK+/HJs64AY5BW4nfzzFeWi4XgeEPHlMirmdBeSjxfufoYNavt5LfErkNW307MEIO0JxujikpCZgwpd+WiHKpntEI+czYUFYYTcBy7SYgMXzoROCLJ5hOkoWUA9aDAmMjLcCA8pvwrj4M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728085303; c=relaxed/simple; bh=zyem4zsBz6hP9z2Df4l7Ur/puwpyMUn8774w+lYc8C4=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=QbaEJ7vNwqk6M4ezJQqmSV3uxV8pftYpE/FOZ8hZ6WTZXb7kBqvf4lOxp7ryV8KvcTsQY+RVJeQAugEyWVMZCP6ChAnekF4075nF24akzBYcVxPNf/uyX/jZmEEUaBrHdExzRxN2keZlZpAYLL4P0DXPzPgWl1B/mFhYbHg2s1U= 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=sgUQP1I6; 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="sgUQP1I6" Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-e035949cc4eso4078885276.1 for ; Fri, 04 Oct 2024 16:41:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1728085300; x=1728690100; 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=QpgTzV/OIl7XVMupREkrhGZ4QI9t8yNiTS28L2B3qXg=; b=sgUQP1I664MAxnVFjQ8aHQciIH9578pA1lQSIMnoF6/xMrhprRuk2UzlevfcgH4zR1 zaeXa6hE9A/3Il8mEtti1+12mphJFVJW3ciIMidUI1qurh9p4F6/7vLtPVZN711ilJVs jXdRwXUeh6ayThH7fiViZjycJxBNsz7ETHnJrdtHjI+OoO7JbHzxlnUsdz8VI6a2gSXF /oU+hnUzlues4hVIcAeawcPa7OQiUySDQXNdH32LVj2Y7NXgnSEwAN/uP3hr/l9STFum 8TS8LjRiy9WZ9CgfPRdrC198fTNBm6DVlGnOvz8cmDC3tpSm+KStZWFQs/IEufWkElLY meBg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728085300; x=1728690100; 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=QpgTzV/OIl7XVMupREkrhGZ4QI9t8yNiTS28L2B3qXg=; b=oqqNB27c4d2scTLTdUS2kShyzxprou4q1XLSmDEXO5kdl/KQQyW6rgR65nFGKQ2PYg z5RZg69XAl6dZ5J7meyvn4LGZ5sPEmhEan8U4oJcFM4aM0NFwu++jzKUkGYZopZ7TpWp RqgeABHNK2Rw4NzapY8hC8QqYVMDWMKPNQtJRiSRmSy3g++bdhm8Vmyl84e7YPge4eGq bbtRnb3nFBfic8OmVpVVohcNGOIj+OX7fuXlKSwAw6i3Lsixg1WX0oQHfOV2C8eHIKzy NqJtlIdHRzQeBWKDcUiTlmrIBtDHBXNNs3fRAEsSji0/TIaaj7sYsnXiEKXj3zUvUbxK HLRw== X-Forwarded-Encrypted: i=1; AJvYcCUsgPiQw6WIZebxZcwSvcMTp1qaJJddg1+cIfGsKSn3ifAvY3xzvfKV8jfnwsq14uX3uytt8uz8rgDFetU=@vger.kernel.org X-Gm-Message-State: AOJu0YyrQIrAQmWHE7rYJAGmH7t0ibELJwNoIhYuu3cBZaB4HaWahGGU zD5OJYRwva/Uo4HoEwkQ2dU5FxrH11EUg6cIr/j/sT3skY1SMW2P3SG3DwN55HkYupv8+7JAdJ3 CUkxAbQ== X-Google-Smtp-Source: AGHT+IEkxqe6hc8Mhd+9jCgeyt5gzoKBHKTkvCZ4fqNrqsrjKfHSSRa/LYFnHpibk62DVvEx9cChl/EmA60l X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:8d23:e3c7:679f:19df]) (user=irogers job=sendgmr) by 2002:a25:7488:0:b0:e16:51f9:59da with SMTP id 3f1490d57ef6-e289391f800mr7051276.6.1728085300022; Fri, 04 Oct 2024 16:41:40 -0700 (PDT) Date: Fri, 4 Oct 2024 16:41:19 -0700 In-Reply-To: <20241004234120.1495209-1-irogers@google.com> Message-Id: <20241004234120.1495209-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: <20241004234120.1495209-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.rc0.187.ge670bccf7e-goog Subject: [PATCH v1 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 Acked-by: Namhyung Kim --- tools/perf/tests/shell/lib/perf_json_output_lint.py | 5 ++++- tools/perf/util/stat-display.c | 6 +++++- 2 files changed, 9 insertions(+), 2 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 c8f3f5a30542..b897dc3c54d3 100644 --- a/tools/perf/util/stat-display.c +++ b/tools/perf/util/stat-display.c @@ -496,7 +496,7 @@ static void print_metric_csv(struct perf_stat_config *c= onfig, =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) { @@ -506,6 +506,10 @@ static void print_metric_json(struct perf_stat_config = *config __maybe_unused, fprintf(out, "\"metric-value\" : \"%f\"", val); if (unit) fprintf(out, ", \"metric-unit\" : \"%s\"", 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.rc0.187.ge670bccf7e-goog From nobody Thu Nov 28 02:34:27 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 0DB001B4F18 for ; Fri, 4 Oct 2024 23:41:42 +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=1728085304; cv=none; b=cbaDb99B4dXOB+WTWLndyrt5OD1JxfWQKPjlvdBOMGOzMYPKb5XYoxhP/BG/SUoQ1Zzaqfxv5R/Kshtx8nDnEtONPzj+cINMATDEqjZtromxeQa4rRdTkV/r2g7hZAEdOFefDY2a+GYZ7Pd/aWIZErA82thUhnFCi6MqXxYFSJs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728085304; c=relaxed/simple; bh=/EG7+O6Y5sI1sqJ9JCrlN0rHuPRE3RnaTN8M5JC+X/s=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=C3rPc5ADRpdSeZG4Y0h7tgoADvbBsEUwcQAta8sqHQmFS+pzrsSwy/69SrTrMV+TMK6MNJEUzt3qPiiINGzH/8WG/YGqKtVDayJNh6G71kpsz2SYl0OL0IWGioyQcebzgVh/wTGZQcN6rw8VTwaPLBh1P2STVFBBf5gGdN9naJM= 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=OK1547E9; 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="OK1547E9" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-6db791c42e3so38961197b3.1 for ; Fri, 04 Oct 2024 16:41:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1728085302; x=1728690102; 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=Htru2Ya5IP3NbTe9LfBJEaUggdoz7+W4SDsNaFUqUv8=; b=OK1547E95ij7pBJQiVeOvbylIS5wdJ3gDamK+V9oHSZ9rsXDvm+vcanYufpFkD7TlY vN0T9syH7IfR1R9+WcchNtV/oXuPodZE1nD4SjUE8EJh6NZNiPNnaVqdwcC1n5nEzkhM lnMv5yE9+33Yi3z57ClA+Q7SMrOfB3vEl2WSQe1tNDFz66i7FN6GZKHTq/Z9o8L/ggEw Yd3nPe/zh58KB9kDzXh92HTLn6XaV05H2Km9Ru3VSdqOLAtaa+lkpLNh9/D3EBKg32bD emSznUT6EJ0EColU8b81O37g4qa5q0+LX1qC3z/KSW8UluU9ptNigAefstA6Sbfrrf5N HsMw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728085302; x=1728690102; 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=Htru2Ya5IP3NbTe9LfBJEaUggdoz7+W4SDsNaFUqUv8=; b=eIFgnUFTZqHNMSFlU5fo1fajnuHhK2txJM5RqXSsAtaMiHsZTBouQZLGZ4r5BBLUyy ZLWj9FZUxNuVFs146oL0LtQ71BH0pDPm5t6SNjOFw99qJmcuqnR3+3pdjylo6BCCN6uF 3ionbXVQ3t2WKDEjhnwrzkjTtCuEqDHomQsp7DtrV5YOpGE40b/apThcqEhEe67ez9jV hbY2mwrlhNvZe1x8f1lws/ZfH9ced9Ry1fUPq5il/5ukIMyKF76unlgjDs0u/w/WGFFO vK8+ZJMa7s6cje6TPVdxqUraz80FzciSf+it4xHEqy0LzyXgp2Z5pMfSIJvEg+z63qRu 3Qgw== X-Forwarded-Encrypted: i=1; AJvYcCWAryqBrts/u2zk2qqFlTPWE7PI3jOptHMnT/qYR8bbqbNw0HkSJ56IGwV/MrpTOnckH9sOkvrftWGjwtU=@vger.kernel.org X-Gm-Message-State: AOJu0YzotMzSaWRAh5Pg7OKHXo/8zI14tSWA2+lNwJFSbOYyEdU2AZwY Pmyrm35SOK+vr8jiW8S6vmahGIG1GZqAGlGe/lfXtxs3XlFwmXO6AhB/2tgdhMkXz2N0xA145eU bAMYvEg== X-Google-Smtp-Source: AGHT+IGn6EqBSWKYjPESqwVXd7FRY2h0IBlixSFdyZwjmp6nCTeyU5aGOeNbDZK2kjK0BzmIwzspzqBUa+VL X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:8d23:e3c7:679f:19df]) (user=irogers job=sendgmr) by 2002:a05:690c:2d83:b0:6e0:1ad:b197 with SMTP id 00721157ae682-6e2c728ffa8mr430617b3.3.1728085302109; Fri, 04 Oct 2024 16:41:42 -0700 (PDT) Date: Fri, 4 Oct 2024 16:41:20 -0700 In-Reply-To: <20241004234120.1495209-1-irogers@google.com> Message-Id: <20241004234120.1495209-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: <20241004234120.1495209-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.rc0.187.ge670bccf7e-goog Subject: [PATCH v1 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 Acked-by: Namhyung Kim --- 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.rc0.187.ge670bccf7e-goog