From nobody Tue Nov 26 17:32:36 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 8D68A210C1A for ; Wed, 16 Oct 2024 17:53:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729101238; cv=none; b=ZlcLmQGbF3X5xdl/fapOZkuAEygGA1yJeZgP6wbC9aHAkDdPm+jRu2y/31hWISs7FOscRNSTXVtdSVXh4Dhmf1VNgmHWHdCibq52PRBhZ4RCc3m0H62mWUsI4SVhsSikhy2ZoZspEZ9vbCBhRDz3bnnyFll+mjO81/G77ISLOTc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729101238; c=relaxed/simple; bh=hIfcHkHzDrh7Kl0V0epeaWp/DUbuxIY5GC52UGsnaoo=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=WvhrXOXQ0d42/sMO4ht7wJ7PgfGLJ/9odAnC+hWJLE2V+uB9pnzgsSb65iE/fGU4/zYc3rzJ5SBFmDi0t+uzXnRWGULbgxDreuTP6vh0lWhvaBKiV6W3/nrB2U/N1nLtdgevRK0Ii1F05q7bqNsI+qDOoA4gX1abCObWWLE5w5I= 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=zwXe7FCQ; 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="zwXe7FCQ" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-6e59dc7df64so1018007b3.1 for ; Wed, 16 Oct 2024 10:53:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1729101235; x=1729706035; 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=zwXe7FCQhPwOTA56IGILK3xgFFG7YQEK6DFVV7i1g85Vc8XcTMVrBoFnTq/b0exTV4 1gygAzBXy7hW12WdX2rDtcAXCVOMbH8m07sPD7PegJxQsNqZqSdQ15E4hJRHDn+P+EsT y4oM+c9OyyYAv4TWIqWWox32yNtuWAMVIxkM1s1zmr/h/HToBr60SJSvBDO/M7m0ODPE EzhaiF2upcvndqOpx8TOQX4TMGrPAUR0jTZKLUI2ve+Lp9UHt2Ts1VUs1f9N1AGC/jUg QiTjo553UpmQI3Qj8FnPnPGZncRJnRTpNSek8grMrJfOltq2hn/VdVOy1MhGxA1/0Obf NxNw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729101235; x=1729706035; 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=II5SZycdcq0BdMvkhq+z7tz7Lpz+f5h1mZn1usPb7TrMfbfjKsCsagkCqHgA7KOntq wiwAC8/Ck38UTNjDQom9c4cW6+pueV2dkEnhMXh75NJ0N0S5yUdumpS1+v/vzpJ0usdP 9w98hwmSa6K5y2nCkqZnxQ7PTqaBc4vZDC94wHlOm+s8c1x7l4CJTd4a6dRhIRpXAbKS 5tMl4+87Pq1qal7QINt6eiK2f9CUw9UkTR3ADmn+bBjCEyqJt1vlDJUXOlN9njE06OzI zB+4Ocr2F4CvUsqQ5rP7KoXQ5vh16d6AVQfBkAxhajG8PByCLfGZmdYo4hmzc9sTVSA4 TAEw== X-Forwarded-Encrypted: i=1; AJvYcCVjaWUuMcPP6gO7/spomIbOA6mNjxlA8hm9pDxmQpTeuvf4XThTxhNEejhsxA5l/S8ot7c9zjMef7U3r2A=@vger.kernel.org X-Gm-Message-State: AOJu0Yx+wyiA02hSWO1ZSnV1HLd40+EexnPRKH7BzEE1nkB0KO7dNjfM VjL204REFM61Wwhh+HeLhwUoDaYMB4XDjRUhLUsB3g1jXbaboOlBC4Rkj+eMxC7RhG4LqxvDK0r jqbU5GA== X-Google-Smtp-Source: AGHT+IHghdnDabAVtg4aQluzkItxsQJIbOBN1RLFr1KgdtLOjqOCkNjfC6nVzxxiGf+wQIsF2t40LHHATwkW X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:a00a:f237:9bc0:79c]) (user=irogers job=sendgmr) by 2002:a05:690c:480b:b0:6e3:ad3:1f19 with SMTP id 00721157ae682-6e5a3d7052cmr29347b3.3.1729101235651; Wed, 16 Oct 2024 10:53:55 -0700 (PDT) Date: Wed, 16 Oct 2024 10:53:43 -0700 In-Reply-To: <20241016175350.116227-1-irogers@google.com> Message-Id: <20241016175350.116227-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: <20241016175350.116227-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.105.g07ac214952-goog Subject: [PATCH v3 1/8] perf color: Add printf format checking and resolve issues From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , John Garry , Will Deacon , James Clark , Mike Leach , Leo Yan , Yicong Yang , Weilin Wang , Tim Chen , Thomas Richter , Sumanth Korikkar , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add printf format checking to vararg printf routines in color.h. Resolve build errors/bugs that are found through this checking. Signed-off-by: Ian Rogers --- tools/perf/builtin-sched.c | 2 +- tools/perf/builtin-trace.c | 2 +- tools/perf/util/arm-spe.c | 2 +- tools/perf/util/color.h | 9 +++++---- tools/perf/util/intel-bts.c | 2 +- tools/perf/util/intel-pt.c | 2 +- tools/perf/util/s390-cpumsf.c | 2 +- tools/perf/util/s390-sample-raw.c | 6 +++--- 8 files changed, 14 insertions(+), 13 deletions(-) diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c index fdf979aaf275..99bfc3ad71e2 100644 --- a/tools/perf/builtin-sched.c +++ b/tools/perf/builtin-sched.c @@ -1739,7 +1739,7 @@ static int map_switch_event(struct perf_sched *sched,= struct evsel *evsel, } =20 if (sched->map.comp && new_cpu) - color_fprintf(stdout, color, " (CPU %d)", this_cpu); + color_fprintf(stdout, color, " (CPU %d)", this_cpu.cpu); =20 if (proceed !=3D 1) { color_fprintf(stdout, color, "\n"); diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c index 0b30297b4ecb..748b061f8678 100644 --- a/tools/perf/builtin-trace.c +++ b/tools/perf/builtin-trace.c @@ -1873,7 +1873,7 @@ static int trace__process_event(struct trace *trace, = struct machine *machine, switch (event->header.type) { case PERF_RECORD_LOST: color_fprintf(trace->output, PERF_COLOR_RED, - "LOST %" PRIu64 " events!\n", event->lost.lost); + "LOST %" PRIu64 " events!\n", (u64)event->lost.lost); ret =3D machine__process_lost_event(machine, event, sample); break; default: diff --git a/tools/perf/util/arm-spe.c b/tools/perf/util/arm-spe.c index 13fd2c8afebd..fd0d793ecad8 100644 --- a/tools/perf/util/arm-spe.c +++ b/tools/perf/util/arm-spe.c @@ -122,7 +122,7 @@ static void arm_spe_dump(struct arm_spe *spe __maybe_un= used, else pkt_len =3D 1; printf("."); - color_fprintf(stdout, color, " %08x: ", pos); + color_fprintf(stdout, color, " %08zx: ", pos); for (i =3D 0; i < pkt_len; i++) color_fprintf(stdout, color, " %02x", buf[i]); for (; i < 16; i++) diff --git a/tools/perf/util/color.h b/tools/perf/util/color.h index 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:32:36 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 1C1E9212F13 for ; Wed, 16 Oct 2024 17:53:59 +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=1729101243; cv=none; b=CpcaTPSoWkQpIvAAezl/BTF4UvNJL/amhu1kTPPhr4qz+e0GWrDouNa1P4oE+MQsx+D0ku4ropXG7a2/7KZKsw3FfVGF1PpvX0u3N/4co2tSd6GzNrwA0YHl4hyg8RhcmxdASL5JizIa6eYaGEMzJf+d2dIf+MQ2xTTEov8SQW0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729101243; c=relaxed/simple; bh=WUodcAb4TVW2yeFy1LDOu4j2dnFFiTlcHPQcWZN06qw=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=imR8+CMQyT8iequEPApIeAFoSPjr7USvdZLTBmcjTS44b6KsoFb74L2N09ufq1euGInuu52HLiQNvwDIuxl791cfUbVgmLqjd7vslwsFHdkRe1LrgzhA3ui6SzzZIFJRa0HiL12G9Eg6v+XGBPb/Oo3VU+Z0B5alrQ+7GNk7Dyo= 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=FG6c/AQe; 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="FG6c/AQe" Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-e2974759f5fso125356276.0 for ; Wed, 16 Oct 2024 10:53:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1729101239; x=1729706039; 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=FG6c/AQeG8UtzaTm7kBo9jhbnteYYU0YfY6AmOv6jzJbR15r8HhvBghrT8eeC+oC8R gpj69pfzIkjc00sMegJxqqODl4G11JdUr+I9uU6IQMGc94ZztpufWRKizN67PNV4biTU o2TK4BroqMsClLDLKHK1WVo3eq2T8oUHjQkVVwkgy5x+CwRVmibgOMe8Jgzj5jqh3Azv DQ0ly1pjrMqth+PzNlCHqBZ+JoNA0Mv7sluRlCYKs6QFNA1SIPLkQ0Q08sxKbp9ur4rJ NPqG057kqd3li0i51VEnHh8RS44dQf210sF/oMuWEsF5+VYjqupZo4XsdbyfazcuAWAb 7kkg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729101239; x=1729706039; 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=soPI17mi+sdlBohy9vYtPDhrDCsVv3lPuMkIjztq0aHVNfgV9ddZ2XAsBnuX4HyyhL gh0jSd3uMRratjSbkQ+CvAcZUODixBLut2RfgaqEqMQB8bbGmwmkaVSJZwmcXVsyIKMt f7l7LyYeoQMpPMAqIWLn61XtrDXbMW8dQtTXkVR5H9YvxNsDPfLXJLvhhgvs8GQLl5X8 cdFTWQsJp3zNFrqJr6MKJkVrCMy4dbIY2E6LjtjmpyCDeO3duYroJHqz2oHgLbv/AGnb cjAnfarPBf5E7z9yuQUVtNdZtVh6Nil9aG3NZ7CreQPRC9S8gmbznPa2yYMdWDtwU6Vr Jstw== X-Forwarded-Encrypted: i=1; AJvYcCVJcZ2ac26qhSfgOiwnrdXZVUi6dHP5XHX6Sn84XdCwA8Dpa3qvQcEvxCAjvL7pb4ApSxPhRHOb8ACBhC0=@vger.kernel.org X-Gm-Message-State: AOJu0YxL/JA478Sl5b1syR2dh8COyvEbOIce3eY+Tqhh+2lgvXWP8YNc SLa4RUMZgh+bAze5VpjZi3NfJait2AjfS8UlxLUTZbVrkSciP19WWH0zCz9SzFmFWLj221Aw2W8 m4N2vww== X-Google-Smtp-Source: AGHT+IF9yLM5WuIVC3/No1r0D9VnbRMfMBx4GY90c+0EZ2aDfR2GLFW//5ZuXISkFdhjg/a8djEvdyBOmda5 X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:a00a:f237:9bc0:79c]) (user=irogers job=sendgmr) by 2002:a05:6902:d47:b0:e29:7587:66d6 with SMTP id 3f1490d57ef6-e2b9ce7583cmr317276.4.1729101239076; Wed, 16 Oct 2024 10:53:59 -0700 (PDT) Date: Wed, 16 Oct 2024 10:53:44 -0700 In-Reply-To: <20241016175350.116227-1-irogers@google.com> Message-Id: <20241016175350.116227-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: <20241016175350.116227-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.105.g07ac214952-goog Subject: [PATCH v3 2/8] perf stat: Fix/add parameter names for print_metric From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , John Garry , Will Deacon , James Clark , Mike Leach , Leo Yan , Yicong Yang , Weilin Wang , Tim Chen , Thomas Richter , Sumanth Korikkar , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The print_metric parameter names were rearranged, fix and add comments in the stat-shadow callers to ensure they are correct. Signed-off-by: Ian Rogers --- tools/perf/util/stat-shadow.c | 55 ++++++++++++++++++++--------------- tools/perf/util/stat.h | 6 ++-- 2 files changed, 36 insertions(+), 25 deletions(-) diff --git a/tools/perf/util/stat-shadow.c b/tools/perf/util/stat-shadow.c index 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:32:36 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 06B752141C7 for ; Wed, 16 Oct 2024 17:54:02 +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=1729101243; cv=none; b=sWSVdDEOey51AIOLhp/noFg5NNie+n6KLYofh3CwYVUvTNkKY6cvdTQQY6gkUt0QsFVWKd/gY0H6ycWyQ0/ruDnBhJaVpCGbsIGO73uBnZbWxC9nHkWIWDU1vV8K5rpyyi5W2iI+gXhyj20ceMkgD3BcZs52eFfGGY6qOF2IS2g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729101243; c=relaxed/simple; bh=d4p2SSC+jRmzGX9QPS6kNxF3hzHXI6/kfpx81KrMoUw=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=kzz924P1YpDFpSpaHDvbQJQu6yxYHTpQ2JwjEwO+LuOs3XX47PXMlVj/flGcMitLy0LQ06CHR1NFq7i5K4PDapVpWHlF2uM13lza6h7IvsSbNkeGdKhooys6DoVx93FAQc6tL9JkBZfW8pnz6VdiSo/s/f984JbMVf2Zw1v0Lu8= 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=OkB0J/f2; 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="OkB0J/f2" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-6e376aa4586so3341197b3.1 for ; Wed, 16 Oct 2024 10:54:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1729101241; x=1729706041; 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=OkB0J/f2hP9TFV7P62zun8ZB0OuWZEPuVPtCU3UYh2Eal0/ZyFLfyTec4jSYx8Atru jrePS5Ta9uQGL5gYxSy6QIEAAmGNY4Stvw2OOYOYM5s8f4Ec8hy80s2XvcGftyRpuMi5 LFl/cK6EgnulqgSUxMBMs8/SHeM/1kkgnDpSKmJQDHcawq1LI40nMeNQpJ+u6YpmGeSl j9lBiSLGXVNAGyRaTWIv8unVz6JgPxfdefk/5diag7COe6tinlnaZWliJsiaWQNt4gCl 8AZqBwDLW20zA89+kBgHk3nDNqvLOrYUewYciqHj3JeF5oq0u3oZTRxq9zY4C1YP077J lq1g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729101241; x=1729706041; 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=h2xx5YOoH0JxC4sjlMVMQZzIXM3cUMjIceCySCN3Xe2bKP/T15nR8V8p1yaxKv4Oyg UnxedkxoN1FN7MbfJJ9Pa7ju927Pyi7g+LGivoBQBXwcqd4aZsmA9ohfU5GDiFByydCC J5Vf/gP0pjSIAupfTrNsB+LVyX3D7V0DMEMPychRrG+xh/Q2b10V6vF0xU4TXcPcuMpR ntpij8TakpI6HcQK+YKA27LHp3wHcob5i27Bvs8LY+PTjj6MsXVd03yZLzlWBBj59VVu tx/CjV43Ii0PYJ+v7cDhwnwwbxquEAVzX2d3b7UScQ371adtTC7R2tR++19aNORt1Dkl WFhg== X-Forwarded-Encrypted: i=1; AJvYcCXtyEHgrC8KU3UhzCKch60WbCOqj3rjfE8wbZ19hXdDVM7ldHRQzfnDsuop4wG/FZOcWgPRuvMm5mSXrHg=@vger.kernel.org X-Gm-Message-State: AOJu0YwdxnpI9YXVtA4rVHGAfmt1h+JhK4S6doS6aU6Ain1nUmWwc0T8 k6Y6ognRxOnBOUOd8DatIbULWVKqMzskaY7dcS3yOHl/fCqoVGxNykp+Xf9YfZJLb1TFBfWX8Yq 51eE0EA== X-Google-Smtp-Source: AGHT+IELo/jxtpIhUM+zuErAUU16bxjwCcPutOaOC6eTpP+GPy7PKQPs4wQx1eWp+F3YHF1VSqeKWTcYrvVB X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:a00a:f237:9bc0:79c]) (user=irogers job=sendgmr) by 2002:a25:a227:0:b0:e29:1864:5215 with SMTP id 3f1490d57ef6-e29782d1629mr2522276.1.1729101241059; Wed, 16 Oct 2024 10:54:01 -0700 (PDT) Date: Wed, 16 Oct 2024 10:53:45 -0700 In-Reply-To: <20241016175350.116227-1-irogers@google.com> Message-Id: <20241016175350.116227-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: <20241016175350.116227-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.105.g07ac214952-goog Subject: [PATCH v3 3/8] perf stat: Display "none" for NaN with metric only json From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , John Garry , Will Deacon , James Clark , Mike Leach , Leo Yan , Yicong Yang , Weilin Wang , Tim Chen , Thomas Richter , Sumanth Korikkar , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Return earlier for an empty unit case. If snprintf of the fmt doesn't produce digits between vals and ends, as happens with NaN, make the value "none" as happens in print_metric_end. Signed-off-by: Ian Rogers --- tools/perf/util/stat-display.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/tools/perf/util/stat-display.c b/tools/perf/util/stat-display.c index 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:32:36 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 2601B2144AC for ; Wed, 16 Oct 2024 17:54:03 +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=1729101245; cv=none; b=egNhuK83WUpmAOLf1tBsNnbX6/NlKFzVZaE1xi5ZOeveUVXYHon3d/2/zSDGn/LBH31sQUZcq5bLEOg8nJl7osICvdyc97ojXKMFsRyzyrGlrATUmtgRNKWxJK9B+tvcgdF9am3IZTMzmNsmJ794cVjsNADPauErYDomDsCnq4E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729101245; c=relaxed/simple; bh=tWKJqnfBwSOmrMspZ2sdkDVmtmOQkJadh5Otwb2PTrM=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=FbDLRgGfYBeqaOrmsOEz6eiZST9O2JNKndFb8y4krh8GKfvDD4FbJ3KOYismmU2kriM1HiLQiqbav51E5EwWOgSC5+NHQ264NoE1tn2ddtBywGBRv3W3S5VsruB2I/wz3IcPOXqY0iePUzfrV80ngaYkPGzZaZtdKSV7Miu/vDk= 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=nSFuQ3zv; 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="nSFuQ3zv" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-6e3204db795so2229207b3.2 for ; Wed, 16 Oct 2024 10:54:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1729101243; x=1729706043; 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=nSFuQ3zv66b3+ICwOEnquoFChnbGinRg9mzWc9uWveUrqxeAG08VyQFH+EOjj8KESa ZBvJQg4TvwynzA882n69dDe3cR3v7shN4Jf+baKR2t9F9mvLXKNj2BRejIyJeTF4NuwX qOarH0H2rBEoohjfNdjswKypw0N5Y1hWcVlQINlKNxZ1qEjZ/Zd8Vsv9CR55vCzs1Pdg 7ei7TP+9jwyOvF++8Eo+zju2MVsHvQogNxaJbIIRfWwpivSkB15pI/z+CSdJfcJDbGiX J1E0KM2vdvPUsGjW9yqYDivz3YraLeFfBmy3RZRdgdOeO4WKyOyTS8+tdBRLxWZ1FR8L eUUQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729101243; x=1729706043; 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=TEHLANbNT3+SCfkWaHlFDXurU2uiofoLxzLOfSJhZZd/Sj3h+L4D5WNIAkRWCBSJM4 kZe7lPnYjfRDcgFXpFjRrsmHPOe1IYIY2DoI7IdqOFJK7Npu8XnBIFex2X9YLd2uNv83 eN4vC7OXt5ll/xUuYNPdkZq7ISTm3ZMO5JLUsEM5iKyJxMo2XtmHhQ/q7ZllHGmtgDfH 7pLd1kXmjFvmgrdvNVkYFmqO7q+ZuTH9/deFIqf+6IG3nQuaj5yBwYoQO62IO86QMp5/ SghD+VDdY3z+ZwYvfVVltQyEMQ+dMwIXrq7WWM5If6hFgdJjpy2OS9/OagGVv7Vch902 e3tw== X-Forwarded-Encrypted: i=1; AJvYcCUHAvN8baSALXGl+SRCJ1vqoPE0t3So6UIvfpGkZDg4RTkrjugXF+AvTLjdBqvCEQUyS+Va1tWtAaeWuJA=@vger.kernel.org X-Gm-Message-State: AOJu0YzFcmt4jdgpwhzKQWq1DB6yS4DVgjKtoc6v+4Zuvbgnwja4Pl6J F8qMWb+lCGWNWK8b4rtPbEr9LufbiWiK/3Zvmg+TOeAfNIIOn72un36rAHfAIxNbsmkX/oU4NlO VwSzuWw== X-Google-Smtp-Source: AGHT+IHCPG9L9oWbfk5tOWCZkv2tp2sF7rrGkdVUIb+ubd1ZsfFeQQS6KOfWmd9ApJSK1xc5jRsIrFnSeVvf X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:a00a:f237:9bc0:79c]) (user=irogers job=sendgmr) by 2002:a25:dc10:0:b0:e2a:e7e2:60cf with SMTP id 3f1490d57ef6-e2ae7e2629bmr1152276.10.1729101243038; Wed, 16 Oct 2024 10:54:03 -0700 (PDT) Date: Wed, 16 Oct 2024 10:53:46 -0700 In-Reply-To: <20241016175350.116227-1-irogers@google.com> Message-Id: <20241016175350.116227-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: <20241016175350.116227-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.105.g07ac214952-goog Subject: [PATCH v3 4/8] perf stat: Drop metric-unit if unit is NULL From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , John Garry , Will Deacon , James Clark , Mike Leach , Leo Yan , Yicong Yang , Weilin Wang , Tim Chen , Thomas Richter , Sumanth Korikkar , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Avoid cases like: ``` $ perf stat -a -M topdownl1 -j -I 1000 ... {"interval" : 11.127757275, "counter-value" : "85715898.000000", "unit" : "= ", "event" : "IDQ.MITE_UOPS", "event-runtime" : 988376123, "pcnt-running" := 100.00, "metric-value" : "0.000000", "metric-unit" : "(null)"} ... ``` If there is no unit then drop the metric-value too as: Suggested-by: Tim Chen Signed-off-by: Ian Rogers --- tools/perf/util/stat-display.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/perf/util/stat-display.c b/tools/perf/util/stat-display.c index 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:32:36 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 36E7F2139CD for ; Wed, 16 Oct 2024 17:54:06 +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=1729101248; cv=none; b=RqNkS2o1EO92D+GWEobb4EaXvMbcajMnAsPi7h6ep59FSGRsI8yPNKXhCB1J4lt2r5qrJX0jDqfdEsnYdNfiYUvLaT2ROaRpmqq7F6GzaN7fi9cPWskbhTDdGihfzOUsb7HZfV57hXEDjdOokfSKo/4N/f7pG36yV5KaPjceD7E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729101248; c=relaxed/simple; bh=RVW6wkDVKjRG51bYEhA4x0xQ+lNpEYTqs22+cLMthkA=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=SVOwDkzjUW+iUlR/24KFEUqaTW+2fnugIm/Xq/vNv9IWfF9ZZ3JWm2YCPCuTgdopMks7sxfrXvYV5P2KEf41WUWuVn3MnNroU9bPnQkNr0PILGPwbv45mQtiP7hUyGFS3Z4JReWD91sxIj1E6rOQ5ksGCteJhQ0tHG3qXPN0hXA= 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=SoGK99tZ; 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="SoGK99tZ" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-690404fd230so2704197b3.3 for ; Wed, 16 Oct 2024 10:54:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1729101245; x=1729706045; 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=SoGK99tZ2Tr1O9SRja9aQ+954D9NeIKr4VTKU8XA4AV6lTSTJvcfx6+0ofpYjJ7W4x O1nrbjrmxDfFqQy5vCYW+fzTangUt2ucQOC733SKicKWVuso9TmYfo+fA0lU/Q4gl7SZ 6pGv1fOb6TBgrBauoXq945n04XDvop3Jf2XnVEx2JTK++C8E48/YHcakq+zDUeN7uuS1 0+/TxxAcq5gmsGtQRu3rVKfbm43M9iLbyp92IZ1kmd85YeDzXGWpTG4M9kwxH910/3Ca fwMrcgvx1+u2izfXLkiz8M3/mHBvyxWXRzFqdxdTwiLR+7g2VP+J10XAU8F4R61uCvd+ SuJw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729101245; x=1729706045; 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=gV1RU7UGSW6noV2/A6g7EcKJVPLcss4UlXaL9rn3sp2uEio5TwhaBVJvrAZjqSLV6Y 6spJLuHx6zDTIWFrFKACAFliLF+bWOttkhn9ZS/eWkDvV6DKomwnadqb3HCF7OHjgd4S H8ZSCfKZvjIzJemRwYN/kP5UrOXB/zxJkL7oEWaVg9zTHR8NKq8dMlAK2OxJ+bZapTDS b1obt6x49QZWtfo1yxqRMSZ5k1yhQz94Q6vdr1mHBs9LGihj7nbYdxFScBnknC8ssMTL wLCyhocmq0Tv9dTgdfqdFQ9pq4MDjsQG+/5fz0HUb7tnvUP/IRQVWRZDp8mxP2pYhkuI rDVg== X-Forwarded-Encrypted: i=1; AJvYcCW0hlArP6bIZNBFGdD25Wyo8SNNmbYq4wkd4SbXhtEcTuffzK8Cxgy8OV70sGBwRhQkWfCQ+6fOHiSTQRI=@vger.kernel.org X-Gm-Message-State: AOJu0Yyb86QS8bt7ODwxQPJehF/QCE44bcv8Fp0E2HLQufymOoZ0U1EL 0w/EdV7N4fvfRB5C6M0rMTJN+XnZw3ZSjvsKxCYYE2wbIqoq9sWDrK1952Gj8Mh0tI+BBLsjbX1 iuv3gZg== X-Google-Smtp-Source: AGHT+IGnjGhMvSzFHtZVcWPfdwWsuD0sysf4JIVTVrQ37M/sAfCzj1Luw0ZPOV2J/4JItSFYfyglzY+Xq9bC X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:a00a:f237:9bc0:79c]) (user=irogers job=sendgmr) by 2002:a05:6902:1824:b0:e28:fba4:8b6e with SMTP id 3f1490d57ef6-e2979482a97mr2696276.7.1729101245270; Wed, 16 Oct 2024 10:54:05 -0700 (PDT) Date: Wed, 16 Oct 2024 10:53:47 -0700 In-Reply-To: <20241016175350.116227-1-irogers@google.com> Message-Id: <20241016175350.116227-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: <20241016175350.116227-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.105.g07ac214952-goog Subject: [PATCH v3 5/8] perf stat: Change color to threshold in print_metric From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , John Garry , Will Deacon , James Clark , Mike Leach , Leo Yan , Yicong Yang , Weilin Wang , Tim Chen , Thomas Richter , Sumanth Korikkar , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Colors don't mean things in CSV and JSON output, switch to a threshold enum value that the standard output can convert to a color. Updating the CSV and JSON output will be later changes. Signed-off-by: Ian Rogers --- tools/perf/arch/x86/util/iostat.c | 2 +- tools/perf/builtin-script.c | 6 +- tools/perf/util/stat-display.c | 40 ++++++++---- tools/perf/util/stat-shadow.c | 105 +++++++++++++++--------------- tools/perf/util/stat.h | 12 +++- 5 files changed, 97 insertions(+), 68 deletions(-) diff --git a/tools/perf/arch/x86/util/iostat.c b/tools/perf/arch/x86/util/i= ostat.c index df7b5dfcc26a..366b44d0bb7e 100644 --- a/tools/perf/arch/x86/util/iostat.c +++ b/tools/perf/arch/x86/util/iostat.c @@ -444,7 +444,7 @@ void iostat_print_metric(struct perf_stat_config *confi= g, struct evsel *evsel, iostat_value =3D (count->val - prev_count_val) / ((double) count->run / count->ena); } - out->print_metric(config, out->ctx, NULL, "%8.0f", iostat_metric, + out->print_metric(config, out->ctx, METRIC_THRESHOLD_UNKNOWN, "%8.0f", io= stat_metric, iostat_value / (256 * 1024)); } =20 diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c index a644787fa9e1..8c5d5cecfba4 100644 --- a/tools/perf/builtin-script.c +++ b/tools/perf/builtin-script.c @@ -2136,11 +2136,11 @@ struct metric_ctx { }; =20 static void script_print_metric(struct perf_stat_config *config __maybe_un= used, - void *ctx, const char *color, - const char *fmt, - const char *unit, double val) + void *ctx, enum metric_threshold_classify thresh, + const char *fmt, const char *unit, double val) { struct metric_ctx *mctx =3D ctx; + const char *color =3D metric_threshold_classify__color(thresh); =20 if (!fmt) return; diff --git a/tools/perf/util/stat-display.c b/tools/perf/util/stat-display.c index 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:32:36 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 8CF37212EF1 for ; Wed, 16 Oct 2024 17:54:08 +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=1729101250; cv=none; b=XelVX6Cqf0vAo40sTH+VLhbPnGxFkjIje0KwFKW9kZHwqR2jaBgiXC9eKcALppBJGb5zD5By4bC/cMccxAi36wYa7iSImlgIlauqlR9DS/Xetx26bv7jcj85k2JnH25KDp2Plln9p6j8Ae0pC4vL1NWsvZUrXFwzsHKyvv3iN34= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729101250; c=relaxed/simple; bh=E4U7wuaBoI9LgrVIYNQQ2sVZhXY461X+XET2GkpBy3I=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=ZaqCNHji5g4uza+bJB94QTJDZAhgzSwsL3CXmC92tvtmkCwweZGVkaXp/teXA/8yGmU07UzjxpCInJYoTn3w1Qd6M6vpT8XxReltWblMsj3GBjnUu3lsbfXvpnLIp49MYLSDml9zegQ2rvNncu6IQZ6Fd+i/cM9rLy1zqQg8PAA= 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=i7gGUFOQ; 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="i7gGUFOQ" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-6e3c638cc27so4101437b3.0 for ; Wed, 16 Oct 2024 10:54:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1729101247; x=1729706047; 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=LGXxZcfS4OJGTX3QvHqzTzFNN5FRZqsvmi/1r7EUvS4=; b=i7gGUFOQXRl1k3KQIKT01U/zYwe2lfirE2OjD93wJxLTq0hk82qra4y21YbPGqNL9l COVbKyXKY+AQDStIG0nR+fLdFO5t/ut0w4zGAUsn0Qu+hd03s+WTL/LAJXXkdwqAyQVh Gn9kYU9OvUKGdGlF2+7NCeAwylS/UzgtROwMDwfmKWzPvzwP0DlPOtUHfgn+ZaYFXrXF 5u/7VqM6PCa2y2RoxbJvHkgeGtwUQBKq/UgMvaV+fJeblSwcSCD0LywdNyv/pFUT4QVp eIiibg9vnhCdmZ8HSCbTm60bU4Vox9VFnyLyErIRc6cZz41u9VEIidgsm8nQXDT6Qr3n n1vA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729101247; x=1729706047; 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=LGXxZcfS4OJGTX3QvHqzTzFNN5FRZqsvmi/1r7EUvS4=; b=pBiu7YlXzMhfO4Pb1H/eKvAKQ8Lo4wBWfDHfCx213jgoLdgKEHQTWbz8Vyczl1+O3l CUbhp6b7x8ZKxuVdpa4QwhZ3IDQvqqY+5eK3GiF1Xs/2IwtildUbGzrCy1518OlW1aNC D7VY+D1Ivsk4spFR0XQtwtHan6QvFCgxLL1gHOqQg6Me6aqezhlyRR0jVKR+V7XLWK2m 9e+a0VqMbVusCvNA7qNbfOXKkOGdQ9QDEWXolvCZGgqHOzTE4CA01OU5Ihh/Smy+NKrE faGUWGs79wfpIn21O56Zm+B9aL1m/QQUuaIcC935AIpb3OY7aeR/f2o0XtYEd0vjYkMJ WYlA== X-Forwarded-Encrypted: i=1; AJvYcCXpwm6ChfMKOTcSo9CfqqT5aQsOPts2v68szYbl7Q0q7IqDMa+5I1YzOyz9B6Oa2/CnFCANpk/Z/Q0Soow=@vger.kernel.org X-Gm-Message-State: AOJu0Yy/ugDVAKu4L3vOykKQ6QvYE1fjz0banZvmWAIlh4iMI5XqPWDd O+4EZO0lbgv2L1nBQ1H5dUia5acw7xgKPmxjREb1mvhpXLjQLbSbm87hmAaoGdXS9H9E0AnyqEH 4jxa+Gw== X-Google-Smtp-Source: AGHT+IEwDyVefJvbnEcXnUCGDgtLYI48Vd4K1wm26M6QP/9FKjnedwPjo/gKvNj2E5l5gpOWprueXZVBXC8I X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:a00a:f237:9bc0:79c]) (user=irogers job=sendgmr) by 2002:a05:6902:3284:b0:e29:7cd6:593b with SMTP id 3f1490d57ef6-e297cd65b8amr5311276.8.1729101247548; Wed, 16 Oct 2024 10:54:07 -0700 (PDT) Date: Wed, 16 Oct 2024 10:53:48 -0700 In-Reply-To: <20241016175350.116227-1-irogers@google.com> Message-Id: <20241016175350.116227-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: <20241016175350.116227-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.105.g07ac214952-goog Subject: [PATCH v3 6/8] perf stat: Display metric threshold value in CSV output From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , John Garry , Will Deacon , James Clark , Mike Leach , Leo Yan , Yicong Yang , Weilin Wang , Tim Chen , Thomas Richter , Sumanth Korikkar , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add a column with a metric threshold value. For example, the bad/good in the last column below: ``` $ perf stat -a -M topdownl1 -x, -I 1000 1.000103288,4677067630,,TOPDOWN.SLOTS,16029302700,100.00,31.1,% tma_backen= d_bound,bad 1.000103288,,,,,,51.0,% tma_frontend_bound,bad 1.000103288,,,,,,7.6,% tma_bad_speculation,good 1.000103288,,,,,,10.2,% tma_retiring,good 1.000103288,476781750,,topdown-retiring,16029302700,100.00,, 1.000103288,2389693619,,topdown-fe-bound,16029302700,100.00,, 1.000103288,1431602465,,topdown-be-bound,16029302700,100.00,, 1.000103288,378991388,,topdown-bad-spec,16029302700,100.00,, 1.000103288,4934535,,INT_MISC.CLEARS_COUNT,16029339890,100.00,, 1.000103288,56474476,,IDQ.MS_UOPS,16029292873,100.00,, 1.000103288,3188888,,INT_MISC.UOP_DROPPING,16029239908,100.00,, 1.000103288,484429099,,UOPS_RETIRED.SLOTS,16029176080,100.00,, 1.000103288,49066178,,UOPS_DECODED.DEC0,16029100912,100.00,, 1.000103288,26472844,,cpu/UOPS_DECODED.DEC0,cmask=3D1/,16029009707,100.00,, 1.000103288,709313662,,UOPS_ISSUED.ANY,16028914990,100.00,, 1.000103288,346833383,,IDQ.MITE_UOPS,16028820330,100.00,, ``` Signed-off-by: Ian Rogers --- tools/perf/Documentation/perf-stat.txt | 1 + tools/perf/tests/shell/stat+csv_output.sh | 24 ++++++++++---------- tools/perf/util/stat-display.c | 27 +++++++++++++++++++---- 3 files changed, 36 insertions(+), 16 deletions(-) diff --git a/tools/perf/Documentation/perf-stat.txt b/tools/perf/Documentat= ion/perf-stat.txt index 2bc063672486..9bfa1a085e98 100644 --- a/tools/perf/Documentation/perf-stat.txt +++ b/tools/perf/Documentation/perf-stat.txt @@ -622,6 +622,7 @@ The fields are in this order: - optional variance if multiple values are collected with -r - optional metric value - optional unit of metric + - optional how the value relates to a metric threshold =20 Additional metrics may be printed with all earlier fields being empty. =20 diff --git a/tools/perf/tests/shell/stat+csv_output.sh b/tools/perf/tests/s= hell/stat+csv_output.sh index fc2d8cc6e5e0..a3bc3c99b534 100755 --- a/tools/perf/tests/shell/stat+csv_output.sh +++ b/tools/perf/tests/shell/stat+csv_output.sh @@ -31,19 +31,19 @@ function commachecker() local exp=3D0 =20 case "$1" - in "--no-args") exp=3D6 - ;; "--system-wide") exp=3D6 - ;; "--event") exp=3D6 - ;; "--interval") exp=3D7 + in "--no-args") exp=3D7 + ;; "--system-wide") exp=3D7 + ;; "--event") exp=3D7 + ;; "--interval") exp=3D8 ;; "--per-thread") exp=3D7 - ;; "--system-wide-no-aggr") exp=3D7 - [ "$(uname -m)" =3D "s390x" ] && exp=3D'^[6-7]$' - ;; "--per-core") exp=3D8 - ;; "--per-socket") exp=3D8 - ;; "--per-node") exp=3D8 - ;; "--per-die") exp=3D8 - ;; "--per-cluster") exp=3D8 - ;; "--per-cache") exp=3D8 + ;; "--system-wide-no-aggr") exp=3D8 + [ "$(uname -m)" =3D "s390x" ] && exp=3D'^[7-8]$' + ;; "--per-core") exp=3D9 + ;; "--per-socket") exp=3D9 + ;; "--per-node") exp=3D9 + ;; "--per-die") exp=3D9 + ;; "--per-cluster") exp=3D9 + ;; "--per-cache") exp=3D9 esac =20 while read line diff --git a/tools/perf/util/stat-display.c b/tools/perf/util/stat-display.c index 5974aaead95f..f2750d1b34aa 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) @@ -455,14 +468,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); @@ -473,7 +487,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.105.g07ac214952-goog From nobody Tue Nov 26 17:32:36 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 981E6215F75 for ; Wed, 16 Oct 2024 17:54:10 +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=1729101252; cv=none; b=PP9Mk8gzFXyvFfLsGhrFERCNBKCH7/JkOQqnD5srNGJf0Of1+l3fcJELRE9ZsoX39SHk1OlEXXI6cDRSMYDSnkVIvQGyDf/17Zc4YbSg5FjdadXEr/F6Ar02kXwoDAoXlZUVbYXamXW4160rUuWX17y89KxqzoDTUcWVTCMtep0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729101252; c=relaxed/simple; bh=WKjU1a/lx3TbexW2NN4+1n8Opn4CO4/epvYjmMZ59go=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=APQy4M6VBasZ8o344ajor6mOW9HjfL8GByc3bOi6Jvev5BLMKaSjofQtRi2geSVK69lh8fZtzzH+xSi+jzk0iuq9m2sAHPcds0pJapP4XhSzUnBnQtKCFsYC7whG6nOgo/R/vHZFAoqC7a5EFMqAbb+qeVR643ia0C75sqUC+GU= 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=1IfefOmx; 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="1IfefOmx" Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-e17bb508bb9so77291276.2 for ; Wed, 16 Oct 2024 10:54:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1729101250; x=1729706050; 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=h17ekCegbTr4famvRlkpL0Qc+dXqqCi6gDChEA388fo=; b=1IfefOmx6STIPQ30UFtpuXO8G8zA09MlE/t33IswOJS/XJkTnlw1te982NNx0wNLOt wM6+O5c8hakTSpPxZdMNKfy9iGyAoRHE5j7Po99ItHectUoYljiJxQfkCipQ4gPzcfCD +vtkvtfCmxqLfB0k9MRah8ca7gB2hTOqVLc2dI85ZMHEGlCIBicQ79rccNeYIrFRyPSN JizReRdDlIS3/K82cSTLJ4ctv5CtFn0ILxQE9nSCctHKxESjqxm19mUy4F31/nqGema5 yErwqZ4hrNmyxanF84tFXO/w0CeCaD9MD1q64RYDUnAq8iJHYFQ9Pr5xIuyWDA1i672X Nczw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729101250; x=1729706050; 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=h17ekCegbTr4famvRlkpL0Qc+dXqqCi6gDChEA388fo=; b=FTYtIxxvdZmE5l/CRUH179CEwlsuIiii4VR4DR4HGqW0AjNwYA3qvZu1PiPRj5zUcp 2fnUgbTLnYerN2zxBRZt9S4PTtiw7Q0uF5iNIu3zG5qeV/8wQKcWCqD+06vCBrGyPJT5 e6QL4kPHuDumw3vOLq8kSx7DNnZVjqWLRnm0HI+f9lBVDjczce1QjPSFr3kC1TfsDmTd e4jJYzYfXvmqDVuRNt2TReuCz3MjsbenSaovTzaySRpAIWU8A1WI60eSDOd+eghLzaTT HnllJKZE0RY8MKAVSmFENABMZzxVYElTHu/OcgXLVS8f3Loz+Q49KCrc5rfP8weWwf4W T7xA== X-Forwarded-Encrypted: i=1; AJvYcCXZMNjJoDWBCKB78nuhgsrkdJhqjNP2ek8n9ORudJ2H9ze8brFsSN0VjLjj1+vg6ze9tFMY5nHpROXwLkQ=@vger.kernel.org X-Gm-Message-State: AOJu0Yz/5YvEPpGR1wcZW4zdhxzfN4vave6ZofFLzjeHJXxrnliAR7gr ttPzghzIt1FOGwEsLLvtTwzoQmxIIX6wVCjWtyxpZzcsDZ1QevDfP+4ej0xDZdiWl25qTtdCHUa D5FgzKA== X-Google-Smtp-Source: AGHT+IGbtXQuViQyESTsQNdCvj0QvKmS2njrdxDrBpkQZ2WTjfdpex+ZxXZpJMCWC9ztNlNC03yf8ZAvNR1Y X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:a00a:f237:9bc0:79c]) (user=irogers job=sendgmr) by 2002:a25:b227:0:b0:e28:ee55:c3d with SMTP id 3f1490d57ef6-e29782b0251mr3864276.1.1729101249705; Wed, 16 Oct 2024 10:54:09 -0700 (PDT) Date: Wed, 16 Oct 2024 10:53:49 -0700 In-Reply-To: <20241016175350.116227-1-irogers@google.com> Message-Id: <20241016175350.116227-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: <20241016175350.116227-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.105.g07ac214952-goog Subject: [PATCH v3 7/8] perf stat: Add metric-threshold to json output From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , John Garry , Will Deacon , James Clark , Mike Leach , Leo Yan , Yicong Yang , Weilin Wang , Tim Chen , Thomas Richter , Sumanth Korikkar , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" When the threshold isn't unknown add a value to the json like: "metric-threshold" : "good" A more complete example: ``` $ perf stat -a -j -I 1000 {"interval" : 1.001089747, "counter-value" : "16045.281449", "unit" : "msec= ", "event" : "cpu-clock", "event-runtime" : 16045355135, "pcnt-running" : 1= 00.00, "metric-value" : "16.045281", "metric-unit" : "CPUs utilized"} {"interval" : 1.001089747, "counter-value" : "10003.000000", "unit" : "", "= event" : "context-switches", "event-runtime" : 16045314844, "pcnt-running" = : 100.00, "metric-value" : "623.423156", "metric-unit" : "/sec"} {"interval" : 1.001089747, "counter-value" : "328.000000", "unit" : "", "ev= ent" : "cpu-migrations", "event-runtime" : 16045321403, "pcnt-running" : 10= 0.00, "metric-value" : "20.442147", "metric-unit" : "/sec"} {"interval" : 1.001089747, "counter-value" : "20114.000000", "unit" : "", "= event" : "page-faults", "event-runtime" : 16045355927, "pcnt-running" : 100= .00, "metric-value" : "1.253577", "metric-unit" : "K/sec"} {"interval" : 1.001089747, "counter-value" : "4066679471.000000", "unit" : = "", "event" : "instructions", "event-runtime" : 16045369123, "pcnt-running"= : 100.00, "metric-value" : "1.628330", "metric-unit" : "insn per cycle"} {"interval" : 1.001089747, "counter-value" : "2497454658.000000", "unit" : = "", "event" : "cycles", "event-runtime" : 16045374810, "pcnt-running" : 100= .00, "metric-value" : "0.155650", "metric-unit" : "GHz"} {"interval" : 1.001089747, "counter-value" : "914974294.000000", "unit" : "= ", "event" : "branches", "event-runtime" : 16045379877, "pcnt-running" : 10= 0.00, "metric-value" : "57.024509", "metric-unit" : "M/sec"} {"interval" : 1.001089747, "counter-value" : "9237201.000000", "unit" : "",= "event" : "branch-misses", "event-runtime" : 16045375017, "pcnt-running" := 100.00, "metric-value" : "1.009559", "metric-unit" : "of all branches", "m= etric-threshold" : "good"} {"interval" : 1.001089747, "event-runtime" : 16045397172, "pcnt-running" : = 100.00, "metricgroup" : "TopdownL1"} {"interval" : 1.001089747, "metric-value" : "22.036686", "metric-unit" : "%= tma_backend_bound", "metric-threshold" : "bad"} {"interval" : 1.001089747, "metric-value" : "7.610161", "metric-unit" : "% = tma_bad_speculation", "metric-threshold" : "good"} {"interval" : 1.001089747, "metric-value" : "36.729687", "metric-unit" : "%= tma_frontend_bound", "metric-threshold" : "bad"} {"interval" : 1.001089747, "metric-value" : "33.623465", "metric-unit" : "%= tma_retiring"} ... ``` Signed-off-by: Ian Rogers --- tools/perf/tests/shell/lib/perf_json_output_lint.py | 5 ++++- tools/perf/util/stat-display.c | 9 +++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/tools/perf/tests/shell/lib/perf_json_output_lint.py b/tools/pe= rf/tests/shell/lib/perf_json_output_lint.py index abc1fd737782..8ddb85586131 100644 --- a/tools/perf/tests/shell/lib/perf_json_output_lint.py +++ b/tools/perf/tests/shell/lib/perf_json_output_lint.py @@ -57,6 +57,7 @@ def check_json_output(expected_items): 'interval': lambda x: isfloat(x), 'metric-unit': lambda x: True, 'metric-value': lambda x: isfloat(x), + 'metric-threshold': lambda x: x in ['unknown', 'good', 'less good', = 'nearly bad', 'bad'], 'metricgroup': lambda x: True, 'node': lambda x: True, 'pcnt-running': lambda x: isfloat(x), @@ -68,13 +69,15 @@ def check_json_output(expected_items): for item in json.loads(input): if expected_items !=3D -1: count =3D len(item) - if count !=3D expected_items and count >=3D 1 and count <=3D 6 and '= metric-value' in item: + if count !=3D expected_items and count >=3D 1 and count <=3D 7 and '= metric-value' in item: # Events that generate >1 metric may have isolated metric # values and possibly other prefixes like interval, core, # aggregate-number, or event-runtime/pcnt-running from multiplexin= g. pass elif count !=3D expected_items and count >=3D 1 and count <=3D 5 and= 'metricgroup' in item: pass + elif count =3D=3D expected_items + 1 and 'metric-threshold' in item: + pass elif count !=3D expected_items: raise RuntimeError(f'wrong number of fields. counted {count} expec= ted {expected_items}' f' in \'{item}\'') diff --git a/tools/perf/util/stat-display.c b/tools/perf/util/stat-display.c index f2750d1b34aa..5b700b259572 100644 --- a/tools/perf/util/stat-display.c +++ b/tools/perf/util/stat-display.c @@ -497,15 +497,20 @@ static void print_metric_csv(struct perf_stat_config = *config, =20 static void print_metric_json(struct perf_stat_config *config __maybe_unus= ed, void *ctx, - enum metric_threshold_classify thresh __maybe_unused, + enum metric_threshold_classify thresh, const char *fmt __maybe_unused, const char *unit, double val) { struct outstate *os =3D ctx; FILE *out =3D os->fh; =20 - if (unit) + if (unit) { fprintf(out, "\"metric-value\" : \"%f\", \"metric-unit\" : \"%s\"", val,= unit); + if (thresh !=3D METRIC_THRESHOLD_UNKNOWN) { + fprintf(out, ", \"metric-threshold\" : \"%s\"", + metric_threshold_classify__str(thresh)); + } + } if (!config->metric_only) fprintf(out, "}"); } --=20 2.47.0.105.g07ac214952-goog From nobody Tue Nov 26 17:32:36 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 E7EC5216A14 for ; Wed, 16 Oct 2024 17:54:12 +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=1729101254; cv=none; b=Wy9wjyQx+OR/sYMm8RLp2cQ6+sZsAtZGEo6wlA3kM0tG5MxuUGc+1AnoZ0jfEsiCWoX2AxB1hB1gX3EL2BXCcKG/9f4sr1HQ5cDFYwQZA4lWHF4aCgyOJTl9GHZgu14+Eee9iyJk6xAnTh3dC9k47sLhACMOxGu4YfEHL3oJZLI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729101254; c=relaxed/simple; bh=fee7TAq/eP5tzXna+g+K/Sx9L8xSc4L9m1SCV2eHqNc=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=hed/04vo+HjNOT+0oAAS2REuRxJuBvMCyUHzftkuIzWhUn0Go2WR9FzH9DKrKSWEFj9gNBcAPmCulqQw3ohCHijbZNtaiaBmg6MN0CSUWgqMrgXNL0LkDBGyMcOlOLo0+4P438odZME4E55wM2y7RMUrmo5eTjJvBA1g4ZR1hAY= 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=yxf9k3vJ; 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="yxf9k3vJ" Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-e02b5792baaso74641276.2 for ; Wed, 16 Oct 2024 10:54:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1729101252; x=1729706052; 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=vsMWssyTOvP1WMheCN0DpJ+nfzBtD5CMizHYReN/aDk=; b=yxf9k3vJeI89kk2mvr1QoC68znsICyXQbdgq4uYwVWntBuvmuJFvi0LrAfQhlB9aCa Xa1+qB1UeFMsfRykBb8jq0vnFBFp9T7VDKxOk67ZvwGMx51XYfflJKeIh6YZ90JyLuBt tJX38ulotvqeL3gRkDWkg+gVM8ObLXXQ+hkEeoHF2R5vrtNRuHOEz4FqO7eF3Em08KPc fArljDBAiqF0Ce89RFkms11f2fisiYnIUbddwEt5naQw5NzpGWmFf7wwwgn4aQR57d1e 2KAsBRRyVsr2tpNui2GVSrbZvjccyDROog2xgY12XMtFAs9PuyVbtT9EBEIJRPJQy9Nr O8hw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729101252; x=1729706052; 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=vsMWssyTOvP1WMheCN0DpJ+nfzBtD5CMizHYReN/aDk=; b=AOBPDC1TsuXeAAc/sf3GmXBFY89304nwCJOoTIsKmVSoifH+tjwB+6Eiq1bl+BVfQ6 bpXlarKWZa0EFKGbtb4aaEHnLD+CoH6MqkR0Y1zvcCTBmyyg3Z3NtDbSAuQ+Po6eHu9e 4wWdqAiVy6iPI3rdEoSg5QrnJ+53Eq0WShbXzYeVBuhj+3mofZxrZeNxFKpsS8B2iCvN MvMVB30fHIWijth+KZR/UID9bJ0+p97AREtA34N/lkPGhXXJxV4MfxDpQcEL4J/5WS2S homl02WOTLmMD1tjI7WVrgilPnhlFrrHo2hP19FmEiQZTrS5Ykrz8NelTRCVoDHfCMkV jFgw== X-Forwarded-Encrypted: i=1; AJvYcCW2JuTh2hsg4pCeRRiIH9VjwQeFSqGQy6t+wQF4NKj9/vsrOscK4etK9r5M3+zPpcPj5sFMz1wb0+s+ERw=@vger.kernel.org X-Gm-Message-State: AOJu0YzN8a1NYj/cBHPgfJqGHs+Z0eSQvC3Bgm4exb3wEyhfUFLROPvz z7aBJoHN3geWqk5LewfBW79q2MVZ4grBJMTS50yFvl1yB4oS8u1y7hVpN2t9KZM4Tot8gUQHPf2 E3l1ejg== X-Google-Smtp-Source: AGHT+IGwzJ8F80Se119mAueQ7bqO735E4nJLUizxWDlBOxLr87KBzIrWBt25r2jhZ9ZswgpsimkIQAxCJR04 X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:a00a:f237:9bc0:79c]) (user=irogers job=sendgmr) by 2002:a25:a2c4:0:b0:e25:caa3:9c2e with SMTP id 3f1490d57ef6-e297858905emr5272276.11.1729101251943; Wed, 16 Oct 2024 10:54:11 -0700 (PDT) Date: Wed, 16 Oct 2024 10:53:50 -0700 In-Reply-To: <20241016175350.116227-1-irogers@google.com> Message-Id: <20241016175350.116227-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: <20241016175350.116227-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.105.g07ac214952-goog Subject: [PATCH v3 8/8] perf stat: Disable metric thresholds for CSV/JSON metric-only mode From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , John Garry , Will Deacon , James Clark , Mike Leach , Leo Yan , Yicong Yang , Weilin Wang , Tim Chen , Thomas Richter , Sumanth Korikkar , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" These modes don't use the threshold, so don't compute it saving time and potentially reducing events. Signed-off-by: Ian Rogers --- tools/perf/builtin-stat.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c index b5e18853982c..60d747c2e0e3 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.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.105.g07ac214952-goog