From nobody Tue Nov 26 17:19:29 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 68CDF1D31B6 for ; Wed, 16 Oct 2024 21:51:56 +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=1729115518; cv=none; b=utf2Bl7KK1T0Z/GW4hSUOMOwWvY+N72pK7SHq0hcAfLJW2vFnPX36CKwjW8/E1nLdhG1Z5oROAOATuDaRF8W9P0WfOzDs58LmuraGEwWsF2ypBcBKJW7YkTljBcUOaPDbSM4wXs8+EWt3TXYEBBhEbCtjWMG0E4Lhmel069FVIw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729115518; c=relaxed/simple; bh=hIfcHkHzDrh7Kl0V0epeaWp/DUbuxIY5GC52UGsnaoo=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=q1RVsZFMsN4lcM+UwVtkPVopyfiYavI20MPVPxL8CN+vWvypgdq0RI3puJCEeVDVJ6G7rKDt7ZL+tz1570qUsyvn2DQezNR5+7cNeeJDGDMDj1ylw4HIz0lhwKVXCgZmBd7zopDAj1HEuMwe1n54DtJdsQqth0hqKwwDTX5eJKA= 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=d0d19/7T; 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="d0d19/7T" Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-e29716957d9so503684276.1 for ; Wed, 16 Oct 2024 14:51:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1729115515; x=1729720315; 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=kkjT0g4MiHoVVvClTypMTgAC9u7lo6APGb+q2prEWZ0=; b=d0d19/7TvWIxb2a2C+OjFq5BL6tCB+IAstfl67mlIppR8wtE9qm95ULYooJRJH2U2N fGJHpLAL7Keonp9u4flDYMuJQrfOUqzz0Gg9jNj4HfmhBrFquaFpr76GhWTo1arohw84 FhKorVIMSnf96hiXpRfSsTWOgmkq5e5exbGLNlfVzP/5P6QLM1JvdNISjKUCBoNiiOl2 XpsVPXaBM4GqYScCd4N/rfekmVrT1h4gVEbOUXUavH7IV3enVkrEA/TRI1EnspyR7fHw DIc514PqSy3/PLoSdVs26Ort+d3yQ0MgZ39TZamBMw2UI6Y4u26dadYgkuS3syWae/sr oXsg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729115515; x=1729720315; 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=kkjT0g4MiHoVVvClTypMTgAC9u7lo6APGb+q2prEWZ0=; b=jc7FRi5zTp4wETN+P1qjKid8fEvZrdeJXcfO0JhI5zs/7J0wfiG7Sima0bMqar5xtj nTysS1819woLAWYxKaQ6H80wgCzcB0G/9g+RhVd2rJXsefrS9BNv2sln/ic/JNHHjTsH o03MxRUQpImRRT5+p+evAcqk0nQ4M0ApCe+tzAg8ezUuvR3JILVdvPggv3pers7PaM+5 7nKlx0/lSM1vE2hIHh6FNTKTzoomwEr3yLXcDe9vKx5tLnFB9UJBObcO0Nvwkt+hvcL7 IWAg+r6pmVYfHqLtuKsPTbNEi6vkihFibZ4O31MBJficVlXnLzH7GoQcoX3sPauHhK9c Aoyg== X-Forwarded-Encrypted: i=1; AJvYcCVk4EcESw83zi8H3K68ce3pWkXNx6ribl/jWT1Yq6wwnbtpttjK16ueDs3zq2Mc/9sQrEyEqCJbIhlc9EI=@vger.kernel.org X-Gm-Message-State: AOJu0Yz/2S4bhOK6GPcNQG5hNjZ/yrbXrO1vuZIQuilrEFLSUrP3aQ+b 30iGLpQn54rdgHwEq3oDhwR18mI3k60jY2XhL8nTXsHoDlr+FMV88712IeSbYXrguSzV7MQmgzZ Fh8ZB3A== X-Google-Smtp-Source: AGHT+IGPtEpNCcYMKmnD2warbzivYn5negSNOOvHsLN9JPAMbCC5Xzlp07HZRR6Fl9wcVEyJg8V8GcxU5Mzi X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:a00a:f237:9bc0:79c]) (user=irogers job=sendgmr) by 2002:a25:d60c:0:b0:e24:a393:bb8e with SMTP id 3f1490d57ef6-e2978559a93mr6070276.7.1729115515257; Wed, 16 Oct 2024 14:51:55 -0700 (PDT) Date: Wed, 16 Oct 2024 14:51:32 -0700 In-Reply-To: <20241016215139.212939-1-irogers@google.com> Message-Id: <20241016215139.212939-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: <20241016215139.212939-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.105.g07ac214952-goog Subject: [PATCH v4 1/7] 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 aecf56dae73f..b2f37de305f6 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,11 +38,11 @@ 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 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.105.g07ac214952-goog From nobody Tue Nov 26 17:19:29 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 760BA1D3639 for ; Wed, 16 Oct 2024 21:51:58 +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=1729115520; cv=none; b=IsxaxC7Y0KaFDrkBl9W8gHy9WSALQAIq/Nk1THKtVHFSU8KgxeZ39OnQNXhSTiXYYQ2tl3DgCGH36/NlqMFAj82y1gwcv7UEymEPiBd47B0ZngvOWRWr7UeNuq84frzhosgo5X8Y8DLQUU0icBeW/irDrHM8To4qxOUHb5tcU8c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729115520; c=relaxed/simple; bh=WUodcAb4TVW2yeFy1LDOu4j2dnFFiTlcHPQcWZN06qw=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=or74ZYNLgy1x2ESNx4+7thNHccFXJaRbRUsil0s0y5FjOLYJ8EOAXdhUm+zFCqSaYQOE/dcQji7GDRqpvkZf1SSe34ByKfVXoYQTpUPPfiwyjMHUV5Z7XWKc5MHRkKKhvOJh9pGUMdCingqbt4PagiKv4PybpvwpS2HoiCQStkw= 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=ECO/QGd0; 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="ECO/QGd0" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-6e376aa4586so9574927b3.1 for ; Wed, 16 Oct 2024 14:51:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1729115517; x=1729720317; 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=SvCFzl8c1PGWsh4EV+hkwTVYrXNfM9i5AC+z8XoTGw0=; b=ECO/QGd0zbpWI8Cu296VyStTzTD7kpLFDePAAhqIGOZ38K01HJRzWpz6K6hubdx0rG nAdZTiQujiDxlDHzFT9TjfvLe2vn3UJwgSVJypAgTMIQuxU97Kk77z7zhCFPgxhtGooC j7pZtBC5YO43w6XzM/KMVPrE3qDM3v4S7g6/sghPi2FKn9PAw9Fp53mXOBj+Pu+K7elM DdMuSRwrHfV4+0m+38E8gUYx1tRYxTGtShpyBGafCiY0qddLhDyiBvEevXhwX41pGQLX WrnOp3gpqGvgchZzYT4LsJVuRFwCA/Mfd6I1TAKpjuLm4tO8NWlbEPweihw/Wk+selup Sz1A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729115517; x=1729720317; 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=SvCFzl8c1PGWsh4EV+hkwTVYrXNfM9i5AC+z8XoTGw0=; b=miyaT1/TnvgFgYQXo9yPxHaGJ6bSVoX0MXyf4RFvVo9g/SFrEZ8xeahZJyMYnNTyBt IybOlrMfZqwP4Zuh4evbUo46L9iqxks1XHg7PpxEbrQ9lxGpQOLPlUhTBnYz3aHcPZvF 7b1GuUK+iDgH4z1J0euhVy1DstzWUMSt5VLJ37UXhJKWJBuBOg1W98f1ca0kcDoc1evK 4KQjfbdzCQAwVJcJvOFVteAGBTU4ECRqJmy6hX8uTUcdH64ok2Wq5hMHTo0kzhd7onYy yWqM5jtZKquQaK3k4gjVq4Q62a5UxLaMBUFFZE3vTNZ1etDOq4ZE+L7cZzgshAVqElZM K+ag== X-Forwarded-Encrypted: i=1; AJvYcCV6DhrzpSmtR/Kkf8iMcN0G2DdF+0f/kW5S1Tm/lVlKLMK3B5kRxHKsA02TcyqfDDaFVyt2FygsoZgLlQU=@vger.kernel.org X-Gm-Message-State: AOJu0YyS93Mw3vmqikEwfBnUYa8+xYL66odEGcuBek6B2KE5PcYMe0i5 YHsqftP0vdqodPH3JGjlVftj6ITE1bXgbYEXXg/GY1U1Y4dolzHEldjywqcMp8oRtXPyprxZLB5 Vj9BlBg== X-Google-Smtp-Source: AGHT+IF+KF71BkYq4wOBn0ecxwWR7LcsJubPFlGD1z2qvk5vl0Vi4Ey1q4uQj5of/dkOlYE8ndNhvSV0pSsr X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:a00a:f237:9bc0:79c]) (user=irogers job=sendgmr) by 2002:a05:690c:6781:b0:6e3:b08:92cb with SMTP id 00721157ae682-6e3d3bec4bemr1502517b3.0.1729115517488; Wed, 16 Oct 2024 14:51:57 -0700 (PDT) Date: Wed, 16 Oct 2024 14:51:33 -0700 In-Reply-To: <20241016215139.212939-1-irogers@google.com> Message-Id: <20241016215139.212939-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: <20241016215139.212939-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.105.g07ac214952-goog Subject: [PATCH v4 2/7] 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 6227de848083..512890d50b69 100644 --- a/tools/perf/util/stat-shadow.c +++ b/tools/perf/util/stat-shadow.c @@ -196,17 +196,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, @@ -320,14 +324,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); } } @@ -342,9 +347,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, @@ -357,10 +363,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, @@ -542,12 +549,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); } @@ -718,9 +725,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 @@ -728,7 +737,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.105.g07ac214952-goog From nobody Tue Nov 26 17:19:29 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 AB57F1D415B for ; Wed, 16 Oct 2024 21:52:00 +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=1729115522; cv=none; b=L6kFXbmTkgjNUTX84E5stQJZOKk/Ily6TQcTSKHwnanp20kiuz0/luYCzrqAAVntQ/bDjq1kMDYd8SI/xHWM4W9qe6GCXKtJUwN2Hj1Y/7uj/uOaDw7zW2z2cdq5ksxUbTUZ0DT7qMnDQkEIglUiPUhwh1g9vSaErVDuVUv6SOU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729115522; c=relaxed/simple; bh=d4p2SSC+jRmzGX9QPS6kNxF3hzHXI6/kfpx81KrMoUw=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=F3SGNYMzXIXJteQc5aBm39IIfEGRvKHCPsIl0gWVSFvddo4N638aYKwLKZNjMgw/6ix+CWiUS0TjH1pAsgsH5a/X3BA1ln8L89R+rg2eEIcC+8qAz4oXxbADaaUnCnf3hXiidk9bIH8+ngZLY0uKjh1bBh1l7+C7NQ64NOQq7ps= 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=nOmWYb97; 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="nOmWYb97" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-6886cd07673so7690297b3.3 for ; Wed, 16 Oct 2024 14:52:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1729115520; x=1729720320; 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=82hKZR8Ty5xgYC+xyYfKClAaNBzZJMlhS4+fNhwIq44=; b=nOmWYb97tgLhVRST7jIFxiX6+3C11QzzV9uORvsOUqmziOGWLnzrWTz9n+cAi0HxSM a70pLA5I7JyZmPbfvupyfJ3LIKtXYhjRw+ihZCudA8DjGja/fy6OvgcHIu96AZSTkjhD StnhIaBzSkhmwld1t0ltbj9ChjUkoN6zx8+dCTQBv8Vq+ioJzTWiIN3WolWMCDbLPTc0 yW5hgjP1KuxZujHyVO688tEt3WD0tPbgk5dkFzUScVEs8IBQEsrqtBeaAqizjK/L+LuP bZFLq/RupkEyCOWE0DD4uZMwosJfok6iKNB2k4Xv2HjRAaEUMbh/NswMjw3mjjwRvbsN kGXw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729115520; x=1729720320; 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=82hKZR8Ty5xgYC+xyYfKClAaNBzZJMlhS4+fNhwIq44=; b=CoxhKxgzPsqYbQsvxoPweyEyrBfBOkv3+5IAvNE/Rxafh2e6SRA16JBKbfKpJZCsa4 bPt7hSoDLdK+1pciYLIbPUiZPLiRR0ECtPCPbiRz7fegS6ZJPgp2Vby4MxQSG/0Q14QX JtxtSI7aoSd8pdGJ0rcCQIrlsKgguAdVn5kdXweosR7gLG8WTAFtFLLMFcLrIgZCRucJ AOHiY+QF5grGrIe+0bWjWBD/wCcQfWdwW4xuzdhfEadbkQHVgRVAYihmKTPcsk9Fv2vG q6KuaIIQUGYACCBpMfx+wHaPBVOFRFA8kVFBd1Z8SN6zZbg9PJl3X6nPNlux71CMiTKW vXRg== X-Forwarded-Encrypted: i=1; AJvYcCWjpCV3NixQaZlfyT/r4YDdgonxPUG940sTEM7iJ5tyr7bPCdk3qovuIEkuGQHYakkDEt4I2ZnM13tEtB8=@vger.kernel.org X-Gm-Message-State: AOJu0YxfM3vP8jzWDnOcM/BrrEkKpc1XhGxE+d7WDY1Ns7BvvLGT8Ybp p/pfSn5Pjq5vztzu09m/M+hl+mWNfBDvNwdis5hPshHQKhQIMhe82FlvOgDMiIMXhgywjGCgx1Y curhX+Q== X-Google-Smtp-Source: AGHT+IHYLGCrAS7wsnpPLNLCwRIdj/82Nvg4w9FR5SgswF7g/KhN9wQduXAv8HJvlw2EV2tnrt3IkAKSmr9M X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:a00a:f237:9bc0:79c]) (user=irogers job=sendgmr) by 2002:a05:690c:4b12:b0:62c:f6fd:5401 with SMTP id 00721157ae682-6e3d41ca698mr818757b3.6.1729115519815; Wed, 16 Oct 2024 14:51:59 -0700 (PDT) Date: Wed, 16 Oct 2024 14:51:34 -0700 In-Reply-To: <20241016215139.212939-1-irogers@google.com> Message-Id: <20241016215139.212939-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: <20241016215139.212939-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.105.g07ac214952-goog Subject: [PATCH v4 3/7] 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 ef0ca8cd802d..a137b377efa4 100644 --- a/tools/perf/util/stat-display.c +++ b/tools/perf/util/stat-display.c @@ -610,19 +610,22 @@ static void print_metric_only_json(struct perf_stat_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.105.g07ac214952-goog From nobody Tue Nov 26 17:19:29 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 F00511D4359 for ; Wed, 16 Oct 2024 21:52:02 +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=1729115524; cv=none; b=DkJM2LWJ/1yP3sVxChEDcB73E1pz7D4V8Ric6b2hiLmBMnkOhu/UDfXhwJUCNDbMy8otxz6CVZk9QwLD9eCW0LHJFybpJjNaMm87P0IDK4wdXpRhtgf5FswG7zov9jiZxlKpJCrNVlog9Qfw0oVZfK2EuBbnhIyFWQlGjn8spZU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729115524; c=relaxed/simple; bh=tWKJqnfBwSOmrMspZ2sdkDVmtmOQkJadh5Otwb2PTrM=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=XTMD/ex63gOyFHnK1mejK2PJaaP/gw+oYfNPf2jSk8dBFFNxaRf0RoUS+CNiZRnbXW9pR4zXqifQB0/CrH4O1BLnedd8t5ykcGDYWuuwTKh6eK5muunnqkwcI8aQTrC2M1Ek4GykgoJGeypfcxITxzM0XvfCO5jCstx7/HQG/sk= 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=yxBxVH8i; 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="yxBxVH8i" Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-e290947f6f8so533541276.2 for ; Wed, 16 Oct 2024 14:52:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1729115522; x=1729720322; 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=e2/oyoGU6HrX/Xxl9SMoDXlcRLOo1IYbCdJ0T7Dlej0=; b=yxBxVH8i3u+xGNDryIDhYNLmlk2A3zJZUg/ImHsTvkb2e76g1NRuc5r2BWS1/CRPdh yMm4REhPLHFweKGNw7JoWvznT1mIRUpOdA8Y4TtI0Ej1Klc3+ZC9bGyYUd3VyYs3/5Gb F/QryG5TlU840j3aDBzF5g9OHMJZXTGKRfMsQPI/bHvgdxxcbAr2lLkSGzVfe20ErJM9 Cm/SIyvWBcnPgQMGCaW1dw0p+K7zLeLXsqWXtkzJDppNBVJ5q40WFTO7zqRGCzJ8dKIX TISWi0R84jOMhNqkaAbSUaM0l2pM5qfqQtnIlIoaJyU2t5uUxwMgJj1JQNIx9JqnNmCK nKEQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729115522; x=1729720322; 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=e2/oyoGU6HrX/Xxl9SMoDXlcRLOo1IYbCdJ0T7Dlej0=; b=QYllCId+EmBgrdlv35Vza/ajIvivbKwnhF6k+70NgFE/FBCkX5XxE+t4yhkH7FsQaz Y91iP12ntsm5ohtfhygHw6joGFmvikoOfkq6MbOxNw8yEMCmC+X/kVosS/py+3dVXYMw 8jbFmsupdCZye8MzqxD5iRlYgfvGdILFd+mj/EngU5RvrRiKJ4aRUe5/ksrrez5B+3+T DzlTTrznVtm+DtRMaGCZw0Sm72wEby9cjYFcsuEWGzd/EjUpxxsgBNIf6tVtiMyEY3l4 f+QLbRTqf7DeiWXwNATzzuEALL5iascYHIb1OKxbjKIfQzWPPDWRafTgBRisSbqy6fo1 ntjg== X-Forwarded-Encrypted: i=1; AJvYcCWldxHpAfrsxt673/jXH/l9iEXZirPDLrZX60ifitP1XH/hfxw5RmoPPFWRezfrwu1OLryBZfDoeGqQCPA=@vger.kernel.org X-Gm-Message-State: AOJu0YyrPbZfm/2lTaNjKm7oFOH2wlsHjjAbw9QWAdUyuN1YzhMi7Ye3 MSFdKZr/zmVuujbATRosB2Xw773l8renxfYXJPiVIi2S0ll5SeLvhXgk4Fg7FRvHzFdB8FZnO7m 2U5YicA== X-Google-Smtp-Source: AGHT+IFCBcL2WI1OJ/qL8tTsZfu56WPN4fK7Lp+XqvP5F6nW8xQvXYG5rGEA97JIV3Z+cvI8Pf9Ow7NrHkAi X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:a00a:f237:9bc0:79c]) (user=irogers job=sendgmr) by 2002:a25:b204:0:b0:e25:cea9:b0e with SMTP id 3f1490d57ef6-e2978594b05mr2587276.9.1729115521830; Wed, 16 Oct 2024 14:52:01 -0700 (PDT) Date: Wed, 16 Oct 2024 14:51:35 -0700 In-Reply-To: <20241016215139.212939-1-irogers@google.com> Message-Id: <20241016215139.212939-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: <20241016215139.212939-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.105.g07ac214952-goog Subject: [PATCH v4 4/7] 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 a137b377efa4..c6d33010ed22 100644 --- a/tools/perf/util/stat-display.c +++ b/tools/perf/util/stat-display.c @@ -471,8 +471,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.105.g07ac214952-goog From nobody Tue Nov 26 17:19:29 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 2561B1D47A6 for ; Wed, 16 Oct 2024 21:52:04 +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=1729115527; cv=none; b=n/rIAYDt1k9V8gvRhkr6cxxpuVirxED3gTLS9v8IagB9NKrC9Hmu9bUVWJovWE/ju8IrQacEGnN/v7dShu/idITi9M9KoWxZbjSpSdR6Wk9vS11yzhC5CiekeynZvLyvde67exJ2ryRP3GKUvWTSdOsBwxBdFIEVJA/tFAEiKBM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729115527; c=relaxed/simple; bh=RVW6wkDVKjRG51bYEhA4x0xQ+lNpEYTqs22+cLMthkA=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=B8yFolj+L6Qyi1rQcr/dmNx8deOSbjEURA2HT3sgXNp4FeGArZL7tZmqHXiiCF+UK0xGlN5ZVPEvCIAI1T6oS05JM55pDd+yWzQJFXSiPIU6uxIIPv4Dd9z97ErRfQfXb1C8dPCdwgEHcPtE5xSKgAMVgb25IAPKQMRgmvxBskA= 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=1v5HpJvu; 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="1v5HpJvu" Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-e2928d9e615so507872276.0 for ; Wed, 16 Oct 2024 14:52:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1729115524; x=1729720324; 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=YGfOVTovWxk2hP7JLrRDPs7H1ZDJlZRA8sfvnLLeCQY=; b=1v5HpJvusUk9/7za7zXekTlZjsgrzVNaKZz6jEI6RIOsWljk640UzxS+oXuYjLGcCq 0EdN//85w6aNHreTNlI7l409QqPIjF5W4of1itRpBiRwpEp9SMy7lNM/pu/oWpBijQrK kD60CliAatISh2du/GA/XfgyjDn7PcYkLRJRpr6gFaZpsytI/TAPLYpnNYZQXbYxlN4v hAJVJl59DFyPnVKJuxjGl9X0xA6h9XO4eXbk8hBg9MWcSvkRijXxYdvSCf87rpUhSiRR TwwH8OkVCwXwFZfseFVsfFumYk6K0iJ6pgDPjZKuaBWAfX52LI3Datxi08Lm/0hx27Nn lqxQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729115524; x=1729720324; 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=YGfOVTovWxk2hP7JLrRDPs7H1ZDJlZRA8sfvnLLeCQY=; b=QKnAhrT5BsIDV0jkE7nxADmpcE1mMCvLj4AKO2lijPcA7qPtjyIDpvwxYB9cqFShyZ QoyPTwSj1HKE1I2AJ5uI752/OHnz89LiE74l4tuF/qhhbY0zO3U2cjOl8ihv5aLUCrPE TcOuPjfrBmonvn1PtZIEKnNn+ZVhhVLZVn2bLLhiquuQc3ijTDFH+Cz/UA09TAJwTVrn /vGjtQWbAAOIoKhprlHwQVDV7NofNye1Z6kuUIQuc8jNuy1r/jcOQYCIBat9nKRLb1zq qNg0Z+b621OsKKaiXzcS7qGmMwI857OFImG3nFHiSSGD0GBkxMlJeF91J5B8nkQqvJrU O05Q== X-Forwarded-Encrypted: i=1; AJvYcCWV0uO89mSeTX55PfbSmpTpzj0OOcN1DDwhFXOMjOB9SB/RzPXgYrTn256GP7Xb914TOpamKUtzvJrsKtQ=@vger.kernel.org X-Gm-Message-State: AOJu0YxNwcWiDRCv8gnpltvociYbqz2i1mMYBDm/5YlAKn/U/HVjEOBi QQwPXp+ncnsRw1i7iDBzjacGlNsNas60atDO5QYWlgJetCJqU/ja95qcJK4OJHdOIUT4w4XNuSv 8NxopmQ== X-Google-Smtp-Source: AGHT+IGkcYSO1t7QSQxUWCXc9irqlpZzLrvSziZ6CKhyi73uSI0RthAUgoRr+5+ypn6+JNjGXmciUEeNI5Ql X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:a00a:f237:9bc0:79c]) (user=irogers job=sendgmr) by 2002:a25:dc4e:0:b0:e28:f231:1aa8 with SMTP id 3f1490d57ef6-e29782bbb03mr7420276.2.1729115523978; Wed, 16 Oct 2024 14:52:03 -0700 (PDT) Date: Wed, 16 Oct 2024 14:51:36 -0700 In-Reply-To: <20241016215139.212939-1-irogers@google.com> Message-Id: <20241016215139.212939-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: <20241016215139.212939-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.105.g07ac214952-goog Subject: [PATCH v4 5/7] 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 c6d33010ed22..5974aaead95f 100644 --- a/tools/perf/util/stat-display.c +++ b/tools/perf/util/stat-display.c @@ -73,6 +73,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) @@ -405,13 +418,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 @@ -443,7 +457,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; @@ -464,7 +478,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 512890d50b69..ada787947e16 100644 --- a/tools/perf/util/stat-shadow.c +++ b/tools/perf/util/stat-shadow.c @@ -137,18 +137,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) @@ -196,21 +192,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, @@ -218,9 +214,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 @@ -229,9 +225,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 @@ -240,9 +236,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 @@ -251,9 +247,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 @@ -262,9 +258,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 @@ -273,9 +269,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 @@ -284,9 +280,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 @@ -295,9 +291,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 @@ -306,9 +302,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 @@ -324,16 +320,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 @@ -347,9 +343,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 @@ -363,10 +361,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 @@ -500,7 +499,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) @@ -523,8 +522,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) { @@ -539,22 +538,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); } @@ -725,7 +724,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; @@ -736,8 +735,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.105.g07ac214952-goog From nobody Tue Nov 26 17:19:29 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 284D91D47C3 for ; Wed, 16 Oct 2024 21:52:07 +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=1729115528; cv=none; b=lLuwNaK/bW0oA8JzssRABefplP5kHfJU2HAcLWKxPnzPi6Nx/R1LLZrIUIpflG0FWG0aGpNe8po8bu1ckuitoDdptA3V/KXy4ZyE6rWLmhpR/hCwx8vRfQ8+xvFQPAmyCI8+44d7B08l/G3iehIn1bOaAiIpl8LlbL3vUm/4Xqw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729115528; c=relaxed/simple; bh=nR/8QLcBCh+39nvfzpZZaCLHNApxIUJpcbhdwvA+Oxk=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=SVu7Q7wrlxC+mnubzO9iBTwpjqyvXBDKKF0PaNqY7apOrgdmuTHlmBOCAy1pBx7LFIPhpXOvNiwEXaBsZl/dnBMs7TK3/tWlP/0vYwTbuoVPnlEAq4r0s6j1SWeXvEBNlxuekRWdrqDXFL9ekAM5jgWybn8PjUu37YqQ4lAieD0= 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=bm89Csiw; 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="bm89Csiw" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-6e31d9c8efcso8747157b3.0 for ; Wed, 16 Oct 2024 14:52:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1729115526; x=1729720326; 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=Y/n/isiF2Sq7ntpurAmJIm0kx07dBkasA8rH7Du+HlQ=; b=bm89Csiw/+BWqYpC8Xzm1Or+pAEqQVIZmuFg6FC98M2Q9vDVhldAZE9BNkEmTyVQEv nRYGOJ+bVqzBdqoJi+6tUsRxU7PYrd5mG/HE4rRJD05wgFoLryy1HWS+r2Qg0JWY8kjl PZ3Pl0apVcsD1BtHD/GWGZ+nACInMEyfVIz+Y/HCIxZeaamTdilbVUVj2/zzhIYK54GQ o3iMCC4L9NNJz7lOi3rzTdrXfO1/RwoPTzs2zmsQFskcIolULXz9K9Nr5QYhEZ8JkYIO 9lLQucptcOY0lbob2xeFFcSDqTFPYA0v5T4ffelT3HN2K5bNEEBkW5QN1lbpXlqr9Ze3 Er+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729115526; x=1729720326; 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=Y/n/isiF2Sq7ntpurAmJIm0kx07dBkasA8rH7Du+HlQ=; b=qakMOCzdv1RmTWzdayIjBEWSijqKCVwL6dbmkOE2yFdIdA2baPmfJYGoIDZnV0GZfT 0pU2eSujgutt8LIlc0dyVQRifxa0ODYNYZVv9NOVVnXgZePFsff2GXuQ6bhs2E2/cBm9 RWtsUPW/o8JtjlM4cAhkm8EQsG+xiH1jBwHn0XS5iZEOIUaoh77DIlfO7ntbbsfwDnoP Zgou9x9AhVzeB1QgkbtJoLDB+KVekn76RZ75lpTyHqJN7fT953DBqOqbvgGDS6ZxkGP4 fhjDe24R35Ey+gxLY8GuFw6RXIO7ITBByVqHg8toy0idewUotybbKpP8ZwECqy/xxYys 6LkA== X-Forwarded-Encrypted: i=1; AJvYcCUduDGUlKxEfVIbvbCl21bYkYyufKpB9HHa9fIhhkbyJhFUolHyDNdow7CYYMI+OZm07NkGf6KypW4wc3w=@vger.kernel.org X-Gm-Message-State: AOJu0YwLUl7AYLoCNhowgHTqNUZRa/AmyCAwD5FyBCta2nuUVl+BKuF2 OKS5smDn7K/puIDf8LEtR19WnFRRTBtjW21QuY55cbS9J0/ZPxd5ThqAoYqyE2uWmZkBwY9y/r/ k7AulEA== X-Google-Smtp-Source: AGHT+IFSvAouIEyGKuUHCGGxmtliMqlphatHL69knjIbTi+zL83r9H3bHCah6svBmYQ3oXXSz2bxFLai+XrX X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:a00a:f237:9bc0:79c]) (user=irogers job=sendgmr) by 2002:a25:6982:0:b0:e29:6e61:3daf with SMTP id 3f1490d57ef6-e29782d5207mr2545276.2.1729115526329; Wed, 16 Oct 2024 14:52:06 -0700 (PDT) Date: Wed, 16 Oct 2024 14:51:37 -0700 In-Reply-To: <20241016215139.212939-1-irogers@google.com> Message-Id: <20241016215139.212939-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: <20241016215139.212939-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.105.g07ac214952-goog Subject: [PATCH v4 6/7] 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 --- .../tests/shell/lib/perf_json_output_lint.py | 5 ++++- tools/perf/util/stat-display.c | 22 +++++++++++++++++-- 2 files changed, 24 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 5974aaead95f..53dcdf07f5a2 100644 --- a/tools/perf/util/stat-display.c +++ b/tools/perf/util/stat-display.c @@ -86,6 +86,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) @@ -478,15 +491,20 @@ static void print_metric_csv(struct perf_stat_config = *config __maybe_unused, =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.105.g07ac214952-goog From nobody Tue Nov 26 17:19:29 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 725121D3581 for ; Wed, 16 Oct 2024 21:52:09 +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=1729115530; cv=none; b=MrUUCR4JZETGN2JKYiWG/Bm1R7e8RHmnbUcvcEMQSbUQun6I0DKreCnWLQcgB681M4Peb55rZu7bt6Rkp9h6oSsnSsfoHqNGY7odRX6WXO/UqpIhUEhUj2+N2VEDIqN6H8TDf4l4bKkfR++n8bslzKVou0i7d6Z1ym6taU0OzC0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729115530; c=relaxed/simple; bh=xxNoLSb6kFTUL1OnMX+2sTQ86EFI5XTgz4LWu0BFnc8=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=Tor9TWJ96G2QM+3UnYKdNNndgHKWK2pmOOUf9dryKuE1tNPtrd9DpSz7DOAUM4y0nU/KR/c+ytD3Q6ilX1CLVwkambyv6lBwTGagJ+aL6IYSpIAj67ctHvKBFPW385FRgZaq2agdj2NEgetmWSr0Pm746oySEBPDsQE58JQozxw= 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=GkXn++DS; 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="GkXn++DS" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-6e3c638cc27so8628807b3.0 for ; Wed, 16 Oct 2024 14:52:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1729115528; x=1729720328; 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=PO/jFnTS1VOsCUFZImr0igUuGTgy/DTrx5IiSFpgwUc=; b=GkXn++DSPhaPxgg9orAmlw9FWKSHH1hNzkEZjZLQy08dQEY1uO5udxPtRI1PZ+dYu0 z7NvNYfAYscu5UaYNHCn3Y7R/bbE3F36kJLAkGiPQosDNbkgga/YoecBHkYxikwI5/3Q S1erpEb7Uums1J3krqH+7fXhmsjsnxZhIRmc+nBy0wk6jBnFlD+dsPCGITU19xLrqaTy UwFHGYQVop3G2NB/hp2SHKh2sM7yOE4s4T+Wjuuk8eje2fSeoG7Ce8adGdkGSPucSzO3 AlgfgZ329IROfD0QcfrHQkniORoWFUtsEctZqW2flNUTxHYa0bqUPjUg8LjkBn3bypVf tkmA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729115528; x=1729720328; 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=PO/jFnTS1VOsCUFZImr0igUuGTgy/DTrx5IiSFpgwUc=; b=pg1fhuh5wg6werPlVOCtFceMBt/fdii9XEXm+JP3dk/k5Fny+RfiH2FFu3HcaN4xJ2 tmD+XLcBhM7kOyIC4kj7xAM3fbxgaxQnEfwwLqH0hTjQB2YpWxlsFGa91KOj4OKjbroK Y5cUDLg+e4Jb7+ZcfF9SdRGXxbFPrbY6MlrRb/HGPOyu6Ju22AlBsyGzS1/q2oyJ50av t2x7eBrbv2mM0m3EfzgGy/ToKUjmPOEPNpd0Vxp7USxLaiJZh40BxIJH4+mlugfS6PzP myrfAQ2yecLhHzQJBRAS6WJnkpSPUV4HkbpJzJvoC6fzE4LPFlkqOHJjtFYaLg8W6zBX 4RHg== X-Forwarded-Encrypted: i=1; AJvYcCX5+pFqhVqnJs09q80WsVvGifv8bkaLC2/Vm4UgiLcFCYX/PCwQ6dGJUmrkmAMQo9abCIEO8S8Jt+EqejI=@vger.kernel.org X-Gm-Message-State: AOJu0Yzy/Fo0Kz6RjwPI8bVW88grydcemQAmIBXYbaHVMiPMo0tz8wos sK+OlcfXXOYJEA4lljmoSuBsPRjCHR13H1D1Ah55M7iMHXQR2HocwZv3lwo4XZwzbQdnzzQS+4v W8yU2kg== X-Google-Smtp-Source: AGHT+IEZ/3okGxqKo52wIDEn7oVplnHQSqmsfGn8AYDNPEd7z/jQScRIZ0BVQENfrM+1EqkxY/OrF8JWG4El X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:a00a:f237:9bc0:79c]) (user=irogers job=sendgmr) by 2002:a05:690c:6f11:b0:6e3:1023:3645 with SMTP id 00721157ae682-6e3d41ea284mr1443167b3.8.1729115528496; Wed, 16 Oct 2024 14:52:08 -0700 (PDT) Date: Wed, 16 Oct 2024 14:51:38 -0700 In-Reply-To: <20241016215139.212939-1-irogers@google.com> Message-Id: <20241016215139.212939-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: <20241016215139.212939-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.105.g07ac214952-goog Subject: [PATCH v4 7/7] perf stat: Disable metric thresholds for CSV and 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 b5e18853982c..7639ecda6c05 100644 --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c @@ -2561,6 +2561,14 @@ int cmd_stat(int argc, const char **argv) goto out; } =20 + if (stat_config.csv_output || (stat_config.metric_only && stat_config.jso= n_output)) { + /* + * Current CSV and metric-only 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.105.g07ac214952-goog