Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp1399556ybh; Fri, 13 Mar 2020 00:12:49 -0700 (PDT) X-Google-Smtp-Source: ADFU+vsicQ7rliOBmOpwAexepOf1AaGuMQ7EKfRIPldY+9duc9n9A9hmjkrbODmCuJVjT1xoOt3i X-Received: by 2002:a05:6808:910:: with SMTP id w16mr5632396oih.66.1584083569117; Fri, 13 Mar 2020 00:12:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584083569; cv=none; d=google.com; s=arc-20160816; b=m+7mm3ddlBh83zk1TwdQT+g/90ks+te+MB2y6lAOFy1lL1jsHfzPIlcff81tiD2H4K QWJXNeakFLN5h+TL+qfTox/x0xSJxEQhUGzffLCub47RU0TTxaSlYrhm+ZF+00Vudlby 93AcbUgX4TSK1Vt4ZysHu3pGZAMUG3FZCSZosXsRcaam7Su+KsyZ9Cv+Bpp4yFFQ8DaD b0Kgnxy8CZYTmnyH2fnP7FKh8YIpqIP82r0Qu2n4wIO5SjGdvgfSAXPCBugVxnjjPO2g yKs1H5IvLtc+Kxa9HGR2lDZvKhyPkC3coUshPpRa/7JzsJIrYEHytUwo4xU6WbTiYT0T r0ug== 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; bh=Zbo6MyZ7WnoIXy6Fr5r6IFK+aoWWyGts5LftMjDALxE=; b=lb1YgbroyFZbB80RbxhzNR4eUwRPmb4a4BfsAnZhgBWD28cZsN0RE3FXJaTLjo3r13 2xB//Zab8Tej59TFuDqS1Cb+k8wlgDzvqxPPPpvkMxSxl/bDUvy8RsLhLXzXjHxQtQX+ 6i+DeRbO/m9uagRP7B1sp+vE0ReHXO7GnoC47UJjVWuVFOZ1vGmxMaMU/deLUiZqWa01 aI3xmO2JQoSlCk6gYes0BPu5oLrfywOwONeUIYJQRj2RKSrDmsxbMFLMcWFGkAr49o5B ydr3ylTmzZkHxWLgYrUvQqGTh2YoDqJLMtPnnkA0OoaRz5bDpHuCdZlFN32piQFXbhyC GM+w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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. [209.132.180.67]) by mx.google.com with ESMTP id k194si4089449oib.251.2020.03.13.00.12.34; Fri, 13 Mar 2020 00:12:49 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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 S1726713AbgCMHMJ (ORCPT + 99 others); Fri, 13 Mar 2020 03:12:09 -0400 Received: from mga02.intel.com ([134.134.136.20]:7782 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726682AbgCMHMG (ORCPT ); Fri, 13 Mar 2020 03:12:06 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 13 Mar 2020 00:12:05 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.70,547,1574150400"; d="scan'208";a="266642260" Received: from kbl.sh.intel.com ([10.239.159.24]) by fmsmga004.fm.intel.com with ESMTP; 13 Mar 2020 00:12:03 -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 v2 06/14] perf util: Report hot streams Date: Fri, 13 Mar 2020 15:11:10 +0800 Message-Id: <20200313071118.11983-7-yao.jin@linux.intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200313071118.11983-1-yao.jin@linux.intel.com> References: <20200313071118.11983-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 We show the streams separately. They are divided into different sections. 1. "Matched hot chains between old perf data and new perf data" 2. "Hot chains in old perf data but source line changed in new perf data" 3. "Hot chains in old perf data only" 4. "Hot chains in new perf data only". For each stream, we report the cycles and hot percent (hits%). For example, cycles: 2, hits: 4.08% -------------------------- main div.c:42 compute_flag div.c:28 Signed-off-by: Jin Yao --- tools/perf/util/callchain.c | 155 ++++++++++++++++++++++++++++++++++++ tools/perf/util/callchain.h | 3 + 2 files changed, 158 insertions(+) diff --git a/tools/perf/util/callchain.c b/tools/perf/util/callchain.c index b0c8757c2dcf..84fe8e418532 100644 --- a/tools/perf/util/callchain.c +++ b/tools/perf/util/callchain.c @@ -1777,6 +1777,9 @@ static bool chain_srclist_match(struct srclist *src_list, const char *srcline_a, struct src_node *node; struct line_pair *lp; + if (!srcline_a || !srcline_b) + return false; + if (sscanf(srcline_a, "%[^:]:%d", file_a, &line_a) != 2) return false; @@ -1817,6 +1820,10 @@ static bool chain_match(struct callchain_list *base_chain, *src_changed = false; + /* + * Check sourceline first. If not matched, + * fallback to symbol match and address match. + */ if (src_list && chain_srclist_match(src_list, pair_chain->srcline, base_chain->srcline, &src_found, src_changed)) { @@ -1939,3 +1946,151 @@ void callchain_match_streams(struct callchain_streams *cs_base, if (src_list) srclist__dump(src_list); } + +static s64 callchain_avg_cycles(struct callchain_node *cnode) +{ + struct callchain_list *chain; + s64 cycles = 0; + + list_for_each_entry(chain, &cnode->val, list) { + if (chain->srcline && chain->branch_count) + cycles += chain->cycles_count / chain->branch_count; + } + + return cycles; +} + +static void print_callchain_pair(struct stream_node *base_node, int idx, + struct callchain_streams *cs_base, + struct callchain_streams *cs_pair) +{ + struct callchain_node *base_cnode = base_node->cnode; + struct callchain_node *pair_cnode = base_node->pair_cnode; + struct callchain_list *base_chain, *pair_chain; + char buf1[512], buf2[512], cbuf1[256], cbuf2[256]; + char *s1, *s2; + double pct; + + printf("\nhot chain pair %d:\n", idx); + + pct = (double)base_cnode->hit / (double)cs_base->chain_hits; + scnprintf(buf1, sizeof(buf1), "cycles: %ld, hits: %.2f%%", + callchain_avg_cycles(base_cnode), pct * 100.0); + + pct = (double)pair_cnode->hit / (double)cs_pair->chain_hits; + scnprintf(buf2, sizeof(buf2), "cycles: %ld, hits: %.2f%%", + callchain_avg_cycles(pair_cnode), pct * 100.0); + + printf("%35s\t%35s\n", buf1, buf2); + + printf("%35s\t%35s\n", + "---------------------------", + "--------------------------"); + + 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; + + s1 = callchain_list__sym_name(base_chain, cbuf1, sizeof(cbuf1), + false); + s2 = callchain_list__sym_name(pair_chain, cbuf2, sizeof(cbuf2), + false); + + if (!pair_chain->src_changed) + scnprintf(buf1, sizeof(buf1), "%35s\t%35s", s1, s2); + else + scnprintf(buf1, sizeof(buf1), "%35s\t%35s*", s1, s2); + + printf("%s\n", buf1); + pair_chain = list_next_entry(pair_chain, list); + } +} + +static void print_stream_callchain(struct stream_node *node, int idx, + struct callchain_streams *cs, bool pair) +{ + struct callchain_node *cnode = node->cnode; + struct callchain_list *chain; + char buf[512], cbuf[256], *s; + double pct; + + printf("\nhot chain %d:\n", idx); + + pct = (double)cnode->hit / (double)cs->chain_hits; + scnprintf(buf, sizeof(buf), "cycles: %ld, hits: %.2f%%", + callchain_avg_cycles(cnode), pct * 100.0); + + if (pair) { + printf("%35s\t%35s\n", "", buf); + printf("%35s\t%35s\n", + "", "--------------------------"); + } else { + printf("%35s\n", buf); + printf("%35s\n", "--------------------------"); + } + + list_for_each_entry(chain, &cnode->val, list) { + s = callchain_list__sym_name(chain, cbuf, sizeof(cbuf), false); + + if (pair) + scnprintf(buf, sizeof(buf), "%35s\t%35s", "", s); + else + scnprintf(buf, sizeof(buf), "%35s", s); + + printf("%s\n", buf); + } +} + +void callchain_stream_report(struct callchain_streams *cs_base, + struct callchain_streams *cs_pair) +{ + struct stream_node *base_node; + int i, idx = 0; + + printf("[ Matched hot chains between old perf data and new perf data ]\n"); + for (i = 0; i < cs_base->nr_streams; i++) { + base_node = &cs_base->streams[i]; + if (base_node->pair_cnode) { + if (!base_node->src_changed) { + print_callchain_pair(base_node, ++idx, + cs_base, cs_pair); + } + } + } + + idx = 0; + printf("\n[ Hot chains in old perf data but source line changed (*) in new perf data ]\n"); + for (i = 0; i < cs_base->nr_streams; i++) { + base_node = &cs_base->streams[i]; + if (base_node->pair_cnode) { + if (base_node->src_changed) { + print_callchain_pair(base_node, ++idx, + cs_base, cs_pair); + } + } + } + + idx = 0; + printf("\n[ Hot chains in old perf data only ]\n"); + for (i = 0; i < cs_base->nr_streams; i++) { + base_node = &cs_base->streams[i]; + if (!base_node->pair_cnode) { + print_stream_callchain(base_node, ++idx, + cs_base, false); + } + } + + idx = 0; + printf("\n[ Hot chains in new perf data only ]\n"); + for (i = 0; i < cs_pair->nr_streams; i++) { + base_node = &cs_pair->streams[i]; + if (!base_node->pair_cnode) { + print_stream_callchain(base_node, ++idx, + cs_pair, true); + } + } +} diff --git a/tools/perf/util/callchain.h b/tools/perf/util/callchain.h index 3c0e0b45656b..90826a280476 100644 --- a/tools/perf/util/callchain.h +++ b/tools/perf/util/callchain.h @@ -318,4 +318,7 @@ void callchain_match_streams(struct callchain_streams *cs_base, struct callchain_streams *cs_pair, struct srclist *src_list); +void callchain_stream_report(struct callchain_streams *cs_base, + struct callchain_streams *cs_pair); + #endif /* __PERF_CALLCHAIN_H */ -- 2.17.1