From patchwork Fri Jun 16 07:32:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Namhyung Kim X-Patchwork-Id: 108907 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp1154812vqr; Fri, 16 Jun 2023 00:47:49 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5GlqEe3wn18DGGlz424DD4jJeHtIo+8W2EnK1nai7A8uapivbpmstkuMms25FGA4xjongF X-Received: by 2002:a05:6a00:148f:b0:64f:5406:d59e with SMTP id v15-20020a056a00148f00b0064f5406d59emr1755617pfu.17.1686901668790; Fri, 16 Jun 2023 00:47:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686901668; cv=none; d=google.com; s=arc-20160816; b=Z9G644RBqjk/lS1GKAXtnrKSSPa6FKDg2aGD0USZqokC+ULIHfZU4pisbLH2YbOTnG j/KJaUUg6f9Y5ZYKUIeaUmP2p7bE/xT4KwoPCCG9IAvwy7287pxiKikxzkS0wQK/ndc/ vU5Nyn3zC/Aj61vAQSZPe2YGtO+zThP1CCJcL0qY1fy5U0kYrEND+/m5g3q0CmQ3pFxi Ft7XhSFoAtMbd7HpcLdKqWWYfbY2dscsXgJ+9tJUKnqdv2FuIM2O0uaEwRnsJoV/1EzQ 5JgjerWu5EXp93+JPTLLAMrPg3kZSwXNDhRI8oXjJqLDxEHzNGX5p0nCNHcX9Fj1Bz4I 6JZQ== 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 :message-id:date:subject:cc:to:from:sender:dkim-signature; bh=zoV8AIWoN8isNFc8d/A+grHcBDoOF9LX+RgpFHY7YR4=; b=baiA5RTiabzuLHzlP9nD+W74tByzzPdreDlZy7cEVARzfyIWg10sqqrgSVSlvgbU0A lhI2eJpgTVix4AqZmqowqS2rZ6RD54vnY2jC2qkugSKxEEFbyqf5DTM+Q6VmLFdxyZCF NzPw69H7pdzIWE5+f8tVB/rrigfUbCP4LTrR1gWiWTTeass/Y9kaAviJV5BmSJr+CowS ZvvoTebzaY73g31YMJac++NFs6cvfQX8ttUVvSpbGu+ixVC/jIQvqnz4oQl8MWNiTSf4 EcJH6hZ8Dy5JKErRKkC4YQ8X9wkjxvKny4ohi4kC1txGaFp33odp1tkmMQ8CYwaHmvKe uN3Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=Z2NZjr4p; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q12-20020aa7982c000000b006666cc2f03csi4355210pfl.296.2023.06.16.00.47.34; Fri, 16 Jun 2023 00:47:48 -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=Z2NZjr4p; 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 S231190AbjFPHdL (ORCPT + 99 others); Fri, 16 Jun 2023 03:33:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34920 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241982AbjFPHcs (ORCPT ); Fri, 16 Jun 2023 03:32:48 -0400 Received: from mail-pg1-x535.google.com (mail-pg1-x535.google.com [IPv6:2607:f8b0:4864:20::535]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D356E30ED; Fri, 16 Jun 2023 00:32:14 -0700 (PDT) Received: by mail-pg1-x535.google.com with SMTP id 41be03b00d2f7-54fb1bbc3f2so383599a12.0; Fri, 16 Jun 2023 00:32:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1686900734; x=1689492734; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:sender:from:to:cc:subject:date:message-id:reply-to; bh=zoV8AIWoN8isNFc8d/A+grHcBDoOF9LX+RgpFHY7YR4=; b=Z2NZjr4peOLLbax/erCsvvSUkW61U3Wq8uNLX2sXBySWtImwRKRH0BPrcEnGpbwDXG 6Pftto2cm2AFVztDmaNBC5gb9cuZeNmceuYIcJfSEutJYwBJezb58Ds3dW7N1yo9ITHm XwLSGAwLHAlFLKGWKR8c1YreRTrosD+MQliMwJuDFEB8E7H0mzD4iGfOayrHAOls5/QG 9A57CEWBjO4ly/HTqAM+hh6PKS9yK3jpAkfcl0deYvCVROCxv2jpaL9sviAtcHPxMTWL YjKJClSwAv4YpTupcMQoiOovak0K8ZVONLY8acUkCVxN5fqcFKx4ljnrlcnS1m/Ae5SX VhfA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686900734; x=1689492734; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:sender:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=zoV8AIWoN8isNFc8d/A+grHcBDoOF9LX+RgpFHY7YR4=; b=AStsXqnzFRoJHrATP2JVw2lDb4H2cWBrp4r94EsEbqIFDwddyGrnMRyIfmalBK7Uvu cpF27aM5axUmwUC4hVy1LEm1od+0H8gDDe7eeVk2D65F1jFyjn4JS2wpRRYFKG/vP64R KRuk6IqL4tnLIIYREN5lYQ3FdgNwCsMtH7BIM4umo4EvasYA5XRPzir0MEttGHhQFQW+ w2xHrTCThc8Ium+K3U+XjhHZ6b4NjBLSZXEkAcTm9b/8z4b5zTmWK4yv/Cjsk/nTc5/O jQ4RmZARV3EdfOvR4oQfovfXxkKvJlBk4Bq1/AbaWMsWx75Xtf5nk8NHjhx2UbrPVPik oPhg== X-Gm-Message-State: AC+VfDzNVLwTrCuM6FRP5KBYcrw7gdqsrME2vDZQA3W46GiaHMsTu6po UMyFbZWGzm7T5HjLlQDyloQ= X-Received: by 2002:a17:90b:250:b0:25b:f764:580a with SMTP id fz16-20020a17090b025000b0025bf764580amr1100888pjb.12.1686900734082; Fri, 16 Jun 2023 00:32:14 -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.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Jun 2023 00:32:13 -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 1/2] perf stat: Reset aggr stats for each run Date: Fri, 16 Jun 2023 00:32:10 -0700 Message-ID: <20230616073211.1057936-1-namhyung@kernel.org> X-Mailer: git-send-email 2.41.0.162.gfafddb0af9-goog MIME-Version: 1.0 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1768844603988848778?= X-GMAIL-MSGID: =?utf-8?q?1768844603988848778?= When it runs multiple times with -r option, it missed to reset the aggregation counters and the values were added up. The aggregation count has the values to be printed in the end. It should reset the counters at the beginning of each run. But the current code does that only when -I/--interval-print option is given. Fixes: 91f85f98da7a ("perf stat: Display event stats using aggr counts") Reported-by: Jiri Olsa Signed-off-by: Namhyung Kim --- tools/perf/builtin-stat.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c index c87c6897edc9..e549862f90f0 100644 --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c @@ -725,6 +725,8 @@ static int __run_perf_stat(int argc, const char **argv, int run_idx) all_counters_use_bpf = false; } + evlist__reset_aggr_stats(evsel_list); + evlist__for_each_cpu(evlist_cpu_itr, evsel_list, affinity) { counter = evlist_cpu_itr.evsel; From patchwork Fri Jun 16 07:32:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Namhyung Kim X-Patchwork-Id: 108901 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp1151074vqr; Fri, 16 Jun 2023 00:37:27 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7SF9C1R+VAnZXj+hidHLJ5Grg9SUZKm85vh/wSE2ocd6G45UXfk6KTG10eFl7G4R+6xiv5 X-Received: by 2002:a17:90b:1643:b0:256:5174:f58b with SMTP id il3-20020a17090b164300b002565174f58bmr764268pjb.46.1686901047583; Fri, 16 Jun 2023 00:37:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686901047; cv=none; d=google.com; s=arc-20160816; b=jySNL+BdmuB2Wd+QqzLeKKOhQKOTe0i6mF3NReBLki8RLzsW6aezo6TX9XOTx5/AxQ NM460ylmxRxMAix38Q3ZrW4+aci0zzeVLb7v9L2hh4sJPRMWJc3l7+Ep5NOnZd7Ptkph xlqt52tSjOcrqHqVrrkUoXP/s0xNoR4dVX8Bf7M/IZN/zneBGm9MpIC921qeo9IQ1isK bgLnecD2IJcp+YHB2vR9mTohOu0SJJ90B//JIDBVab29efQnMqKylm0FuoF4UEK7j4Ol qZmd1Sk02OQx7logm/uVyjXBCOH0ySiuxUu8WWBvcxBYIwpqnOY/Nx+SMrrnQgD8WXI1 p+ag== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u15-20020a17090a3fcf00b0025bec0eac2csi1038484pjm.65.2023.06.16.00.37.13; Fri, 16 Jun 2023 00:37:27 -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 S244285AbjFPHdO (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 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1768843952916593015?= X-GMAIL-MSGID: =?utf-8?q?1768843952916593015?= 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);