Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp2955866pxk; Sun, 6 Sep 2020 21:19:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxvRG9CDnWuC9XsmPrR53i3KzmYD0cO+qBfqE4DeVplbGmVRBwB5IzftfCoSegOJEyaWY5C X-Received: by 2002:a50:8e17:: with SMTP id 23mr19524359edw.42.1599452361434; Sun, 06 Sep 2020 21:19:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1599452361; cv=none; d=google.com; s=arc-20160816; b=CMBrCUR6j313rnUqeXAWdaK6dSzJLZDyhzbnOsuzEAS/14fw9lcqFo7iWt0foj/X/2 WUEOvB+NGmz5GfHNFZ2Crzrg/SEKXGtFhqUVUOxQbd0doxGLcG2B4yL137ASDx9wSsz7 /hU8YN/1r5Vu80PtbaQ+inuZO9tJJM/+2onO1kFfMbNZMMURHmGBTvJen4lm0WDL6/1D zpqpWFbpdQQ+opr94waxH1r5le7jCFxb5odpfKU9dmvOAm+LOcKudmGrfhwgefz3R6B7 beOyIq7Mlzgd8geDWGvmKM40OaAUJNL0hH4SibT9cKQ5uIrOctg5YaMOUEw/umQqi8DC LkJw== 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=uqcs8qIMkFInf3BJk2dP8YCRSE0Fg/50nPXhrd/1dOg=; b=eBCzhYgxCvBdYAuwOhU3bGf/3N2165h9sWjZMpTRcV3zXquOdYl4l0cQ/76cx+qBPV 8Ul+hTKgSVKPtmbBEmvIsrxB1Hq/IyfmjR6gNxb+QFQfYRbJG28VFjzH6SKn6QPWdR9W 9XpFHq87SC2vGYFXpIVrPwBAi5WQrY4mZZtTj2FZhgjASXcAxrgJaxxCRLcj55mGOlJI L1kAmTTSszwIU1J+h3didgFH+bMAUqCcU9X0vZCNnsKc19bJhk8P4XsGMJNLltu8Jyjf 9GVRs4SNkd/jXZVN3x/lMZu/Ar7b9QyEhkQ3Iaoko5Jynqq/KktOeu+kx/Nd1NbXQW5O GF7A== 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 u6si8542418edx.293.2020.09.06.21.18.59; Sun, 06 Sep 2020 21:19:21 -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 S1726568AbgIGERB (ORCPT + 99 others); Mon, 7 Sep 2020 00:17:01 -0400 Received: from mga14.intel.com ([192.55.52.115]:58721 "EHLO mga14.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726132AbgIGEQz (ORCPT ); Mon, 7 Sep 2020 00:16:55 -0400 IronPort-SDR: HVpVEEGTSr8cEC6YZ5sKdltHd+BjdTe2dKgBeEiP0oHG9WItFw7UGsC3ie0mnA0nayDwO4c1Bx LGcpKnqEnk1A== X-IronPort-AV: E=McAfee;i="6000,8403,9736"; a="157215560" X-IronPort-AV: E=Sophos;i="5.76,400,1592895600"; d="scan'208";a="157215560" 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:55 -0700 IronPort-SDR: 4IeShO1W0kSru4lTLYtCIOQA56JzP/iKf4OVwdGAD4j+a9HrYPa4oNDtp2yc/zXU5Ut1oLG+Mp az6CN+4eZhrQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.76,400,1592895600"; d="scan'208";a="406709942" Received: from kbl-ppc.sh.intel.com ([10.239.159.55]) by fmsmga001.fm.intel.com with ESMTP; 06 Sep 2020 21:16:53 -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 5/7] perf util: Calculate the sum of total streams hits Date: Mon, 7 Sep 2020 12:16:04 +0800 Message-Id: <20200907041606.14500-6-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 have used callchain_node->hit to measure the hot level of one stream. This patch calculates the sum of hits of total streams. Thus in next patch, we can use following formula to report hot percent for one stream. hot percent = callchain_node->hit / sum of total hits Signed-off-by: Jin Yao --- v5: - Rebase to perf/core v4: - No functional change. v2: - Combine the variable decl line with its initial assignment in total_callchain_hits(). tools/perf/util/callchain.c | 32 ++++++++++++++++++++++++++++++++ tools/perf/util/callchain.h | 3 +++ tools/perf/util/stream.c | 2 ++ tools/perf/util/stream.h | 1 + 4 files changed, 38 insertions(+) diff --git a/tools/perf/util/callchain.c b/tools/perf/util/callchain.c index 7cab271e656b..90d31582393e 100644 --- a/tools/perf/util/callchain.c +++ b/tools/perf/util/callchain.c @@ -1653,3 +1653,35 @@ bool callchain_cnode_matched(struct callchain_node *base_cnode, return match; } + +static u64 count_callchain_hits(struct hist_entry *he) +{ + struct rb_root *root = &he->sorted_chain; + struct rb_node *rb_node = rb_first(root); + struct callchain_node *node; + u64 chain_hits = 0; + + while (rb_node) { + node = rb_entry(rb_node, struct callchain_node, rb_node); + chain_hits += node->hit; + rb_node = rb_next(rb_node); + } + + return chain_hits; +} + +u64 callchain_total_hits(struct hists *hists) +{ + struct rb_node *next = rb_first_cached(&hists->entries); + u64 chain_hits = 0; + + while (next) { + struct hist_entry *he = rb_entry(next, struct hist_entry, + rb_node); + + chain_hits += count_callchain_hits(he); + next = rb_next(&he->rb_node); + } + + return chain_hits; +} diff --git a/tools/perf/util/callchain.h b/tools/perf/util/callchain.h index 72134bed49d8..082f73524c9a 100644 --- a/tools/perf/util/callchain.h +++ b/tools/perf/util/callchain.h @@ -13,6 +13,7 @@ struct ip_callchain; struct map; struct perf_sample; struct thread; +struct hists; #define HELP_PAD "\t\t\t\t" @@ -293,4 +294,6 @@ int callchain_branch_counts(struct callchain_root *root, bool callchain_cnode_matched(struct callchain_node *base_cnode, struct callchain_node *pair_cnode); +u64 callchain_total_hits(struct hists *hists); + #endif /* __PERF_CALLCHAIN_H */ diff --git a/tools/perf/util/stream.c b/tools/perf/util/stream.c index e96e21d6e07b..642316078e40 100644 --- a/tools/perf/util/stream.c +++ b/tools/perf/util/stream.c @@ -106,6 +106,8 @@ static void init_hot_callchain(struct hists *hists, struct evsel_streams *es) update_hot_callchain(he, es); next = rb_next(&he->rb_node); } + + es->streams_hits = callchain_total_hits(hists); } static int evlist_init_callchain_streams(struct evlist *evlist, diff --git a/tools/perf/util/stream.h b/tools/perf/util/stream.h index 2eb6f17a834e..56dfa90c810d 100644 --- a/tools/perf/util/stream.h +++ b/tools/perf/util/stream.h @@ -14,6 +14,7 @@ struct evsel_streams { int nr_streams_max; int nr_streams; int evsel_idx; + u64 streams_hits; }; struct evlist; -- 2.17.1