Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp2956784pxk; Sun, 6 Sep 2020 21:21:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy7ZmtaKXXke6OvgEqeX8L9jrII8mikQNoBJwNGdmDEM3BEO2j4w5nkR8bJEvyAUkCHYEQ4 X-Received: by 2002:a17:906:d1d9:: with SMTP id bs25mr15080208ejb.408.1599452504302; Sun, 06 Sep 2020 21:21:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1599452504; cv=none; d=google.com; s=arc-20160816; b=pnHMfFzIS0ixHqLmQTOY2TQ0wb0lGHM60G2Tiac7nMc4uYthuCepMTrLuJUZrw5pKH uodeR/UW2nIN5s24O/7c2NVeIEAoY1KiLXJHqDevXfQlPc+G9FPgYNWKqBmfoy7lt6/F sc1ARJDlV3LqEbxcJ5/2Aqg8nMRMA/mCK4N9DCeKXB1Mfm94CeJPhkl0QaQQSs40GW0r TN9pNeKsriX9bChip/94qFoH9bGrnkEAoHwWD9pAAD1jNfCgGGoib5NHW7Z4fbLldPWq uNDT/5Mrrr9DcnZe0p0jMlfBmNxkVO9lsZl4IFpM/V61FpxEcIiSIjjgywLOLWVQQEKZ xrLQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:ironport-sdr:ironport-sdr; bh=Kdi2suHBT+5OfZFLBpV16gFpGIDuIg9H1ApQ0hl0p1w=; b=W8y0fgP8gBPTrtPAIWLAJyXvEJCxCH21fn5BpkqSWrDaj8F0GN50QrriOHls6E1A1i atWSr/F/eTQeOdpuVo26AXdC7VL1yUdBa6kXD8FDtW4wFYCkY4WnH/DuhCo+WppFIR5m PAnnnoTJqaE7Px35Cz8/yT0mK8czGEL+41Y6RXiVAt0QDjHq9Ca7KyFe2TXC+NE199Mh rwniR9Ffyf2/ZZUb9TbOGjKJkuMztZ7ZkI9mLeRvOjWMxpKfnSml/vK7k9t2ATWYyo6l bvPhuJVHZcgqDL4yoNWHTx2bAvThXiTVeWk2gmZndkF0vbgAfqb3lrkyBRvghThNkwpp Cmzw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h2si8319157ejy.315.2020.09.06.21.21.22; Sun, 06 Sep 2020 21:21:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726496AbgIGEQ5 (ORCPT + 99 others); Mon, 7 Sep 2020 00:16:57 -0400 Received: from mga14.intel.com ([192.55.52.115]:58719 "EHLO mga14.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726376AbgIGEQx (ORCPT ); Mon, 7 Sep 2020 00:16:53 -0400 IronPort-SDR: +4hNBy4KbWpeX4FIHaXBLuGjfLyiI91WPtl1F25ODdf7P+ZLN5L4daqw5/W+hXhOdBpZRhH1vA NTALiAi4inUQ== X-IronPort-AV: E=McAfee;i="6000,8403,9736"; a="157215556" X-IronPort-AV: E=Sophos;i="5.76,400,1592895600"; d="scan'208";a="157215556" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Sep 2020 21:16:53 -0700 IronPort-SDR: /1N+pY4NZGOh3DnzWjqZGq/ij2hOY7AZQCv2/3vxyG+vus2D726hZBYG0Bzf9sJ12YiTlru4MA ikGs5zfMzXiA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.76,400,1592895600"; d="scan'208";a="406709935" Received: from kbl-ppc.sh.intel.com ([10.239.159.55]) by fmsmga001.fm.intel.com with ESMTP; 06 Sep 2020 21:16:50 -0700 From: Jin Yao To: acme@kernel.org, jolsa@kernel.org, peterz@infradead.org, mingo@redhat.com, alexander.shishkin@linux.intel.com Cc: Linux-kernel@vger.kernel.org, ak@linux.intel.com, kan.liang@intel.com, yao.jin@intel.com, Jin Yao Subject: [PATCH v5 4/7] perf util: Link stream pair Date: Mon, 7 Sep 2020 12:16:03 +0800 Message-Id: <20200907041606.14500-5-yao.jin@linux.intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200907041606.14500-1-yao.jin@linux.intel.com> References: <20200907041606.14500-1-yao.jin@linux.intel.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In previous patch, we have created an evsel_streams for one event, and top N hottest streams will be saved in a stream array in evsel_streams. This patch compares total streams among two evsel_streams. Once two streams are fully matched, they will be linked as a pair. From the pair, we can know which streams are matched. Signed-off-by: Jin Yao --- v5: - Remove enum stream_type v4: - New patch in v4. tools/perf/util/stream.c | 40 ++++++++++++++++++++++++++++++++++++++++ tools/perf/util/stream.h | 4 ++++ 2 files changed, 44 insertions(+) diff --git a/tools/perf/util/stream.c b/tools/perf/util/stream.c index 7882a7f05d97..e96e21d6e07b 100644 --- a/tools/perf/util/stream.c +++ b/tools/perf/util/stream.c @@ -157,3 +157,43 @@ struct evsel_streams *evsel_streams_get(struct evsel_streams *es, return NULL; } + +static struct stream *stream_callchain_match(struct stream *base_stream, + struct evsel_streams *es_pair) +{ + for (int i = 0; i < es_pair->nr_streams; i++) { + struct stream *pair_stream = &es_pair->streams[i]; + + if (callchain_cnode_matched(base_stream->cnode, + pair_stream->cnode)) { + return pair_stream; + } + } + + return NULL; +} + +static struct stream *stream_match(struct stream *base_stream, + struct evsel_streams *es_pair) +{ + return stream_callchain_match(base_stream, es_pair); +} + +static void stream_link(struct stream *base_stream, struct stream *pair_stream) +{ + base_stream->pair_cnode = pair_stream->cnode; + pair_stream->pair_cnode = base_stream->cnode; +} + +void match_evsel_streams(struct evsel_streams *es_base, + struct evsel_streams *es_pair) +{ + for (int i = 0; i < es_base->nr_streams; i++) { + struct stream *base_stream = &es_base->streams[i]; + struct stream *pair_stream; + + pair_stream = stream_match(base_stream, es_pair); + if (pair_stream) + stream_link(base_stream, pair_stream); + } +} diff --git a/tools/perf/util/stream.h b/tools/perf/util/stream.h index 66f61d954eef..2eb6f17a834e 100644 --- a/tools/perf/util/stream.h +++ b/tools/perf/util/stream.h @@ -6,6 +6,7 @@ struct stream { struct callchain_node *cnode; + struct callchain_node *pair_cnode; }; struct evsel_streams { @@ -23,4 +24,7 @@ struct evsel_streams *perf_evlist__create_streams(struct evlist *evlist, struct evsel_streams *evsel_streams_get(struct evsel_streams *es, int nr_evsel, int evsel_idx); +void match_evsel_streams(struct evsel_streams *es_base, + struct evsel_streams *es_pair); + #endif /* __PERF_STREAM_H */ -- 2.17.1