From mboxrd@z Thu Jan 1 00:00:00 1970 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 1C2432139CF 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=1729101241; cv=none; b=Am4+1m6ZWDwRzyXnN20kfY4pUS/rX8I6xeCxIKMKxZSrWTgwnlylYwdyFh6wIrWrC6TniC2dtdRb+/nyJ7CvT4q4NkZ7ZrkDdO9gm5Ec9sMRX8zKO2Kw+564zXcAhm9ooFf0j3KNoINsb2Pqh3b2VFmqRhRAqsTBLO+D/HJ4ums= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729101241; c=relaxed/simple; bh=WUodcAb4TVW2yeFy1LDOu4j2dnFFiTlcHPQcWZN06qw=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=qL0JMKmsIDnTnAuD+FsCiV5d1oRc/ajUW6IHKf55IOGhDGry6zn/dnlwSU+GAWl3Zur8zltSqGWzlFRmlRViMNgVXR4lP+FjHple4NlEPT56A2ZwRltwYTANm/92Xd/e3OSC0SzXValxQd8sVyvEaHmgI+i7TBR4ztGGtwmDOME= 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-e2946a143efso112295276.1 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=i8XpKcjSM9453x10VRk8T95dDDC/LVm6g/CBn8zR/Rk3CD3Eb9QzoiBf1qa11fySWR r8HKK1UyjU0lwgwVATgKMISVP0QoqYnFP335criTFy0Ol+cQ0rsELf5kvv4rq0x6kliw Epp6yq9r9Tv+C6rkFR/RuUfNeZsjLComrfU8s65hW+XzC1/vG7OlpAuIlmHivvnNACsE CY3a+qpGEwNu2Qw0HFcaKMwFTpNkpRjLLLfFPQh9pof3tyiDrSZLLV1dZh3EE/2wlvXL CrpRZi2Dau4TcF29dhUDU/1LzQPWdZdDcR03xPYTLTV3M3edgkgXkfUsm8zp0R5RVIYS 72Bw== X-Forwarded-Encrypted: i=1; AJvYcCX9yyJDi6XahyfDShSgFdKZlkHsD8+fls2NU0P6OS0dKIykVdQHb0VVMvo7iw7qalYJeF1Y934jB+SCov9mfDFB@vger.kernel.org X-Gm-Message-State: AOJu0YxLSsVGukOvMzJCPikWqwL89X4o8f67hrlISGKWo0hBWYqJy7Jk SpXKSlgwKzt4Swugoh5FMpoDkRBIaa8n1Yy0WWRa/DfKLGbACYSjARkJP1myT0sIe8oKuDUyQ5h /5XiOSg== 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-perf-users@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-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 *config, 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 = find_stat(evsel, aggr_idx, denominator_type); + double ratio = 0; + const char *color = NULL; + const char *fmt = NULL; + const char *unit = NULL; if (numerator && denominator) { - double ratio = numerator / denominator * 100.0; - const char *color = 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 = numerator / denominator * 100.0; + color = get_ratio_color(color_ratios, ratio); + fmt = "%7.2f%%"; + unit = _unit; + } + out->print_metric(config, out->ctx, color, fmt, unit, ratio); } static void print_stalled_cycles_front(struct perf_stat_config *config, @@ -320,14 +324,15 @@ static void print_instructions(struct perf_stat_config *config, find_stat(evsel, aggr_idx, STAT_STALLED_CYCLES_BACK)); 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=*/NULL, "%7.2f ", "insn per cycle", + instructions / cycles); + } else { + print_metric(config, ctxp, /*color=*/NULL, /*fmt=*/NULL, "insn per cycle", 0); + } 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=*/NULL, "%7.2f ", "stalled cycles per insn", max_stalled / instructions); } } @@ -342,9 +347,10 @@ static void print_cycles(struct perf_stat_config *config, if (cycles && nsecs) { double ratio = cycles / nsecs; - 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=*/NULL, "%8.3f", "GHz", ratio); + } else { + out->print_metric(config, out->ctx, /*color=*/NULL, /*fmt=*/NULL, "GHz", 0); + } } static void print_nsecs(struct perf_stat_config *config, @@ -357,10 +363,11 @@ static void print_nsecs(struct perf_stat_config *config, double wall_time = avg_stats(&walltime_nsecs_stats); if (wall_time) { - print_metric(config, ctxp, NULL, "%8.3f", "CPUs utilized", + print_metric(config, ctxp, /*color=*/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=*/NULL, /*fmt=*/NULL, "CPUs utilized", 0); + } } static int prepare_metric(const struct metric_expr *mexp, @@ -542,12 +549,12 @@ static void generic_metric(struct perf_stat_config *config, ratio); } } else { - print_metric(config, ctxp, color, /*unit=*/NULL, + print_metric(config, ctxp, color, /*fmt=*/NULL, out->force_header ? (metric_name ?: evsel->name) : "", 0); } } else { - print_metric(config, ctxp, color, /*unit=*/NULL, + print_metric(config, ctxp, color, /*fmt=*/NULL, out->force_header ? (metric_name ?: evsel->name) : "", 0); } @@ -718,9 +725,11 @@ void perf_stat__print_shadow_stats(struct perf_stat_config *config, if (unit != ' ') 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=*/NULL, "%8.3f", + unit_buf, ratio); + } else { num = 0; + } } } @@ -728,7 +737,7 @@ void perf_stat__print_shadow_stats(struct perf_stat_config *config, &num, NULL, out, metric_events); if (num == 0) - print_metric(config, ctxp, NULL, NULL, NULL, 0); + print_metric(config, ctxp, /*color=*/NULL, /*fmt=*/NULL, /*unit=*/NULL, 0); } /** 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; 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); /* Used to print the display name of the Default metricgroup for now. */ -- 2.47.0.105.g07ac214952-goog