mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Arnaldo Carvalho de Melo <acme@infradead.org>
To: Ingo Molnar <mingo@kernel.org>
Cc: linux-kernel@vger.kernel.org, Namhyung Kim <namhyung@kernel.org>,
	Andi Kleen <andi@firstfloor.org>, Jiri Olsa <jolsa@redhat.com>,
	Namhyung Kim <namhyung.kim@lge.com>,
	Paul Mackerras <paulus@samba.org>,
	Pekka Enberg <penberg@kernel.org>,
	Peter Zijlstra <a.p.zijlstra@chello.nl>,
	Arnaldo Carvalho de Melo <acme@redhat.com>
Subject: [PATCH 32/54] perf annotate browser: Support event group view on TUI
Date: Mon, 18 Mar 2013 13:25:17 -0300	[thread overview]
Message-ID: <1363623939-10748-33-git-send-email-acme@infradead.org> (raw)
In-Reply-To: <1363623939-10748-1-git-send-email-acme@infradead.org>

From: Namhyung Kim <namhyung@kernel.org>

Dynamically allocate browser_disasm_line according to a number of group
members.  This way we can handle multiple events in a general manner.

Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Cc: Andi Kleen <andi@firstfloor.org>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung.kim@lge.com>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Pekka Enberg <penberg@kernel.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Link: http://lkml.kernel.org/r/878v5tl2vc.fsf@sejong.aot.lge.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/ui/browsers/annotate.c |   93 +++++++++++++++++++++++++++++-------
 1 files changed, 75 insertions(+), 18 deletions(-)

diff --git a/tools/perf/ui/browsers/annotate.c b/tools/perf/ui/browsers/annotate.c
index 8b16926..f56247a 100644
--- a/tools/perf/ui/browsers/annotate.c
+++ b/tools/perf/ui/browsers/annotate.c
@@ -17,6 +17,10 @@ struct browser_disasm_line {
 	u32		idx;
 	int		idx_asm;
 	int		jump_sources;
+	/*
+	 * actual length of this array is saved on the nr_events field
+	 * of the struct annotate_browser
+	 */
 	double		percent[1];
 };
 
