public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Jin Yao <yao.jin@linux.intel.com>
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 <yao.jin@linux.intel.com>
Subject: [PATCH v1 4/9] perf diff: Get a list of symbols(functions)
Date: Mon, 20 May 2019 21:27:51 +0800	[thread overview]
Message-ID: <1558358876-32211-5-git-send-email-yao.jin@linux.intel.com> (raw)
In-Reply-To: <1558358876-32211-1-git-send-email-yao.jin@linux.intel.com>

We already have a function hist__account_cycles() which can be used
to account cycles per basic block in symbol/function. But we also
need to know what the symbols are, since we need to get basic blocks
of all symbols(functions) before diff.

This patch records the sorted symbols in sym_hists, which will be
used in next patch for accounting cycles per basic block per
function.

Signed-off-by: Jin Yao <yao.jin@linux.intel.com>
---
 tools/perf/builtin-diff.c | 81 ++++++++++++++++++++++++++++++++++++++++++-----
 1 file changed, 73 insertions(+), 8 deletions(-)

diff --git a/tools/perf/builtin-diff.c b/tools/perf/builtin-diff.c
index 6023f8c..e067ac6 100644
--- a/tools/perf/builtin-diff.c
+++ b/tools/perf/builtin-diff.c
@@ -26,6 +26,12 @@
 #include <stdlib.h>
 #include <math.h>
 
