Received: by 2002:a05:6358:701b:b0:131:369:b2a3 with SMTP id 27csp935719rwo; Sat, 22 Jul 2023 03:24:06 -0700 (PDT) X-Google-Smtp-Source: APBJJlGuMTfl72NhO+XMNvlKJCrbuJDqCTFtz5VYjRL7mFtxJVt0o7MoVOkp4r8F3roCAnrffWK2 X-Received: by 2002:a17:907:784f:b0:99b:518a:9e4 with SMTP id lb15-20020a170907784f00b0099b518a09e4mr4328966ejc.59.1690021446348; Sat, 22 Jul 2023 03:24:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690021446; cv=none; d=google.com; s=arc-20160816; b=GFxHZYRDL8wfhhoU6LdlF/FVL9E8Pt8X2bkECQmslKx45cwBXLsbKG+h1cEukVimEr mrCKl9yMWgOuFYcQzM5I7osd5Vl+PZ46aivvnZrO4+cWuZQdOe2CPyToXuwraUmFLDS/ mlLOPgzV/P7Vwzq2BcleBFkSx5wtcbKWbj7CGZHAh9elbmyOjmSouGOxOTlaP4pzpbk7 IKC/BUwyJcK6+a2su47xRKNjv2o+IEscDnQog7VbNdxKtCSocsYBFe5dQn3zdoxFx765 I0crUXIrATfraKXUgq5j97aWEwAaC8wMIrsD6JJhzb2EfBsk1i0Uf+PIsuuvcjzFJAZX 7p1A== 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; bh=Op/wOwUQ6kgLn1wSpQN6Nxcm0PTNIgrnEOInp+6SHFk=; fh=Ib1wi7jRbo+eNDLEErvWCJx+cnUm87PkGFthhdFf08Y=; b=W6mxo3esvEugrZS2H1qCmsOS0i821c1vP3opeKM4CvkhI4+GkUvlzR0MTuYXPmbgfz zsSko+5hGaGrm/WdnQUUP2tSXGYTdEoFEAxuh2Tl8EVSLdcdnhJIcMO5kKz+Q/PAcUdu YXxMluVInhOHKOPptn1zJGN5sprA3yONL56F6iZziznLh+XNd+0FSdtr5y4hujpPyoWn FnAhy33tL3L2ehtPGgufSAS18ejdBJ640lexs4+ucvYAt0TQ541XYxO4o6HpKVfmrRKb jLLPIO3bg3iYkT8NqnuPaVXq7E5IUl0+SJ8RIs8x45mtMwz6QevTI+jTzPyXq1qYc43w rXcA== 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=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s2-20020a170906354200b009930253bc69si3454526eja.1011.2023.07.22.03.23.41; Sat, 22 Jul 2023 03:24:06 -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=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230054AbjGVJfN (ORCPT + 99 others); Sat, 22 Jul 2023 05:35:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56362 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229779AbjGVJes (ORCPT ); Sat, 22 Jul 2023 05:34:48 -0400 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A1B4A30EC; Sat, 22 Jul 2023 02:34:45 -0700 (PDT) Received: from kwepemm600003.china.huawei.com (unknown [172.30.72.54]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4R7Lnk3nf7zVjHV; Sat, 22 Jul 2023 17:33:14 +0800 (CST) Received: from localhost.localdomain (10.67.174.95) by kwepemm600003.china.huawei.com (7.193.23.202) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Sat, 22 Jul 2023 17:34:41 +0800 From: Yang Jihong To: , , , , , , , , , , , , , , , CC: Subject: [PATCH v3 2/7] perf evlist: Add evlist__findnew_tracking_event() helper Date: Sat, 22 Jul 2023 09:32:14 +0000 Message-ID: <20230722093219.174898-3-yangjihong1@huawei.com> X-Mailer: git-send-email 2.30.GIT In-Reply-To: <20230722093219.174898-1-yangjihong1@huawei.com> References: <20230722093219.174898-1-yangjihong1@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.67.174.95] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To kwepemm600003.china.huawei.com (7.193.23.202) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham 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 Currently, intel-bts, intel-pt, and arm-spe may add a dummy event for tracking to the evlist. We may need to search for the dummy event for some settings. Therefore, add evlist__findnew_tracking_event() helper. evlist__findnew_tracking_event() also deal with system_wide maps if system_wide is true. Signed-off-by: Yang Jihong --- tools/perf/builtin-record.c | 11 +++-------- tools/perf/util/evlist.c | 18 ++++++++++++++++++ tools/perf/util/evlist.h | 1 + 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c index aec18db7ff23..ca83599cc50c 100644 --- a/tools/perf/builtin-record.c +++ b/tools/perf/builtin-record.c @@ -1295,14 +1295,9 @@ static int record__open(struct record *rec) */ if (opts->target.initial_delay || target__has_cpu(&opts->target) || perf_pmus__num_core_pmus() > 1) { - pos = evlist__get_tracking_event(evlist); - if (!evsel__is_dummy_event(pos)) { - /* Set up dummy event. */ - if (evlist__add_dummy(evlist)) - return -ENOMEM; - pos = evlist__last(evlist); - evlist__set_tracking_event(evlist, pos); - } + pos = evlist__findnew_tracking_event(evlist, false); + if (!pos) + return -ENOMEM; /* * Enable the dummy event when the process is forked for diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c index 7ef43f72098e..25c3ebe2c2f5 100644 --- a/tools/perf/util/evlist.c +++ b/tools/perf/util/evlist.c @@ -1694,6 +1694,24 @@ void evlist__set_tracking_event(struct evlist *evlist, struct evsel *tracking_ev tracking_evsel->tracking = true; } +struct evsel *evlist__findnew_tracking_event(struct evlist *evlist, bool system_wide) +{ + struct evsel *evsel; + + evsel = evlist__get_tracking_event(evlist); + if (!evsel__is_dummy_event(evsel)) { + evsel = evlist__add_aux_dummy(evlist, system_wide); + if (!evsel) + return NULL; + + evlist__set_tracking_event(evlist, evsel); + } else if (system_wide) { + perf_evlist__go_system_wide(&evlist->core, &evsel->core); + } + + return evsel; +} + struct evsel *evlist__find_evsel_by_str(struct evlist *evlist, const char *str) { struct evsel *evsel; diff --git a/tools/perf/util/evlist.h b/tools/perf/util/evlist.h index 664c6bf7b3e0..98e7ddb2bd30 100644 --- a/tools/perf/util/evlist.h +++ b/tools/perf/util/evlist.h @@ -387,6 +387,7 @@ bool evlist_cpu_iterator__end(const struct evlist_cpu_iterator *evlist_cpu_itr); struct evsel *evlist__get_tracking_event(struct evlist *evlist); void evlist__set_tracking_event(struct evlist *evlist, struct evsel *tracking_evsel); +struct evsel *evlist__findnew_tracking_event(struct evlist *evlist, bool system_wide); struct evsel *evlist__find_evsel_by_str(struct evlist *evlist, const char *str); -- 2.30.GIT