@@ -34,8 +38,9 @@ struct annotate_browser {
 	struct ui_browser b;
 	struct rb_root	  entries;
 	struct rb_node	  *curr_hot;
-	struct disasm_line	  *selection;
+	struct disasm_line  *selection;
 	struct disasm_line  **offsets;
+	int		    nr_events;
 	u64		    start;
 	int		    nr_asm_entries;
 	int		    nr_entries;
@@ -95,14 +100,24 @@ static void annotate_browser__write(struct ui_browser *browser, void *entry, int
 			     (!current_entry || (browser->use_navkeypressed &&
 					         !browser->navkeypressed)));
 	int width = browser->width, printed;
+	int i, pcnt_width = 7 * ab->nr_events;
+	double percent_max = 0.0;
 	char bf[256];
 
-	if (dl->offset != -1 && bdl->percent[0] != 0.0) {
-		ui_browser__set_percent_color(browser, bdl->percent[0], current_entry);
-		slsmg_printf("%6.2f ", bdl->percent[0]);
+	for (i = 0; i < ab->nr_events; i++) {
+		if (bdl->percent[i] > percent_max)
+			percent_max = bdl->percent[i];
+	}
+
+	if (dl->offset != -1 && percent_max != 0.0) {
+		for (i = 0; i < ab->nr_events; i++) {
+			ui_browser__set_percent_color(browser, bdl->percent[i],
+						      current_entry);
+			slsmg_printf("%6.2f ", bdl->percent[i]);
+		}
 	} else {
 		ui_browser__set_percent_color(browser, 0, current_entry);
-		slsmg_write_nstring(" ", 7);
+		slsmg_write_nstring(" ", pcnt_width);
 	}
 
 	SLsmg_write_char(' ');
@@ -112,12 +127,12 @@ static void annotate_browser__write(struct ui_browser *browser, void *entry, int
 		width += 1;
 
 	if (!*dl->line)
-		slsmg_write_nstring(" ", width - 7);
+		slsmg_write_nstring(" ", width - pcnt_width);
 	else if (dl->offset == -1) {
 		printed = scnprintf(bf, sizeof(bf), "%*s  ",
 				    ab->addr_width, " ");
 		slsmg_write_nstring(bf, printed);
-		slsmg_write_nstring(dl->line, width - printed - 6);
+		slsmg_write_nstring(dl->line, width - printed - pcnt_width + 1);
 	} else {
 		u64 addr = dl->offset;
 		int color = -1;
@@ -176,7 +191,7 @@ static void annotate_browser__write(struct ui_browser *browser, void *entry, int
 		}
 
 		disasm_line__scnprintf(dl, bf, sizeof(bf), !annotate_browser__opts.use_offset);
-		slsmg_write_nstring(bf, width - 10 - printed);
+		slsmg_write_nstring(bf, width - pcnt_width - 3 - printed);
 	}
 
 	if (current_entry)
@@ -201,6 +216,7 @@ static void annotate_browser__draw_current_jump(struct ui_browser *browser)
 	unsigned int from, to;
 	struct map_symbol *ms = ab->b.priv;
 	struct symbol *sym = ms->sym;
+	u8 pcnt_width = 7;
 
 	/* PLT symbols contain external offsets */
 	if (strstr(sym->name, "@plt"))
@@ -224,23 +240,44 @@ static void annotate_browser__draw_current_jump(struct ui_browser *browser)
 		to = (u64)btarget->idx;
 	}
 
+	pcnt_width *= ab->nr_events;
+
 	ui_browser__set_color(browser, HE_COLORSET_CODE);
-	__ui_browser__line_arrow(browser, 9 + ab->addr_width, from, to);
+	__ui_browser__line_arrow(browser, pcnt_width + 2 + ab->addr_width,
+				 from, to);
 }
 
 static unsigned int annotate_browser__refresh(struct ui_browser *browser)
 {
+	struct annotate_browser *ab = container_of(browser, struct annotate_browser, b);
 	int ret = ui_browser__list_head_refresh(browser);
+	int pcnt_width;
+
+	pcnt_width = 7 * ab->nr_events;
 
 	if (annotate_browser__opts.jump_arrows)
 		annotate_browser__draw_current_jump(browser);
 
 	ui_browser__set_color(browser, HE_COLORSET_NORMAL);
-	__ui_browser__vline(browser, 7, 0, browser->height - 1);
+	__ui_browser__vline(browser, pcnt_width, 0, browser->height - 1);
 	return ret;
 }
 
-static void disasm_rb_tree__insert(struct rb_root *root, struct browser_disasm_line *bdl)
+static int disasm__cmp(struct browser_disasm_line *a,
+		       struct browser_disasm_line *b, int nr_pcnt)
+{
+	int i;
+
+	for (i = 0; i < nr_pcnt; i++) {
+		if (a->percent[i] == b->percent[i])
+			continue;
+		return a->percent[i] < b->percent[i];
+	}
+	return 0;
+}
+
+static void disasm_rb_tree__insert(struct rb_root *root, struct browser_disasm_line *bdl,
+				   int nr_events)
 {
 	struct rb_node **p = &root->rb_node;
 	struct rb_node *parent = NULL;
@@ -249,7 +286,8 @@ static void disasm_rb_tree__insert(struct rb_root *root, struct browser_disasm_l
 	while (*p != NULL) {
 		parent = *p;
 		l = rb_entry(parent, struct browser_disasm_line, rb_node);
-		if (bdl->percent[0] < l->percent[0])
+
+		if (disasm__cmp(bdl, l, nr_events))
 			p = &(*p)->rb_left;
 		else
 			p = &(*p)->rb_right;
@@ -313,6 +351,8 @@ static void annotate_browser__calc_percent(struct annotate_browser *browser,
 	list_for_each_entry(pos, &notes->src->source, node) {
 		struct browser_disasm_line *bpos = disasm_line__browser(pos);
 		const char *path = NULL;
+		double max_percent = 0.0;
+		int i;
 
 		if (pos->offset == -1) {
 			RB_CLEAR_NODE(&bpos->rb_node);
@@ -320,15 +360,24 @@ static void annotate_browser__calc_percent(struct annotate_browser *browser,
 		}
 
 		next = disasm__get_next_ip_line(&notes->src->source, pos);
-		bpos->percent[0] = disasm__calc_percent(notes, evsel->idx,
-					pos->offset, next ? next->offset : len,
-				        &path);
 
-		if (bpos->percent[0] < 0.01) {
+		for (i = 0; i < browser->nr_events; i++) {
+			bpos->percent[i] = disasm__calc_percent(notes,
+						evsel->idx + i,
+						pos->offset,
+						next ? next->offset : len,
+					        &path);
+
+			if (max_percent < bpos->percent[i])
+				max_percent = bpos->percent[i];
+		}
+
+		if (max_percent < 0.01) {
 			RB_CLEAR_NODE(&bpos->rb_node);
 			continue;
 		}
-		disasm_rb_tree__insert(&browser->entries, bpos);
+		disasm_rb_tree__insert(&browser->entries, bpos,
+				       browser->nr_events);
 	}
 	pthread_mutex_unlock(&notes->lock);
 
@@ -829,6 +878,8 @@ int symbol__tui_annotate(struct symbol *sym, struct map *map,
 		},
 	};
 	int ret = -1;
+	int nr_pcnt = 1;
+	size_t sizeof_bdl = sizeof(struct browser_disasm_line);
 
 	if (sym == NULL)
 		return -1;
@@ -844,7 +895,12 @@ int symbol__tui_annotate(struct symbol *sym, struct map *map,
 		return -1;
 	}
 
-	if (symbol__annotate(sym, map, sizeof(struct browser_disasm_line)) < 0) {
+	if (perf_evsel__is_group_event(evsel)) {
+		nr_pcnt = evsel->nr_members;
+		sizeof_bdl += sizeof(double) * (nr_pcnt - 1);
+	}
+
+	if (symbol__annotate(sym, map, sizeof_bdl) < 0) {
 		ui__error("%s", ui_helpline__last_msg);
 		goto out_free_offsets;
 	}
@@ -882,6 +938,7 @@ int symbol__tui_annotate(struct symbol *sym, struct map *map,
 	browser.addr_width = browser.target_width = browser.min_addr_width = hex_width(size);
 	browser.max_addr_width = hex_width(sym->end);
 	browser.jumps_width = width_jumps(browser.max_jump_sources);
+	browser.nr_events = nr_pcnt;
 	browser.b.nr_entries = browser.nr_entries;
 	browser.b.entries = &notes->src->source,
 	browser.b.width += 18; /* Percentage */
-- 
1.7.1


  parent reply	other threads:[~2013-03-18 16:37 UTC|newest]

Thread overview: 56+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-03-18 16:24 [GIT PULL 00/54] perf/core improvements and fixes Arnaldo Carvalho de Melo
2013-03-18 16:24 ` [PATCH 01/54] perf tools: Fix build on non-glibc systems due to libio.h absence Arnaldo Carvalho de Melo
2013-03-18 16:24 ` [PATCH 02/54] perf tools: Remove a write-only variable in the debugfs code Arnaldo Carvalho de Melo
2013-03-18 16:24 ` [PATCH 03/54] perf tools: Honor parallel jobs Arnaldo Carvalho de Melo
2013-03-18 16:24 ` [PATCH 04/54] perf tools: Correct Makefile.include Arnaldo Carvalho de Melo
2013-03-18 16:24 ` [PATCH 05/54] perf tools: Sort command-list.txt alphabetically Arnaldo Carvalho de Melo
2013-03-18 16:24 ` [PATCH 06/54] perf tests: Make attr script verbose friendly Arnaldo Carvalho de Melo
2013-03-18 16:24 ` [PATCH 07/54] perf tests: Make attr script test event cpu Arnaldo Carvalho de Melo
2013-03-18 16:24 ` [PATCH 08/54] perf tests: Add attr record -C cpu test Arnaldo Carvalho de Melo
2013-03-18 16:24 ` [PATCH 09/54] perf tests: Add attr stat " Arnaldo Carvalho de Melo
2013-03-18 16:24 ` [PATCH 10/54] perf tools: Introduce tools/lib/lk library Arnaldo Carvalho de Melo
2013-03-18 16:24 ` [PATCH 11/54] perf tools: Extract perf-specific stuff from debugfs.c Arnaldo Carvalho de Melo
2013-03-18 16:24 ` [PATCH 12/54] tools/vm: Switch to liblk library Arnaldo Carvalho de Melo
2013-03-18 16:24 ` [PATCH 13/54] tools lib lk: Fix _FORTIFY_SOURCE builds Arnaldo Carvalho de Melo
2013-03-18 16:24 ` [PATCH 14/54] perf evlist: Remove cpus and threads arguments from perf_evlist__new() Arnaldo Carvalho de Melo
2013-03-18 16:25 ` [PATCH 15/54] perf evlist: Use cpu_map__nr() helper Arnaldo Carvalho de Melo
2013-03-18 16:25 ` [PATCH 16/54] perf evlist: Add thread_map__nr() helper Arnaldo Carvalho de Melo
2013-03-18 16:25 ` [PATCH 17/54] perf evlist: Pass struct perf_target to perf_evlist__prepare_workload() Arnaldo Carvalho de Melo
2013-03-18 16:25 ` [PATCH 18/54] perf evlist: Do not pass struct record_opts " Arnaldo Carvalho de Melo
2013-03-18 16:25 ` [PATCH 19/54] perf evlist: Add want_signal parameter " Arnaldo Carvalho de Melo
2013-03-18 16:25 ` [PATCH 20/54] perf stat: Use perf_evlist__prepare/start_workload() Arnaldo Carvalho de Melo
2013-03-18 16:25 ` [PATCH 21/54] perf annotate: Pass evsel instead of evidx on annotation functions Arnaldo Carvalho de Melo
2013-03-18 16:25 ` [PATCH 22/54] perf annotate: Add a comment on the symbol__parse_objdump_line() Arnaldo Carvalho de Melo
2013-03-18 16:25 ` [PATCH 23/54] perf annotate: Factor out disasm__calc_percent() Arnaldo Carvalho de Melo
2013-03-18 16:25 ` [PATCH 24/54] perf annotate: Cleanup disasm__calc_percent() Arnaldo Carvalho de Melo
2013-03-18 16:25 ` [PATCH 25/54] perf annotate: Add basic support to event group view Arnaldo Carvalho de Melo
2013-03-18 16:25 ` [PATCH 26/54] perf evsel: Introduce perf_evsel__is_group_event() helper Arnaldo Carvalho de Melo
2013-03-18 16:25 ` [PATCH 27/54] perf annotate: Factor out struct source_line_percent Arnaldo Carvalho de Melo
2013-03-18 16:25 ` [PATCH 28/54] perf annotate: Support event group view for --print-line Arnaldo Carvalho de Melo
2013-03-18 16:25 ` [PATCH 29/54] perf annotate browser: Make browser_disasm_line->percent an array Arnaldo Carvalho de Melo
2013-03-18 16:25 ` [PATCH 30/54] perf annotate browser: Use disasm__calc_percent() Arnaldo Carvalho de Melo
2013-03-18 16:25 ` [PATCH 31/54] perf annotate/gtk: Support event group view on GTK Arnaldo Carvalho de Melo
2013-03-18 16:25 ` Arnaldo Carvalho de Melo [this message]
2013-03-18 16:25 ` [PATCH 33/54] perf trace: Get rid of a duplicate code Arnaldo Carvalho de Melo
2013-03-18 16:25 ` [PATCH 34/54] perf tools: Remove unused tracing functions Arnaldo Carvalho de Melo
2013-03-18 16:25 ` [PATCH 35/54] perf session: Remove unused perf_session__remove_thread method Arnaldo Carvalho de Melo
2013-03-18 16:25 ` [PATCH 36/54] perf machine: Move machine__remove_thread and make static Arnaldo Carvalho de Melo
2013-03-18 16:25 ` [PATCH 37/54] perf report: Remove duplicated include Arnaldo Carvalho de Melo
2013-03-18 16:25 ` [PATCH 38/54] perf tools: Remove unused trace_read_data function Arnaldo Carvalho de Melo
2013-03-18 16:25 ` [PATCH 39/54] perf tools: Remove unused struct definitions Arnaldo Carvalho de Melo
2013-03-18 16:25 ` [PATCH 40/54] perf tools: Remove unnecessary calc_data_size variable Arnaldo Carvalho de Melo
2013-03-18 16:25 ` [PATCH 41/54] perf tools: Remove unused macro definitions Arnaldo Carvalho de Melo
2013-03-18 16:25 ` [PATCH 42/54] perf tools: Remove duplicated page_size definition Arnaldo Carvalho de Melo
2013-03-18 16:25 ` [PATCH 43/54] perf tests: Test breakpoint overflow signal handler Arnaldo Carvalho de Melo
2013-03-18 16:25 ` [PATCH 44/54] perf tests: Test breakpoint overflow signal handler counts Arnaldo Carvalho de Melo
2013-03-18 16:25 ` [PATCH 45/54] perf evsel: Cleanup perf_evsel__exit() Arnaldo Carvalho de Melo
2013-03-18 16:25 ` [PATCH 46/54] perf evlist: Introduce perf_evlist__close() Arnaldo Carvalho de Melo
2013-03-18 16:25 ` [PATCH 47/54] perf trace: Free evlist resources properly on return path Arnaldo Carvalho de Melo
2013-03-18 16:25 ` [PATCH 48/54] perf record: Fixup return path of cmd_record() Arnaldo Carvalho de Melo
2013-03-18 16:25 ` [PATCH 49/54] perf tests: Fixup return path of open-syscall-tp-fields test case Arnaldo Carvalho de Melo
2013-03-18 16:25 ` [PATCH 50/54] perf tests: Fixup return path of perf record " Arnaldo Carvalho de Melo
2013-03-18 16:25 ` [PATCH 51/54] perf test: Add test case for checking number of EXIT events Arnaldo Carvalho de Melo
2013-03-18 16:25 ` [PATCH 52/54] perf stat: Introduce --repeat forever Arnaldo Carvalho de Melo
2013-03-18 16:25 ` [PATCH 53/54] perf stat: Introduce evlist methods to allocate/free the stats Arnaldo Carvalho de Melo
2013-03-18 16:25 ` [PATCH 54/54] perf tests: Add a test case for checking sw clock event frequency Arnaldo Carvalho de Melo
2013-03-21 10:08 ` [GIT PULL 00/54] perf/core improvements and fixes Ingo Molnar

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=1363623939-10748-33-git-send-email-acme@infradead.org \
    --to=acme@infradead.org \
    --cc=a.p.zijlstra@chello.nl \
    --cc=acme@redhat.com \
    --cc=andi@firstfloor.org \
    --cc=jolsa@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=namhyung.kim@lge.com \
    --cc=namhyung@kernel.org \
    --cc=paulus@samba.org \
    --cc=penberg@kernel.org \
    /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

all inboxes | Powered by JetHome®