Skip to contentSkip to conversation

perf util: Move block tui function to ui browsers

PATCH Superseded Jin Yao 2 participants 8 messages Nov 13, 2019 – Nov 18, 2019 perf events

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Jin Yao

author
#0 lore raw

PATCH 1/2 perf util: Move block tui function to ui browsers

It would be nice if we could jump to the assembler/source view (like the normal perf report) from total cycles view.

This patch moves the block_hists_tui_browse from block-info.c to ui/browsers/hists.c in order to reuse some browser codes (i.e do_annotate) for implementing new annotation view.

---
 tools/perf/ui/browsers/hists.c | 55 ++++++++++++++++++++++++++++
 tools/perf/util/block-info.c   | 65 +---------------------------------
 tools/perf/util/hist.h         | 12 +++++++
 3 files changed, 68 insertions(+), 64 deletions(-)
tools/perf/ui/browsers/hists.c +55 -0
index 334afc2139e7..04301303c246 100644
@@ -3448,3 +3448,58 @@ int perf_evlist__tui_browse_hists(struct evlist *evlist, const char *help,
 					       warn_lost_event,
 					       annotation_opts);
 }
+
+static int block_hists_browser__title(struct hist_browser *browser, char *bf,
+				      size_t size)
+{
+	struct hists *hists = evsel__hists(browser->block_evsel);
+	const char *evname = perf_evsel__name(browser->block_evsel);
+	unsigned long nr_samples = hists->stats.nr_events[PERF_RECORD_SAMPLE];
+	int ret;
+
+	ret = scnprintf(bf, size, "# Samples: %lu", nr_samples);
+	if (evname)
+		scnprintf(bf + ret, size -  ret, " of event '%s'", evname);
+
+	return 0;
+}
+
+int block_hists_tui_browse(struct block_hist *bh, struct evsel *evsel,
+			   float min_percent)
+{
+	struct hists *hists = &bh->block_hists;
+	struct hist_browser *browser;
+	int key = -1;
+	static const char help[] =
+	" q             Quit \n";
+
+	browser = hist_browser__new(hists);
+	if (!browser)
+		return -1;
+
+	browser->block_evsel = evsel;
+	browser->title = block_hists_browser__title;
+	browser->min_pcnt = min_percent;
+
+	/* reset abort key so that it can get Ctrl-C as a key */
+	SLang_reset_tty();
+	SLang_init_tty(0, 0, 0);
+
+	while (1) {
+		key = hist_browser__run(browser, "? - help", true);
+
+		switch (key) {
+		case 'q':
+			goto out;
+		case '?':
+			ui_browser__help_window(&browser->b, help);
+			break;
+		default:
+			break;
+		}
+	}
+
+out:
+	hist_browser__delete(browser);
+	return 0;
+}
tools/perf/util/block-info.c +1 -64

77 lines not on this page · raw message

tools/perf/util/hist.h +12 -0
index 4d87c7b4c1b2..e8b3122a30a7 100644
@@ -449,6 +449,8 @@ enum rstype {
 	A_SOURCE
 };
 
+struct block_hist;
+
 #ifdef HAVE_SLANG_SUPPORT
 #include "../ui/keysyms.h"
 void attr_to_script(char *buf, struct perf_event_attr *attr);
@@ -474,6 +476,9 @@ void run_script(char *cmd);
 int res_sample_browse(struct res_sample *res_samples, int num_res,
 		      struct evsel *evsel, enum rstype rstype);
 void res_sample_init(void);
