Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp6842545rwd; Mon, 19 Jun 2023 13:22:43 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5ZQSV07pGkmXBfa9EvymDPk8xil8l8yWP5mgF11rRHGz3pntpN+xMsSce/hDzp65Ptis4p X-Received: by 2002:a17:902:8bcc:b0:1b3:d432:3026 with SMTP id r12-20020a1709028bcc00b001b3d4323026mr5182516plo.15.1687206163604; Mon, 19 Jun 2023 13:22:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687206163; cv=none; d=google.com; s=arc-20160816; b=Ck6wGtgM2MNOPsXdU8bSv3MBSiMM5cvcwGlicXQJZFW5v4Ac4C3X9IsEx0/r4LSWtl lu1GR9zQj3sPoQhORNDoer/gzwePmDfljPR/JudOh8P9FBEX+lelgcPeupWkFhBfPtrE i3jnWmKuZw9QplsWyue2CHlc1zX4nc2WihwhTB/d3FZgAzg8pTZN/FkNutuDir+V1dgW bJZBl9/MmEz2qaMkF6gqhuXgY2vdIi2zf2PmOJuJFK1MCojnLg3X2D5tFJ03Wy/akU2Q dbMr8Bp3SkzcOrUrvS1pDsW9JBIA29qIL4Msg6NFA1+7cUEKh2Fn4jEpkdb19yBh1e6Y uQYQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version; bh=yXWg+0tfRTWfrw/dAXkGrQjYU9F60UhjjtCLQAgSFZ0=; b=Vcqegt1ZBN0IGSk9oMmQCN3x6ldNIPcZ4K1+kWvtqjHxKafQpMSA4PGrinTJdpl6Bn EhaZRdpdoY3TzjRxTkMM1edYHE2mEiB7EfNN3rlAJQ06safFxpzMizIC81YABBfjToD5 4jPeKxyqmkrZldyzrIZXqWVgD1h5TQi0YxlK2hWT5iVPJEBXvo4h+Vv7NU/+DOMxNmtp 2FyZL1hEe6mJ9LQE3jhQaqnTqrrkI1Ufu+vMDQ03QlgJJysqD8u2fRP8hgtg7r2G/pBf fXnGAlunRO6WWsWMe2vWF0msWHjUiiO84WNFy7y0DK+oMURXpFn6zBMdqf1FgLksUxCR nXAA== ARC-Authentication-Results: i=1; mx.google.com; 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 i16-20020a17090332d000b001ae38227983si475066plr.199.2023.06.19.13.22.26; Mon, 19 Jun 2023 13:22:43 -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; 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 S230222AbjFSUA7 convert rfc822-to-8bit (ORCPT + 99 others); Mon, 19 Jun 2023 16:00:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53330 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230047AbjFSUA6 (ORCPT ); Mon, 19 Jun 2023 16:00:58 -0400 Received: from mail-io1-f43.google.com (mail-io1-f43.google.com [209.85.166.43]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 08B9211B; Mon, 19 Jun 2023 13:00:57 -0700 (PDT) Received: by mail-io1-f43.google.com with SMTP id ca18e2360f4ac-77faf29bdf1so3062139f.0; Mon, 19 Jun 2023 13:00:56 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687204856; x=1689796856; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=oAro3jK74ZfeFA/3l4ku7dA8uGjjLqikZaPjW5cbOLU=; b=UixJu0g88riVMvh9HxXm1IYrElyfTFzetzrmzmwMxUTnsMPXmHngZXqjJxIfvV1bC/ J6rLCizeF/xGn+LjVJKKov4rNCp7l+pKUt1wqwUhnR/CZHbv7RywXd2V47I5QadQvZp1 cA/03hbDTTlspwnIgQHBthM9+mEm5vK41Uj3psjCrFt9lBg5mbjeoqNw6/mG32FWdcCR trw68znXN+x6ovL9FmzkgcpcD/aa/b8vieYv0xRwaMeiYiK2rpyoD7sanYlJrg9z+97p 2FvUZttDIB4jRfdyP9FSRyjIgYWRuh7NbhDhO3DjYZXTq57J24janmoIc2jG1kpATDAb pJRg== X-Gm-Message-State: AC+VfDwqZUl7u0b5pgw2rLKHHD+eWQiICbUwlByn4guzRrEJZpmJU3KZ 2ssfKs6HxkyLO0flF29MxRxXO/3nrLQszmjFhug= X-Received: by 2002:a5e:c814:0:b0:777:abbb:2b6a with SMTP id y20-20020a5ec814000000b00777abbb2b6amr10152871iol.19.1687204856062; Mon, 19 Jun 2023 13:00:56 -0700 (PDT) MIME-Version: 1.0 References: <20230616073211.1057936-1-namhyung@kernel.org> <20230616073211.1057936-2-namhyung@kernel.org> In-Reply-To: From: Namhyung Kim Date: Mon, 19 Jun 2023 13:00:44 -0700 Message-ID: Subject: Re: [PATCH 2/2] perf stat: Show average value on multiple runs To: Jiri Olsa Cc: Arnaldo Carvalho de Melo , Ian Rogers , Adrian Hunter , Peter Zijlstra , Ingo Molnar , LKML , linux-perf-users@vger.kernel.org, Kan Liang , Andi Kleen Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8BIT X-Spam-Status: No, score=-1.4 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,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 On Sat, Jun 17, 2023 at 11:45 AM Jiri Olsa wrote: > > On Fri, Jun 16, 2023 at 12:32:11AM -0700, Namhyung Kim wrote: > > 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 > > this is the 'real' fix right? I thought this was the way it worked before It worked like the patch 1/2 before. > > anyway works nicely now, would be nice to add some tests for this, > but not sure how bad it'd be ;-) Maybe we can parse the raw counter output from the -v option and calculate the average then compare. > > Acked/Tested-by: Jiri Olsa Thanks, Namhyung > > > --- > > 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 > >