+struct block_hists {
+	struct hists		sym_hists;
+	struct perf_hpp_list	sym_list;
+	struct perf_hpp_fmt	sym_fmt;
+};
+
 struct perf_diff {
 	struct perf_tool		 tool;
 	const char			*time_str;
@@ -33,6 +39,8 @@ struct perf_diff {
 	int				 range_size;
 	int				 range_num;
 	bool				 has_br_stack;
+	bool				 basic_block;
+	struct block_hists		*block_hists;
 };
 
 /* Diff command specific HPP columns. */
@@ -62,6 +70,7 @@ struct data__file {
 	int			 idx;
 	struct hists		*hists;
 	struct diff_hpp_fmt	 fmt[PERF_HPP_DIFF__MAX_INDEX];
+	struct block_hists       block_hists;
 };
 
 static struct data__file *data__files;
@@ -363,9 +372,18 @@ static int diff__process_sample_event(struct perf_tool *tool,
 		goto out_put;
 	}
 
-	if (!hists__add_entry(hists, &al, NULL, NULL, NULL, sample, true)) {
-		pr_warning("problem incrementing symbol period, skipping event\n");
-		goto out_put;
+	if (pdiff->has_br_stack && pdiff->basic_block) {
+		if (!hists__add_entry(&pdiff->block_hists->sym_hists, &al,
+			NULL, NULL, NULL, sample, false)) {
+			pr_warning("problem counting symbol for basic block\n");
+			goto out_put;
+		}
+	} else {
+		if (!hists__add_entry(hists, &al, NULL, NULL, NULL,
+				      sample, true)) {
+			pr_warning("problem incrementing symbol period, skipping event\n");
+			goto out_put;
+		}
 	}
 
 	/*
@@ -899,6 +917,37 @@ static int check_file_brstack(void)
 	return 0;
 }
 
+static int64_t symbol_se_cmp(struct perf_hpp_fmt *fmt __maybe_unused,
+			     struct hist_entry *a, struct hist_entry *b)
+{
+	return sort_sym.se_cmp(a, b);
+}
+
+static int block_sym_hists_init(struct block_hists *hists)
+{
+	struct perf_hpp_fmt *fmt;
+
+	__hists__init(&hists->sym_hists, &hists->sym_list);
+	perf_hpp_list__init(&hists->sym_list);
+	fmt = &hists->sym_fmt;
+	INIT_LIST_HEAD(&fmt->list);
+	INIT_LIST_HEAD(&fmt->sort_list);
+
+	fmt->cmp = symbol_se_cmp;
+	perf_hpp_list__register_sort_field(&hists->sym_list, fmt);
+	return 0;
+}
+
+static void basic_block_process(void)
+{
+	struct data__file *d;
+	int i;
+
+	data__for_each_file(i, d) {
+		hists__delete_entries(&d->block_hists.sym_hists);
+	}
+}
+
 static int __cmd_diff(void)
 {
 	struct data__file *d;
@@ -937,6 +986,16 @@ static int __cmd_diff(void)
 				goto out_delete;
 		}
 
+		if (pdiff.has_br_stack && pdiff.basic_block) {
+			ret = block_sym_hists_init(&d->block_hists);
+			if (ret) {
+				pr_err("Failed to initialize basic block hists\n");
+				goto out_delete;
+			}
+
+			pdiff.block_hists = &d->block_hists;
+		}
+
 		ret = perf_session__process_events(d->session);
 		if (ret) {
 			pr_err("Failed to process %s\n", d->data.path);
@@ -949,7 +1008,10 @@ static int __cmd_diff(void)
 			zfree(&pdiff.ptime_range);
 	}
 
-	data_process();
+	if (pdiff.has_br_stack && pdiff.basic_block)
+		basic_block_process();
+	else
+		data_process();
 
  out_delete:
 	data__for_each_file(i, d) {
@@ -1019,6 +1081,8 @@ static const struct option options[] = {
 		   "only consider symbols in these pids"),
 	OPT_STRING(0, "tid", &symbol_conf.tid_list_str, "tid[,tid...]",
 		   "only consider symbols in these tids"),
+	OPT_BOOLEAN(0, "basic-block", &pdiff.basic_block,
+		    "display the differential program basic block"),
 	OPT_END()
 };
 
@@ -1517,10 +1581,11 @@ int cmd_diff(int argc, const char **argv)
 	if (data_init(argc, argv) < 0)
 		return -1;
 
-	if (ui_init() < 0)
-		return -1;
-
-	sort__mode = SORT_MODE__DIFF;
+	if (!pdiff.basic_block) {
+		if (ui_init() < 0)
+			return -1;
+		sort__mode = SORT_MODE__DIFF;
+	}
 
 	if (setup_sorting(NULL) < 0)
 		usage_with_options(diff_usage, options);
-- 
2.7.4


  parent reply	other threads:[~2019-05-20  5:38 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-20 13:27 [PATCH v1 0/9] perf diff: diff cycles at basic block level Jin Yao
2019-05-20 13:27 ` [PATCH v1 1/9] perf util: Create block_info structure Jin Yao
2019-05-20 13:27 ` [PATCH v1 2/9] perf util: Add block_info in hist_entry Jin Yao
2019-05-20 13:27 ` [PATCH v1 3/9] perf diff: Check if all data files with branch stacks Jin Yao
2019-05-20 13:27 ` Jin Yao [this message]
2019-05-20 13:27 ` [PATCH v1 5/9] perf diff: Use hists to manage basic blocks Jin Yao
2019-05-20 13:27 ` [PATCH v1 6/9] perf diff: Link same basic blocks among different data files Jin Yao
2019-05-20 13:27 ` [PATCH v1 7/9] perf diff: Compute cycles diff of basic blocks Jin Yao
2019-05-20 13:27 ` [PATCH v1 8/9] perf diff: Print the basic block cycles diff Jin Yao
2019-05-22 14:04   ` Jiri Olsa
2019-05-24  0:39     ` Jin, Yao
2019-05-20 13:27 ` [PATCH v1 9/9] perf diff: Documentation --basic-block option Jin Yao

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1558358876-32211-5-git-send-email-yao.jin@linux.intel.com \
    --to=yao.jin@linux.intel.com \
    --cc=Linux-kernel@vger.kernel.org \
    --cc=acme@kernel.org \
    --cc=ak@linux.intel.com \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=jolsa@kernel.org \
    --cc=kan.liang@intel.com \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=yao.jin@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox