From nobody Thu Nov 28 05:44:08 2024 Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0AEDA1553AB for ; Fri, 4 Oct 2024 23:41:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728085290; cv=none; b=nghzZXg0CWM2O5lXs7d7NYMqlEwfEhMBl0JjZ0eCFuMku6DTjYm4wja2DYvUjJE8oVKGdXSuOY+XFj1qLXc/OixMbd0Kxvs+DfcWJzYTayvlzkR+MqthD3/aajVh/kLJOEu+STvKO5n+vKpphgrJIT7XiwKWxOMOJf17iY6+7qo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728085290; c=relaxed/simple; bh=LvLeqWxdA2TeKOaDt4auOtFHYmifqW5hHzjxgLb+wnk=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=fvLVFLGcaLmA+YL4yUJW2VY8bMOxRwVtS4GZfJ1ojFo/s/avAUzQ8dKDQb+NzFyWoul2VQInBqcBBEKgcdKXPlayfbwf9S9cw/hB1dIv0X5Yi0ZpE+yqCWODBNUVsg0E348jqs4wMVkoyBZM9qnWKc5dBFI/DzotOi5MNC+sks0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=D8cCcljZ; arc=none smtp.client-ip=209.85.128.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="D8cCcljZ" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-6e26ba37314so41994687b3.0 for ; Fri, 04 Oct 2024 16:41:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1728085288; x=1728690088; darn=vger.kernel.org; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=A6CcUNAGP79XtjWuaAPJ4OrijNFqcGuc6YFaoXPXPNs=; b=D8cCcljZtKRLLHmas+tud6Ndo+kDepmj+wMKt05ZgcUA2BLD/R5ks/Y5tHkplX9sEU viIJ4X/KNCnNe0/c5b3oFbe0RwAL/k5AOZjg82uuKFOM+8l8Jl1EE7GBeLBWeawViqV7 R/YQWPIiiGAQ5nCaF6iXLO/fjSyJt3T35fO9ybrGooFtMK2Ew/J1DzcK+IlZMzjSfQxG z4F/nyczaaFkhStKgs3Wcy/ForEKv2NObqbygXqRthxnbUelXWBSuFOaoPz2UpR1iFWf MiyKuWbe4+yf28PB/3Ep2DY7Aq9anVzXSJ5l5Rz0stkyVDNIwyxUuJOp/6pk7/HiVkjT 6wYw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728085288; x=1728690088; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=A6CcUNAGP79XtjWuaAPJ4OrijNFqcGuc6YFaoXPXPNs=; b=Nzolv4AVJxYrCfPA9mvBt7QSdR3+VLm4hxXlmxc0IOi9r0nIYfOgjHNW8hYruwadEW VTRpIoqpz8yh2uF9kDbJVQXHnW1HIVHr2qmoygx62ho9BlDaYHufSnF7hlIa1Pxup2d4 raQhFj++Moj17hQLjm4JUyCBhFbB623c7o3EKnANvCkWzWjzofqb7w2xTRSBIc1JY0AZ P8Evt5g1S03sjnQBDxfbv+wP/ZcInmPyR1uj275sqomNv0yT83miCWRuif67siyrscc5 TtSFUqjEGamYUA62+9gftFmPwuYf0Wof7xL+LSs4byopmMZMB0figBR7PWxUlHRmgpCu EDpA== X-Forwarded-Encrypted: i=1; AJvYcCUssaQ6xLzHenzUc4uooSleO0fU/A0f1hgaZIoZUbyBYCHq+ZG6OTd2HfOrcoU8crIAt+NDXVMQcVpBU7E=@vger.kernel.org X-Gm-Message-State: AOJu0YzO7gTDXV1EWNoJ0Cw4jHocDum5ZjZ4roqqMeJejjc+Xt2otypN 5YRn9G9/WxKaXiP3YCe8TXuZ8mpkgqFzLI1BPH3/yM7J3WOmCsWHNfFh2ife2tyYB1ecEiLWpD8 wL/EOvQ== X-Google-Smtp-Source: AGHT+IFqw6htDoHPrP52f8AD6FsGc60YnuQl8LA6+s9ft64QucdGHglRTtYEDtHIDvGu9pa6YkRbuCsaTeHC X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:8d23:e3c7:679f:19df]) (user=irogers job=sendgmr) by 2002:a05:690c:6686:b0:6db:da20:fa12 with SMTP id 00721157ae682-6e2c6e90bb5mr215817b3.0.1728085287901; Fri, 04 Oct 2024 16:41:27 -0700 (PDT) Date: Fri, 4 Oct 2024 16:41:14 -0700 In-Reply-To: <20241004234120.1495209-1-irogers@google.com> Message-Id: <20241004234120.1495209-3-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241004234120.1495209-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.rc0.187.ge670bccf7e-goog Subject: [PATCH v1 2/8] perf stat: Fix/add parameter names for print_metric From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , John Garry , Will Deacon , James Clark , Mike Leach , Leo Yan , Yicong Yang , Weilin Wang , Tim Chen , Thomas Richter , Sumanth Korikkar , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The print_metric parameter names were rearranged, fix and add comments in the stat-shadow callers to ensure they are correct. Signed-off-by: Ian Rogers --- tools/perf/util/stat-shadow.c | 55 ++++++++++++++++++++--------------- tools/perf/util/stat.h | 6 ++-- 2 files changed, 36 insertions(+), 25 deletions(-) diff --git a/tools/perf/util/stat-shadow.c b/tools/perf/util/stat-shadow.c index 3ce756b8ede5..1e6ba6bf244a 100644 --- a/tools/perf/util/stat-shadow.c +++ b/tools/perf/util/stat-shadow.c @@ -195,17 +195,21 @@ static void print_ratio(struct perf_stat_config *conf= ig, const struct evsel *evsel, int aggr_idx, double numerator, struct perf_stat_output_ctx *out, enum stat_type denominator_type, - const double color_ratios[3], const char *unit) + const double color_ratios[3], const char *_unit) { double denominator =3D find_stat(evsel, aggr_idx, denominator_type); + double ratio =3D 0; + const char *color =3D NULL; + const char *fmt =3D NULL; + const char *unit =3D NULL; =20 if (numerator && denominator) { - double ratio =3D numerator / denominator * 100.0; - const char *color =3D get_ratio_color(color_ratios, ratio); - - out->print_metric(config, out->ctx, color, "%7.2f%%", unit, ratio); - } else - out->print_metric(config, out->ctx, NULL, NULL, unit, 0); + ratio =3D numerator / denominator * 100.0; + color =3D get_ratio_color(color_ratios, ratio); + fmt =3D "%7.2f%%"; + unit =3D _unit; + } + out->print_metric(config, out->ctx, color, fmt, unit, ratio); } =20 static void print_stalled_cycles_front(struct perf_stat_config *config, @@ -319,14 +323,15 @@ static void print_instructions(struct perf_stat_confi= g *config, find_stat(evsel, aggr_idx, STAT_STALLED_CYCLES_BACK)); =20 if (cycles) { - print_metric(config, ctxp, NULL, "%7.2f ", "insn per cycle", - instructions / cycles); - } else - print_metric(config, ctxp, NULL, NULL, "insn per cycle", 0); + print_metric(config, ctxp, /*color=3D*/NULL, "%7.2f ", "insn per cycle", + instructions / cycles); + } else { + print_metric(config, ctxp, /*color=3D*/NULL, /*fmt=3D*/NULL, "insn per c= ycle", 0); + } =20 if (max_stalled && instructions) { out->new_line(config, ctxp); - print_metric(config, ctxp, NULL, "%7.2f ", "stalled cycles per insn", + print_metric(config, ctxp, /*color=3D*/NULL, "%7.2f ", "stalled cycles p= er insn", max_stalled / instructions); } } @@ -341,9 +346,10 @@ static void print_cycles(struct perf_stat_config *conf= ig, if (cycles && nsecs) { double ratio =3D cycles / nsecs; =20 - out->print_metric(config, out->ctx, NULL, "%8.3f", "GHz", ratio); - } else - out->print_metric(config, out->ctx, NULL, NULL, "GHz", 0); + out->print_metric(config, out->ctx, /*color=3D*/NULL, "%8.3f", "GHz", ra= tio); + } else { + out->print_metric(config, out->ctx, /*color=3D*/NULL, /*fmt=3D*/NULL, "G= Hz", 0); + } } =20 static void print_nsecs(struct perf_stat_config *config, @@ -356,10 +362,11 @@ static void print_nsecs(struct perf_stat_config *conf= ig, double wall_time =3D avg_stats(&walltime_nsecs_stats); =20 if (wall_time) { - print_metric(config, ctxp, NULL, "%8.3f", "CPUs utilized", + print_metric(config, ctxp, /*color=3D*/NULL, "%8.3f", "CPUs utilized", nsecs / (wall_time * evsel->scale)); - } else - print_metric(config, ctxp, NULL, NULL, "CPUs utilized", 0); + } else { + print_metric(config, ctxp, /*color=3D*/NULL, /*fmt=3D*/NULL, "CPUs utili= zed", 0); + } } =20 static int prepare_metric(const struct metric_expr *mexp, @@ -532,12 +539,12 @@ static void generic_metric(struct perf_stat_config *c= onfig, ratio); } } else { - print_metric(config, ctxp, color, /*unit=3D*/NULL, + print_metric(config, ctxp, color, /*fmt=3D*/NULL, out->force_header ? (metric_name ?: evsel->name) : "", 0); } } else { - print_metric(config, ctxp, color, /*unit=3D*/NULL, + print_metric(config, ctxp, color, /*fmt=3D*/NULL, out->force_header ? (metric_name ?: evsel->name) : "", 0); } @@ -708,9 +715,11 @@ void perf_stat__print_shadow_stats(struct perf_stat_co= nfig *config, =20 if (unit !=3D ' ') snprintf(unit_buf, sizeof(unit_buf), "%c/sec", unit); - print_metric(config, ctxp, NULL, "%8.3f", unit_buf, ratio); - } else + print_metric(config, ctxp, /*color=3D*/NULL, "%8.3f", + unit_buf, ratio); + } else { num =3D 0; + } } } =20 @@ -718,7 +727,7 @@ void perf_stat__print_shadow_stats(struct perf_stat_con= fig *config, &num, NULL, out, metric_events); =20 if (num =3D=3D 0) - print_metric(config, ctxp, NULL, NULL, NULL, 0); + print_metric(config, ctxp, /*color=3D*/NULL, /*fmt=3D*/NULL, /*unit=3D*/= NULL, 0); } =20 /** diff --git a/tools/perf/util/stat.h b/tools/perf/util/stat.h index fd7a187551bd..a5f3d7d00101 100644 --- a/tools/perf/util/stat.h +++ b/tools/perf/util/stat.h @@ -155,8 +155,10 @@ extern struct stats walltime_nsecs_stats; extern struct rusage_stats ru_stats; =20 typedef void (*print_metric_t)(struct perf_stat_config *config, - void *ctx, const char *color, const char *unit, - const char *fmt, double val); + void *ctx, const char *color, + const char *fmt, + const char *unit, + double val); typedef void (*new_line_t)(struct perf_stat_config *config, void *ctx); =20 /* Used to print the display name of the Default metricgroup for now. */ --=20 2.47.0.rc0.187.ge670bccf7e-goog