Skip to contentSkip to conversation

perf annotate: Add support for GTK+ annotation browser (v1)

PATCH In review Namhyung Kim 3 participants 16 messages Dec 21, 2012 – Jan 25, 2013 perf events

lore
Share & tools
lore

Namhyung Kim

author maintainer
#0 lore raw

cover perf annotate: Add support for GTK+ annotation browser (v1)

Hi,

This patchset adds support to GTK+ annotation browser. For now only the first symbol gets sampled mostly per evsel will be shown. IOW it shows the hottest symbol per evsel by default and you can change it by giving the --symbol option or an argument.

Thanks,
Namhyung

Namhyung Kim (6):
perf ui/gtk: Factor out common browser routines perf ui/gtk: Setup browser window early
perf ui/gtk: Implement basic GTK2 annotation browser perf gtk/annotate: Support multiple annotation result perf gtk/annotate: Show source lines with gray color perf annotate: Add --gtk option

 tools/perf/Documentation/perf-annotate.txt |   4 +
 tools/perf/Makefile                        |   2 +
 tools/perf/builtin-annotate.c              |  14 +-
 tools/perf/ui/gtk/annotate.c               | 227 +++++++++++++++++++++++++++++
 tools/perf/ui/gtk/browser.c                | 227 +----------------------------
 tools/perf/ui/gtk/gtk.h                    |  10 +-
 tools/perf/ui/gtk/hists.c                  | 226 ++++++++++++++++++++++++++++
 tools/perf/util/annotate.h                 |  24 +++
 8 files changed, 509 insertions(+), 225 deletions(-)
 create mode 100644 tools/perf/ui/gtk/annotate.c
 create mode 100644 tools/perf/ui/gtk/hists.c
Signature · 1 line
1.7.11.7
author maintainer
#1 lore raw

PATCH 1/6 perf ui/gtk: Factor out common browser routines

Separate out common codes for setting up a browser, and move report/hist browser codes into hists.c. The common codes can be used for annotation browser.

---
 tools/perf/Makefile         |   1 +
 tools/perf/ui/gtk/browser.c | 227 +-------------------------------------------
 tools/perf/ui/gtk/gtk.h     |   9 +-
 tools/perf/ui/gtk/hists.c   | 226 +++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 240 insertions(+), 223 deletions(-)
 create mode 100644 tools/perf/ui/gtk/hists.c
tools/perf/Makefile +1 -0
index dbf1c35d3f16..103ed956ca80 100644
@@ -688,6 +688,7 @@ ifndef NO_GTK2
 		BASIC_CFLAGS += $(shell pkg-config --cflags gtk+-2.0 2>/dev/null)
 		EXTLIBS += $(shell pkg-config --libs gtk+-2.0 2>/dev/null)
 		LIB_OBJS += $(OUTPUT)ui/gtk/browser.o
+		LIB_OBJS += $(OUTPUT)ui/gtk/hists.o
 		LIB_OBJS += $(OUTPUT)ui/gtk/setup.o
 		LIB_OBJS += $(OUTPUT)ui/gtk/util.o
 		LIB_OBJS += $(OUTPUT)ui/gtk/helpline.o
tools/perf/ui/gtk/browser.c +5 -222

260 lines not on this page · raw message

tools/perf/ui/gtk/gtk.h +8 -1
index 856320e2cc05..5d3693754828 100644
@@ -33,7 +33,14 @@ void perf_gtk__init_helpline(void);
 void perf_gtk__init_progress(void);
 void perf_gtk__init_hpp(void);
 
