Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp2699099pxa; Tue, 25 Aug 2020 00:11:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyNUXA/vGMOiZHyrGJk55Y4ww1kqXJTm2/Ye8YNOXKELmhB0AVIhmb8K8YBrXntCEnkKAiu X-Received: by 2002:a17:906:c78f:: with SMTP id cw15mr9410476ejb.330.1598339464687; Tue, 25 Aug 2020 00:11:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1598339464; cv=none; d=google.com; s=arc-20160816; b=ZoFWLv8M1lOqUUqBZPT6v6wM02kDzLd5G3mtGkeg6flnG3/U+7LYdoHnXypIvBW1Qb ZMXwcsMcscyX90dYM9Hlcb1SkVer46RBTyOhq2VeMZBrj5kcHO02rP/2uDvAG7wsv+kt +/Mf6ouSYKx5kb7wWGajr58t92cp6roEwepBAZ6GBA7ZX34opaHr3Gt6Sj1Ke9psBgxZ uzw0pw95VgG9h587aBJboXhACr+gvk6PuF8s708k+rjuPYNewA3QSG+Y1aWO2wclMqJG GaXrTAvOsphm4XoVeXdoNdOCoBnlhduWMud8g2VrOntwdWj8wMzl+dVZWKegdIQGMMft mw+A== 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=VIBaMlJeBmH+t20jmBEcGwS3CbX2tAci5ZF4rgGvUkw=; b=ZXHgNQNrHSGNJYsYxjGFGcbb+qEtSgH4sKFJgFlv9pZXnSu2o0Zhl1Z5IjIxL5WVRM rk7GipJYNCjqPr53yx7k0kLDmgxlJozzxfYQngVqVm8fq/7wSMcKqJNiKLyQiS6aaSp7 ihZjzLmUP+iG3kAZAxWurtVKdHrNLCx0p06QLzWmlIP5PNlRvwcVvClFQfOQypy6ao7m j5LDe0F5CbLvlxIHbjw7M+wvI27ztZF5stW7jsOhldWtFR5CJsqicEnghZzv1IVK3Y8S UrFQiGDKr5adcgciZoHs9HrcJPeCahTaqCKM2abhmA+1jNcdQa7j4b3AXU1xo+faPjY7 vXvQ== 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 i1si8451099edn.445.2020.08.25.00.10.42; Tue, 25 Aug 2020 00:11:04 -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 S1729336AbgHYHHF (ORCPT + 99 others); Tue, 25 Aug 2020 03:07:05 -0400 Received: from mga03.intel.com ([134.134.136.65]:4110 "EHLO mga03.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729304AbgHYHGu (ORCPT ); Tue, 25 Aug 2020 03:06:50 -0400 IronPort-SDR: 5xEyw9Ql1iKVoTXTH8CDVennJdl6yKxMpVylGdOli7pGg84J44LUTQaWKtJps9TaAk0rOCocNn zDVUnAb2NgDA== X-IronPort-AV: E=McAfee;i="6000,8403,9723"; a="156050070" X-IronPort-AV: E=Sophos;i="5.76,351,1592895600"; d="scan'208";a="156050070" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Aug 2020 00:06:49 -0700 IronPort-SDR: wm9gxmzIOffJ5ZLgUT0NjoAMN8o16Woe43oW3P4B0xPRr3jqZr8reycvhOGk9JMKcGMfLiJSTB ecWkSm4JXeyA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.76,351,1592895600"; d="scan'208";a="322655132" Received: from kbl-ppc.sh.intel.com ([10.239.159.55]) by fmsmga004.fm.intel.com with ESMTP; 25 Aug 2020 00:06:47 -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 v4 4/7] perf util: Link stream pair Date: Tue, 25 Aug 2020 07:35:10 +0800 Message-Id: <20200824233513.16930-5-yao.jin@linux.intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200824233513.16930-1-yao.jin@linux.intel.com> References: <20200824233513.16930-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 --- v4: - New patch in v4. tools/perf/util/stream.c | 53 ++++++++++++++++++++++++++++++++++++++++ tools/perf/util/stream.h | 4 +++ 2 files changed, 57 insertions(+) diff --git a/tools/perf/util/stream.c b/tools/perf/util/stream.c index 7f538d1085ef..76896a790798 100644 --- a/tools/perf/util/stream.c +++ b/tools/perf/util/stream.c @@ -161,3 +161,56 @@ 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, + enum stream_type stream_type) +{ + if (stream_type == STREAM_CALLCHAIN) + return stream_callchain_match(base_stream, es_pair); + + return NULL; +} + +static void stream_link(struct stream *base_stream, struct stream *pair_stream, + enum stream_type stream_type) +{ + if (stream_type == STREAM_CALLCHAIN) { + 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) +{ + if (es_base->stream_type != es_pair->stream_type) + return; + + 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, + es_base->stream_type); + if (pair_stream) { + stream_link(base_stream, pair_stream, + es_base->stream_type); + } + } +} diff --git a/tools/perf/util/stream.h b/tools/perf/util/stream.h index 705aa7cde3de..53f34e63f8fb 100644 --- a/tools/perf/util/stream.h +++ b/tools/perf/util/stream.h @@ -11,6 +11,7 @@ enum stream_type { struct stream { struct callchain_node *cnode; + struct callchain_node *pair_cnode; }; struct evsel_streams { @@ -30,4 +31,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