Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp1400327ybh; Fri, 13 Mar 2020 00:13:47 -0700 (PDT) X-Google-Smtp-Source: ADFU+vtaJB2nYdeFnp8ceTuBurqTfDPSLQ2TWxhPizJEQplwTxooTTQUF19b+JvFX+EETSXG8/rg X-Received: by 2002:aca:abcd:: with SMTP id u196mr5927413oie.86.1584083627211; Fri, 13 Mar 2020 00:13:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584083627; cv=none; d=google.com; s=arc-20160816; b=dsD1XLE6q57aq6f9uFAUCL+ajlDCPT+kN64RiHFh4dd5+UPC0gNPpCJNqPQBrytjZY Uh0ye1II5sNmmu3nxw1w+1aMTloJtU7fQ1uz3Ok+0tliHFYgYU6ihygtrkBFqdJ1XuvA fNFfoLWy8Fn06HeNjV4WajhGsgtNU4UZukju62fMYAK07nZ+w4LceITmymrf5qgKn4uk LrT1RYRADFmDh4fb51HE/m5KXqGCANwtpG7MKNwJVEV2+Mi7Qz+nptAdGgMhlDqnjIga 6lTZu575zqsK+s/CHYJvOGIIFkmjPUMqcGoMC0V8gQ5ydGn0Zr+1iQvucY3pAa4olKAg dzew== 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=257MRhsfELSpJgq+TKenuFtG6vilkdWBgyOM5yJnJ60=; b=rMUFK2JHRtkHVkHH2qXPwh/a8ube7rkc0iMClhbA2okFv1pE5z108F28I/ZI3rszyT Yss89dKP/M0XU22pkBT2rfnSgQxAFcK1bfXbckDFMi+8rr4wjZy+XkgYBBV4z7xd/Ko+ A4dbs/dCFFA+FUEHRK+hj60SqPdIDcP54Udje83uWSStAd/xtnwjMWhdDT7unx95gbFg r2y0QDqc77VZcTOfaS3zGbUakvVKbbbIy9l120XMTiQePST2bySBVtNlL0RjAAgo6c29 oOr27Zn38YEeu9egywApq0ZI1Ulxw1DA1Nr93mPNw+50ZKeAewD6wQRwPa1cnQ8xN9Tn ZaeQ== 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 a5si423023otr.237.2020.03.13.00.13.35; Fri, 13 Mar 2020 00:13:47 -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 S1726691AbgCMHMG (ORCPT + 99 others); Fri, 13 Mar 2020 03:12:06 -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 S1726628AbgCMHMD (ORCPT ); Fri, 13 Mar 2020 03:12:03 -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:03 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.70,547,1574150400"; d="scan'208";a="266642254" Received: from kbl.sh.intel.com ([10.239.159.24]) by fmsmga004.fm.intel.com with ESMTP; 13 Mar 2020 00:12:01 -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 05/14] perf util: Calculate the sum of all streams hits Date: Fri, 13 Mar 2020 15:11:09 +0800 Message-Id: <20200313071118.11983-6-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 have used callchain_node->hit to measure the hot level of one stream. This patch calculates the sum of hits of all streams. Then in next patch, we can use following formula to report hot percent for one stream. hot percent = callchain_node->hit / sum of all hits v2: --- Combine the variable decl line with its inital assignment in total_callchain_hits(). Signed-off-by: Jin Yao --- tools/perf/util/callchain.c | 34 ++++++++++++++++++++++++++++++++++ tools/perf/util/callchain.h | 1 + 2 files changed, 35 insertions(+) diff --git a/tools/perf/util/callchain.c b/tools/perf/util/callchain.c index 1619f7fa4076..b0c8757c2dcf 100644 --- a/tools/perf/util/callchain.c +++ b/tools/perf/util/callchain.c @@ -1683,6 +1683,38 @@ static void update_hot_streams(struct hist_entry *he, } } +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; +} + +static u64 total_callchain_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; +} + static void get_hot_streams(struct hists *hists, struct callchain_streams *s) { @@ -1695,6 +1727,8 @@ static void get_hot_streams(struct hists *hists, update_hot_streams(he, s); next = rb_next(&he->rb_node); } + + s->chain_hits = total_callchain_hits(hists); } struct callchain_streams *callchain_evsel_streams_create(struct evlist *evlist, diff --git a/tools/perf/util/callchain.h b/tools/perf/util/callchain.h index c996ab4fb108..3c0e0b45656b 100644 --- a/tools/perf/util/callchain.h +++ b/tools/perf/util/callchain.h @@ -173,6 +173,7 @@ struct callchain_streams { int nr_streams_max; int nr_streams; int evsel_idx; + u64 chain_hits; }; extern __thread struct callchain_cursor callchain_cursor; -- 2.17.1