-#ifndef HAVE_GTK_INFO_BAR
+void perf_gtk__signal(int sig);
+void perf_gtk__resize_window(GtkWidget *window);
+const char *perf_gtk__get_percent_color(double percent);
+GtkWidget *perf_gtk__setup_statusbar(void);
+
+#ifdef HAVE_GTK_INFO_BAR
+GtkWidget *perf_gtk__setup_info_bar(void);
+#else
 static inline GtkWidget *perf_gtk__setup_info_bar(void)
 {
 	return NULL;
tools/perf/ui/gtk/hists.c new file +226 -0

226 lines not on this page · raw message

Signature · 1 line
1.7.11.7
author maintainer
#2 lore raw

[tip:perf/core] perf ui/gtk: Factor out common browser routines

Commit-ID:  0da41ce954840a74e7a0de9c8268bf855147e902
Gitweb:     http://git.kernel.org/tip/0da41ce954840a74e7a0de9c8268bf855147e902
Author:     Namhyung Kim <[email protected]>
AuthorDate: Fri, 21 Dec 2012 17:20:13 +0900
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Thu, 24 Jan 2013 16:40:16 -0300

perf ui/gtk: Factor out common browser routines

Separate out common codes for setting up a browser, and move report/hist browser codes into hists.c. The common codes can be used for annotation browser.

---
 tools/perf/Makefile                      |   1 +
 tools/perf/ui/gtk/browser.c              | 227 +------------------------------
 tools/perf/ui/gtk/gtk.h                  |   9 +-
 tools/perf/ui/gtk/{browser.c => hists.c} |  82 +----------
 4 files changed, 16 insertions(+), 303 deletions(-)
tools/perf/Makefile +1 -0
index 1539eb4..e18163b 100644
@@ -688,6 +688,7 @@ ifndef NO_GTK2
 		BASIC_CFLAGS += $(shell pkg-config --cflags gtk+-2.0 2>/dev/null)
 		EXTLIBS += $(shell pkg-config --libs gtk+-2.0 2>/dev/null)
 		LIB_OBJS += $(OUTPUT)ui/gtk/browser.o
+		LIB_OBJS += $(OUTPUT)ui/gtk/hists.o
 		LIB_OBJS += $(OUTPUT)ui/gtk/setup.o
 		LIB_OBJS += $(OUTPUT)ui/gtk/util.o
 		LIB_OBJS += $(OUTPUT)ui/gtk/helpline.o
tools/perf/ui/gtk/browser.c +5 -222

260 lines not on this page · raw message

tools/perf/ui/gtk/gtk.h +8 -1
index 856320e..5d36937 100644
@@ -33,7 +33,14 @@ void perf_gtk__init_helpline(void);
 void perf_gtk__init_progress(void);
 void perf_gtk__init_hpp(void);
 
-#ifndef HAVE_GTK_INFO_BAR
+void perf_gtk__signal(int sig);
+void perf_gtk__resize_window(GtkWidget *window);
+const char *perf_gtk__get_percent_color(double percent);
+GtkWidget *perf_gtk__setup_statusbar(void);
+
+#ifdef HAVE_GTK_INFO_BAR
+GtkWidget *perf_gtk__setup_info_bar(void);
+#else
 static inline GtkWidget *perf_gtk__setup_info_bar(void)
 {
 	return NULL;
tools/perf/ui/gtk/hists.c renamed from tools/perf/ui/gtk/browser.c +2 -80

108 lines not on this page · raw message

author maintainer
#3 lore raw

PATCH 2/6 perf ui/gtk: Setup browser window early

In reply to Namhyung Kim

The ui__error/warning functions use gtk infobar or statusbar and pr_* functions use statusbar too. But after perf gtk context created but those infobar and/or statusbar not yet set up, calling one of those functions will get a segment fault.

Although current code has no problem, move these setting as early as possible so that it can prevent the segfault from future change.

---
 tools/perf/ui/gtk/hists.c | 22 +++++++++++-----------
 1 file changed, 11 insertions(+), 11 deletions(-)
tools/perf/ui/gtk/hists.c +11 -11
index 26912f86e032..c03da79d524f 100644
@@ -180,6 +180,17 @@ int perf_evlist__gtk_browse_hists(struct perf_evlist *evlist,
 
 	notebook = gtk_notebook_new();
 
+	gtk_box_pack_start(GTK_BOX(vbox), notebook, TRUE, TRUE, 0);
+
+	info_bar = perf_gtk__setup_info_bar();
+	if (info_bar)
+		gtk_box_pack_start(GTK_BOX(vbox), info_bar, FALSE, FALSE, 0);
+
+	statbar = perf_gtk__setup_statusbar();
+	gtk_box_pack_start(GTK_BOX(vbox), statbar, FALSE, FALSE, 0);
+
+	gtk_container_add(GTK_CONTAINER(window), vbox);
+
 	list_for_each_entry(pos, &evlist->entries, node) {
 		struct hists *hists = &pos->hists;
 		const char *evname = perf_evsel__name(pos);
@@ -199,17 +210,6 @@ int perf_evlist__gtk_browse_hists(struct perf_evlist *evlist,
 		gtk_notebook_append_page(GTK_NOTEBOOK(notebook), scrolled_window, tab_label);
 	}
 
-	gtk_box_pack_start(GTK_BOX(vbox), notebook, TRUE, TRUE, 0);
-
-	info_bar = perf_gtk__setup_info_bar();
-	if (info_bar)
-		gtk_box_pack_start(GTK_BOX(vbox), info_bar, FALSE, FALSE, 0);
-
-	statbar = perf_gtk__setup_statusbar();
-	gtk_box_pack_start(GTK_BOX(vbox), statbar, FALSE, FALSE, 0);
-
-	gtk_container_add(GTK_CONTAINER(window), vbox);
-
 	gtk_widget_show_all(window);
 
 	perf_gtk__resize_window(window);
Signature · 1 line
1.7.11.7
author maintainer
#4 lore raw

[tip:perf/core] perf ui/gtk: Setup browser window early

Commit-ID:  6bf1a295a896c8dbe8cad663c6344e8c877a0570
Gitweb:     http://git.kernel.org/tip/6bf1a295a896c8dbe8cad663c6344e8c877a0570
Author:     Namhyung Kim <[email protected]>
AuthorDate: Fri, 21 Dec 2012 17:20:14 +0900
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Thu, 24 Jan 2013 16:40:16 -0300

perf ui/gtk: Setup browser window early

The ui__error/warning functions use gtk infobar or statusbar and pr_* functions use statusbar too. But after perf gtk context created but those infobar and/or statusbar not yet set up, calling one of those functions will get a segment fault.

Although current code has no problem, move these setting as early as possible so that it can prevent the segfault from future change.

---
 tools/perf/ui/gtk/hists.c | 22 +++++++++++-----------
 1 file changed, 11 insertions(+), 11 deletions(-)
tools/perf/ui/gtk/hists.c +11 -11
index 26912f8..c03da79 100644
@@ -180,6 +180,17 @@ int perf_evlist__gtk_browse_hists(struct perf_evlist *evlist,
 
 	notebook = gtk_notebook_new();
 
+	gtk_box_pack_start(GTK_BOX(vbox), notebook, TRUE, TRUE, 0);
+
+	info_bar = perf_gtk__setup_info_bar();
+	if (info_bar)
+		gtk_box_pack_start(GTK_BOX(vbox), info_bar, FALSE, FALSE, 0);
+
+	statbar = perf_gtk__setup_statusbar();
+	gtk_box_pack_start(GTK_BOX(vbox), statbar, FALSE, FALSE, 0);
+
+	gtk_container_add(GTK_CONTAINER(window), vbox);
+
 	list_for_each_entry(pos, &evlist->entries, node) {
 		struct hists *hists = &pos->hists;
 		const char *evname = perf_evsel__name(pos);
@@ -199,17 +210,6 @@ int perf_evlist__gtk_browse_hists(struct perf_evlist *evlist,
 		gtk_notebook_append_page(GTK_NOTEBOOK(notebook), scrolled_window, tab_label);
 	}
 
-	gtk_box_pack_start(GTK_BOX(vbox), notebook, TRUE, TRUE, 0);
-
-	info_bar = perf_gtk__setup_info_bar();
-	if (info_bar)
-		gtk_box_pack_start(GTK_BOX(vbox), info_bar, FALSE, FALSE, 0);
-
-	statbar = perf_gtk__setup_statusbar();
-	gtk_box_pack_start(GTK_BOX(vbox), statbar, FALSE, FALSE, 0);
-
-	gtk_container_add(GTK_CONTAINER(window), vbox);
-
 	gtk_widget_show_all(window);
 
 	perf_gtk__resize_window(window);
author maintainer
#5 lore raw

PATCH 3/6 perf ui/gtk: Implement basic GTK2 annotation browser

In reply to Namhyung Kim

Basic implementation of perf annotate on GTK2. Currently only shows first symbol.

---
 tools/perf/Makefile           |   1 +
 tools/perf/builtin-annotate.c |   5 +-
 tools/perf/ui/gtk/annotate.c  | 185 ++++++++++++++++++++++++++++++++++++++++++
 tools/perf/util/annotate.h    |  20 +++++
 4 files changed, 210 insertions(+), 1 deletion(-)
 create mode 100644 tools/perf/ui/gtk/annotate.c
tools/perf/Makefile +1 -0
index 103ed956ca80..4be79a469229 100644
@@ -693,6 +693,7 @@ ifndef NO_GTK2
 		LIB_OBJS += $(OUTPUT)ui/gtk/util.o
 		LIB_OBJS += $(OUTPUT)ui/gtk/helpline.o
 		LIB_OBJS += $(OUTPUT)ui/gtk/progress.o
+		LIB_OBJS += $(OUTPUT)ui/gtk/annotate.o
 	endif
 endif
 
tools/perf/builtin-annotate.c +4 -1
index dc870cf31b79..9f84bc45672c 100644
@@ -138,7 +138,10 @@ find_next:
 			continue;
 		}
 
-		if (use_browser > 0) {
+		if (use_browser == 2) {
+			hist_entry__gtk_annotate(he, evidx, NULL);
+			return;
+		} else if (use_browser == 1) {
 			key = hist_entry__tui_annotate(he, evidx, NULL);
 			switch (key) {
 			case K_RIGHT:
tools/perf/ui/gtk/annotate.c new file +185 -0

185 lines not on this page · raw message

tools/perf/util/annotate.h +20 -0
index 8eec94358a4a..a8ccbda4aeb7 100644
@@ -6,6 +6,7 @@
 #include "types.h"
 #include "symbol.h"
 #include "hist.h"
+#include "sort.h"
 #include <linux/list.h>
 #include <linux/rbtree.h>
 #include <pthread.h>
@@ -154,6 +155,25 @@ static inline int symbol__tui_annotate(struct symbol *sym __maybe_unused,
 }
 #endif
 
+#ifdef GTK2_SUPPORT
+int symbol__gtk_annotate(struct symbol *sym, struct map *map, int evidx,
+			 struct hist_browser_timer *hbt);
+
+static inline int hist_entry__gtk_annotate(struct hist_entry *he, int evidx,
+					   struct hist_browser_timer *hbt)
+{
+	return symbol__gtk_annotate(he->ms.sym, he->ms.map, evidx, hbt);
+}
+#else
+static inline int hist_entry__gtk_annotate(struct hist_entry *he __maybe_unused,
+					   int evidx __maybe_unused,
+					   struct hist_browser_timer *hbt
+					   __maybe_unused)
+{
+	return 0;
+}
+#endif
+
 extern const char	*disassembler_style;
 
 #endif	/* __PERF_ANNOTATE_H */
Signature · 1 line
1.7.11.7
#6 lore raw

Re: [PATCH 3/6] perf ui/gtk: Implement basic GTK2 annotation browser

Em Fri, Dec 21, 2012 at 05:20:15PM +0900, Namhyung Kim escreveu:

Quoted 2 lines

Basic implementation of perf annotate on GTK2. Currently only shows first symbol.

I merged the first two patches in this series, but this one needs to be merged with the sixth patch, so that we can try it at this point, then you can add more features (patches 4 and 5) that can be tested as we merge them.

Just pushed my perf/core branch with the 2 first patches.

- Arnaldo

Quoted 269 lines
---
 tools/perf/Makefile           |   1 +
 tools/perf/builtin-annotate.c |   5 +-
 tools/perf/ui/gtk/annotate.c  | 185 ++++++++++++++++++++++++++++++++++++++++++
 tools/perf/util/annotate.h    |  20 +++++
 4 files changed, 210 insertions(+), 1 deletion(-)
 create mode 100644 tools/perf/ui/gtk/annotate.c
tools/perf/Makefile +1 -0
index 103ed956ca80..4be79a469229 100644
@@ -693,6 +693,7 @@ ifndef NO_GTK2
 		LIB_OBJS += $(OUTPUT)ui/gtk/util.o
 		LIB_OBJS += $(OUTPUT)ui/gtk/helpline.o
 		LIB_OBJS += $(OUTPUT)ui/gtk/progress.o
+		LIB_OBJS += $(OUTPUT)ui/gtk/annotate.o
 	endif
 endif
 
tools/perf/builtin-annotate.c +4 -1
index dc870cf31b79..9f84bc45672c 100644
@@ -138,7 +138,10 @@ find_next:
 			continue;
 		}
 
-		if (use_browser > 0) {
+		if (use_browser == 2) {
+			hist_entry__gtk_annotate(he, evidx, NULL);
+			return;
+		} else if (use_browser == 1) {
 			key = hist_entry__tui_annotate(he, evidx, NULL);
 			switch (key) {
 			case K_RIGHT:
tools/perf/ui/gtk/annotate.c new file +185 -0
new file mode 100644
index 000000000000..19d84fa327af
@@ -0,0 +1,185 @@
+#include "gtk.h"
+#include "util/debug.h"
+#include "util/annotate.h"
+#include "ui/helpline.h"
+
+
+enum {
+	ANN_COL__PERCENT,
+	ANN_COL__OFFSET,
+	ANN_COL__LINE,
+
+	MAX_ANN_COLS
+};
+
+static const char *const col_names[] = {
+	"Overhead",
+	"Offset",
+	"Line"
+};
+
+static int perf_gtk__get_percent(char *buf, size_t size, struct symbol *sym,
+				 struct disasm_line *dl, int evidx)
+{
+	struct sym_hist *symhist;
+	double percent = 0.0;
+	const char *markup;
+	int ret = 0;
+
+	strcpy(buf, "");
+
+	if (dl->offset == (s64) -1)
+		return 0;
+
+	symhist = annotation__histogram(symbol__annotation(sym), evidx);
+	if (!symhist->addr[dl->offset])
+		return 0;
+
+	percent = 100.0 * symhist->addr[dl->offset] / symhist->sum;
+
+	markup = perf_gtk__get_percent_color(percent);
+	if (markup)
+		ret += scnprintf(buf, size, "%s", markup);
+	ret += scnprintf(buf + ret, size - ret, "%6.2f%%", percent);
+	if (markup)
+		ret += scnprintf(buf + ret, size - ret, "</span>");
+
+	return ret;
+}
+
+static int perf_gtk__get_offset(char *buf, size_t size, struct symbol *sym,
+				struct map *map, struct disasm_line *dl)
+{
+	u64 start = map__rip_2objdump(map, sym->start);
+
+	strcpy(buf, "");
+
+	if (dl->offset == (s64) -1)
+		return 0;
+
+	return scnprintf(buf, size, "%"PRIx64, start + dl->offset);
+}
+
+static int perf_gtk__annotate_symbol(GtkWidget *window, struct symbol *sym,
+				struct map *map, int evidx,
+				struct hist_browser_timer *hbt __maybe_unused)
+{
+	struct disasm_line *pos, *n;
+	struct annotation *notes;
+	GType col_types[MAX_ANN_COLS];
+	GtkCellRenderer *renderer;
+	GtkListStore *store;
+	GtkWidget *view;
+	int i;
+	char s[512];
+
+	if (map->dso->annotate_warned)
+		return -1;
+
+	if (symbol__annotate(sym, map, 0) < 0) {
+		ui__error("%s", ui_helpline__current);
+		return -1;
+	}
+
+	notes = symbol__annotation(sym);
+
+	for (i = 0; i < MAX_ANN_COLS; i++) {
+		col_types[i] = G_TYPE_STRING;
+	}
+	store = gtk_list_store_newv(MAX_ANN_COLS, col_types);
+
+	view = gtk_tree_view_new();
+	renderer = gtk_cell_renderer_text_new();
+
+	for (i = 0; i < MAX_ANN_COLS; i++) {
+		gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(view),
+					-1, col_names[i], renderer,
+					i == ANN_COL__PERCENT ? "markup" : "text",
+					i, NULL);
+	}
+
+	gtk_tree_view_set_model(GTK_TREE_VIEW(view), GTK_TREE_MODEL(store));
+	g_object_unref(GTK_TREE_MODEL(store));
+
+	list_for_each_entry(pos, &notes->src->source, node) {
+		GtkTreeIter iter;
+
+		gtk_list_store_append(store, &iter);
+
+		if (perf_gtk__get_percent(s, sizeof(s), sym, pos, evidx))
+			gtk_list_store_set(store, &iter, ANN_COL__PERCENT, s, -1);
+		if (perf_gtk__get_offset(s, sizeof(s), sym, map, pos))
+			gtk_list_store_set(store, &iter, ANN_COL__OFFSET, s, -1);
+		gtk_list_store_set(store, &iter, ANN_COL__LINE, pos->line, -1);
+	}
+
+	gtk_container_add(GTK_CONTAINER(window), view);
+
+	list_for_each_entry_safe(pos, n, &notes->src->source, node) {
+		list_del(&pos->node);
+		disasm_line__free(pos);
+	}
+
+	return 0;
+}
+
+int symbol__gtk_annotate(struct symbol *sym, struct map *map, int evidx,
+			 struct hist_browser_timer *hbt)
+{
+	GtkWidget *vbox;
+	GtkWidget *notebook;
+	GtkWidget *infobar;
+	GtkWidget *statbar;
+	GtkWidget *window;
+	GtkWidget *scrolled_window;
+	GtkWidget *tab_label;
+
+	signal(SIGSEGV, perf_gtk__signal);
+	signal(SIGFPE,  perf_gtk__signal);
+	signal(SIGINT,  perf_gtk__signal);
+	signal(SIGQUIT, perf_gtk__signal);
+	signal(SIGTERM, perf_gtk__signal);
+
+	window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
+	gtk_window_set_title(GTK_WINDOW(window), "perf annotate");
+
+	g_signal_connect(window, "delete_event", gtk_main_quit, NULL);
+
+	pgctx = perf_gtk__activate_context(window);
+	if (!pgctx)
+		return -1;
+
+	vbox = gtk_vbox_new(FALSE, 0);
+	notebook = gtk_notebook_new();
+	scrolled_window = gtk_scrolled_window_new(NULL, NULL);
+	tab_label = gtk_label_new(sym->name);
+
+	gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled_window),
+				       GTK_POLICY_AUTOMATIC,
+				       GTK_POLICY_AUTOMATIC);
+
+	gtk_notebook_append_page(GTK_NOTEBOOK(notebook), scrolled_window,
+				 tab_label);
+	gtk_box_pack_start(GTK_BOX(vbox), notebook, TRUE, TRUE, 0);
+
+	infobar = perf_gtk__setup_info_bar();
+	if (infobar)
+		gtk_box_pack_start(GTK_BOX(vbox), infobar, FALSE, FALSE, 0);
+
+	statbar = perf_gtk__setup_statusbar();
+	gtk_box_pack_start(GTK_BOX(vbox), statbar, FALSE, FALSE, 0);
+
+	gtk_container_add(GTK_CONTAINER(window), vbox);
+
+	perf_gtk__annotate_symbol(scrolled_window, sym, map, evidx, hbt);
+
+	gtk_widget_show_all(window);
+
+	perf_gtk__resize_window(window);
+	gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
+
+	gtk_main();
+
+	perf_gtk__deactivate_context(&pgctx);
+	return 0;
+}
tools/perf/util/annotate.h +20 -0
index 8eec94358a4a..a8ccbda4aeb7 100644
@@ -6,6 +6,7 @@
 #include "types.h"
 #include "symbol.h"
 #include "hist.h"
+#include "sort.h"
 #include <linux/list.h>
 #include <linux/rbtree.h>
 #include <pthread.h>
@@ -154,6 +155,25 @@ static inline int symbol__tui_annotate(struct symbol *sym __maybe_unused,
 }
 #endif
 
+#ifdef GTK2_SUPPORT
+int symbol__gtk_annotate(struct symbol *sym, struct map *map, int evidx,
+			 struct hist_browser_timer *hbt);
+
+static inline int hist_entry__gtk_annotate(struct hist_entry *he, int evidx,
+					   struct hist_browser_timer *hbt)
+{
+	return symbol__gtk_annotate(he->ms.sym, he->ms.map, evidx, hbt);
+}
+#else
+static inline int hist_entry__gtk_annotate(struct hist_entry *he __maybe_unused,
+					   int evidx __maybe_unused,
+					   struct hist_browser_timer *hbt
+					   __maybe_unused)
+{
+	return 0;
+}
+#endif
+
 extern const char	*disassembler_style;
 
 #endif	/* __PERF_ANNOTATE_H */
Signature · 1 line
1.7.11.7
author maintainer
#7 lore raw

Re: [PATCH 3/6] perf ui/gtk: Implement basic GTK2 annotation browser

Hi all,

Merry Christmas!

Quoted 8 lines · Arnaldo Carvalho de Melo

Em Fri, Dec 21, 2012 at 05:20:15PM +0900, Namhyung Kim escreveu:

Quoted 2 lines

Basic implementation of perf annotate on GTK2. Currently only shows first symbol.

I merged the first two patches in this series, but this one needs to be merged with the sixth patch, so that we can try it at this point, then you can add more features (patches 4 and 5) that can be tested as we merge them.

You can apply patch 6 before 4 and 5 since it's not depends on them. But if you want, I'll resend a squashed patch for 3 + 6.

Quoted 1 line

Just pushed my perf/core branch with the 2 first patches.

Thanks a lot! :)

Signature · 2 lines
Thanks,
Namhyung
author maintainer
#8 lore raw

PATCH 4/6 perf gtk/annotate: Support multiple annotation result

In reply to Namhyung Kim

From: Namhyung Kim <[email protected]>

Show multiple annotation result for each tab. For this add reference to main container (notebook) to the pgctx.

For the first call to annotate browser, hist_entry__find_annotations() will setup a new browser, and next calls will add new tabs to the browser. But it requires final perf_gtk__show_annotations() to start processing GUI events.

---
 tools/perf/builtin-annotate.c |  4 +++
 tools/perf/ui/gtk/annotate.c  | 72 +++++++++++++++++++++++++++----------------
 tools/perf/ui/gtk/gtk.h       |  1 +
 tools/perf/util/annotate.h    |  4 +++
 4 files changed, 54 insertions(+), 27 deletions(-)
tools/perf/builtin-annotate.c +4 -0
index 9f84bc45672c..034e9b003c62 100644
@@ -227,6 +227,10 @@ static int __cmd_annotate(struct perf_annotate *ann)
 		ui__error("The %s file has no samples!\n", session->filename);
 		goto out_delete;
 	}
+
+	if (use_browser == 2)
+		perf_gtk__show_annotations();
+
 out_delete:
 	/*
 	 * Speed up the exit process, for large files this can
tools/perf/ui/gtk/annotate.c +45 -27

100 lines not on this page · raw message

tools/perf/ui/gtk/gtk.h +1 -0
index 5d3693754828..3d96785ef155 100644
@@ -10,6 +10,7 @@
 
 struct perf_gtk_context {
 	GtkWidget *main_window;
+	GtkWidget *notebook;
 
 #ifdef HAVE_GTK_INFO_BAR
 	GtkWidget *info_bar;
tools/perf/util/annotate.h +4 -0
index a8ccbda4aeb7..c422440fe611 100644
@@ -164,6 +164,8 @@ static inline int hist_entry__gtk_annotate(struct hist_entry *he, int evidx,
 {
 	return symbol__gtk_annotate(he->ms.sym, he->ms.map, evidx, hbt);
 }
+
+void perf_gtk__show_annotations(void);
 #else
 static inline int hist_entry__gtk_annotate(struct hist_entry *he __maybe_unused,
 					   int evidx __maybe_unused,
@@ -172,6 +174,8 @@ static inline int hist_entry__gtk_annotate(struct hist_entry *he __maybe_unused,
 {
 	return 0;
 }
+
+static inline void perf_gtk__show_annotations(void) {}
 #endif
 
 extern const char	*disassembler_style;
Signature · 1 line
1.7.11.7
author maintainer
#9 lore raw

PATCH 5/6 perf gtk/annotate: Show source lines with gray color

In reply to Namhyung Kim

From: Namhyung Kim <[email protected]>

In order to differentiate source lines from asm line, print them with gray color. To do this, it needs to be escaped since sometimes it contains "<" and/or ">" characters so that it should not be considered as a markup tags. Use glib's g_markup_escape_text() for this.

---
 tools/perf/ui/gtk/annotate.c | 30 +++++++++++++++++++++++++++---
 1 file changed, 27 insertions(+), 3 deletions(-)
tools/perf/ui/gtk/annotate.c +27 -3
index 191ee4e30d93..771b04c0df30 100644
@@ -60,6 +60,30 @@ static int perf_gtk__get_offset(char *buf, size_t size, struct symbol *sym,
 	return scnprintf(buf, size, "%"PRIx64, start + dl->offset);
 }
 
+static int perf_gtk__get_line(char *buf, size_t size, struct disasm_line *dl)
+{
+	int ret = 0;
+	char *line = g_markup_escape_text(dl->line, -1);
+	const char *markup = "<span fgcolor='gray'>";
+
+	strcpy(buf, "");
+
+	if (!line)
+		return 0;
+
+	if (dl->offset != (s64) -1)
+		markup = NULL;
+
+	if (markup)
+		ret += scnprintf(buf, size, "%s", markup);
+	ret += scnprintf(buf + ret, size - ret, "%s", line);
+	if (markup)
+		ret += scnprintf(buf + ret, size - ret, "</span>");
+
+	g_free(line);
+	return ret;
+}
+
 static int perf_gtk__annotate_symbol(GtkWidget *window, struct symbol *sym,
 				struct map *map, int evidx,
 				struct hist_browser_timer *hbt __maybe_unused)
@@ -93,8 +117,7 @@ static int perf_gtk__annotate_symbol(GtkWidget *window, struct symbol *sym,
 
 	for (i = 0; i < MAX_ANN_COLS; i++) {
 		gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(view),
-					-1, col_names[i], renderer,
-					i == ANN_COL__PERCENT ? "markup" : "text",
+					-1, col_names[i], renderer, "markup",
 					i, NULL);
 	}
 
@@ -110,7 +133,8 @@ static int perf_gtk__annotate_symbol(GtkWidget *window, struct symbol *sym,
 			gtk_list_store_set(store, &iter, ANN_COL__PERCENT, s, -1);
 		if (perf_gtk__get_offset(s, sizeof(s), sym, map, pos))
 			gtk_list_store_set(store, &iter, ANN_COL__OFFSET, s, -1);
-		gtk_list_store_set(store, &iter, ANN_COL__LINE, pos->line, -1);
+		if (perf_gtk__get_line(s, sizeof(s), pos))
+			gtk_list_store_set(store, &iter, ANN_COL__LINE, s, -1);
 	}
 
 	gtk_container_add(GTK_CONTAINER(window), view);
Signature · 1 line
1.7.11.7
author maintainer
#10 lore raw

PATCH 6/6 perf annotate: Add --gtk option

In reply to Namhyung Kim

Now we have GTK2 implementation, add a new --gtk option to use it.

---
 tools/perf/Documentation/perf-annotate.txt | 4 ++++
 tools/perf/builtin-annotate.c              | 5 ++++-
 2 files changed, 8 insertions(+), 1 deletion(-)
tools/perf/Documentation/perf-annotate.txt +4 -0
index c8ffd9fd5c6a..482e1f753127 100644
@@ -66,6 +66,10 @@ OPTIONS
 	used. This interfaces starts by centering on the line with more
 	samples, TAB/UNTAB cycles through the lines with more samples.
 
+--gtk:: Use the GTK interface. Use of --gtk requires (but not uses) a tty,
+	if one is not present, as when piping to other commands, the stdio
+	interface is used.
+
 -C::
 --cpu:: Only report samples for the list of CPUs provided. Multiple CPUs can
 	be provided as a comma-separated list with no space: 0,1. Ranges of
tools/perf/builtin-annotate.c +4 -1
index 034e9b003c62..dcc090526e56 100644
@@ -34,7 +34,7 @@
 
 struct perf_annotate {
 	struct perf_tool tool;
-	bool	   force, use_tui, use_stdio;
+	bool	   force, use_tui, use_stdio, use_gtk;
 	bool	   full_paths;
 	bool	   print_line;
 	const char *sym_hist_filter;
@@ -277,6 +277,7 @@ int cmd_annotate(int argc, const char **argv, const char *prefix __maybe_unused)
 		    "be more verbose (show symbol address, etc)"),
 	OPT_BOOLEAN('D', "dump-raw-trace", &dump_trace,
 		    "dump raw trace in ASCII"),
+	OPT_BOOLEAN(0, "gtk", &annotate.use_gtk, "Use the GTK interface"),
 	OPT_BOOLEAN(0, "tui", &annotate.use_tui, "Use the TUI interface"),
 	OPT_BOOLEAN(0, "stdio", &annotate.use_stdio, "Use the stdio interface"),
 	OPT_STRING('k', "vmlinux", &symbol_conf.vmlinux_name,
@@ -307,6 +308,8 @@ int cmd_annotate(int argc, const char **argv, const char *prefix __maybe_unused)
 		use_browser = 0;
 	else if (annotate.use_tui)
 		use_browser = 1;
+	else if (annotate.use_gtk)
+		use_browser = 2;
 
 	setup_browser(true);
 
Signature · 1 line
1.7.11.7
#11 lore raw

Re: [PATCH 6/6] perf annotate: Add --gtk option

Quoted 14 lines · Namhyung Kim

Now we have GTK2 implementation, add a new --gtk option to use it.

---
 tools/perf/Documentation/perf-annotate.txt | 4 ++++
 tools/perf/builtin-annotate.c              | 5 ++++-
 2 files changed, 8 insertions(+), 1 deletion(-)
tools/perf/Documentation/perf-annotate.txt +0 -0
index c8ffd9fd5c6a..482e1f753127 100644

tools/perf/Documentation/perf-annotate.txt OPTIONS · line 69

Quoted 4 lines
tools/perf/Documentation/perf-annotate.txt +1 -0
@@ -66,6 +66,10 @@ OPTIONS
 	used. This interfaces starts by centering on the line with more
 	samples, TAB/UNTAB cycles through the lines with more samples.
 
+--gtk:: Use the GTK interface. Use of --gtk requires (but not uses) a tty,

What does that even mean?

* it requires one but doesn't use it by default

* it requires one but if none is present, falls back to stdio

* it simply checks for tty presence and uses something completely different

* something else

?

Quoted 28 lines
tools/perf/Documentation/perf-annotate.txt +3 -0
+	if one is not present, as when piping to other commands, the stdio
+	interface is used.
+
 -C::
 --cpu:: Only report samples for the list of CPUs provided. Multiple CPUs can
 	be provided as a comma-separated list with no space: 0,1. Ranges of
tools/perf/builtin-annotate.c +2 -1
index 034e9b003c62..dcc090526e56 100644
@@ -34,7 +34,7 @@
 
 struct perf_annotate {
 	struct perf_tool tool;
-	bool	   force, use_tui, use_stdio;
+	bool	   force, use_tui, use_stdio, use_gtk;
 	bool	   full_paths;
 	bool	   print_line;
 	const char *sym_hist_filter;
@@ -277,6 +277,7 @@ int cmd_annotate(int argc, const char **argv, const char *prefix __maybe_unused)
 		    "be more verbose (show symbol address, etc)"),
 	OPT_BOOLEAN('D', "dump-raw-trace", &dump_trace,
 		    "dump raw trace in ASCII"),
+	OPT_BOOLEAN(0, "gtk", &annotate.use_gtk, "Use the GTK interface"),
 	OPT_BOOLEAN(0, "tui", &annotate.use_tui, "Use the TUI interface"),
 	OPT_BOOLEAN(0, "stdio", &annotate.use_stdio, "Use the stdio interface"),
 	OPT_STRING('k', "vmlinux", &symbol_conf.vmlinux_name,

tools/perf/builtin-annotate.c int cmd_annotate(int argc, const char **argv, const char *prefix __maybe_unused) · line 312

Quoted 5 lines
tools/perf/builtin-annotate.c +2 -0
@@ -307,6 +308,8 @@ int cmd_annotate(int argc, const char **argv, const char *prefix __maybe_unused)
 		use_browser = 0;
 	else if (annotate.use_tui)
 		use_browser = 1;
+	else if (annotate.use_gtk)
+		use_browser = 2;

Btw, acme, those use_browser values could use proper defines like:

#define PERF_BROWSER_NONE 0
#define PERF_BROWSER_TUI 1
#define PERF_BROWSER_GTK 2

or even an enum or whatever else comes natural in perf-speak.

Thanks.

Signature · 5 lines
Regards/Gruss,
    Boris.

Sent from a fat crate under my desk. Formatting is fine.
--
author maintainer
#12 lore raw

Re: [PATCH 6/6] perf annotate: Add --gtk option

Hi Boris,

Quoted 24 lines · Borislav Petkov
Quoted 14 lines · Namhyung Kim

Now we have GTK2 implementation, add a new --gtk option to use it.

---
 tools/perf/Documentation/perf-annotate.txt | 4 ++++
 tools/perf/builtin-annotate.c              | 5 ++++-
 2 files changed, 8 insertions(+), 1 deletion(-)
tools/perf/Documentation/perf-annotate.txt +0 -0
index c8ffd9fd5c6a..482e1f753127 100644

tools/perf/Documentation/perf-annotate.txt OPTIONS · line 69

Quoted 4 lines
tools/perf/Documentation/perf-annotate.txt +1 -0
@@ -66,6 +66,10 @@ OPTIONS
 	used. This interfaces starts by centering on the line with more
 	samples, TAB/UNTAB cycles through the lines with more samples.
 
+--gtk:: Use the GTK interface. Use of --gtk requires (but not uses) a tty,

What does that even mean?

* it requires one but doesn't use it by default

Quoted 7 lines

* it requires one but if none is present, falls back to stdio

* it simply checks for tty presence and uses something completely different

* something else

?

Hmm.. sorry for the unclear message. I just copied description of --tui option and failed to make it clear. :/

Current setup_browser() code checks the stdin to be a tty and if not it assumes piping to other commands so set the use_browser to 0 (stdio) and disables GTK output.

Maybe we can change this behavior for --gtk case.

Quoted 9 lines

tools/perf/Documentation/perf-annotate.txt int cmd_annotate(int argc, const char **argv, const char *prefix __maybe_unused) · line 312

Quoted 6 lines
tools/perf/Documentation/perf-annotate.txt +2 -0
@@ -307,6 +308,8 @@ int cmd_annotate(int argc, const char **argv, const char *prefix __maybe_unused)
 		use_browser = 0;
 	else if (annotate.use_tui)
 		use_browser = 1;
+	else if (annotate.use_gtk)
+		use_browser = 2;

Btw, acme, those use_browser values could use proper defines like:

Quoted 5 lines

#define PERF_BROWSER_NONE 0
#define PERF_BROWSER_TUI 1
#define PERF_BROWSER_GTK 2

or even an enum or whatever else comes natural in perf-speak.

Looks good, will change in the next spin.

Thanks,
Namhyung

#13 lore raw

Re: [PATCH 6/6] perf annotate: Add --gtk option

Quoted 5 lines · Namhyung Kim

Current setup_browser() code checks the stdin to be a tty and if not it assumes piping to other commands so set the use_browser to 0 (stdio) and disables GTK output.

Maybe we can change this behavior for --gtk case.

Change it in the sense that for the --gtk case stdin doesn't have to be a tty? So that with --gtk you can still pipe perf output to other commands?

I can't imagine a sensible --gtk use case with output piped to other commands. Hmm.

Thanks.

Signature · 5 lines
Regards/Gruss,
    Boris.

Sent from a fat crate under my desk. Formatting is fine.
--
author maintainer
#14 lore raw

Re: [PATCH 6/6] perf annotate: Add --gtk option

Quoted 5 lines · Borislav Petkov
Quoted 4 lines · Namhyung Kim

Current setup_browser() code checks the stdin to be a tty and if not it assumes piping to other commands so set the use_browser to 0 (stdio) and disables GTK output.

Quoted 8 lines
Quoted 1 line

Maybe we can change this behavior for --gtk case.

Change it in the sense that for the --gtk case stdin doesn't have to be a tty? So that with --gtk you can still pipe perf output to other commands?

I can't imagine a sensible --gtk use case with output piped to other commands. Hmm.

Right. I also have no idea what's the best way to handle --gtk option with the piped output. I can think of 3 options for this:

1) exit with a error message
2) honor --gtk option and launch a gui browser
3) honor piped output and print to stdout (thus ignore --gtk) like this patch does

Any thoughts?

Signature · 2 lines
Thanks,
Namhyung
#15 lore raw

Re: [PATCH 6/6] perf annotate: Add --gtk option

Quoted 5 lines · Namhyung Kim

Right. I also have no idea what's the best way to handle --gtk option with the piped output. I can think of 3 options for this:

1) exit with a error message
2) honor --gtk option and launch a gui browser

I could befriend #2, probably. Reasoning? Well, user gets what she
requested: --gtk with piped output and if it works, we give it to her.

Of course, I'm hardly the person to ask about user-visible stuff so maybe the others would have a more sensible idea :-).

Signature · 5 lines
Regards/Gruss,
    Boris.

Sent from a fat crate under my desk. Formatting is fine.
--