From mboxrd@z Thu Jan 1 00:00:00 1970 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 38EDBC64EC7 for ; Tue, 28 Feb 2023 11:54:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231473AbjB1Lyh (ORCPT ); Tue, 28 Feb 2023 06:54:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50510 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231156AbjB1LyY (ORCPT ); Tue, 28 Feb 2023 06:54:24 -0500 Received: from mail-pj1-x1031.google.com (mail-pj1-x1031.google.com [IPv6:2607:f8b0:4864:20::1031]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2171BA5DD for ; Tue, 28 Feb 2023 03:53:55 -0800 (PST) Received: by mail-pj1-x1031.google.com with SMTP id cp7-20020a17090afb8700b0023756229427so13427706pjb.1 for ; Tue, 28 Feb 2023 03:53:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; 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=owO6RMSXMhELaAiCDQfYtj1K3jFcb8cutoYS8UegXjk=; b=ITgM8j1GNblZluoCqcj6FUwDHNTxwKsb1LYP1MNGuaxh5G+XqwLEIsI4/pwROkU+I8 8p5oBFu7V/VHOX6pMAjvbKB79L7Blhmrs/36PnPgRJYQrhv/QxikWDsg8TedlTxYMiWh /Zk9N3ZeLqXIXOxRejXRBAdpvCr7s0aW0/vBUAroM+dL8txrhE/hpHyTN9bqgEQg9etH de03ZvVRY3lLYt2aBgusTebVc4FVjtAbaIZa9qOE7GVT8/yv6aajd/x0YCYpSoGUwLR0 lKMU2vI2TEMxS7JM2iE5UrZY77+RxfM5kEGLjzTN5GHOJC+pXAjS3qgMJSMXp9tatkFs pN7Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=owO6RMSXMhELaAiCDQfYtj1K3jFcb8cutoYS8UegXjk=; b=23gFvWg4KTdmH448j0LDIH17/cGpodVYtVdaPLelJDACAxOUw1o7R2JQQnW5GJT36Q blC6BVXpkeZKaLHqbboWj7RkaIRNhbWZeyA6Kn9C1V5yIBsjBfjVns77H3zwxKS3OmXI wpU+ytCxL3tpNQpSitsQ+jota0U1LLEzwe+7IRAz0AingdwmxQq/ulnI/G12KrTbXU31 FIElRRTXlSKvAEX7cHD79Zl6XK3RFn8WqA0ieMxN8usCY3EG9vEGf487gSxthc1MWBBZ jkR0EmP3UUF2pVYnk7BVI1VH0122RVr7vb10MRlmevtU81OuLE/jJgCWtBOV5ZDip8mx ukyw== X-Gm-Message-State: AO0yUKUUQmSw/ScTqi0XWQdUrnibhMW+MkDXpxIzW+Dix+xspF0x5/tt 8tAtevbNIFSEgcneqAelQ9XDBw== X-Google-Smtp-Source: AK7set8DtAIgce991bpJ51nCnfZYsOa3okIXdYADpriVE9RxYoxKWUHTjjKquyTj/2m7RtgRDvpzTg== X-Received: by 2002:a17:90b:4b4a:b0:22b:fd93:7286 with SMTP id mi10-20020a17090b4b4a00b0022bfd937286mr3107411pjb.4.1677585233710; Tue, 28 Feb 2023 03:53:53 -0800 (PST) Received: from leoy-huanghe.lan (n058152048225.netvigator.com. [58.152.48.225]) by smtp.gmail.com with ESMTPSA id gk8-20020a17090b118800b002339491ead6sm7922317pjb.5.2023.02.28.03.53.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Feb 2023 03:53:53 -0800 (PST) From: Leo Yan To: Arnaldo Carvalho de Melo , Peter Zijlstra , Ingo Molnar , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Adrian Hunter , James Clark , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Leo Yan Subject: [PATCH v3 12/14] perf kvm: Add dimensions for percentages Date: Tue, 28 Feb 2023 19:51:23 +0800 Message-Id: <20230228115125.144172-13-leo.yan@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230228115125.144172-1-leo.yan@linaro.org> References: <20230228115125.144172-1-leo.yan@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-perf-users@vger.kernel.org Add dimensions for count and time percentages, it would 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 a56d0983c585..5b1b2042dfed 100644 --- a/tools/perf/builtin-kvm.c +++ b/tools/perf/builtin-kvm.c @@ -230,10 +230,105 @@ static struct kvm_dimension dim_mean_time = { .width = 14, }; +#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 = container_of(he, struct kvm_event, he); \ + perf_kvm = 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 = fmt_width(fmt, hpp, he->hists); + double per; + char buf[10]; + + per = 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 = ev_percent_time(left); + per_right = ev_percent_time(right); + + return per_left - per_right; +} + +static struct kvm_dimension dim_time_percent = { + .header = "Time%", + .name = "percent_time", + .cmp = ev_cmp_time_precent, + .entry = ev_entry_time_precent, + .width = 12, +}; + +static int ev_entry_count_precent(struct perf_hpp_fmt *fmt, + struct perf_hpp *hpp, + struct hist_entry *he) +{ + int width = fmt_width(fmt, hpp, he->hists); + double per; + char buf[10]; + + per = 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 = ev_percent_count(left); + per_right = ev_percent_count(right); + + return per_left - per_right; +} + +static struct kvm_dimension dim_count_percent = { + .header = "Sample%", + .name = "percent_sample", + .cmp = ev_cmp_count_precent, + .entry = ev_entry_count_precent, + .width = 12, +}; + static struct kvm_dimension *dimensions[] = { &dim_event, &dim_time, + &dim_time_percent, &dim_count, + &dim_count_percent, &dim_max_time, &dim_min_time, &dim_mean_time, @@ -406,7 +501,8 @@ static int kvm_hpp_list__parse(struct perf_hpp_list *hpp_list, static int kvm_hists__init(struct perf_kvm_stat *kvm) { - const char *output_columns = "name,sample,time,max_t,min_t,mean_t"; + const char *output_columns = "name,sample,percent_sample," + "time,percent_time,max_t,min_t,mean_t"; __hists__init(&kvm_hists.hists, &kvm_hists.list); perf_hpp_list__init(&kvm_hists.list); -- 2.34.1