Skip to contentSkip to conversation

perf annotate browser: Initial loop detection

tip:perf/core tip-bot for Arnaldo Carvalho de Melo 1 participant 1 message Apr 27, 2012 perf events

lore
Share & tools
lore
#0 lore raw
Commit-ID:  a3f895be1f1ed17f66e6e71adeef0cc7f937512c
Gitweb:     http://git.kernel.org/tip/a3f895be1f1ed17f66e6e71adeef0cc7f937512c
Author:     Arnaldo Carvalho de Melo <[email protected]>
AuthorDate: Tue, 24 Apr 2012 14:24:28 -0300
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Tue, 24 Apr 2012 14:24:28 -0300

perf annotate browser: Initial loop detection

Simple algorithm, just look for the next backward jump that points to before the cursor.

Then draw an arrow connecting the jump to its target.

Do this as you move the cursor, entering/exiting possible loops.

Ex (graph chars replaced to avoid mail encoding woes):

avc_has_perm_flags

    0.00 |         nopl   0x0(%rax)
    5.36 |+-> 68:  mov    (%rax),%rax
    5.15 ||        test   %rax,%rax
    0.00 ||      v je     130
    2.96 ||   74:  cmp    -0x20(%rax),%ebx
   47.38 ||        lea    -0x20(%rax),%rcx
    0.28 ||      ^ jne    68
    3.16 ||        cmp    -0x18(%rax),%dx
    0.00 |+------^ jne    68
    4.92 |         cmp    0x4(%rcx),%r13d
    0.00 |       v jne    68
    1.15 |         test   %rcx,%rcx
    0.00 |       v je     130
Cc David Ahern <[email protected]>
Cc Frederic Weisbecker <[email protected]>
Cc Linus Torvalds <[email protected]>
Cc Mike Galbraith <[email protected]>
Cc Namhyung Kim <[email protected]>
Cc Paul Mackerras <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Stephane Eranian <[email protected]>
---
 tools/perf/ui/browser.c           |   39 +++++++++++++++++++++++
 tools/perf/ui/browser.h           |    2 +
 tools/perf/ui/browsers/annotate.c |   61 ++++++++++++++++++++++++++++++++++--
 3 files changed, 98 insertions(+), 4 deletions(-)
tools/perf/ui/browser.c +39 -0
index 973ff74..32ac116 100644
@@ -600,6 +600,45 @@ void ui_browser__write_graph(struct ui_browser *browser __used, int graph)
 	SLsmg_set_char_set(0);
 }
 
+void __ui_browser__line_arrow_up(struct ui_browser *browser, unsigned int column,
+				 u64 start, u64 end, int start_width)
+{
+	unsigned int row, end_row;
+
+	SLsmg_set_char_set(1);
+
+	if (start < browser->top_idx + browser->height) {
+		row = start - browser->top_idx;
+		ui_browser__gotorc(browser, row, column);
+		SLsmg_write_char(SLSMG_LLCORN_CHAR);
+		ui_browser__gotorc(browser, row, column + 1);
+		SLsmg_draw_hline(start_width);
+
+		if (row-- == 0)
+			goto out;
+	} else
+		row = browser->height - 1;
+
+	if (end > browser->top_idx)
+		end_row = end - browser->top_idx;
+	else
+		end_row = 0;
+
+	ui_browser__gotorc(browser, end_row, column);
+	SLsmg_draw_vline(row - end_row + 1);
+
+	ui_browser__gotorc(browser, end_row, column);
+	if (end >= browser->top_idx) {
+		SLsmg_write_char(SLSMG_ULCORN_CHAR);
+		ui_browser__gotorc(browser, end_row, column + 1);
+		SLsmg_write_char(SLSMG_HLINE_CHAR);
+		ui_browser__gotorc(browser, end_row, column + 2);
+		SLsmg_write_char(SLSMG_RARROW_CHAR);
+	}
+out:
+	SLsmg_set_char_set(0);
+}
+
 void ui_browser__init(void)
 {
 	int i = 0;
tools/perf/ui/browser.h +2 -0
index ce20975..2f226cb 100644
@@ -38,6 +38,8 @@ void ui_browser__reset_index(struct ui_browser *self);
 
 void ui_browser__gotorc(struct ui_browser *self, int y, int x);
 void ui_browser__write_graph(struct ui_browser *browser, int graph);
+void __ui_browser__line_arrow_up(struct ui_browser *browser, unsigned int column,
+				 u64 start, u64 end, int start_width);
 void __ui_browser__show_title(struct ui_browser *browser, const char *title);
 void ui_browser__show_title(struct ui_browser *browser, const char *title);
 int ui_browser__show(struct ui_browser *self, const char *title,
tools/perf/ui/browsers/annotate.c +57 -4

83 lines not on this page · raw message