Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp172646rwi; Thu, 13 Oct 2022 23:41:33 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4vd79jy7ecjuo0IJb4789inyNhR5ogka+Hkgy3nJDu2QdSkEz/YuWAKAXp+aE9l+CRESb0 X-Received: by 2002:a05:6402:3890:b0:45c:2b5:b622 with SMTP id fd16-20020a056402389000b0045c02b5b622mr3026089edb.69.1665729693010; Thu, 13 Oct 2022 23:41:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665729693; cv=none; d=google.com; s=arc-20160816; b=XdR9r2aqzq6Vawh5cnaiX8NEmnkQZzFlYUa9cVAE41XuyUsIGbJ11XZDSpx1pH+8Lz a+j+mhTimm2alrbeXuMU2lb305tQsY6CY/GRIMLVUDLPSieTdxCRL3FIqiqWoiFAC2Cj z23g3df8f8EstEiZQhmy0cPVO5XFFXXA6wO1f3Dc4PsH1uBMBfLRfJg5DYmLAQtYLs6e YfPLw8adqBADf6Kra7MyGUxWPIP00g3IRl95KpUwFbYXoOorg+BQtnRIoYFIww5r7pVD ACgcwUDJjNjZ/qSme0XHnT3QSVLOzTLwg8FXn/1HZBIBIchChE1Kkq0fapLk6dhjY9vK CTwg== 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=NJyT/jhQLO0o6wsISkqr66GasnJPnHjtYGimcC6nrmI=; b=L1gDf8fdxH0cBbW1PX9vfq871xvmpuL9XWzUs+1vYtLJMMAUYFeRn6FSrzgfQ+kB2k nRADKGScsj4CdIXhQhAUAZpzk3jWwR4rbdDed3deG2Y+TEShuGe2Z1UHCIKviKKjtSC9 O/w6e8ra33LW22dfFfBXvCM9uLpVWKGyyzVpFDTSlMalsXLMJiF+ntY1l6TwuCk3E0oV HxP2idHpLiPfLvBRrJGExL9vRkVStzfXWrykaglBYCoW3jYKgn73ei/5b9uImTXVGDuP HEtFB7CI9ZoO3DrRlSOyeS7Xr8hXjYXylvve+/9iM3/T7mhuH+u3qFfmRLE+zkAWkdVf WqFA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=RlaMO08o; 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 j22-20020aa7c0d6000000b00457463dfc74si1468203edp.83.2022.10.13.23.41.07; Thu, 13 Oct 2022 23:41: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=20210112 header.b=RlaMO08o; 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 S229926AbiJNGQm (ORCPT + 99 others); Fri, 14 Oct 2022 02:16:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58858 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229832AbiJNGQW (ORCPT ); Fri, 14 Oct 2022 02:16:22 -0400 Received: from mail-pj1-x102a.google.com (mail-pj1-x102a.google.com [IPv6:2607:f8b0:4864:20::102a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E838517423; Thu, 13 Oct 2022 23:16:09 -0700 (PDT) Received: by mail-pj1-x102a.google.com with SMTP id pq16so4046038pjb.2; Thu, 13 Oct 2022 23:16:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; 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=NJyT/jhQLO0o6wsISkqr66GasnJPnHjtYGimcC6nrmI=; b=RlaMO08oW0Y/4ls0tD3F9i8Ffvq6PcyYUdkqEBiT+Nq8vy7gqVceZf2G4GZ5l18tde Ox0Vha0o0+aaUCGznLuwuGG65al57mrPWGxNizDW1mWEwsyEYjjMkY/0PQCeHcT4othb nawh0We3wf9UvtgKXVsvheJiEjLsJRMnj9PivffA1EiZ0frZU0Dq4jWmdVoXe+W7KDz6 cwEV2DOGrv7r1DnX8lXjU0hQEVVayAyZdAlKyYsn0MDYXrz4tZPfvjnPlG8fzFMNCGoH iEw4c/WIBiDYbYon8yOUwUyBpbHpSrk7QWfPqogQJCVtga018vkKqDYkOIpu3YvBMXNx kJbw== 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:sender:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=NJyT/jhQLO0o6wsISkqr66GasnJPnHjtYGimcC6nrmI=; b=xy4ga/3yUHtitwmiCS5zsPMDFibl2u8vB1i3dTRUueF/istKr6cudwEYduv3DHE0j6 H0FPIoPbWldRGUQMfiq6lpYG4thWZvE0/xeWHjSG2pjteXlWV7/AeiG4Om4BcP44xpA6 iT2JF3hg08l1EMIIAoZwscHLXN7j7Y94hlLEXnVWqaHdAEOwhUk2IUcHKZjSEzIXg0Xd AiKb3cjHrNeNW5jtyrPV5Hwh49C00Uqcql7qXPcjBjlmWbs+9S/Ap2Wkaiy26wdTTj6/ NyPqCMlT5ipITfWI7Zy6GDQQpsBK/aEawZ5+dVvHSXgpnF7qS/wHWTF/7N3ibTto/uiw AI9w== X-Gm-Message-State: ACrzQf0HkDARc6Vu4rjy9JWnP35JTpJZ71T3OMhgsxKHVXdu5JePza88 Z7/70KeABSLi4JTgtXYTFrM++J8Wn+k= X-Received: by 2002:a17:903:1207:b0:185:4042:23d2 with SMTP id l7-20020a170903120700b00185404223d2mr2852807plh.143.1665728168967; Thu, 13 Oct 2022 23:16:08 -0700 (PDT) Received: from balhae.hsd1.ca.comcast.net ([2601:647:6780:1040:630:195c:38a7:a411]) by smtp.gmail.com with ESMTPSA id 94-20020a17090a09e700b0020af2411721sm721942pjo.34.2022.10.13.23.16.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Oct 2022 23:16:08 -0700 (PDT) Sender: Namhyung Kim From: Namhyung Kim To: Arnaldo Carvalho de Melo , Jiri Olsa Cc: Ingo Molnar , Peter Zijlstra , LKML , Ian Rogers , Adrian Hunter , linux-perf-users@vger.kernel.org, Kan Liang , Leo Yan , Andi Kleen , Athira Rajeev , James Clark , Xing Zhengjun Subject: [PATCH 10/19] perf stat: Aggregate per-thread stats using evsel->stats->aggr Date: Thu, 13 Oct 2022 23:15:41 -0700 Message-Id: <20221014061550.463644-11-namhyung@kernel.org> X-Mailer: git-send-email 2.38.0.413.g74048e4d9e-goog In-Reply-To: <20221014061550.463644-1-namhyung@kernel.org> References: <20221014061550.463644-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 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 Per-thread aggregation doesn't use the CPU numbers but the logic should be the same. Initialize cpu_aggr_map separately for AGGR_THREAD and use thread map idx to aggregate counter values. Acked-by: Ian Rogers Signed-off-by: Namhyung Kim --- tools/perf/builtin-stat.c | 31 +++++++++++++++++++++++++++++++ tools/perf/util/stat.c | 26 +++++++++++++++++++++++--- 2 files changed, 54 insertions(+), 3 deletions(-) diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c index abede56d79b6..6777fef0d56c 100644 --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c @@ -1465,6 +1465,21 @@ static int perf_stat_init_aggr_mode(void) stat_config.aggr_get_id = aggr_mode__get_id(stat_config.aggr_mode); } + if (stat_config.aggr_mode == AGGR_THREAD) { + nr = perf_thread_map__nr(evsel_list->core.threads); + stat_config.aggr_map = cpu_aggr_map__empty_new(nr); + if (stat_config.aggr_map == NULL) + return -ENOMEM; + + for (int s = 0; s < nr; s++) { + struct aggr_cpu_id id = aggr_cpu_id__empty(); + + id.thread_idx = s; + stat_config.aggr_map->map[s] = id; + } + return 0; + } + /* * The evsel_list->cpus is the base we operate on, * taking the highest cpu number to be the size of @@ -1674,6 +1689,22 @@ static int perf_stat_init_aggr_mode_file(struct perf_stat *st) aggr_cpu_id_get_t get_id = aggr_mode__get_aggr_file(stat_config.aggr_mode); bool needs_sort = stat_config.aggr_mode != AGGR_NONE; + if (stat_config.aggr_mode == AGGR_THREAD) { + int nr = perf_thread_map__nr(evsel_list->core.threads); + + stat_config.aggr_map = cpu_aggr_map__empty_new(nr); + if (stat_config.aggr_map == NULL) + return -ENOMEM; + + for (int s = 0; s < nr; s++) { + struct aggr_cpu_id id = aggr_cpu_id__empty(); + + id.thread_idx = s; + stat_config.aggr_map->map[s] = id; + } + return 0; + } + if (!get_id) return 0; diff --git a/tools/perf/util/stat.c b/tools/perf/util/stat.c index 99874254809d..3593af403188 100644 --- a/tools/perf/util/stat.c +++ b/tools/perf/util/stat.c @@ -403,6 +403,24 @@ process_counter_values(struct perf_stat_config *config, struct evsel *evsel, evsel__compute_deltas(evsel, cpu_map_idx, thread, count); perf_counts_values__scale(count, config->scale, NULL); + if (config->aggr_mode == AGGR_THREAD) { + struct perf_counts_values *aggr_counts = &ps->aggr[thread].counts; + + /* + * Skip value 0 when enabling --per-thread globally, + * otherwise too many 0 output. + */ + if (count->val == 0 && config->system_wide) + return 0; + + ps->aggr[thread].nr++; + + aggr_counts->val += count->val; + aggr_counts->ena += count->ena; + aggr_counts->run += count->run; + goto update; + } + if (ps->aggr) { struct perf_cpu cpu = perf_cpu_map__cpu(evsel->core.cpus, cpu_map_idx); struct aggr_cpu_id aggr_id = config->aggr_get_id(config, cpu); @@ -417,10 +435,11 @@ process_counter_values(struct perf_stat_config *config, struct evsel *evsel, ps_aggr->nr++; /* - * When any result is bad, make them all to give - * consistent output in interval mode. + * When any result is bad, make them all to give consistent output + * in interval mode. But per-task counters can have 0 enabled time + * when some tasks are idle. */ - if (count->ena == 0 || count->run == 0 || + if (((count->ena == 0 || count->run == 0) && cpu.cpu != -1) || evsel->counts->scaled == -1) { ps_aggr->counts.val = 0; ps_aggr->counts.ena = 0; @@ -437,6 +456,7 @@ process_counter_values(struct perf_stat_config *config, struct evsel *evsel, } } +update: switch (config->aggr_mode) { case AGGR_THREAD: case AGGR_CORE: -- 2.38.0.413.g74048e4d9e-goog