From nobody Wed Feb 11 17:25:42 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2BB1FC61DA4 for ; Mon, 13 Mar 2023 11:43:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231390AbjCMLnP (ORCPT ); Mon, 13 Mar 2023 07:43:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49398 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230480AbjCMLmK (ORCPT ); Mon, 13 Mar 2023 07:42:10 -0400 Received: from mail-pj1-x1030.google.com (mail-pj1-x1030.google.com [IPv6:2607:f8b0:4864:20::1030]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CABCD6423B for ; Mon, 13 Mar 2023 04:41:37 -0700 (PDT) Received: by mail-pj1-x1030.google.com with SMTP id nn12so11678101pjb.5 for ; Mon, 13 Mar 2023 04:41:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1678707697; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=lYZdsrHdzQhNgPnVDhJiRxXzSTwxol5Us4hF+GT6h6U=; b=HtcQ1Dsqji+5/51Jgddi4wmF19iXqpi5/q3y1S7vRBhkcO+9eiAHZNJgGKugNGFJe3 UkoD8p5470YfPpMcfbRLFm5bOStdn4VWkAeoMi+TZxn/D3t3pSicndN++cAPueo3Hvbz LKRjR1hcEmtJosnFX8Z4prmbcLX5cNAyfkDsR7ygVXxehulkCD7Izhd+0Ub0LgtdDHhJ tIsa7ldlKyyL/QRvQP9yDoAhy6IYqsHZVfLUCstKIRUlKliUeGbQ5JHl9ISaj+XJM3db rjZOjynBXF9AG20TqUhT3PFcYJ9T758CuiZQ5EC76W+4cbLkqpefNzrSaE8/0LOmdxJE hVbA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678707697; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=lYZdsrHdzQhNgPnVDhJiRxXzSTwxol5Us4hF+GT6h6U=; b=IbuwBBEGmVaMifzGsmiBRo2kjQytV7no07N0c6SWURR6OY/CT+mnGPmoHjD0IzpYtU UJ2cLaSRureFjBx18UkqlsKlAriNXDHBXx+NvEHjMgzWLXVH5cgntJPuPFAgCvicF/cz Uiln9p2wk54J4kF8J545omHUzF9wt1JI0KQfjg8RzDPNR7tg5M0Bus5dF0SUvbSd/HGZ qsyYq5u0JAwEAwehH50sQoqIwPRYCsneUQhcr0U7WovZgH/KwR6E15fPWLdjzzBYNyQj sG7QHFPJ67xnOlisom8v+GuUiQ+1+I+w4w1BjpPumpPq1h1ODVicb/M79mbHEO+QYd5W /IIg== X-Gm-Message-State: AO0yUKXBWayeFJpT1lf9kDV38mtjNQJjYIxwuyzvHAT3zRj86r2P/glA 9dqrbtiTrO1VKU0KzlqGPKGs6w== X-Google-Smtp-Source: AK7set/BOeUqqeuViWC/Z5kQPNArKlQiD0EepwzcBVBkbMOYcfXI7afFPERJ2nJOxEjyUZWsVdxaSA== X-Received: by 2002:a17:90b:1d12:b0:234:e3f:f53b with SMTP id on18-20020a17090b1d1200b002340e3ff53bmr34768751pjb.21.1678707697421; Mon, 13 Mar 2023 04:41:37 -0700 (PDT) Received: from leoy-huanghe.lan ([156.59.236.112]) by smtp.gmail.com with ESMTPSA id q21-20020a17090a2e1500b0022335f1dae2sm4281625pjd.22.2023.03.13.04.41.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Mar 2023 04:41:37 -0700 (PDT) From: Leo Yan To: Arnaldo Carvalho de Melo , Jiri Olsa , Namhyung Kim , Ian Rogers , John Garry , James Clark , Adrian Hunter , Peter Zijlstra , Ingo Molnar , Mark Rutland , Alexander Shishkin , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Cc: Leo Yan Subject: [PATCH v4 13/16] perf kvm: Support printing attributions for dimensions Date: Mon, 13 Mar 2023 19:40:15 +0800 Message-Id: <20230313114018.543254-14-leo.yan@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230313114018.543254-1-leo.yan@linaro.org> References: <20230313114018.543254-1-leo.yan@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" This patch adds header, entry callback and width for every dimension, thus in TUI mode the tool can print items with the defined attributions. Signed-off-by: Leo Yan Reviewed-by: James Clark --- tools/perf/builtin-kvm.c | 97 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 94 insertions(+), 3 deletions(-) diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c index 1e9338855239..0d857df826cf 100644 --- a/tools/perf/builtin-kvm.c +++ b/tools/perf/builtin-kvm.c @@ -83,8 +83,12 @@ struct kvm_hists { =20 struct kvm_dimension { const char *name; + const char *header; + int width; int64_t (*cmp)(struct perf_hpp_fmt *fmt, struct hist_entry *left, struct hist_entry *right); + int (*entry)(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp, + struct hist_entry *he); }; =20 struct kvm_fmt { @@ -102,9 +106,24 @@ static int64_t ev_name_cmp(struct perf_hpp_fmt *fmt __= maybe_unused, return -strcmp(left->kvm_info->name, right->kvm_info->name); } =20 +static int fmt_width(struct perf_hpp_fmt *fmt, + struct perf_hpp *hpp __maybe_unused, + struct hists *hists __maybe_unused); + +static int ev_name_entry(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp, + struct hist_entry *he) +{ + int width =3D fmt_width(fmt, hpp, he->hists); + + return scnprintf(hpp->buf, hpp->size, "%*s", width, he->kvm_info->name); +} + static struct kvm_dimension dim_event =3D { + .header =3D "Event name", .name =3D "ev_name", .cmp =3D ev_name_cmp, + .entry =3D ev_name_entry, + .width =3D 40, }; =20 #define EV_METRIC_CMP(metric) \ @@ -130,29 +149,77 @@ EV_METRIC_CMP(max) EV_METRIC_CMP(min) EV_METRIC_CMP(mean) =20 +#define EV_METRIC_ENTRY(metric) \ +static int ev_entry_##metric(struct perf_hpp_fmt *fmt, \ + struct perf_hpp *hpp, \ + struct hist_entry *he) \ +{ \ + struct kvm_event *event; \ + int width =3D fmt_width(fmt, hpp, he->hists); \ + struct perf_kvm_stat *perf_kvm; \ + \ + event =3D container_of(he, struct kvm_event, he); \ + perf_kvm =3D event->perf_kvm; \ + return scnprintf(hpp->buf, hpp->size, "%*lu", width, \ + get_event_##metric(event, perf_kvm->trace_vcpu)); \ +} + +EV_METRIC_ENTRY(time) +EV_METRIC_ENTRY(count) +EV_METRIC_ENTRY(max) +EV_METRIC_ENTRY(min) + static struct kvm_dimension dim_time =3D { + .header =3D "Time (ns)", .name =3D "time", .cmp =3D ev_cmp_time, + .entry =3D ev_entry_time, + .width =3D 12, }; =20 static struct kvm_dimension dim_count =3D { + .header =3D "Samples", .name =3D "sample", .cmp =3D ev_cmp_count, + .entry =3D ev_entry_count, + .width =3D 12, }; =20 static struct kvm_dimension dim_max_time =3D { + .header =3D "Max Time (ns)", .name =3D "max_t", .cmp =3D ev_cmp_max, + .entry =3D ev_entry_max, + .width =3D 14, }; =20 static struct kvm_dimension dim_min_time =3D { + .header =3D "Min Time (ns)", .name =3D "min_t", .cmp =3D ev_cmp_min, + .entry =3D ev_entry_min, + .width =3D 14, }; =20 +static int ev_entry_mean(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp, + struct hist_entry *he) +{ + struct kvm_event *event; + int width =3D fmt_width(fmt, hpp, he->hists); + struct perf_kvm_stat *perf_kvm; + + event =3D container_of(he, struct kvm_event, he); + perf_kvm =3D event->perf_kvm; + return scnprintf(hpp->buf, hpp->size, "%*lu", width, + get_event_mean(event, perf_kvm->trace_vcpu)); +} + static struct kvm_dimension dim_mean_time =3D { + .header =3D "Mean Time (ns)", .name =3D "mean_t", .cmp =3D ev_cmp_mean, + .entry =3D ev_entry_mean, + .width =3D 14, }; =20 static struct kvm_dimension *dimensions[] =3D { @@ -165,6 +232,30 @@ static struct kvm_dimension *dimensions[] =3D { NULL, }; =20 +static int fmt_width(struct perf_hpp_fmt *fmt, + struct perf_hpp *hpp __maybe_unused, + struct hists *hists __maybe_unused) +{ + struct kvm_fmt *kvm_fmt; + + kvm_fmt =3D container_of(fmt, struct kvm_fmt, fmt); + return kvm_fmt->dim->width; +} + +static int fmt_header(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp, + struct hists *hists, int line __maybe_unused, + int *span __maybe_unused) +{ + struct kvm_fmt *kvm_fmt; + struct kvm_dimension *dim; + int width =3D fmt_width(fmt, hpp, hists); + + kvm_fmt =3D container_of(fmt, struct kvm_fmt, fmt); + dim =3D kvm_fmt->dim; + + return scnprintf(hpp->buf, hpp->size, "%*s", width, dim->header); +} + static bool fmt_equal(struct perf_hpp_fmt *a, struct perf_hpp_fmt *b) { struct kvm_fmt *kvm_fmt_a =3D container_of(a, struct kvm_fmt, fmt); @@ -214,9 +305,9 @@ static struct kvm_fmt *get_format(const char *name) fmt->cmp =3D dim->cmp; fmt->sort =3D dim->cmp; fmt->color =3D NULL; - fmt->entry =3D NULL; - fmt->header =3D NULL; - fmt->width =3D NULL; + fmt->entry =3D dim->entry; + fmt->header =3D fmt_header; + fmt->width =3D fmt_width; fmt->collapse =3D dim->cmp; fmt->equal =3D fmt_equal; fmt->free =3D fmt_free; --=20 2.34.1