Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp2849205pxk; Sun, 20 Sep 2020 20:36:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzVKKX7IQ9fw6VitShyC/aP4ds+y58TJRrbsslHFDRoU1Ej9p3KpzinJe/rHEF1SnrAp5Bx X-Received: by 2002:a50:84a2:: with SMTP id 31mr51246999edq.138.1600659364139; Sun, 20 Sep 2020 20:36:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600659364; cv=none; d=google.com; s=arc-20160816; b=YN7leAgObw6eTlC1mThLt5GMKFejP6Zd5qwDRyGYkmf0N+Cjea7JQeLIXYe5n7u54S lU9SxSOenwltIfeNrvgNFxraG6a2amZ40+GXpJ1ba+a8XzsLDiUZ2r4L897t7SoFfK8A KdsievSK7xmqSkzRWHI5ZVCN+3dPKT3aGY+6QHcjmEGrinXgKcDrqMb3rApwDjGaEtWu IkTfJqkbXVCfeEcZYkmFtZthYBu1jswvwoX3MOW/RfAwj8BrV5dbCqrR39UWVhHNeSxx gCE5IzVcsYd1tPPrS7R/pQIwI7OGQQ83+QGlEI4SISGjwsn6obNgBvdtZHuJjiIZKbXI SDSA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from:ironport-sdr:ironport-sdr; bh=eCczaGHiia5AWZ42S0j0S3HdZwuNt/mv8CkPEe6u7bE=; b=W7z/3eHxbH+r0ncb+xBygxzfwg/iMucRmEF6RnwJJJ3vFM86gvFgWjvzSglAtqCkG0 us5uu/rngz2SoJ9JwzoEHScHhyOcowq+jfsxvHZNRhBaX3f3poKh8RX4/pRqSaoGcW/j Ci9p1qi3J2J9wmNujHNAUqoq2MYDEf4BQ+f2DhvVX+/Qd/sik/bhT9n93HD0kaeXqo1X dOdbR3P5fs5OFxrq/Z0/Fd2EYt6Qkr4fHdDtAKqIionXvFrpXf5zEVW5d8LVu0bFTv7u aKbfH33wAJzMNhqnjvAJ6+r1+hz9OMu1S29zqhEyI+kyh7ImZ+DdifydGJ+YT44W1g4v KmaA== 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 x1si7555094edq.177.2020.09.20.20.35.41; Sun, 20 Sep 2020 20:36: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 S1726419AbgIUDej (ORCPT + 99 others); Sun, 20 Sep 2020 23:34:39 -0400 Received: from mga05.intel.com ([192.55.52.43]:56863 "EHLO mga05.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726415AbgIUDei (ORCPT ); Sun, 20 Sep 2020 23:34:38 -0400 IronPort-SDR: qp6igGxLKZwnNEyH5TazuX1WkuAqanDpPEjM5RI04kZ9wlFbSiPC9AycSvyTDVW5RmTNx3mu7C PAbMfsA0eF3g== X-IronPort-AV: E=McAfee;i="6000,8403,9750"; a="245136864" X-IronPort-AV: E=Sophos;i="5.77,285,1596524400"; d="scan'208";a="245136864" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Sep 2020 20:34:37 -0700 IronPort-SDR: qtrx70Jw1CcTgYIqtAi5jSR7vIESiCZeWGD1YW1JiHcaAnoYy+4QS57ZOwCH6fjEb8W4HXy1gM WOxITWNBll/Q== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.77,285,1596524400"; d="scan'208";a="411943782" Received: from kbl-ppc.sh.intel.com ([10.239.159.55]) by fmsmga001.fm.intel.com with ESMTP; 20 Sep 2020 20:34:35 -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 v7 4/7] perf util: Link stream pair Date: Mon, 21 Sep 2020 11:33:59 +0800 Message-Id: <20200921033402.25129-5-yao.jin@linux.intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200921033402.25129-1-yao.jin@linux.intel.com> References: <20200921033402.25129-1-yao.jin@linux.intel.com> 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 --- v7: - Rename functions with 'stream__' prefix. v6: - Rebase to perf/core 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 e1c7d6c6126b..0d6a7452320a 100644 --- a/tools/perf/util/stream.c +++ b/tools/perf/util/stream.c @@ -175,3 +175,43 @@ struct evsel_streams *evsel_streams__entry(struct evlist_streams *els, 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 evsel_streams__match(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 f01335677479..cb131f41f5b1 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 { @@ -30,4 +31,7 @@ struct evlist_streams *evlist__create_streams(struct evlist *evlist, struct evsel_streams *evsel_streams__entry(struct evlist_streams *els, int evsel_idx); +void evsel_streams__match(struct evsel_streams *es_base, + struct evsel_streams *es_pair); + #endif /* __PERF_STREAM_H */ -- 2.17.1