+
+int block_hists_tui_browse(struct block_hist *bh, struct evsel *evsel,
+			   float min_percent);
 #else
 static inline
 int perf_evlist__tui_browse_hists(struct evlist *evlist __maybe_unused,
@@ -518,6 +523,13 @@ static inline int res_sample_browse(struct res_sample *res_samples __maybe_unuse
 
 static inline void res_sample_init(void) {}
 
+int block_hists_tui_browse(struct block_hist *bh __maybe_unused,
+			   struct evsel *evsel __maybe_unused,
+			   float min_percent __maybe_unused)
+{
+	return 0;
+}
+
 #define K_LEFT  -1000
 #define K_RIGHT -2000
 #define K_SWITCH_INPUT_DATA -3000
Signature · 1 line
2.17.1
author
#1 lore raw

PATCH 2/2 perf report: Jump to symbol source view from total cycles view

This patch supports jumping from tui total cycles view to symbol source view.

For example,

perf record -b ./div
perf report --total-cycles

In total cycles view, we can select one entry and press 'a' or press ENTER key to jump to symbol source view.

---
 tools/perf/builtin-report.c    |  9 ++++++---
 tools/perf/ui/browsers/hists.c | 25 +++++++++++++++++++++++--
 tools/perf/util/block-info.c   |  6 ++++--
 tools/perf/util/block-info.h   |  3 ++-
 tools/perf/util/hist.h         |  7 +++++--
 5 files changed, 40 insertions(+), 10 deletions(-)
tools/perf/builtin-report.c +6 -3
index 1e81985b7d56..ceebea4013ca 100644
@@ -493,7 +493,9 @@ static int perf_evlist__tui_block_hists_browse(struct evlist *evlist,
 
 	evlist__for_each_entry(evlist, pos) {
 		ret = report__browse_block_hists(&rep->block_reports[i++].hist,
-						 rep->min_percent, pos);
+						 rep->min_percent, pos,
+						 &rep->session->header.env,
+						 &rep->annotation_opts);
 		if (ret != 0)
 			return ret;
 	}
@@ -525,7 +527,8 @@ static int perf_evlist__tty_browse_hists(struct evlist *evlist,
 
 		if (rep->total_cycles_mode) {
 			report__browse_block_hists(&rep->block_reports[i++].hist,
-						   rep->min_percent, pos);
+						   rep->min_percent, pos,
+						   NULL, NULL);
 			continue;
 		}
 
@@ -1418,7 +1421,7 @@ int cmd_report(int argc, const char **argv)
 		if (sort__mode != SORT_MODE__BRANCH)
 			report.total_cycles_mode = false;
 		else
-			sort_order = "sym";
+			sort_order = NULL;
 	}
 
 	if (strcmp(input_name, "-") != 0)
tools/perf/ui/browsers/hists.c +23 -2
index 04301303c246..31fc5d589128 100644
@@ -2385,7 +2385,11 @@ do_annotate(struct hist_browser *browser, struct popup_action *act)
 	if (!notes->src)
 		return 0;
 
-	evsel = hists_to_evsel(browser->hists);
+	if (browser->block_evsel)
+		evsel = browser->block_evsel;
+	else
+		evsel = hists_to_evsel(browser->hists);
+
 	err = map_symbol__tui_annotate(&act->ms, evsel, browser->hbt,
 				       browser->annotation_opts);
 	he = hist_browser__selected_entry(browser);
@@ -3465,11 +3469,13 @@ static int block_hists_browser__title(struct hist_browser *browser, char *bf,
 }
 
 int block_hists_tui_browse(struct block_hist *bh, struct evsel *evsel,
-			   float min_percent)
+			   float min_percent, struct perf_env *env,
+			   struct annotation_options *annotation_opts)
 {
 	struct hists *hists = &bh->block_hists;
 	struct hist_browser *browser;
 	int key = -1;
+	struct popup_action action;
 	static const char help[] =
 	" q             Quit \n";
 
@@ -3480,11 +3486,15 @@ int block_hists_tui_browse(struct block_hist *bh, struct evsel *evsel,
 	browser->block_evsel = evsel;
 	browser->title = block_hists_browser__title;
 	browser->min_pcnt = min_percent;
+	browser->env = env;
+	browser->annotation_opts = annotation_opts;
 
 	/* reset abort key so that it can get Ctrl-C as a key */
 	SLang_reset_tty();
 	SLang_init_tty(0, 0, 0);
 
+	memset(&action, 0, sizeof(action));
+
 	while (1) {
 		key = hist_browser__run(browser, "? - help", true);
 
@@ -3494,6 +3504,17 @@ int block_hists_tui_browse(struct block_hist *bh, struct evsel *evsel,
 		case '?':
 			ui_browser__help_window(&browser->b, help);
 			break;
+		case 'a':
+		case K_ENTER:
+			if (!browser->selection ||
+			    !browser->selection->sym) {
+				continue;
+			}
+
+			action.ms.map = browser->selection->map;
+			action.ms.sym = browser->selection->sym;
+			do_annotate(browser, &action);
+			continue;
 		default:
 			break;
 		}
tools/perf/util/block-info.c +4 -2
index 5887f8f9149f..c4b030bf6ec2 100644
@@ -441,7 +441,8 @@ struct block_report *block_info__create_report(struct evlist *evlist,
 }
 
 int report__browse_block_hists(struct block_hist *bh, float min_percent,
-			       struct evsel *evsel)
+			       struct evsel *evsel, struct perf_env *env,
+			       struct annotation_options *annotation_opts)
 {
 	int ret;
 
@@ -454,7 +455,8 @@ int report__browse_block_hists(struct block_hist *bh, float min_percent,
 		return 0;
 	case 1:
 		symbol_conf.report_individual_block = true;
-		ret = block_hists_tui_browse(bh, evsel, min_percent);
+		ret = block_hists_tui_browse(bh, evsel, min_percent,
+					     env, annotation_opts);
 		hists__delete_entries(&bh->block_hists);
 		return ret;
 	default:
tools/perf/util/block-info.h +2 -1
index e4d20bccd9b6..bef0d75e9819 100644
@@ -71,7 +71,8 @@ struct block_report *block_info__create_report(struct evlist *evlist,
 					       u64 total_cycles);
 
 int report__browse_block_hists(struct block_hist *bh, float min_percent,
-			       struct evsel *evsel);
+			       struct evsel *evsel, struct perf_env *env,
+			       struct annotation_options *annotation_opts);
 
 float block_info__total_cycles_percent(struct hist_entry *he);
 
tools/perf/util/hist.h +5 -2
index e8b3122a30a7..5bf122042c01 100644
@@ -478,7 +478,8 @@ int res_sample_browse(struct res_sample *res_samples, int num_res,
 void res_sample_init(void);
 
 int block_hists_tui_browse(struct block_hist *bh, struct evsel *evsel,
-			   float min_percent);
+			   float min_percent, struct perf_env *env,
+			   struct annotation_options *annotation_opts);
 #else
 static inline
 int perf_evlist__tui_browse_hists(struct evlist *evlist __maybe_unused,
@@ -525,7 +526,9 @@ static inline void res_sample_init(void) {}
 
 int block_hists_tui_browse(struct block_hist *bh __maybe_unused,
 			   struct evsel *evsel __maybe_unused,
-			   float min_percent __maybe_unused)
+			   float min_percent __maybe_unused,
+			   struct perf_env *env __maybe_unused,
+			   struct annotation_options *annotation_opts)
 {
 	return 0;
 }
Signature · 1 line
2.17.1
#2 lore raw

Re: [PATCH v1 2/2] perf report: Jump to symbol source view from total cycles view

Quoted 46 lines · Jin Yao

This patch supports jumping from tui total cycles view to symbol source view.

For example,

perf record -b ./div
perf report --total-cycles

In total cycles view, we can select one entry and press 'a' or press ENTER key to jump to symbol source view.

---
 tools/perf/builtin-report.c    |  9 ++++++---
 tools/perf/ui/browsers/hists.c | 25 +++++++++++++++++++++++--
 tools/perf/util/block-info.c   |  6 ++++--
 tools/perf/util/block-info.h   |  3 ++-
 tools/perf/util/hist.h         |  7 +++++--
 5 files changed, 40 insertions(+), 10 deletions(-)
tools/perf/builtin-report.c +5 -2
index 1e81985b7d56..ceebea4013ca 100644
@@ -493,7 +493,9 @@ static int perf_evlist__tui_block_hists_browse(struct evlist *evlist,
 
 	evlist__for_each_entry(evlist, pos) {
 		ret = report__browse_block_hists(&rep->block_reports[i++].hist,
-						 rep->min_percent, pos);
+						 rep->min_percent, pos,
+						 &rep->session->header.env,
+						 &rep->annotation_opts);
 		if (ret != 0)
 			return ret;
 	}
@@ -525,7 +527,8 @@ static int perf_evlist__tty_browse_hists(struct evlist *evlist,
 
 		if (rep->total_cycles_mode) {
 			report__browse_block_hists(&rep->block_reports[i++].hist,
-						   rep->min_percent, pos);
+						   rep->min_percent, pos,
+						   NULL, NULL);
 			continue;
 		}
 

tools/perf/builtin-report.c int cmd_report(int argc, const char **argv) · line 1424

Quoted 5 lines
tools/perf/builtin-report.c +1 -1
@@ -1418,7 +1421,7 @@ int cmd_report(int argc, const char **argv)
 		if (sort__mode != SORT_MODE__BRANCH)
 			report.total_cycles_mode = false;
 		else
-			sort_order = "sym";
+			sort_order = NULL;

hum, how is this related to this change?

jirka

author
#3 lore raw

Re: [PATCH v1 2/2] perf report: Jump to symbol source view from total cycles view

Quoted 55 lines · Jiri Olsa
Quoted 46 lines · Jin Yao

This patch supports jumping from tui total cycles view to symbol source view.

For example,

perf record -b ./div
perf report --total-cycles

In total cycles view, we can select one entry and press 'a' or press ENTER key to jump to symbol source view.

---
  tools/perf/builtin-report.c    |  9 ++++++---
  tools/perf/ui/browsers/hists.c | 25 +++++++++++++++++++++++--
  tools/perf/util/block-info.c   |  6 ++++--
  tools/perf/util/block-info.h   |  3 ++-
  tools/perf/util/hist.h         |  7 +++++--
  5 files changed, 40 insertions(+), 10 deletions(-)
tools/perf/builtin-report.c +5 -2
index 1e81985b7d56..ceebea4013ca 100644
@@ -493,7 +493,9 @@ static int perf_evlist__tui_block_hists_browse(struct evlist *evlist,
 
  	evlist__for_each_entry(evlist, pos) {
  		ret = report__browse_block_hists(&rep->block_reports[i++].hist,
-						 rep->min_percent, pos);
+						 rep->min_percent, pos,
+						 &rep->session->header.env,
+						 &rep->annotation_opts);
  		if (ret != 0)
  			return ret;
  	}
@@ -525,7 +527,8 @@ static int perf_evlist__tty_browse_hists(struct evlist *evlist,
 
  		if (rep->total_cycles_mode) {
  			report__browse_block_hists(&rep->block_reports[i++].hist,
-						   rep->min_percent, pos);
+						   rep->min_percent, pos,
+						   NULL, NULL);
  			continue;
  		}
 

tools/perf/builtin-report.c int cmd_report(int argc, const char **argv) · line 1424

Quoted 5 lines
tools/perf/builtin-report.c +1 -1
@@ -1418,7 +1421,7 @@ int cmd_report(int argc, const char **argv)
  		if (sort__mode != SORT_MODE__BRANCH)
  			report.total_cycles_mode = false;
  		else
-			sort_order = "sym";
+			sort_order = NULL;

hum, how is this related to this change?

Quoted 2 lines

jirka

Hi Jiri,

If we set the sort_order to NULL, it will use the default branch sort order. The percent value in new annotate view will be consistent with the percent in annotate view which is switched from perf report.

I observed the original percent gap with previous patches and then I decide to use the default sort order. Now the test result looks good.

Thanks
Jin Yao

#4 lore raw

Re: [PATCH v1 2/2] perf report: Jump to symbol source view from total cycles view

Quoted 58 lines · Yao
Quoted 52 lines · Jiri Olsa
Quoted 43 lines · Jin Yao

This patch supports jumping from tui total cycles view to symbol source view.

For example,

perf record -b ./div
perf report --total-cycles

In total cycles view, we can select one entry and press 'a' or press ENTER key to jump to symbol source view.

---
  tools/perf/builtin-report.c    |  9 ++++++---
  tools/perf/ui/browsers/hists.c | 25 +++++++++++++++++++++++--
  tools/perf/util/block-info.c   |  6 ++++--
  tools/perf/util/block-info.h   |  3 ++-
  tools/perf/util/hist.h         |  7 +++++--
  5 files changed, 40 insertions(+), 10 deletions(-)
tools/perf/builtin-report.c +5 -2
index 1e81985b7d56..ceebea4013ca 100644
@@ -493,7 +493,9 @@ static int perf_evlist__tui_block_hists_browse(struct evlist *evlist,
  	evlist__for_each_entry(evlist, pos) {
  		ret = report__browse_block_hists(&rep->block_reports[i++].hist,
-						 rep->min_percent, pos);
+						 rep->min_percent, pos,
+						 &rep->session->header.env,
+						 &rep->annotation_opts);
  		if (ret != 0)
  			return ret;
  	}
@@ -525,7 +527,8 @@ static int perf_evlist__tty_browse_hists(struct evlist *evlist,
  		if (rep->total_cycles_mode) {
  			report__browse_block_hists(&rep->block_reports[i++].hist,
-						   rep->min_percent, pos);
+						   rep->min_percent, pos,
+						   NULL, NULL);
  			continue;
  		}

tools/perf/builtin-report.c int cmd_report(int argc, const char **argv) · line 1424

Quoted 5 lines
tools/perf/builtin-report.c +1 -1
@@ -1418,7 +1421,7 @@ int cmd_report(int argc, const char **argv)
  		if (sort__mode != SORT_MODE__BRANCH)
  			report.total_cycles_mode = false;
  		else
-			sort_order = "sym";
+			sort_order = NULL;

hum, how is this related to this change?

Quoted 2 lines

jirka

Quoted 8 lines

Hi Jiri,

If we set the sort_order to NULL, it will use the default branch sort order. The percent value in new annotate view will be consistent with the percent in annotate view which is switched from perf report.

I observed the original percent gap with previous patches and then I decide to use the default sort order. Now the test result looks good.

ok, plz make note of it in changelog or comment

thanks,
jirka

author
#5 lore raw

Re: [PATCH v1 2/2] perf report: Jump to symbol source view from total cycles view

Quoted 65 lines · Jiri Olsa
Quoted 64 lines · Yao
Quoted 52 lines · Jiri Olsa
Quoted 43 lines · Jin Yao

This patch supports jumping from tui total cycles view to symbol source view.

For example,

perf record -b ./div
perf report --total-cycles

In total cycles view, we can select one entry and press 'a' or press ENTER key to jump to symbol source view.

---
   tools/perf/builtin-report.c    |  9 ++++++---
   tools/perf/ui/browsers/hists.c | 25 +++++++++++++++++++++++--
   tools/perf/util/block-info.c   |  6 ++++--
   tools/perf/util/block-info.h   |  3 ++-
   tools/perf/util/hist.h         |  7 +++++--
   5 files changed, 40 insertions(+), 10 deletions(-)
tools/perf/builtin-report.c +5 -2
index 1e81985b7d56..ceebea4013ca 100644
@@ -493,7 +493,9 @@ static int perf_evlist__tui_block_hists_browse(struct evlist *evlist,
   	evlist__for_each_entry(evlist, pos) {
   		ret = report__browse_block_hists(&rep->block_reports[i++].hist,
-						 rep->min_percent, pos);
+						 rep->min_percent, pos,
+						 &rep->session->header.env,
+						 &rep->annotation_opts);
   		if (ret != 0)
   			return ret;
   	}
@@ -525,7 +527,8 @@ static int perf_evlist__tty_browse_hists(struct evlist *evlist,
   		if (rep->total_cycles_mode) {
   			report__browse_block_hists(&rep->block_reports[i++].hist,
-						   rep->min_percent, pos);
+						   rep->min_percent, pos,
+						   NULL, NULL);
   			continue;
   		}

tools/perf/builtin-report.c int cmd_report(int argc, const char **argv) · line 1424

Quoted 5 lines
tools/perf/builtin-report.c +1 -1
@@ -1418,7 +1421,7 @@ int cmd_report(int argc, const char **argv)
   		if (sort__mode != SORT_MODE__BRANCH)
   			report.total_cycles_mode = false;
   		else
-			sort_order = "sym";
+			sort_order = NULL;

hum, how is this related to this change?

Quoted 2 lines

jirka

Hi Jiri,

If we set the sort_order to NULL, it will use the default branch sort order. The percent value in new annotate view will be consistent with the percent in annotate view which is switched from perf report.

Quoted 8 lines
Quoted 2 lines

I observed the original percent gap with previous patches and then I decide to use the default sort order. Now the test result looks good.

ok, plz make note of it in changelog or comment

thanks,
jirka

OK, I see, thanks Jiri! I will post v2.

Thanks
Jin Yao

#6 lore raw

Re: [PATCH v1 2/2] perf report: Jump to symbol source view from total cycles view

In reply to Jin Yao

On Wed, Nov 13, 2019 at 08:48:52AM +0800, Jin Yao wrote:

SNIP

Quoted 15 lines
tools/perf/util/hist.h +2 -1
index e8b3122a30a7..5bf122042c01 100644
@@ -478,7 +478,8 @@ int res_sample_browse(struct res_sample *res_samples, int num_res,
 void res_sample_init(void);
 
 int block_hists_tui_browse(struct block_hist *bh, struct evsel *evsel,
-			   float min_percent);
+			   float min_percent, struct perf_env *env,
+			   struct annotation_options *annotation_opts);
 #else
 static inline
 int perf_evlist__tui_browse_hists(struct evlist *evlist __maybe_unused,

tools/perf/util/hist.h static inline void res_sample_init(void) {} · line 531

Quoted 7 lines
tools/perf/util/hist.h +3 -1
@@ -525,7 +526,9 @@ static inline void res_sample_init(void) {}
 
 int block_hists_tui_browse(struct block_hist *bh __maybe_unused,
 			   struct evsel *evsel __maybe_unused,
-			   float min_percent __maybe_unused)
+			   float min_percent __maybe_unused,
+			   struct perf_env *env __maybe_unused,
+			   struct annotation_options *annotation_opts)

missing __maybe_unused, this breaks no-tui build 'make NO_SLANG=1'

jirka

author
#7 lore raw

Re: [PATCH v1 2/2] perf report: Jump to symbol source view from total cycles view

Quoted 29 lines · Jiri Olsa

On Wed, Nov 13, 2019 at 08:48:52AM +0800, Jin Yao wrote:

SNIP

Quoted 15 lines
tools/perf/util/hist.h +2 -1
index e8b3122a30a7..5bf122042c01 100644
@@ -478,7 +478,8 @@ int res_sample_browse(struct res_sample *res_samples, int num_res,
  void res_sample_init(void);
 
  int block_hists_tui_browse(struct block_hist *bh, struct evsel *evsel,
-			   float min_percent);
+			   float min_percent, struct perf_env *env,
+			   struct annotation_options *annotation_opts);
  #else
  static inline
  int perf_evlist__tui_browse_hists(struct evlist *evlist __maybe_unused,

tools/perf/util/hist.h static inline void res_sample_init(void) {} · line 531

Quoted 7 lines
tools/perf/util/hist.h +3 -1
@@ -525,7 +526,9 @@ static inline void res_sample_init(void) {}
 
  int block_hists_tui_browse(struct block_hist *bh __maybe_unused,
  			   struct evsel *evsel __maybe_unused,
-			   float min_percent __maybe_unused)
+			   float min_percent __maybe_unused,
+			   struct perf_env *env __maybe_unused,
+			   struct annotation_options *annotation_opts)

missing __maybe_unused, this breaks no-tui build 'make NO_SLANG=1'

Quoted 2 lines

jirka

Oh, yes, I should add __maybe_unused.

Thanks
Jin Yao