* [PATCH 0/6] perf annotate: Add support for GTK+ annotation browser (v1)
@ 2012-12-21 8:20 Namhyung Kim
2012-12-21 8:20 ` [PATCH 1/6] perf ui/gtk: Factor out common browser routines Namhyung Kim
` (5 more replies)
0 siblings, 6 replies; 16+ messages in thread
From: Namhyung Kim @ 2012-12-21 8:20 UTC (permalink / raw)
To: Arnaldo Carvalho de Melo
Cc: Peter Zijlstra, Paul Mackerras, Ingo Molnar, LKML, Pekka Enberg
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
--
1.7.11.7
^ permalink raw reply [flat|nested] 16+ messages in thread
* [PATCH 1/6] perf ui/gtk: Factor out common browser routines
2012-12-21 8:20 [PATCH 0/6] perf annotate: Add support for GTK+ annotation browser (v1) Namhyung Kim
@ 2012-12-21 8:20 ` Namhyung Kim
2013-01-25 11:23 ` [tip:perf/core] " tip-bot for Namhyung Kim
2012-12-21 8:20 ` [PATCH 2/6] perf ui/gtk: Setup browser window early Namhyung Kim
` (4 subsequent siblings)
5 siblings, 1 reply; 16+ messages in thread
From: Namhyung Kim @ 2012-12-21 8:20 UTC (permalink / raw)
To: Arnaldo Carvalho de Melo
Cc: Peter Zijlstra, Paul Mackerras, Ingo Molnar, LKML, Pekka Enberg
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.
Cc: Pekka Enberg <penberg@kernel.org>
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
---
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
diff --git a/tools/perf/Makefile b/tools/perf/Makefile
index dbf1c35d3f16..103ed956ca80 100644
--- a/tools/perf/Makefile
+++ b/tools/perf/Makefile
@@ -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
diff --git a/tools/perf/ui/gtk/browser.c b/tools/perf/ui/gtk/browser.c
index e59ba337f494..c95012cdb438 100644
--- a/tools/perf/ui/gtk/browser.c
+++ b/tools/perf/ui/gtk/browser.c
@@ -8,15 +8,13 @@
#include <signal.h>
-#define MAX_COLUMNS 32
-
-static void perf_gtk__signal(int sig)
+void perf_gtk__signal(int sig)
{
perf_gtk__exit(false);
psignal(sig, "perf");
}
-static void perf_gtk__resize_window(GtkWidget *window)
+void perf_gtk__resize_window(GtkWidget *window)
{
GdkRectangle rect;
GdkScreen *screen;
@@ -36,7 +34,7 @@ static void perf_gtk__resize_window(GtkWidget *window)
gtk_window_resize(GTK_WINDOW(window), width, height);
}
-static const char *perf_gtk__get_percent_color(double percent)
+const char *perf_gtk__get_percent_color(double percent)
{
if (percent >= MIN_RED)
return "<span fgcolor='red'>";
@@ -45,147 +43,8 @@ static const char *perf_gtk__get_percent_color(double percent)
return NULL;
}
-#define HPP__COLOR_FN(_name, _field) \
-static int perf_gtk__hpp_color_ ## _name(struct perf_hpp *hpp, \
- struct hist_entry *he) \
-{ \
- struct hists *hists = he->hists; \
- double percent = 100.0 * he->stat._field / hists->stats.total_period; \
- const char *markup; \
- int ret = 0; \
- \
- markup = perf_gtk__get_percent_color(percent); \
- if (markup) \
- ret += scnprintf(hpp->buf, hpp->size, "%s", markup); \
- ret += scnprintf(hpp->buf + ret, hpp->size - ret, "%6.2f%%", percent); \
- if (markup) \
- ret += scnprintf(hpp->buf + ret, hpp->size - ret, "</span>"); \
- \
- return ret; \
-}
-
-HPP__COLOR_FN(overhead, period)
-HPP__COLOR_FN(overhead_sys, period_sys)
-HPP__COLOR_FN(overhead_us, period_us)
-HPP__COLOR_FN(overhead_guest_sys, period_guest_sys)
-HPP__COLOR_FN(overhead_guest_us, period_guest_us)
-
-#undef HPP__COLOR_FN
-
-void perf_gtk__init_hpp(void)
-{
- perf_hpp__column_enable(PERF_HPP__OVERHEAD);
-
- perf_hpp__init();
-
- perf_hpp__format[PERF_HPP__OVERHEAD].color =
- perf_gtk__hpp_color_overhead;
- perf_hpp__format[PERF_HPP__OVERHEAD_SYS].color =
- perf_gtk__hpp_color_overhead_sys;
- perf_hpp__format[PERF_HPP__OVERHEAD_US].color =
- perf_gtk__hpp_color_overhead_us;
- perf_hpp__format[PERF_HPP__OVERHEAD_GUEST_SYS].color =
- perf_gtk__hpp_color_overhead_guest_sys;
- perf_hpp__format[PERF_HPP__OVERHEAD_GUEST_US].color =
- perf_gtk__hpp_color_overhead_guest_us;
-}
-
-static void perf_gtk__show_hists(GtkWidget *window, struct hists *hists)
-{
- struct perf_hpp_fmt *fmt;
- GType col_types[MAX_COLUMNS];
- GtkCellRenderer *renderer;
- struct sort_entry *se;
- GtkListStore *store;
- struct rb_node *nd;
- GtkWidget *view;
- int col_idx;
- int nr_cols;
- char s[512];
-
- struct perf_hpp hpp = {
- .buf = s,
- .size = sizeof(s),
- };
-
- nr_cols = 0;
-
- perf_hpp__for_each_format(fmt)
- col_types[nr_cols++] = G_TYPE_STRING;
-
- list_for_each_entry(se, &hist_entry__sort_list, list) {
- if (se->elide)
- continue;
-
- col_types[nr_cols++] = G_TYPE_STRING;
- }
-
- store = gtk_list_store_newv(nr_cols, col_types);
-
- view = gtk_tree_view_new();
-
- renderer = gtk_cell_renderer_text_new();
-
- col_idx = 0;
-
- perf_hpp__for_each_format(fmt) {
- fmt->header(&hpp);
- gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(view),
- -1, s,
- renderer, "markup",
- col_idx++, NULL);
- }
-
- list_for_each_entry(se, &hist_entry__sort_list, list) {
- if (se->elide)
- continue;
-
- gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(view),
- -1, se->se_header,
- renderer, "text",
- col_idx++, NULL);
- }
-
- gtk_tree_view_set_model(GTK_TREE_VIEW(view), GTK_TREE_MODEL(store));
-
- g_object_unref(GTK_TREE_MODEL(store));
-
- for (nd = rb_first(&hists->entries); nd; nd = rb_next(nd)) {
- struct hist_entry *h = rb_entry(nd, struct hist_entry, rb_node);
- GtkTreeIter iter;
-
- if (h->filtered)
- continue;
-
- gtk_list_store_append(store, &iter);
-
- col_idx = 0;
-
- perf_hpp__for_each_format(fmt) {
- if (fmt->color)
- fmt->color(&hpp, h);
- else
- fmt->entry(&hpp, h);
-
- gtk_list_store_set(store, &iter, col_idx++, s, -1);
- }
-
- list_for_each_entry(se, &hist_entry__sort_list, list) {
- if (se->elide)
- continue;
-
- se->se_snprintf(h, s, ARRAY_SIZE(s),
- hists__col_len(hists, se->se_width_idx));
-
- gtk_list_store_set(store, &iter, col_idx++, s, -1);
- }
- }
-
- gtk_container_add(GTK_CONTAINER(window), view);
-}
-
#ifdef HAVE_GTK_INFO_BAR
-static GtkWidget *perf_gtk__setup_info_bar(void)
+GtkWidget *perf_gtk__setup_info_bar(void)
{
GtkWidget *info_bar;
GtkWidget *label;
@@ -212,7 +71,7 @@ static GtkWidget *perf_gtk__setup_info_bar(void)
}
#endif
-static GtkWidget *perf_gtk__setup_statusbar(void)
+GtkWidget *perf_gtk__setup_statusbar(void)
{
GtkWidget *stbar;
unsigned ctxid;
@@ -226,79 +85,3 @@ static GtkWidget *perf_gtk__setup_statusbar(void)
return stbar;
}
-
-int perf_evlist__gtk_browse_hists(struct perf_evlist *evlist,
- const char *help,
- struct hist_browser_timer *hbt __maybe_unused)
-{
- struct perf_evsel *pos;
- GtkWidget *vbox;
- GtkWidget *notebook;
- GtkWidget *info_bar;
- GtkWidget *statbar;
- GtkWidget *window;
-
- 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 report");
-
- 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();
-
- list_for_each_entry(pos, &evlist->entries, node) {
- struct hists *hists = &pos->hists;
- const char *evname = perf_evsel__name(pos);
- GtkWidget *scrolled_window;
- GtkWidget *tab_label;
-
- scrolled_window = gtk_scrolled_window_new(NULL, NULL);
-
- gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled_window),
- GTK_POLICY_AUTOMATIC,
- GTK_POLICY_AUTOMATIC);
-
- perf_gtk__show_hists(scrolled_window, hists);
-
- tab_label = gtk_label_new(evname);
-
- 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);
-
- gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
-
- ui_helpline__push(help);
-
- gtk_main();
-
- perf_gtk__deactivate_context(&pgctx);
-
- return 0;
-}
diff --git a/tools/perf/ui/gtk/gtk.h b/tools/perf/ui/gtk/gtk.h
index 856320e2cc05..5d3693754828 100644
--- a/tools/perf/ui/gtk/gtk.h
+++ b/tools/perf/ui/gtk/gtk.h
@@ -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;
diff --git a/tools/perf/ui/gtk/hists.c b/tools/perf/ui/gtk/hists.c
new file mode 100644
index 000000000000..26912f86e032
--- /dev/null
+++ b/tools/perf/ui/gtk/hists.c
@@ -0,0 +1,226 @@
+#include "../evlist.h"
+#include "../cache.h"
+#include "../evsel.h"
+#include "../sort.h"
+#include "../hist.h"
+#include "../helpline.h"
+#include "gtk.h"
+
+#define MAX_COLUMNS 32
+
+#define HPP__COLOR_FN(_name, _field) \
+static int perf_gtk__hpp_color_ ## _name(struct perf_hpp *hpp, \
+ struct hist_entry *he) \
+{ \
+ struct hists *hists = he->hists; \
+ double percent = 100.0 * he->stat._field / hists->stats.total_period; \
+ const char *markup; \
+ int ret = 0; \
+ \
+ markup = perf_gtk__get_percent_color(percent); \
+ if (markup) \
+ ret += scnprintf(hpp->buf, hpp->size, "%s", markup); \
+ ret += scnprintf(hpp->buf + ret, hpp->size - ret, "%6.2f%%", percent); \
+ if (markup) \
+ ret += scnprintf(hpp->buf + ret, hpp->size - ret, "</span>"); \
+ \
+ return ret; \
+}
+
+HPP__COLOR_FN(overhead, period)
+HPP__COLOR_FN(overhead_sys, period_sys)
+HPP__COLOR_FN(overhead_us, period_us)
+HPP__COLOR_FN(overhead_guest_sys, period_guest_sys)
+HPP__COLOR_FN(overhead_guest_us, period_guest_us)
+
+#undef HPP__COLOR_FN
+
+
+void perf_gtk__init_hpp(void)
+{
+ perf_hpp__column_enable(PERF_HPP__OVERHEAD);
+
+ perf_hpp__init();
+
+ perf_hpp__format[PERF_HPP__OVERHEAD].color =
+ perf_gtk__hpp_color_overhead;
+ perf_hpp__format[PERF_HPP__OVERHEAD_SYS].color =
+ perf_gtk__hpp_color_overhead_sys;
+ perf_hpp__format[PERF_HPP__OVERHEAD_US].color =
+ perf_gtk__hpp_color_overhead_us;
+ perf_hpp__format[PERF_HPP__OVERHEAD_GUEST_SYS].color =
+ perf_gtk__hpp_color_overhead_guest_sys;
+ perf_hpp__format[PERF_HPP__OVERHEAD_GUEST_US].color =
+ perf_gtk__hpp_color_overhead_guest_us;
+}
+
+static void perf_gtk__show_hists(GtkWidget *window, struct hists *hists)
+{
+ struct perf_hpp_fmt *fmt;
+ GType col_types[MAX_COLUMNS];
+ GtkCellRenderer *renderer;
+ struct sort_entry *se;
+ GtkListStore *store;
+ struct rb_node *nd;
+ GtkWidget *view;
+ int col_idx;
+ int nr_cols;
+ char s[512];
+
+ struct perf_hpp hpp = {
+ .buf = s,
+ .size = sizeof(s),
+ };
+
+ nr_cols = 0;
+
+ perf_hpp__for_each_format(fmt)
+ col_types[nr_cols++] = G_TYPE_STRING;
+
+ list_for_each_entry(se, &hist_entry__sort_list, list) {
+ if (se->elide)
+ continue;
+
+ col_types[nr_cols++] = G_TYPE_STRING;
+ }
+
+ store = gtk_list_store_newv(nr_cols, col_types);
+
+ view = gtk_tree_view_new();
+
+ renderer = gtk_cell_renderer_text_new();
+
+ col_idx = 0;
+
+ perf_hpp__for_each_format(fmt) {
+ fmt->header(&hpp);
+
+ gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(view),
+ -1, s,
+ renderer, "markup",
+ col_idx++, NULL);
+ }
+
+ list_for_each_entry(se, &hist_entry__sort_list, list) {
+ if (se->elide)
+ continue;
+
+ gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(view),
+ -1, se->se_header,
+ renderer, "text",
+ col_idx++, NULL);
+ }
+
+ gtk_tree_view_set_model(GTK_TREE_VIEW(view), GTK_TREE_MODEL(store));
+
+ g_object_unref(GTK_TREE_MODEL(store));
+
+ for (nd = rb_first(&hists->entries); nd; nd = rb_next(nd)) {
+ struct hist_entry *h = rb_entry(nd, struct hist_entry, rb_node);
+ GtkTreeIter iter;
+
+ if (h->filtered)
+ continue;
+
+ gtk_list_store_append(store, &iter);
+
+ col_idx = 0;
+
+ perf_hpp__for_each_format(fmt) {
+ if (fmt->color)
+ fmt->color(&hpp, h);
+ else
+ fmt->entry(&hpp, h);
+
+ gtk_list_store_set(store, &iter, col_idx++, s, -1);
+ }
+
+ list_for_each_entry(se, &hist_entry__sort_list, list) {
+ if (se->elide)
+ continue;
+
+ se->se_snprintf(h, s, ARRAY_SIZE(s),
+ hists__col_len(hists, se->se_width_idx));
+
+ gtk_list_store_set(store, &iter, col_idx++, s, -1);
+ }
+ }
+
+ gtk_container_add(GTK_CONTAINER(window), view);
+}
+
+int perf_evlist__gtk_browse_hists(struct perf_evlist *evlist,
+ const char *help,
+ struct hist_browser_timer *hbt __maybe_unused)
+{
+ struct perf_evsel *pos;
+ GtkWidget *vbox;
+ GtkWidget *notebook;
+ GtkWidget *info_bar;
+ GtkWidget *statbar;
+ GtkWidget *window;
+
+ 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 report");
+
+ 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();
+
+ list_for_each_entry(pos, &evlist->entries, node) {
+ struct hists *hists = &pos->hists;
+ const char *evname = perf_evsel__name(pos);
+ GtkWidget *scrolled_window;
+ GtkWidget *tab_label;
+
+ scrolled_window = gtk_scrolled_window_new(NULL, NULL);
+
+ gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled_window),
+ GTK_POLICY_AUTOMATIC,
+ GTK_POLICY_AUTOMATIC);
+
+ perf_gtk__show_hists(scrolled_window, hists);
+
+ tab_label = gtk_label_new(evname);
+
+ 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);
+
+ gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
+
+ ui_helpline__push(help);
+
+ gtk_main();
+
+ perf_gtk__deactivate_context(&pgctx);
+
+ return 0;
+}
--
1.7.11.7
^ permalink raw reply related [flat|nested] 16+ messages in thread
* [PATCH 2/6] perf ui/gtk: Setup browser window early
2012-12-21 8:20 [PATCH 0/6] perf annotate: Add support for GTK+ annotation browser (v1) Namhyung Kim
2012-12-21 8:20 ` [PATCH 1/6] perf ui/gtk: Factor out common browser routines Namhyung Kim
@ 2012-12-21 8:20 ` Namhyung Kim
2013-01-25 11:24 ` [tip:perf/core] " tip-bot for Namhyung Kim
2012-12-21 8:20 ` [PATCH 3/6] perf ui/gtk: Implement basic GTK2 annotation browser Namhyung Kim
` (3 subsequent siblings)
5 siblings, 1 reply; 16+ messages in thread
From: Namhyung Kim @ 2012-12-21 8:20 UTC (permalink / raw)
To: Arnaldo Carvalho de Melo
Cc: Peter Zijlstra, Paul Mackerras, Ingo Molnar, LKML, Pekka Enberg
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.
Cc: Pekka Enberg <penberg@kernel.org>
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
---
tools/perf/ui/gtk/hists.c | 22 +++++++++++-----------
1 file changed, 11 insertions(+), 11 deletions(-)
diff --git a/tools/perf/ui/gtk/hists.c b/tools/perf/ui/gtk/hists.c
index 26912f86e032..c03da79d524f 100644
--- a/tools/perf/ui/gtk/hists.c
+++ b/tools/perf/ui/gtk/hists.c
@@ -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);
--
1.7.11.7
^ permalink raw reply related [flat|nested] 16+ messages in thread
* [PATCH 3/6] perf ui/gtk: Implement basic GTK2 annotation browser
2012-12-21 8:20 [PATCH 0/6] perf annotate: Add support for GTK+ annotation browser (v1) Namhyung Kim
2012-12-21 8:20 ` [PATCH 1/6] perf ui/gtk: Factor out common browser routines Namhyung Kim
2012-12-21 8:20 ` [PATCH 2/6] perf ui/gtk: Setup browser window early Namhyung Kim
@ 2012-12-21 8:20 ` Namhyung Kim
2012-12-21 14:51 ` Arnaldo Carvalho de Melo
2012-12-21 8:20 ` [PATCH 4/6] perf gtk/annotate: Support multiple annotation result Namhyung Kim
` (2 subsequent siblings)
5 siblings, 1 reply; 16+ messages in thread
From: Namhyung Kim @ 2012-12-21 8:20 UTC (permalink / raw)
To: Arnaldo Carvalho de Melo
Cc: Peter Zijlstra, Paul Mackerras, Ingo Molnar, LKML, Pekka Enberg
Basic implementation of perf annotate on GTK2. Currently only
shows first symbol.
Cc: Pekka Enberg <penberg@kernel.org>
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
---
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
diff --git a/tools/perf/Makefile b/tools/perf/Makefile
index 103ed956ca80..4be79a469229 100644
--- a/tools/perf/Makefile
+++ b/tools/perf/Makefile
@@ -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
diff --git a/tools/perf/builtin-annotate.c b/tools/perf/builtin-annotate.c
index dc870cf31b79..9f84bc45672c 100644
--- a/tools/perf/builtin-annotate.c
+++ b/tools/perf/builtin-annotate.c
@@ -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:
diff --git a/tools/perf/ui/gtk/annotate.c b/tools/perf/ui/gtk/annotate.c
new file mode 100644
index 000000000000..19d84fa327af
--- /dev/null
+++ b/tools/perf/ui/gtk/annotate.c
@@ -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, ¬es->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, ¬es->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;
+}
diff --git a/tools/perf/util/annotate.h b/tools/perf/util/annotate.h
index 8eec94358a4a..a8ccbda4aeb7 100644
--- a/tools/perf/util/annotate.h
+++ b/tools/perf/util/annotate.h
@@ -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 */
--
1.7.11.7
^ permalink raw reply related [flat|nested] 16+ messages in thread
* [PATCH 4/6] perf gtk/annotate: Support multiple annotation result
2012-12-21 8:20 [PATCH 0/6] perf annotate: Add support for GTK+ annotation browser (v1) Namhyung Kim
` (2 preceding siblings ...)
2012-12-21 8:20 ` [PATCH 3/6] perf ui/gtk: Implement basic GTK2 annotation browser Namhyung Kim
@ 2012-12-21 8:20 ` Namhyung Kim
2012-12-21 8:20 ` [PATCH 5/6] perf gtk/annotate: Show source lines with gray color Namhyung Kim
2012-12-21 8:20 ` [PATCH 6/6] perf annotate: Add --gtk option Namhyung Kim
5 siblings, 0 replies; 16+ messages in thread
From: Namhyung Kim @ 2012-12-21 8:20 UTC (permalink / raw)
To: Arnaldo Carvalho de Melo
Cc: Peter Zijlstra, Paul Mackerras, Ingo Molnar, LKML, Pekka Enberg,
Namhyung Kim
From: Namhyung Kim <namhyung.kim@lge.com>
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.
Cc: Pekka Enberg <penberg@kernel.org>
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
---
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(-)
diff --git a/tools/perf/builtin-annotate.c b/tools/perf/builtin-annotate.c
index 9f84bc45672c..034e9b003c62 100644
--- a/tools/perf/builtin-annotate.c
+++ b/tools/perf/builtin-annotate.c
@@ -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
diff --git a/tools/perf/ui/gtk/annotate.c b/tools/perf/ui/gtk/annotate.c
index 19d84fa327af..191ee4e30d93 100644
--- a/tools/perf/ui/gtk/annotate.c
+++ b/tools/perf/ui/gtk/annotate.c
@@ -126,31 +126,50 @@ static int perf_gtk__annotate_symbol(GtkWidget *window, struct symbol *sym,
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 *notebook;
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);
+ if (perf_gtk__is_active_context(pgctx)) {
+ window = pgctx->main_window;
+ notebook = pgctx->notebook;
+ } else {
+ GtkWidget *vbox;
+ GtkWidget *infobar;
+ GtkWidget *statbar;
- window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
- gtk_window_set_title(GTK_WINDOW(window), "perf annotate");
+ 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);
- g_signal_connect(window, "delete_event", gtk_main_quit, NULL);
+ window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
+ gtk_window_set_title(GTK_WINDOW(window), "perf annotate");
- pgctx = perf_gtk__activate_context(window);
- if (!pgctx)
- return -1;
+ 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();
+ pgctx->notebook = notebook;
+
+ 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);
+ }
- 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);
@@ -160,19 +179,19 @@ int symbol__gtk_annotate(struct symbol *sym, struct map *map, int evidx,
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);
+ perf_gtk__annotate_symbol(scrolled_window, sym, map, evidx, hbt);
+ return 0;
+}
- gtk_container_add(GTK_CONTAINER(window), vbox);
+void perf_gtk__show_annotations(void)
+{
+ GtkWidget *window;
- perf_gtk__annotate_symbol(scrolled_window, sym, map, evidx, hbt);
+ if (!perf_gtk__is_active_context(pgctx))
+ return;
+ window = pgctx->main_window;
gtk_widget_show_all(window);
perf_gtk__resize_window(window);
@@ -181,5 +200,4 @@ int symbol__gtk_annotate(struct symbol *sym, struct map *map, int evidx,
gtk_main();
perf_gtk__deactivate_context(&pgctx);
- return 0;
}
diff --git a/tools/perf/ui/gtk/gtk.h b/tools/perf/ui/gtk/gtk.h
index 5d3693754828..3d96785ef155 100644
--- a/tools/perf/ui/gtk/gtk.h
+++ b/tools/perf/ui/gtk/gtk.h
@@ -10,6 +10,7 @@
struct perf_gtk_context {
GtkWidget *main_window;
+ GtkWidget *notebook;
#ifdef HAVE_GTK_INFO_BAR
GtkWidget *info_bar;
diff --git a/tools/perf/util/annotate.h b/tools/perf/util/annotate.h
index a8ccbda4aeb7..c422440fe611 100644
--- a/tools/perf/util/annotate.h
+++ b/tools/perf/util/annotate.h
@@ -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;
--
1.7.11.7
^ permalink raw reply related [flat|nested] 16+ messages in thread
* [PATCH 5/6] perf gtk/annotate: Show source lines with gray color
2012-12-21 8:20 [PATCH 0/6] perf annotate: Add support for GTK+ annotation browser (v1) Namhyung Kim
` (3 preceding siblings ...)
2012-12-21 8:20 ` [PATCH 4/6] perf gtk/annotate: Support multiple annotation result Namhyung Kim
@ 2012-12-21 8:20 ` Namhyung Kim
2012-12-21 8:20 ` [PATCH 6/6] perf annotate: Add --gtk option Namhyung Kim
5 siblings, 0 replies; 16+ messages in thread
From: Namhyung Kim @ 2012-12-21 8:20 UTC (permalink / raw)
To: Arnaldo Carvalho de Melo
Cc: Peter Zijlstra, Paul Mackerras, Ingo Molnar, LKML, Pekka Enberg,
Namhyung Kim
From: Namhyung Kim <namhyung.kim@lge.com>
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.
Cc: Pekka Enberg <penberg@kernel.org>
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
---
tools/perf/ui/gtk/annotate.c | 30 +++++++++++++++++++++++++++---
1 file changed, 27 insertions(+), 3 deletions(-)
diff --git a/tools/perf/ui/gtk/annotate.c b/tools/perf/ui/gtk/annotate.c
index 191ee4e30d93..771b04c0df30 100644
--- a/tools/perf/ui/gtk/annotate.c
+++ b/tools/perf/ui/gtk/annotate.c
@@ -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);
--
1.7.11.7
^ permalink raw reply related [flat|nested] 16+ messages in thread
* [PATCH 6/6] perf annotate: Add --gtk option
2012-12-21 8:20 [PATCH 0/6] perf annotate: Add support for GTK+ annotation browser (v1) Namhyung Kim
` (4 preceding siblings ...)
2012-12-21 8:20 ` [PATCH 5/6] perf gtk/annotate: Show source lines with gray color Namhyung Kim
@ 2012-12-21 8:20 ` Namhyung Kim
2012-12-21 8:32 ` Borislav Petkov
5 siblings, 1 reply; 16+ messages in thread
From: Namhyung Kim @ 2012-12-21 8:20 UTC (permalink / raw)
To: Arnaldo Carvalho de Melo
Cc: Peter Zijlstra, Paul Mackerras, Ingo Molnar, LKML, Pekka Enberg
Now we have GTK2 implementation, add a new --gtk option to use it.
Cc: Pekka Enberg <penberg@kernel.org>
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
---
tools/perf/Documentation/perf-annotate.txt | 4 ++++
tools/perf/builtin-annotate.c | 5 ++++-
2 files changed, 8 insertions(+), 1 deletion(-)
diff --git a/tools/perf/Documentation/perf-annotate.txt b/tools/perf/Documentation/perf-annotate.txt
index c8ffd9fd5c6a..482e1f753127 100644
--- a/tools/perf/Documentation/perf-annotate.txt
+++ b/tools/perf/Documentation/perf-annotate.txt
@@ -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
diff --git a/tools/perf/builtin-annotate.c b/tools/perf/builtin-annotate.c
index 034e9b003c62..dcc090526e56 100644
--- a/tools/perf/builtin-annotate.c
+++ b/tools/perf/builtin-annotate.c
@@ -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);
--
1.7.11.7
^ permalink raw reply related [flat|nested] 16+ messages in thread
* Re: [PATCH 6/6] perf annotate: Add --gtk option
2012-12-21 8:20 ` [PATCH 6/6] perf annotate: Add --gtk option Namhyung Kim
@ 2012-12-21 8:32 ` Borislav Petkov
2012-12-21 9:16 ` Namhyung Kim
0 siblings, 1 reply; 16+ messages in thread
From: Borislav Petkov @ 2012-12-21 8:32 UTC (permalink / raw)
To: Namhyung Kim
Cc: Arnaldo Carvalho de Melo, Peter Zijlstra, Paul Mackerras,
Ingo Molnar, LKML, Pekka Enberg
On Fri, Dec 21, 2012 at 05:20:18PM +0900, Namhyung Kim wrote:
> Now we have GTK2 implementation, add a new --gtk option to use it.
>
> Cc: Pekka Enberg <penberg@kernel.org>
> Signed-off-by: Namhyung Kim <namhyung@kernel.org>
> ---
> tools/perf/Documentation/perf-annotate.txt | 4 ++++
> tools/perf/builtin-annotate.c | 5 ++++-
> 2 files changed, 8 insertions(+), 1 deletion(-)
>
> diff --git a/tools/perf/Documentation/perf-annotate.txt b/tools/perf/Documentation/perf-annotate.txt
> index c8ffd9fd5c6a..482e1f753127 100644
> --- a/tools/perf/Documentation/perf-annotate.txt
> +++ b/tools/perf/Documentation/perf-annotate.txt
> @@ -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
?
> + 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
> diff --git a/tools/perf/builtin-annotate.c b/tools/perf/builtin-annotate.c
> index 034e9b003c62..dcc090526e56 100644
> --- a/tools/perf/builtin-annotate.c
> +++ b/tools/perf/builtin-annotate.c
> @@ -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;
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.
--
Regards/Gruss,
Boris.
Sent from a fat crate under my desk. Formatting is fine.
--
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH 6/6] perf annotate: Add --gtk option
2012-12-21 8:32 ` Borislav Petkov
@ 2012-12-21 9:16 ` Namhyung Kim
2012-12-21 15:44 ` Borislav Petkov
0 siblings, 1 reply; 16+ messages in thread
From: Namhyung Kim @ 2012-12-21 9:16 UTC (permalink / raw)
To: Borislav Petkov
Cc: Arnaldo Carvalho de Melo, Peter Zijlstra, Paul Mackerras,
Ingo Molnar, LKML, Pekka Enberg
Hi Boris,
On Fri, 21 Dec 2012 09:32:05 +0100, Borislav Petkov wrote:
> On Fri, Dec 21, 2012 at 05:20:18PM +0900, Namhyung Kim wrote:
>> Now we have GTK2 implementation, add a new --gtk option to use it.
>>
>> Cc: Pekka Enberg <penberg@kernel.org>
>> Signed-off-by: Namhyung Kim <namhyung@kernel.org>
>> ---
>> tools/perf/Documentation/perf-annotate.txt | 4 ++++
>> tools/perf/builtin-annotate.c | 5 ++++-
>> 2 files changed, 8 insertions(+), 1 deletion(-)
>>
>> diff --git a/tools/perf/Documentation/perf-annotate.txt b/tools/perf/Documentation/perf-annotate.txt
>> index c8ffd9fd5c6a..482e1f753127 100644
>> --- a/tools/perf/Documentation/perf-annotate.txt
>> +++ b/tools/perf/Documentation/perf-annotate.txt
>> @@ -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
>
> ?
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.
>> @@ -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.
Looks good, will change in the next spin.
Thanks,
Namhyung
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH 3/6] perf ui/gtk: Implement basic GTK2 annotation browser
2012-12-21 8:20 ` [PATCH 3/6] perf ui/gtk: Implement basic GTK2 annotation browser Namhyung Kim
@ 2012-12-21 14:51 ` Arnaldo Carvalho de Melo
2012-12-24 5:55 ` Namhyung Kim
0 siblings, 1 reply; 16+ messages in thread
From: Arnaldo Carvalho de Melo @ 2012-12-21 14:51 UTC (permalink / raw)
To: Namhyung Kim
Cc: Peter Zijlstra, Paul Mackerras, Ingo Molnar, LKML, Pekka Enberg
Em Fri, Dec 21, 2012 at 05:20:15PM +0900, Namhyung Kim escreveu:
> 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
> Cc: Pekka Enberg <penberg@kernel.org>
> Signed-off-by: Namhyung Kim <namhyung@kernel.org>
> ---
> 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
>
> diff --git a/tools/perf/Makefile b/tools/perf/Makefile
> index 103ed956ca80..4be79a469229 100644
> --- a/tools/perf/Makefile
> +++ b/tools/perf/Makefile
> @@ -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
>
> diff --git a/tools/perf/builtin-annotate.c b/tools/perf/builtin-annotate.c
> index dc870cf31b79..9f84bc45672c 100644
> --- a/tools/perf/builtin-annotate.c
> +++ b/tools/perf/builtin-annotate.c
> @@ -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:
> diff --git a/tools/perf/ui/gtk/annotate.c b/tools/perf/ui/gtk/annotate.c
> new file mode 100644
> index 000000000000..19d84fa327af
> --- /dev/null
> +++ b/tools/perf/ui/gtk/annotate.c
> @@ -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, ¬es->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, ¬es->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;
> +}
> diff --git a/tools/perf/util/annotate.h b/tools/perf/util/annotate.h
> index 8eec94358a4a..a8ccbda4aeb7 100644
> --- a/tools/perf/util/annotate.h
> +++ b/tools/perf/util/annotate.h
> @@ -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 */
> --
> 1.7.11.7
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH 6/6] perf annotate: Add --gtk option
2012-12-21 9:16 ` Namhyung Kim
@ 2012-12-21 15:44 ` Borislav Petkov
2012-12-24 6:04 ` Namhyung Kim
0 siblings, 1 reply; 16+ messages in thread
From: Borislav Petkov @ 2012-12-21 15:44 UTC (permalink / raw)
To: Namhyung Kim
Cc: Arnaldo Carvalho de Melo, Peter Zijlstra, Paul Mackerras,
Ingo Molnar, LKML, Pekka Enberg
On Fri, Dec 21, 2012 at 06:16:46PM +0900, Namhyung Kim wrote:
> 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.
--
Regards/Gruss,
Boris.
Sent from a fat crate under my desk. Formatting is fine.
--
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH 3/6] perf ui/gtk: Implement basic GTK2 annotation browser
2012-12-21 14:51 ` Arnaldo Carvalho de Melo
@ 2012-12-24 5:55 ` Namhyung Kim
0 siblings, 0 replies; 16+ messages in thread
From: Namhyung Kim @ 2012-12-24 5:55 UTC (permalink / raw)
To: Arnaldo Carvalho de Melo
Cc: Peter Zijlstra, Paul Mackerras, Ingo Molnar, LKML, Pekka Enberg
Hi all,
Merry Christmas!
On Fri, Dec 21, 2012 at 11:51 PM, Arnaldo Carvalho de Melo
<acme@ghostprotocols.net> wrote:
> Em Fri, Dec 21, 2012 at 05:20:15PM +0900, Namhyung Kim escreveu:
>> 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.
> Just pushed my perf/core branch with the 2 first patches.
Thanks a lot! :)
--
Thanks,
Namhyung
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH 6/6] perf annotate: Add --gtk option
2012-12-21 15:44 ` Borislav Petkov
@ 2012-12-24 6:04 ` Namhyung Kim
2012-12-24 13:18 ` Borislav Petkov
0 siblings, 1 reply; 16+ messages in thread
From: Namhyung Kim @ 2012-12-24 6:04 UTC (permalink / raw)
To: Borislav Petkov, Namhyung Kim, Arnaldo Carvalho de Melo,
Peter Zijlstra, Paul Mackerras, Ingo Molnar, LKML, Pekka Enberg
On Sat, Dec 22, 2012 at 12:44 AM, Borislav Petkov <bp@alien8.de> wrote:
> On Fri, Dec 21, 2012 at 06:16:46PM +0900, Namhyung Kim wrote:
>> 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.
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?
--
Thanks,
Namhyung
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH 6/6] perf annotate: Add --gtk option
2012-12-24 6:04 ` Namhyung Kim
@ 2012-12-24 13:18 ` Borislav Petkov
0 siblings, 0 replies; 16+ messages in thread
From: Borislav Petkov @ 2012-12-24 13:18 UTC (permalink / raw)
To: Namhyung Kim
Cc: Arnaldo Carvalho de Melo, Peter Zijlstra, Paul Mackerras,
Ingo Molnar, LKML, Pekka Enberg
On Mon, Dec 24, 2012 at 03:04:59PM +0900, Namhyung Kim wrote:
> 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 :-).
--
Regards/Gruss,
Boris.
Sent from a fat crate under my desk. Formatting is fine.
--
^ permalink raw reply [flat|nested] 16+ messages in thread
* [tip:perf/core] perf ui/gtk: Factor out common browser routines
2012-12-21 8:20 ` [PATCH 1/6] perf ui/gtk: Factor out common browser routines Namhyung Kim
@ 2013-01-25 11:23 ` tip-bot for Namhyung Kim
0 siblings, 0 replies; 16+ messages in thread
From: tip-bot for Namhyung Kim @ 2013-01-25 11:23 UTC (permalink / raw)
To: linux-tip-commits
Cc: acme, linux-kernel, paulus, hpa, mingo, a.p.zijlstra, penberg,
namhyung, tglx
Commit-ID: 0da41ce954840a74e7a0de9c8268bf855147e902
Gitweb: http://git.kernel.org/tip/0da41ce954840a74e7a0de9c8268bf855147e902
Author: Namhyung Kim <namhyung@kernel.org>
AuthorDate: Fri, 21 Dec 2012 17:20:13 +0900
Committer: Arnaldo Carvalho de Melo <acme@redhat.com>
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.
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Cc: Ingo Molnar <mingo@kernel.org>
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/1356078018-31905-2-git-send-email-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
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(-)
diff --git a/tools/perf/Makefile b/tools/perf/Makefile
index 1539eb4..e18163b 100644
--- a/tools/perf/Makefile
+++ b/tools/perf/Makefile
@@ -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
diff --git a/tools/perf/ui/gtk/browser.c b/tools/perf/ui/gtk/browser.c
index e59ba33..c95012c 100644
--- a/tools/perf/ui/gtk/browser.c
+++ b/tools/perf/ui/gtk/browser.c
@@ -8,15 +8,13 @@
#include <signal.h>
-#define MAX_COLUMNS 32
-
-static void perf_gtk__signal(int sig)
+void perf_gtk__signal(int sig)
{
perf_gtk__exit(false);
psignal(sig, "perf");
}
-static void perf_gtk__resize_window(GtkWidget *window)
+void perf_gtk__resize_window(GtkWidget *window)
{
GdkRectangle rect;
GdkScreen *screen;
@@ -36,7 +34,7 @@ static void perf_gtk__resize_window(GtkWidget *window)
gtk_window_resize(GTK_WINDOW(window), width, height);
}
-static const char *perf_gtk__get_percent_color(double percent)
+const char *perf_gtk__get_percent_color(double percent)
{
if (percent >= MIN_RED)
return "<span fgcolor='red'>";
@@ -45,147 +43,8 @@ static const char *perf_gtk__get_percent_color(double percent)
return NULL;
}
-#define HPP__COLOR_FN(_name, _field) \
-static int perf_gtk__hpp_color_ ## _name(struct perf_hpp *hpp, \
- struct hist_entry *he) \
-{ \
- struct hists *hists = he->hists; \
- double percent = 100.0 * he->stat._field / hists->stats.total_period; \
- const char *markup; \
- int ret = 0; \
- \
- markup = perf_gtk__get_percent_color(percent); \
- if (markup) \
- ret += scnprintf(hpp->buf, hpp->size, "%s", markup); \
- ret += scnprintf(hpp->buf + ret, hpp->size - ret, "%6.2f%%", percent); \
- if (markup) \
- ret += scnprintf(hpp->buf + ret, hpp->size - ret, "</span>"); \
- \
- return ret; \
-}
-
-HPP__COLOR_FN(overhead, period)
-HPP__COLOR_FN(overhead_sys, period_sys)
-HPP__COLOR_FN(overhead_us, period_us)
-HPP__COLOR_FN(overhead_guest_sys, period_guest_sys)
-HPP__COLOR_FN(overhead_guest_us, period_guest_us)
-
-#undef HPP__COLOR_FN
-
-void perf_gtk__init_hpp(void)
-{
- perf_hpp__column_enable(PERF_HPP__OVERHEAD);
-
- perf_hpp__init();
-
- perf_hpp__format[PERF_HPP__OVERHEAD].color =
- perf_gtk__hpp_color_overhead;
- perf_hpp__format[PERF_HPP__OVERHEAD_SYS].color =
- perf_gtk__hpp_color_overhead_sys;
- perf_hpp__format[PERF_HPP__OVERHEAD_US].color =
- perf_gtk__hpp_color_overhead_us;
- perf_hpp__format[PERF_HPP__OVERHEAD_GUEST_SYS].color =
- perf_gtk__hpp_color_overhead_guest_sys;
- perf_hpp__format[PERF_HPP__OVERHEAD_GUEST_US].color =
- perf_gtk__hpp_color_overhead_guest_us;
-}
-
-static void perf_gtk__show_hists(GtkWidget *window, struct hists *hists)
-{
- struct perf_hpp_fmt *fmt;
- GType col_types[MAX_COLUMNS];
- GtkCellRenderer *renderer;
- struct sort_entry *se;
- GtkListStore *store;
- struct rb_node *nd;
- GtkWidget *view;
- int col_idx;
- int nr_cols;
- char s[512];
-
- struct perf_hpp hpp = {
- .buf = s,
- .size = sizeof(s),
- };
-
- nr_cols = 0;
-
- perf_hpp__for_each_format(fmt)
- col_types[nr_cols++] = G_TYPE_STRING;
-
- list_for_each_entry(se, &hist_entry__sort_list, list) {
- if (se->elide)
- continue;
-
- col_types[nr_cols++] = G_TYPE_STRING;
- }
-
- store = gtk_list_store_newv(nr_cols, col_types);
-
- view = gtk_tree_view_new();
-
- renderer = gtk_cell_renderer_text_new();
-
- col_idx = 0;
-
- perf_hpp__for_each_format(fmt) {
- fmt->header(&hpp);
- gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(view),
- -1, s,
- renderer, "markup",
- col_idx++, NULL);
- }
-
- list_for_each_entry(se, &hist_entry__sort_list, list) {
- if (se->elide)
- continue;
-
- gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(view),
- -1, se->se_header,
- renderer, "text",
- col_idx++, NULL);
- }
-
- gtk_tree_view_set_model(GTK_TREE_VIEW(view), GTK_TREE_MODEL(store));
-
- g_object_unref(GTK_TREE_MODEL(store));
-
- for (nd = rb_first(&hists->entries); nd; nd = rb_next(nd)) {
- struct hist_entry *h = rb_entry(nd, struct hist_entry, rb_node);
- GtkTreeIter iter;
-
- if (h->filtered)
- continue;
-
- gtk_list_store_append(store, &iter);
-
- col_idx = 0;
-
- perf_hpp__for_each_format(fmt) {
- if (fmt->color)
- fmt->color(&hpp, h);
- else
- fmt->entry(&hpp, h);
-
- gtk_list_store_set(store, &iter, col_idx++, s, -1);
- }
-
- list_for_each_entry(se, &hist_entry__sort_list, list) {
- if (se->elide)
- continue;
-
- se->se_snprintf(h, s, ARRAY_SIZE(s),
- hists__col_len(hists, se->se_width_idx));
-
- gtk_list_store_set(store, &iter, col_idx++, s, -1);
- }
- }
-
- gtk_container_add(GTK_CONTAINER(window), view);
-}
-
#ifdef HAVE_GTK_INFO_BAR
-static GtkWidget *perf_gtk__setup_info_bar(void)
+GtkWidget *perf_gtk__setup_info_bar(void)
{
GtkWidget *info_bar;
GtkWidget *label;
@@ -212,7 +71,7 @@ static GtkWidget *perf_gtk__setup_info_bar(void)
}
#endif
-static GtkWidget *perf_gtk__setup_statusbar(void)
+GtkWidget *perf_gtk__setup_statusbar(void)
{
GtkWidget *stbar;
unsigned ctxid;
@@ -226,79 +85,3 @@ static GtkWidget *perf_gtk__setup_statusbar(void)
return stbar;
}
-
-int perf_evlist__gtk_browse_hists(struct perf_evlist *evlist,
- const char *help,
- struct hist_browser_timer *hbt __maybe_unused)
-{
- struct perf_evsel *pos;
- GtkWidget *vbox;
- GtkWidget *notebook;
- GtkWidget *info_bar;
- GtkWidget *statbar;
- GtkWidget *window;
-
- 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 report");
-
- 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();
-
- list_for_each_entry(pos, &evlist->entries, node) {
- struct hists *hists = &pos->hists;
- const char *evname = perf_evsel__name(pos);
- GtkWidget *scrolled_window;
- GtkWidget *tab_label;
-
- scrolled_window = gtk_scrolled_window_new(NULL, NULL);
-
- gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled_window),
- GTK_POLICY_AUTOMATIC,
- GTK_POLICY_AUTOMATIC);
-
- perf_gtk__show_hists(scrolled_window, hists);
-
- tab_label = gtk_label_new(evname);
-
- 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);
-
- gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
-
- ui_helpline__push(help);
-
- gtk_main();
-
- perf_gtk__deactivate_context(&pgctx);
-
- return 0;
-}
diff --git a/tools/perf/ui/gtk/gtk.h b/tools/perf/ui/gtk/gtk.h
index 856320e..5d36937 100644
--- a/tools/perf/ui/gtk/gtk.h
+++ b/tools/perf/ui/gtk/gtk.h
@@ -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;
diff --git a/tools/perf/ui/gtk/browser.c b/tools/perf/ui/gtk/hists.c
similarity index 76%
copy from tools/perf/ui/gtk/browser.c
copy to tools/perf/ui/gtk/hists.c
index e59ba33..26912f8 100644
--- a/tools/perf/ui/gtk/browser.c
+++ b/tools/perf/ui/gtk/hists.c
@@ -6,45 +6,8 @@
#include "../helpline.h"
#include "gtk.h"
-#include <signal.h>
-
#define MAX_COLUMNS 32
-static void perf_gtk__signal(int sig)
-{
- perf_gtk__exit(false);
- psignal(sig, "perf");
-}
-
-static void perf_gtk__resize_window(GtkWidget *window)
-{
- GdkRectangle rect;
- GdkScreen *screen;
- int monitor;
- int height;
- int width;
-
- screen = gtk_widget_get_screen(window);
-
- monitor = gdk_screen_get_monitor_at_window(screen, window->window);
-
- gdk_screen_get_monitor_geometry(screen, monitor, &rect);
-
- width = rect.width * 3 / 4;
- height = rect.height * 3 / 4;
-
- gtk_window_resize(GTK_WINDOW(window), width, height);
-}
-
-static const char *perf_gtk__get_percent_color(double percent)
-{
- if (percent >= MIN_RED)
- return "<span fgcolor='red'>";
- if (percent >= MIN_GREEN)
- return "<span fgcolor='dark green'>";
- return NULL;
-}
-
#define HPP__COLOR_FN(_name, _field) \
static int perf_gtk__hpp_color_ ## _name(struct perf_hpp *hpp, \
struct hist_entry *he) \
@@ -72,6 +35,7 @@ HPP__COLOR_FN(overhead_guest_us, period_guest_us)
#undef HPP__COLOR_FN
+
void perf_gtk__init_hpp(void)
{
perf_hpp__column_enable(PERF_HPP__OVERHEAD);
@@ -130,6 +94,7 @@ static void perf_gtk__show_hists(GtkWidget *window, struct hists *hists)
perf_hpp__for_each_format(fmt) {
fmt->header(&hpp);
+
gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(view),
-1, s,
renderer, "markup",
@@ -184,49 +149,6 @@ static void perf_gtk__show_hists(GtkWidget *window, struct hists *hists)
gtk_container_add(GTK_CONTAINER(window), view);
}
-#ifdef HAVE_GTK_INFO_BAR
-static GtkWidget *perf_gtk__setup_info_bar(void)
-{
- GtkWidget *info_bar;
- GtkWidget *label;
- GtkWidget *content_area;
-
- info_bar = gtk_info_bar_new();
- gtk_widget_set_no_show_all(info_bar, TRUE);
-
- label = gtk_label_new("");
- gtk_widget_show(label);
-
- content_area = gtk_info_bar_get_content_area(GTK_INFO_BAR(info_bar));
- gtk_container_add(GTK_CONTAINER(content_area), label);
-
- gtk_info_bar_add_button(GTK_INFO_BAR(info_bar), GTK_STOCK_OK,
- GTK_RESPONSE_OK);
- g_signal_connect(info_bar, "response",
- G_CALLBACK(gtk_widget_hide), NULL);
-
- pgctx->info_bar = info_bar;
- pgctx->message_label = label;
-
- return info_bar;
-}
-#endif
-
-static GtkWidget *perf_gtk__setup_statusbar(void)
-{
- GtkWidget *stbar;
- unsigned ctxid;
-
- stbar = gtk_statusbar_new();
-
- ctxid = gtk_statusbar_get_context_id(GTK_STATUSBAR(stbar),
- "perf report");
- pgctx->statbar = stbar;
- pgctx->statbar_ctx_id = ctxid;
-
- return stbar;
-}
-
int perf_evlist__gtk_browse_hists(struct perf_evlist *evlist,
const char *help,
struct hist_browser_timer *hbt __maybe_unused)
^ permalink raw reply related [flat|nested] 16+ messages in thread
* [tip:perf/core] perf ui/gtk: Setup browser window early
2012-12-21 8:20 ` [PATCH 2/6] perf ui/gtk: Setup browser window early Namhyung Kim
@ 2013-01-25 11:24 ` tip-bot for Namhyung Kim
0 siblings, 0 replies; 16+ messages in thread
From: tip-bot for Namhyung Kim @ 2013-01-25 11:24 UTC (permalink / raw)
To: linux-tip-commits
Cc: acme, linux-kernel, paulus, hpa, mingo, a.p.zijlstra, penberg,
namhyung, tglx
Commit-ID: 6bf1a295a896c8dbe8cad663c6344e8c877a0570
Gitweb: http://git.kernel.org/tip/6bf1a295a896c8dbe8cad663c6344e8c877a0570
Author: Namhyung Kim <namhyung@kernel.org>
AuthorDate: Fri, 21 Dec 2012 17:20:14 +0900
Committer: Arnaldo Carvalho de Melo <acme@redhat.com>
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.
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Cc: Ingo Molnar <mingo@kernel.org>
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/1356078018-31905-3-git-send-email-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
tools/perf/ui/gtk/hists.c | 22 +++++++++++-----------
1 file changed, 11 insertions(+), 11 deletions(-)
diff --git a/tools/perf/ui/gtk/hists.c b/tools/perf/ui/gtk/hists.c
index 26912f8..c03da79 100644
--- a/tools/perf/ui/gtk/hists.c
+++ b/tools/perf/ui/gtk/hists.c
@@ -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);
^ permalink raw reply related [flat|nested] 16+ messages in thread
end of thread, other threads:[~2013-01-25 11:25 UTC | newest]
Thread overview: 16+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-12-21 8:20 [PATCH 0/6] perf annotate: Add support for GTK+ annotation browser (v1) Namhyung Kim
2012-12-21 8:20 ` [PATCH 1/6] perf ui/gtk: Factor out common browser routines Namhyung Kim
2013-01-25 11:23 ` [tip:perf/core] " tip-bot for Namhyung Kim
2012-12-21 8:20 ` [PATCH 2/6] perf ui/gtk: Setup browser window early Namhyung Kim
2013-01-25 11:24 ` [tip:perf/core] " tip-bot for Namhyung Kim
2012-12-21 8:20 ` [PATCH 3/6] perf ui/gtk: Implement basic GTK2 annotation browser Namhyung Kim
2012-12-21 14:51 ` Arnaldo Carvalho de Melo
2012-12-24 5:55 ` Namhyung Kim
2012-12-21 8:20 ` [PATCH 4/6] perf gtk/annotate: Support multiple annotation result Namhyung Kim
2012-12-21 8:20 ` [PATCH 5/6] perf gtk/annotate: Show source lines with gray color Namhyung Kim
2012-12-21 8:20 ` [PATCH 6/6] perf annotate: Add --gtk option Namhyung Kim
2012-12-21 8:32 ` Borislav Petkov
2012-12-21 9:16 ` Namhyung Kim
2012-12-21 15:44 ` Borislav Petkov
2012-12-24 6:04 ` Namhyung Kim
2012-12-24 13:18 ` Borislav Petkov
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).