Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp2955359pxk; Sun, 6 Sep 2020 21:18:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy6c02i3yPg3Jao7ikAQCHUbQ1wF4lbLcSBO3enECY5u0/wID+dWhV/7OVLkGD0D+O8hDVw X-Received: by 2002:a50:f199:: with SMTP id x25mr19195222edl.347.1599452293904; Sun, 06 Sep 2020 21:18:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1599452293; cv=none; d=google.com; s=arc-20160816; b=nDt2Mt0Srs1wlfPFkRtGNNgsfwFMy0W9AvgZbtpTjuR8ySEE1X8h2nJfTHpTpSG8XT ujTs41OHEWF2XlyNcnoogDNBaO/KdM2LNckqm2zpE1YVd3MkriubexFgUA/YGwlg/hH9 BubOmWc3gjYpfPF7p4JuHC2NtCk6QF/ADnC//m1Yc96X8+SY6633URm0fMcwf6/DeJU1 X/r1eqIJls2zvIqtU6LpK+0Vqvl5M+vGla0EqpjWMrkGq2ljwoyLh2tlSGSiF7ki+GJ3 Ktolhj+k1QyOhmsth3GoHKAO3DK8pJXDXetoSJ60tpp2t/Y8kbhsY44wITBYVXSoEqyy YNdQ== 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=jzDEMJRD1bzqZmc1wNniiFM+CK/ZHDlJCqTq8VN57CE=; b=bi5I5P/Fkv4/B7XfLe6uNcU2JlNAtldgZKOHZT9sFSf7nreDCBNIijyZDqWxb0J8Sv 57UqsnPAt2WZNVazX+xY6prkI7poIdbcrf7tJOQcG+nNoqzvbzj5URRMX4N+dhD6hwmY eENGQEJ5yiRuNbo/Vb6zFqyAAOKehQldmPoCJwfT+UFsiKZTZcj3ZKfJ67qZWnGvT0WQ 7KYlh8CP2K7/IYLsHeVgXDsQIcExmPdl5Z6z1CkUa7N+R0IsLg0EyxjN/wJRryh05Dne ts/5kTly7+ORW7axBzD/aTmF80/uk+FGlUmtMyxtYarzhLSBt/39SI31P/3UNfTVCraC atiQ== 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 c24si8930721eja.263.2020.09.06.21.17.45; Sun, 06 Sep 2020 21:18:13 -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 S1726402AbgIGEQy (ORCPT + 99 others); Mon, 7 Sep 2020 00:16:54 -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 S1726259AbgIGEQu (ORCPT ); Mon, 7 Sep 2020 00:16:50 -0400 IronPort-SDR: H0IizkYrG4wwzZz5P+1/BmFhai0mgyMd5CqeI41sGAL5E5aVcQ6BWgZ7++gTL5zsixFoj37Y9y j/5CIEU094+w== X-IronPort-AV: E=McAfee;i="6000,8403,9736"; a="157215553" X-IronPort-AV: E=Sophos;i="5.76,400,1592895600"; d="scan'208";a="157215553" 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:50 -0700 IronPort-SDR: fgvdwIp22FPN+mMtxJZuyvd6eSgolQNCMVehJi2BM4rbmlFd1+L+IwjtHjpvQrLdsPV6FSwGSa OnyCCARZ23Ew== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.76,400,1592895600"; d="scan'208";a="406709927" Received: from kbl-ppc.sh.intel.com ([10.239.159.55]) by fmsmga001.fm.intel.com with ESMTP; 06 Sep 2020 21:16:48 -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 3/7] perf util: Compare two streams Date: Mon, 7 Sep 2020 12:16:02 +0800 Message-Id: <20200907041606.14500-4-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 Stream is the branch history which is aggregated by the branch records from perf samples. Now we support the callchain as stream. If the callchain entries of one stream are fully matched with the callchain entries of another stream, we think two streams are matched. For example, cycles: 1, hits: 26.80% cycles: 1, hits: 27.30% ----------------------- ----------------------- main div.c:39 main div.c:39 main div.c:44 main div.c:44 Above two streams are matched (we don't consider the case that source code is changed). The matching logic is, compare the chain string first. If it's not matched, fallback to dso address comparison. Signed-off-by: Jin Yao --- v5: - Remove enum stream_type - Rebase to perf/core v4: - Remove original source line comparison code. tools/perf/util/callchain.c | 54 +++++++++++++++++++++++++++++++++++++ tools/perf/util/callchain.h | 3 +++ 2 files changed, 57 insertions(+) diff --git a/tools/perf/util/callchain.c b/tools/perf/util/callchain.c index 9a9b56ed3f0a..7cab271e656b 100644 --- a/tools/perf/util/callchain.c +++ b/tools/perf/util/callchain.c @@ -1599,3 +1599,57 @@ void callchain_cursor_reset(struct callchain_cursor *cursor) for (node = cursor->first; node != NULL; node = node->next) map__zput(node->map); } + +static bool chain_match(struct callchain_list *base_chain, + struct callchain_list *pair_chain) +{ + enum match_result match; + + match = match_chain_strings(base_chain->srcline, + pair_chain->srcline); + if (match != MATCH_ERROR) + return match == MATCH_EQ; + + match = match_chain_dso_addresses(base_chain->ms.map, + base_chain->ip, + pair_chain->ms.map, + pair_chain->ip); + + return match == MATCH_EQ; +} + +bool callchain_cnode_matched(struct callchain_node *base_cnode, + struct callchain_node *pair_cnode) +{ + struct callchain_list *base_chain, *pair_chain; + bool match = false; + + pair_chain = list_first_entry(&pair_cnode->val, + struct callchain_list, + list); + + list_for_each_entry(base_chain, &base_cnode->val, list) { + if (&pair_chain->list == &pair_cnode->val) + return false; + + if (!base_chain->srcline || !pair_chain->srcline) { + pair_chain = list_next_entry(pair_chain, list); + continue; + } + + match = chain_match(base_chain, pair_chain); + if (!match) + return false; + + pair_chain = list_next_entry(pair_chain, list); + } + + /* + * Say chain1 is ABC, chain2 is ABCD, we consider they are + * not fully matched. + */ + if (pair_chain && (&pair_chain->list != &pair_cnode->val)) + return false; + + return match; +} diff --git a/tools/perf/util/callchain.h b/tools/perf/util/callchain.h index 83398e5bbe4b..72134bed49d8 100644 --- a/tools/perf/util/callchain.h +++ b/tools/perf/util/callchain.h @@ -290,4 +290,7 @@ int callchain_branch_counts(struct callchain_root *root, u64 *branch_count, u64 *predicted_count, u64 *abort_count, u64 *cycles_count); +bool callchain_cnode_matched(struct callchain_node *base_cnode, + struct callchain_node *pair_cnode); + #endif /* __PERF_CALLCHAIN_H */ -- 2.17.1