From nobody Wed Feb 11 17:25:43 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 8F2F3C74A4B for ; Mon, 13 Mar 2023 11:43:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231238AbjCMLnT (ORCPT ); Mon, 13 Mar 2023 07:43:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49826 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231131AbjCMLmM (ORCPT ); Mon, 13 Mar 2023 07:42:12 -0400 Received: from mail-pl1-x62e.google.com (mail-pl1-x62e.google.com [IPv6:2607:f8b0:4864:20::62e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CC91E65047 for ; Mon, 13 Mar 2023 04:41:44 -0700 (PDT) Received: by mail-pl1-x62e.google.com with SMTP id u5so12584008plq.7 for ; Mon, 13 Mar 2023 04:41:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1678707702; 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=lmJnfY2lbCc2C3dy6sxzWUeYnl8mSWLRJqM4XO3hbV8=; b=pNiVNpQ25MN3oYBxt5/TM6uCwUc4SXP1Z4o4vh/+qLyntiFU4wcRaE6ohhV/RNqOW2 rHce4CMogEGfwLFpKWTQmXNWgcGLssUlmb0X/DKabDIagp5i2zz+Jdjidy5OC0XvprT2 PUnrmmSDm9cTgl7DCgzx/Me6o22O8ESkhhqpCoUaTz23F7oXPEujB7FZ7E5pfLPmMS8d pkohfPUjdUSS3Kb56DFZ8y/kaO8KXmAMWhKJW5tFCu+c9ws0jBh5YE8UuxjnkIgI9D8g egVm1EeGUu0qQ6ulKO5sksvYjDegOtWElEXfyuLiVgE5l33GDU59cQnj+z3mfo5QUqdu WhUQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678707702; 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=lmJnfY2lbCc2C3dy6sxzWUeYnl8mSWLRJqM4XO3hbV8=; b=x3KcX6tRBUKR42gXIqgCjbvRcHm2UPGVVJJnVBaaPa1UcAaRvng8J54CPDkKNLcld1 B7s4XfxSzxdUjzaYX3HjwASOtn/q/U9i/e9B4QN07LIggA8eJxI1xFuciv2eZmZbL8Y9 iEQhEQ/QuQPN2sL8Br4209t5q2cmW1qsuzmbQx63imALfVhNrbzoGNPYMKdFpR61FYOt fld7PZ+yz12t3Xi863zOL51bxisZl7xBAdkxX1aPTO4VFZIFPjWjeeCcgpurgLsOz+1B H5gsYlcQ5nGyiV6zRa9WKhvHHnCCcJDYb5Ycogl7RYbRnspNPO/+WKmV+0aYycMVJmvY FW5A== X-Gm-Message-State: AO0yUKXmL4gIG6R4OUX9uUe/fO62jqUa40+Y7j8gt8DBwnSvjHU1Lb13 6oUYgBZYPMjCJMDHPmXBFafiTg== X-Google-Smtp-Source: AK7set83wd4oHHArPR4ZCKuSZNrPw2lV7a4yfTBhkyt3/X3CHFU6GXj7CbeJUDTJqy3RCZTfnL321g== X-Received: by 2002:a17:90a:c7c3:b0:23b:4bf6:bbee with SMTP id gf3-20020a17090ac7c300b0023b4bf6bbeemr6415765pjb.21.1678707701711; Mon, 13 Mar 2023 04:41:41 -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.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Mar 2023 04:41:41 -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 14/16] perf kvm: Add dimensions for percentages Date: Mon, 13 Mar 2023 19:40:16 +0800 Message-Id: <20230313114018.543254-15-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" Add dimensions for count and time percentages, it would be useful for user to review percentage statistics. Signed-off-by: Leo Yan Reviewed-by: James Clark --- tools/perf/builtin-kvm.c | 98 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 97 insertions(+), 1 deletion(-) diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c index 0d857df826cf..ab1cd6b5e528 100644 --- a/tools/perf/builtin-kvm.c +++ b/tools/perf/builtin-kvm.c @@ -222,10 +222,105 @@ static struct kvm_dimension dim_mean_time =3D { .width =3D 14, }; =20 +#define PERC_STR(__s, __v) \ +({ \ + scnprintf(__s, sizeof(__s), "%.2F%%", __v); \ + __s; \ +}) + +static double percent(u64 st, u64 tot) +{ + return tot ? 100. * (double) st / (double) tot : 0; +} + +#define EV_METRIC_PERCENT(metric) \ +static int ev_percent_##metric(struct hist_entry *he) \ +{ \ + struct kvm_event *event; \ + struct perf_kvm_stat *perf_kvm; \ + \ + event =3D container_of(he, struct kvm_event, he); \ + perf_kvm =3D event->perf_kvm; \ + \ + return percent(get_event_##metric(event, perf_kvm->trace_vcpu), \ + perf_kvm->total_##metric); \ +} + +EV_METRIC_PERCENT(time) +EV_METRIC_PERCENT(count) + +static int ev_entry_time_precent(struct perf_hpp_fmt *fmt, + struct perf_hpp *hpp, + struct hist_entry *he) +{ + int width =3D fmt_width(fmt, hpp, he->hists); + double per; + char buf[10]; + + per =3D ev_percent_time(he); + return scnprintf(hpp->buf, hpp->size, "%*s", width, PERC_STR(buf, per)); +} + +static int64_t +ev_cmp_time_precent(struct perf_hpp_fmt *fmt __maybe_unused, + struct hist_entry *left, struct hist_entry *right) +{ + double per_left; + double per_right; + + per_left =3D ev_percent_time(left); + per_right =3D ev_percent_time(right); + + return per_left - per_right; +} + +static struct kvm_dimension dim_time_percent =3D { + .header =3D "Time%", + .name =3D "percent_time", + .cmp =3D ev_cmp_time_precent, + .entry =3D ev_entry_time_precent, + .width =3D 12, +}; + +static int ev_entry_count_precent(struct perf_hpp_fmt *fmt, + struct perf_hpp *hpp, + struct hist_entry *he) +{ + int width =3D fmt_width(fmt, hpp, he->hists); + double per; + char buf[10]; + + per =3D ev_percent_count(he); + return scnprintf(hpp->buf, hpp->size, "%*s", width, PERC_STR(buf, per)); +} + +static int64_t +ev_cmp_count_precent(struct perf_hpp_fmt *fmt __maybe_unused, + struct hist_entry *left, struct hist_entry *right) +{ + double per_left; + double per_right; + + per_left =3D ev_percent_count(left); + per_right =3D ev_percent_count(right); + + return per_left - per_right; +} + +static struct kvm_dimension dim_count_percent =3D { + .header =3D "Sample%", + .name =3D "percent_sample", + .cmp =3D ev_cmp_count_precent, + .entry =3D ev_entry_count_precent, + .width =3D 12, +}; + static struct kvm_dimension *dimensions[] =3D { &dim_event, &dim_time, + &dim_time_percent, &dim_count, + &dim_count_percent, &dim_max_time, &dim_min_time, &dim_mean_time, @@ -875,7 +970,8 @@ static int filter_cb(struct hist_entry *he, void *arg _= _maybe_unused) =20 static void sort_result(struct perf_kvm_stat *kvm) { - const char *output_columns =3D "ev_name,sample,time,max_t,min_t,mean_t"; + const char *output_columns =3D "ev_name,sample,percent_sample," + "time,percent_time,max_t,min_t,mean_t"; =20 kvm_hists__reinit(output_columns, kvm->sort_key); hists__collapse_resort(&kvm_hists.hists, NULL); --=20 2.34.1