Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp2955394pxk; Sun, 6 Sep 2020 21:18:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzdNdtomPgfvA5lynmv18cwt0HNBOVQtaiYIjPDYpKQyFBV6ydZrmbR14b1Q0jd0uLT48dx X-Received: by 2002:a05:6402:1b9a:: with SMTP id cc26mr19462410edb.30.1599452300035; Sun, 06 Sep 2020 21:18:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1599452300; cv=none; d=google.com; s=arc-20160816; b=lHBVjT/luXEYlv9o82ilCgNfpzEYdWO3pC8F08earWcBCRTztgWIr5jhMCi7VT1sTx 9s/Lf28LHIG9d2iUVGlxKwm2+YEBrQi5XNHt1j+sh6Z+v2eLCCcx58bYGzvjJrdhS5b+ 484JIi85wWAQOPJN1k+yB1gUC5sS8W1Z+lhKi6uqLyoR37Th7v+2UhdL2x++GUeEz0by VVOthxEyfQV7fSs/LZzqh4FOr3tNkRu6LYijrgBqX/MbWlLqs9ELG8lCq9hjj03FgXuP Nsj/MAX5aCuhh6pjEy1c+jbpW8ydu8nNSwZKMel505yf0GU2FbIxGs/x/l3JyWSbxcJm CQpQ== 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=quHAbV5aWBqOPzZWbBfyaoCCI/8nMqAr5T9vYGqN44c=; b=JWVyL0Q6+MRmnbxsNsh+AdDc8qenQ19z4csEDiTyHn9Al/WsXnH4KECj3qA0FXcEb+ qXYDguEBcyfLDpnJ0FmmhL2f27uWkZZhHE6MzKMYXrmh9v8/r1hygO85h/19nbIEwqi1 1XE/s8qVVvjnkYqQhabGdOfuhp8Dkn6Nl/RcV2u22naOygh9j8RB26OMUcqclGU7dVhH sDyUSRDeyrTBhyGorz4rLsM4bYAjHlWuLmEgvFBInazYIdH3g72F0iPctVilnbyugu8n E+XW6E63ZHYzSzn19nhbEm5guF8vjs8PMF6H4gF2EGj//6E3w05Vtaa0g6l+zJRCUAHi hgfw== 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 n18si4089850ejz.158.2020.09.06.21.17.57; Sun, 06 Sep 2020 21:18:20 -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 S1726613AbgIGERE (ORCPT + 99 others); Mon, 7 Sep 2020 00:17:04 -0400 Received: from mga14.intel.com ([192.55.52.115]:58725 "EHLO mga14.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726501AbgIGEQ6 (ORCPT ); Mon, 7 Sep 2020 00:16:58 -0400 IronPort-SDR: PTcOsvcAL2VFxqn2zBdw4QAcMvfH7w4cTNieL8T+8ebfzN7JQD8lnt6nuQyfWZGiEYo3ZJbUkl CyTD+3SghPKg== X-IronPort-AV: E=McAfee;i="6000,8403,9736"; a="157215565" X-IronPort-AV: E=Sophos;i="5.76,400,1592895600"; d="scan'208";a="157215565" 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:57 -0700 IronPort-SDR: aX7QgGaOtn88IyuZddsU345gBfrJKunyCBit898lnhKbuLZKyWExMPPgKrJht90scsmop6zDVi KxPc44ocWLhA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.76,400,1592895600"; d="scan'208";a="406709948" Received: from kbl-ppc.sh.intel.com ([10.239.159.55]) by fmsmga001.fm.intel.com with ESMTP; 06 Sep 2020 21:16:55 -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 6/7] perf util: Report hot streams Date: Mon, 7 Sep 2020 12:16:05 +0800 Message-Id: <20200907041606.14500-7-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 We show the streams separately. They are divided into different sections. 1. "Matched hot streams" 2. "Hot streams in old perf data only" 3. "Hot streams 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 --- v5: - Rebase to perf/core v4: - Remove "Hot chains in old perf data but source line changed in new perf data" tools/perf/util/callchain.c | 13 ++++ tools/perf/util/callchain.h | 2 + tools/perf/util/stream.c | 123 ++++++++++++++++++++++++++++++++++++ tools/perf/util/stream.h | 3 + 4 files changed, 141 insertions(+) diff --git a/tools/perf/util/callchain.c b/tools/perf/util/callchain.c index 90d31582393e..ce66a6308e87 100644 --- a/tools/perf/util/callchain.c +++ b/tools/perf/util/callchain.c @@ -1685,3 +1685,16 @@ u64 callchain_total_hits(struct hists *hists) return chain_hits; } + +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; +} diff --git a/tools/perf/util/callchain.h b/tools/perf/util/callchain.h index 082f73524c9a..9c099f463723 100644 --- a/tools/perf/util/callchain.h +++ b/tools/perf/util/callchain.h @@ -296,4 +296,6 @@ bool callchain_cnode_matched(struct callchain_node *base_cnode, u64 callchain_total_hits(struct hists *hists); +s64 callchain_avg_cycles(struct callchain_node *cnode); + #endif /* __PERF_CALLCHAIN_H */ diff --git a/tools/perf/util/stream.c b/tools/perf/util/stream.c index 642316078e40..2d3dc7361ef1 100644 --- a/tools/perf/util/stream.c +++ b/tools/perf/util/stream.c @@ -199,3 +199,126 @@ void match_evsel_streams(struct evsel_streams *es_base, stream_link(base_stream, pair_stream); } } + +static void print_callchain_pair(struct stream *base_stream, int idx, + struct evsel_streams *es_base, + struct evsel_streams *es_pair) +{ + struct callchain_node *base_cnode = base_stream->cnode; + struct callchain_node *pair_cnode = base_stream->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)es_base->streams_hits; + scnprintf(buf1, sizeof(buf1), "cycles: %ld, hits: %.2f%%", + callchain_avg_cycles(base_cnode), pct * 100.0); + + pct = (double)pair_cnode->hit / (double)es_pair->streams_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); + + 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 *stream, int idx, + struct evsel_streams *es, bool pair) +{ + struct callchain_node *cnode = stream->cnode; + struct callchain_list *chain; + char buf[512], cbuf[256], *s; + double pct; + + printf("\nhot chain %d:\n", idx); + + pct = (double)cnode->hit / (double)es->streams_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); + } +} + +static void callchain_streams_report(struct evsel_streams *es_base, + struct evsel_streams *es_pair) +{ + struct stream *base_stream; + int i, idx = 0; + + printf("[ Matched hot streams ]\n"); + for (i = 0; i < es_base->nr_streams; i++) { + base_stream = &es_base->streams[i]; + if (base_stream->pair_cnode) { + print_callchain_pair(base_stream, ++idx, + es_base, es_pair); + } + } + + idx = 0; + printf("\n[ Hot streams in old perf data only ]\n"); + for (i = 0; i < es_base->nr_streams; i++) { + base_stream = &es_base->streams[i]; + if (!base_stream->pair_cnode) { + print_stream_callchain(base_stream, ++idx, + es_base, false); + } + } + + idx = 0; + printf("\n[ Hot streams in new perf data only ]\n"); + for (i = 0; i < es_pair->nr_streams; i++) { + base_stream = &es_pair->streams[i]; + if (!base_stream->pair_cnode) { + print_stream_callchain(base_stream, ++idx, + es_pair, true); + } + } +} + +void evsel_streams_report(struct evsel_streams *es_base, + struct evsel_streams *es_pair) +{ + return callchain_streams_report(es_base, es_pair); +} diff --git a/tools/perf/util/stream.h b/tools/perf/util/stream.h index 56dfa90c810d..33b02c059d23 100644 --- a/tools/perf/util/stream.h +++ b/tools/perf/util/stream.h @@ -28,4 +28,7 @@ struct evsel_streams *evsel_streams_get(struct evsel_streams *es, void match_evsel_streams(struct evsel_streams *es_base, struct evsel_streams *es_pair); +void evsel_streams_report(struct evsel_streams *es_base, + struct evsel_streams *es_pair); + #endif /* __PERF_STREAM_H */ -- 2.17.1