Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp2235806rwd; Fri, 16 Jun 2023 00:46:34 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4lA6wgkgEta4KIXgNnOi90oAr95+kOA38D/clu0psFOae1OY2PqdhupOanaRFWlUuitjif X-Received: by 2002:a05:6358:610f:b0:12d:a531:166a with SMTP id 15-20020a056358610f00b0012da531166amr811502rws.13.1686901594018; Fri, 16 Jun 2023 00:46:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686901593; cv=none; d=google.com; s=arc-20160816; b=0zp7l8chV57pf3RXAmMBNRDd3VPm8e++WANF52KrnVRyettHS14P8cjWnoZPd4WG+H A3/UoMbYtjm9obIY3hsiXffyd6mR9Sm3ty5mfdNtCutlJ6tHEp7F0slM2rgBli6msuPp qs35qDr6aZCxdMKt0Sn3hVNZ2Lzs+AdpLJQBtuIW+i8TaWsUvxk7rjWXJktPD1C3im5T aNZi9X2kEqsHexuEb3rgzMsyKnO+AW24TgObCf05dcrtUOmcGPSJMiXmZTDq3npIIZ4m HdFK+vmoK63NRbmD0WrjxDEhJEQm3QtmyF4QCQ5I9R2l+WFQUNYxkIrQU0Wk+ucwznIB xn2A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from:sender :dkim-signature; bh=JWGWhFdNFnQmNe1jiV8vMMxLsZzrXaix4YBiXlabS0E=; b=WXOMX3ephA5ZYPQ915Iy8ygcwy1ZDE3+GHqy4gnqyOfvSCrpY75eLc5jabz7IH8HYS mMPHuyrY0RhfBtY6p8gZExW35CqHfYjF3TKKA9Rqx5D5TFdHCtAMuIDznB2b/ry3FPvt Sz55xH//MCnSgz3YbUAN5ub3yolBqpGxgGLmYA1OBi43WkL/k24x8G2yg2iBwywE3C77 ZSIjIxQy31gDThZzgbxEWAhIxRckKilWVJH8Z2H9rGbV3KXDDEj/yLdux42Y04XxVL1N gXJWCZnMshDQoqeJY2LgISkLbLlpf/hlHlGBJ1uNHVJwyNNAG+zKSWIJuJKzPToQjUGo ip7Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=DRRQtr0V; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z8-20020a637e08000000b0054f9f9b333csi7777154pgc.686.2023.06.16.00.46.15; Fri, 16 Jun 2023 00:46:33 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=DRRQtr0V; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245084AbjFPHdO (ORCPT + 99 others); Fri, 16 Jun 2023 03:33:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35226 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245219AbjFPHcu (ORCPT ); Fri, 16 Jun 2023 03:32:50 -0400 Received: from mail-pj1-x102c.google.com (mail-pj1-x102c.google.com [IPv6:2607:f8b0:4864:20::102c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C9F803A8D; Fri, 16 Jun 2023 00:32:15 -0700 (PDT) Received: by mail-pj1-x102c.google.com with SMTP id 98e67ed59e1d1-25e820b8bc1so336653a91.1; Fri, 16 Jun 2023 00:32:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1686900735; x=1689492735; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:from:to:cc:subject:date :message-id:reply-to; bh=JWGWhFdNFnQmNe1jiV8vMMxLsZzrXaix4YBiXlabS0E=; b=DRRQtr0VgJV/ySp/YbqiODXhW0yheiWiY5emon5iu1kh1636Oo1jwJcH5YsL3wL0tI OOBW0jCmy0Ovdr9Zz5E+AmObIduOVjoatKbzOW6MnzCSKfiV1jIr8qzCteFRe4IjvW+t BJSXtRJVf27SP5olDyLJ3AMidsgXoJfRk46cwKhS/1ysYeMYwaR5S4JChkZV5rnLli43 CFEagZj7oMDt/QTqBaClBvfw3vQG0cL9s0VUaE5CQwPXtsZbR5l3s5IEXtaNLBbVRAk2 7Z254noW4nzxr2EtmYMBoA3qt17hRRl+ZhMXJZlPyQxsJ5LgWrt0fGsvF8VkjohwC47I gwfQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686900735; x=1689492735; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=JWGWhFdNFnQmNe1jiV8vMMxLsZzrXaix4YBiXlabS0E=; b=g00txs9cDe2aYDIpIAPuFnV3CWMDfxmZrzqr/jwRWxEFus/AR31FjeuBrNcZTVw6du 7JGlm12MDtwnupBc+wt8cQXNz6NCdbqkHWQd7VDTcMf8JnrfWe+l4IKaO1fO+MprUeAz +S7yhbFqwDJVCVAzCpn92xmHXemqw1uYiXvOrxsB7eor6lFr93pdtOCtzNU9btN+9Alx Lcc629Mm0wDAVCcbRSAb3A52cEvSBAtSbnb8tP0500H5VLM3QjFislS778L5T3EcNBCQ G5sQVRxXoniftfoRcqwfDMzG8bXPLf+DfxzfjKy2wP7qlgGT3Sm9Wxmmmy+OVM6gdtXz 28RQ== X-Gm-Message-State: AC+VfDzx9GI4Faq3aLUTMKiu2J5oRAYeoPjA8wA7EQCeY7TgtBiR8VZt /xgysW10GJaY5k0tu3pI4TI= X-Received: by 2002:a17:90a:ce04:b0:25b:fcbb:62ba with SMTP id f4-20020a17090ace0400b0025bfcbb62bamr848395pju.45.1686900735135; Fri, 16 Jun 2023 00:32:15 -0700 (PDT) Received: from bangji.hsd1.ca.comcast.net ([2601:647:6700:7f00:6cbb:2c15:7306:b23]) by smtp.gmail.com with ESMTPSA id gz10-20020a17090b0eca00b00256b67208b1sm715245pjb.56.2023.06.16.00.32.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Jun 2023 00:32:14 -0700 (PDT) Sender: Namhyung Kim From: Namhyung Kim To: Arnaldo Carvalho de Melo , Jiri Olsa Cc: Ian Rogers , Adrian Hunter , Peter Zijlstra , Ingo Molnar , LKML , linux-perf-users@vger.kernel.org, Kan Liang , Andi Kleen Subject: [PATCH 2/2] perf stat: Show average value on multiple runs Date: Fri, 16 Jun 2023 00:32:11 -0700 Message-ID: <20230616073211.1057936-2-namhyung@kernel.org> X-Mailer: git-send-email 2.41.0.162.gfafddb0af9-goog In-Reply-To: <20230616073211.1057936-1-namhyung@kernel.org> References: <20230616073211.1057936-1-namhyung@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.5 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When -r option is used, perf stat runs the command multiple times and update stats in the evsel->stats.res_stats for global aggregation. But the value is never used and the value it prints at the end is just the value from the last run. I think we should print the average number of multiple runs. Add evlist__copy_res_stats() to update the aggr counter (for display) using the values in the evsel->stats.res_stats. Signed-off-by: Namhyung Kim --- tools/perf/builtin-stat.c | 5 ++++- tools/perf/util/stat.c | 22 ++++++++++++++++++++++ tools/perf/util/stat.h | 1 + 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c index e549862f90f0..42f84975a4d5 100644 --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c @@ -2829,8 +2829,11 @@ int cmd_stat(int argc, const char **argv) } } - if (!forever && status != -1 && (!interval || stat_config.summary)) + if (!forever && status != -1 && (!interval || stat_config.summary)) { + if (stat_config.run_count > 1) + evlist__copy_res_stats(&stat_config, evsel_list); print_counters(NULL, argc, argv); + } evlist__finalize_ctlfd(evsel_list); diff --git a/tools/perf/util/stat.c b/tools/perf/util/stat.c index 0f7b8a8cdea6..967e583392c7 100644 --- a/tools/perf/util/stat.c +++ b/tools/perf/util/stat.c @@ -264,6 +264,28 @@ void evlist__copy_prev_raw_counts(struct evlist *evlist) evsel__copy_prev_raw_counts(evsel); } +static void evsel__copy_res_stats(struct evsel *evsel) +{ + struct perf_stat_evsel *ps = evsel->stats; + + /* + * For GLOBAL aggregation mode, it updates the counts for each run + * in the evsel->stats.res_stats. See perf_stat_process_counter(). + */ + *ps->aggr[0].counts.values = avg_stats(&ps->res_stats); +} + +void evlist__copy_res_stats(struct perf_stat_config *config, struct evlist *evlist) +{ + struct evsel *evsel; + + if (config->aggr_mode != AGGR_GLOBAL) + return; + + evlist__for_each_entry(evlist, evsel) + evsel__copy_res_stats(evsel); +} + static size_t pkg_id_hash(long __key, void *ctx __maybe_unused) { uint64_t *key = (uint64_t *) __key; diff --git a/tools/perf/util/stat.h b/tools/perf/util/stat.h index 7abff7cbb5a1..1cbc26b587ba 100644 --- a/tools/perf/util/stat.h +++ b/tools/perf/util/stat.h @@ -182,6 +182,7 @@ void evlist__save_aggr_prev_raw_counts(struct evlist *evlist); int evlist__alloc_aggr_stats(struct evlist *evlist, int nr_aggr); void evlist__reset_aggr_stats(struct evlist *evlist); +void evlist__copy_res_stats(struct perf_stat_config *config, struct evlist *evlist); int perf_stat_process_counter(struct perf_stat_config *config, struct evsel *counter); -- 2.41.0.162.gfafddb0af9-goog