linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Namhyung Kim <namhyung@kernel.org>
To: Arnaldo Carvalho de Melo <acme@ghostprotocols.net>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>,
	Ingo Molnar <mingo@redhat.com>, David Ahern <dsahern@gmail.com>,
	Jiri Olsa <jolsa@redhat.com>,
	Frederic Weisbecker <fweisbec@gmail.com>,
	Stephane Eranian <eranian@google.com>,
	LKML <linux-kernel@vger.kernel.org>
Subject: [PATCH 5/5] perf gtk/browser: Use hist_period_print functions
Date: Fri, 20 Jul 2012 00:42:38 +0900	[thread overview]
Message-ID: <1342712558-8185-6-git-send-email-namhyung@kernel.org> (raw)
In-Reply-To: <1342712558-8185-1-git-send-email-namhyung@kernel.org>

Now we can support color using pango markup with this change.

Signed-off-by: Namhyung Kim <namhyung@kernel.org>
---
 tools/perf/ui/gtk/browser.c |  103 ++++++++++++++++++++++++++++++++++++-------
 1 file changed, 87 insertions(+), 16 deletions(-)

diff --git a/tools/perf/ui/gtk/browser.c b/tools/perf/ui/gtk/browser.c
index ec12e0b4ded6..653b3f5d1307 100644
--- a/tools/perf/ui/gtk/browser.c
+++ b/tools/perf/ui/gtk/browser.c
@@ -35,6 +35,57 @@ 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)
+{
+	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 hist_print_context *ctx,	\
+					 struct hist_entry *he)			\
+{										\
+	double percent = 100.0 * he->_field / ctx->total_period;		\
+	const char *markup;							\
+	int ret = 0;								\
+										\
+	markup = perf_gtk__get_percent_color(percent);				\
+	if (markup)								\
+		ret += scnprintf(ctx->s, ctx->size, "%s", markup);		\
+	ret += scnprintf(ctx->s + ret, ctx->size - ret, "%5.2f%%", percent); 	\
+	if (markup)								\
+		ret += scnprintf(ctx->s + ret, ctx->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
+
+static void perf_gtk__init_hpp_functions(void)
+{
+	init_hpp_functions(NULL, false);
+
+	hpp_functions[PERF_HPP__OVERHEAD].color =
+				perf_gtk__hpp_color_overhead;
+	hpp_functions[PERF_HPP__OVERHEAD_SYS].color =
+				perf_gtk__hpp_color_overhead_sys;
+	hpp_functions[PERF_HPP__OVERHEAD_US].color =
+				perf_gtk__hpp_color_overhead_us;
+	hpp_functions[PERF_HPP__OVERHEAD_GUEST_SYS].color =
+				perf_gtk__hpp_color_overhead_guest_sys;
+	hpp_functions[PERF_HPP__OVERHEAD_GUEST_US].color =
+				perf_gtk__hpp_color_overhead_guest_us;
+}
+
 static void perf_gtk__show_hists(GtkWidget *window, struct hists *hists)
 {
 	GType col_types[MAX_COLUMNS];
@@ -42,15 +93,25 @@ static void perf_gtk__show_hists(GtkWidget *window, struct hists *hists)
 	struct sort_entry *se;
 	GtkListStore *store;
 	struct rb_node *nd;
-	u64 total_period;
 	GtkWidget *view;
-	int col_idx;
+	int i, col_idx;
 	int nr_cols;
+	char s[512];
+
+	struct hist_print_context ctx = {
+		.s		= s,
+		.size		= sizeof(s),
+		.total_period	= hists->stats.total_period,
+	};
 
 	nr_cols = 0;
 
-	/* The percentage column */
-	col_types[nr_cols++] = G_TYPE_STRING;
+	for (i = 0; i < PERF_HPP__MAX_INDEX; i++) {
+		if (!hpp_functions[i].cond)
+			continue;
+
+		col_types[nr_cols++] = G_TYPE_STRING;
+	}
 
 	list_for_each_entry(se, &hist_entry__sort_list, list) {
 		if (se->elide)
@@ -67,11 +128,17 @@ static void perf_gtk__show_hists(GtkWidget *window, struct hists *hists)
 
 	col_idx = 0;
 
-	/* The percentage column */
-	gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(view),
-						    -1, "Overhead (%)",
-						    renderer, "text",
-						    col_idx++, NULL);
+	for (i = 0; i < PERF_HPP__MAX_INDEX; i++) {
+		if (!hpp_functions[i].cond)
+			continue;
+
+		hpp_functions[i].header(&ctx);
+
+		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)
@@ -87,13 +154,9 @@ static void perf_gtk__show_hists(GtkWidget *window, struct hists *hists)
 
 	g_object_unref(GTK_TREE_MODEL(store));
 
-	total_period = hists->stats.total_period;
-
 	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;
-		double percent;
-		char s[512];
 
 		if (h->filtered)
 			continue;
@@ -102,11 +165,17 @@ static void perf_gtk__show_hists(GtkWidget *window, struct hists *hists)
 
 		col_idx = 0;
 
-		percent = (h->period * 100.0) / total_period;
+		for (i = 0; i < PERF_HPP__MAX_INDEX; i++) {
+			if (!hpp_functions[i].cond)
+				continue;
 
-		snprintf(s, ARRAY_SIZE(s), "%.2f", percent);
+			if (hpp_functions[i].color)
+				hpp_functions[i].color(&ctx, h);
+			else
+				hpp_functions[i].entry(&ctx, h);
 
-		gtk_list_store_set(store, &iter, col_idx++, s, -1);
+			gtk_list_store_set(store, &iter, col_idx++, s, -1);
+		}
 
 		list_for_each_entry(se, &hist_entry__sort_list, list) {
 			if (se->elide)
@@ -193,6 +262,8 @@ int perf_evlist__gtk_browse_hists(struct perf_evlist *evlist,
 	if (!pgctx)
 		return -1;
 
+	perf_gtk__init_hpp_functions();
+
 	vbox = gtk_vbox_new(FALSE, 0);
 
 	notebook = gtk_notebook_new();
-- 
1.7.9.2


  parent reply	other threads:[~2012-07-19 15:44 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-07-19 15:42 [PATCH 0/5] perf report: Cleanup and refactor hist printing code Namhyung Kim
2012-07-19 15:42 ` [PATCH 1/5] perf tools: Separate out hist print functions Namhyung Kim
2012-07-19 15:42 ` [PATCH 2/5] perf tools: Refactor some functions Namhyung Kim
2012-07-19 15:42 ` [PATCH 3/5] perf tools: Introduce hist_period_print functions Namhyung Kim
2012-07-19 15:42 ` [PATCH 4/5] perf ui/browser: Use " Namhyung Kim
2012-07-19 15:42 ` Namhyung Kim [this message]
2012-07-20 13:43   ` [PATCH 5/5] perf gtk/browser: " Pekka Enberg
2012-07-21  0:20     ` Namhyung Kim

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1342712558-8185-6-git-send-email-namhyung@kernel.org \
    --to=namhyung@kernel.org \
    --cc=a.p.zijlstra@chello.nl \
    --cc=acme@ghostprotocols.net \
    --cc=dsahern@gmail.com \
    --cc=eranian@google.com \
    --cc=fweisbec@gmail.com \
    --cc=jolsa@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).