aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorArnaldo Carvalho de Melo <acme@redhat.com>2010-08-11 13:51:47 -0400
committerArnaldo Carvalho de Melo <acme@redhat.com>2010-08-19 18:33:16 -0400
commit8f9bbc408b6f704e84d0ae78e6093005ad58d4fe (patch)
tree2202f2199ceecbc5935eeb333bd123f55247f5b8 /tools
parentc8710ad38900153af7a3e6762e99c062cfa46443 (diff)
perf ui browser: Abstract some more slang operations
Browsers don't have to deal with absolute coordinates, just using (row, column) and leaving the rest to ui_browser is better and removes one more UI backend detail from the browsers. Also shorten the percent_color setting idiom, removing some more direct libslang calls. Cc: Frederic Weisbecker <fweisbec@gmail.com> Cc: Mike Galbraith <efault@gmx.de> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Stephane Eranian <eranian@google.com> LKML-Reference: <new-submission> Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools')
-rw-r--r--tools/perf/util/ui/browser.c47
-rw-r--r--tools/perf/util/ui/browser.h5
-rw-r--r--tools/perf/util/ui/browsers/annotate.c8
-rw-r--r--tools/perf/util/ui/browsers/hists.c12
-rw-r--r--tools/perf/util/ui/browsers/map.c3
5 files changed, 38 insertions, 37 deletions
diff --git a/tools/perf/util/ui/browser.c b/tools/perf/util/ui/browser.c
index 66f2d583d8c4..d237410c973b 100644
--- a/tools/perf/util/ui/browser.c
+++ b/tools/perf/util/ui/browser.c
@@ -1,16 +1,6 @@
1#define _GNU_SOURCE
2#include <stdio.h>
3#undef _GNU_SOURCE
4/*
5 * slang versions <= 2.0.6 have a "#if HAVE_LONG_LONG" that breaks
6 * the build if it isn't defined. Use the equivalent one that glibc
7 * has on features.h.
8 */
9#include <features.h>
10#ifndef HAVE_LONG_LONG
11#define HAVE_LONG_LONG __GLIBC_HAVE_LONG_LONG
12#endif
13#include <slang.h> 1#include <slang.h>
2#include "libslang.h"
3#include <linux/compiler.h>
14#include <linux/list.h> 4#include <linux/list.h>
15#include <linux/rbtree.h> 5#include <linux/rbtree.h>
16#include <stdlib.h> 6#include <stdlib.h>
@@ -19,17 +9,11 @@
19#include "helpline.h" 9#include "helpline.h"
20#include "../color.h" 10#include "../color.h"
21#include "../util.h" 11#include "../util.h"
22 12#include <stdio.h>
23#if SLANG_VERSION < 20104
24#define sltt_set_color(obj, name, fg, bg) \
25 SLtt_set_color(obj,(char *)name, (char *)fg, (char *)bg)
26#else
27#define sltt_set_color SLtt_set_color
28#endif
29 13
30newtComponent newt_form__new(void); 14newtComponent newt_form__new(void);
31 15
32int ui_browser__percent_color(double percent, bool current) 16static int ui_browser__percent_color(double percent, bool current)
33{ 17{
34 if (current) 18 if (current)
35 return HE_COLORSET_SELECTED; 19 return HE_COLORSET_SELECTED;
@@ -40,6 +24,23 @@ int ui_browser__percent_color(double percent, bool current)
40 return HE_COLORSET_NORMAL; 24 return HE_COLORSET_NORMAL;
41} 25}
42 26
27void ui_browser__set_color(struct ui_browser *self __used, int color)
28{
29 SLsmg_set_color(color);
30}
31
32void ui_browser__set_percent_color(struct ui_browser *self,
33 double percent, bool current)
34{
35 int color = ui_browser__percent_color(percent, current);
36 ui_browser__set_color(self, color);
37}
38
39void ui_browser__gotorc(struct ui_browser *self, int y, int x)
40{
41 SLsmg_gotorc(self->y + y, self->x + x);
42}
43
43void ui_browser__list_head_seek(struct ui_browser *self, off_t offset, int whence) 44void ui_browser__list_head_seek(struct ui_browser *self, off_t offset, int whence)
44{ 45{
45 struct list_head *head = self->entries; 46 struct list_head *head = self->entries;
@@ -111,7 +112,7 @@ unsigned int ui_browser__rb_tree_refresh(struct ui_browser *self)
111 nd = self->top; 112 nd = self->top;
112 113
113 while (nd != NULL) { 114 while (nd != NULL) {
114 SLsmg_gotorc(self->y + row, self->x); 115 ui_browser__gotorc(self, row, 0);
115 self->write(self, nd, row); 116 self->write(self, nd, row);
116 if (++row == self->height) 117 if (++row == self->height)
117 break; 118 break;
@@ -196,7 +197,7 @@ int ui_browser__refresh(struct ui_browser *self)
196 197
197 newtScrollbarSet(self->sb, self->index, self->nr_entries - 1); 198 newtScrollbarSet(self->sb, self->index, self->nr_entries - 1);
198 row = self->refresh(self); 199 row = self->refresh(self);
199 SLsmg_set_color(HE_COLORSET_NORMAL); 200 ui_browser__set_color(self, HE_COLORSET_NORMAL);
200 SLsmg_fill_region(self->y + row, self->x, 201 SLsmg_fill_region(self->y + row, self->x,
201 self->height - row, self->width, ' '); 202 self->height - row, self->width, ' ');
202 203
@@ -294,7 +295,7 @@ unsigned int ui_browser__list_head_refresh(struct ui_browser *self)
294 pos = self->top; 295 pos = self->top;
295 296
296 list_for_each_from(pos, head) { 297 list_for_each_from(pos, head) {
297 SLsmg_gotorc(self->y + row, self->x); 298 ui_browser__gotorc(self, row, 0);
298 self->write(self, pos, row); 299 self->write(self, pos, row);
299 if (++row == self->height) 300 if (++row == self->height)
300 break; 301 break;
diff --git a/tools/perf/util/ui/browser.h b/tools/perf/util/ui/browser.h
index 0b9f829214f7..27c23c277ab1 100644
--- a/tools/perf/util/ui/browser.h
+++ b/tools/perf/util/ui/browser.h
@@ -25,11 +25,14 @@ struct ui_browser {
25}; 25};
26 26
27 27
28int ui_browser__percent_color(double percent, bool current); 28void ui_browser__set_color(struct ui_browser *self, int color);
29void ui_browser__set_percent_color(struct ui_browser *self,
30 double percent, bool current);
29bool ui_browser__is_current_entry(struct ui_browser *self, unsigned row); 31bool ui_browser__is_current_entry(struct ui_browser *self, unsigned row);
30void ui_browser__refresh_dimensions(struct ui_browser *self); 32void ui_browser__refresh_dimensions(struct ui_browser *self);
31void ui_browser__reset_index(struct ui_browser *self); 33void ui_browser__reset_index(struct ui_browser *self);
32 34
35void ui_browser__gotorc(struct ui_browser *self, int y, int x);
33int ui_browser__show(struct ui_browser *self, const char *title, 36int ui_browser__show(struct ui_browser *self, const char *title,
34 const char *helpline, ...); 37 const char *helpline, ...);
35void ui_browser__hide(struct ui_browser *self); 38void ui_browser__hide(struct ui_browser *self);
diff --git a/tools/perf/util/ui/browsers/annotate.c b/tools/perf/util/ui/browsers/annotate.c
index a90273e63f4f..a00d529caaff 100644
--- a/tools/perf/util/ui/browsers/annotate.c
+++ b/tools/perf/util/ui/browsers/annotate.c
@@ -40,14 +40,12 @@ static void annotate_browser__write(struct ui_browser *self, void *entry, int ro
40 40
41 if (ol->offset != -1) { 41 if (ol->offset != -1) {
42 struct objdump_line_rb_node *olrb = objdump_line__rb(ol); 42 struct objdump_line_rb_node *olrb = objdump_line__rb(ol);
43 int color = ui_browser__percent_color(olrb->percent, current_entry); 43 ui_browser__set_percent_color(self, olrb->percent, current_entry);
44 SLsmg_set_color(color);
45 slsmg_printf(" %7.2f ", olrb->percent); 44 slsmg_printf(" %7.2f ", olrb->percent);
46 if (!current_entry) 45 if (!current_entry)
47 SLsmg_set_color(HE_COLORSET_CODE); 46 ui_browser__set_color(self, HE_COLORSET_CODE);
48 } else { 47 } else {
49 int color = ui_browser__percent_color(0, current_entry); 48 ui_browser__set_percent_color(self, 0, current_entry);
50 SLsmg_set_color(color);
51 slsmg_write_nstring(" ", 9); 49 slsmg_write_nstring(" ", 9);
52 } 50 }
53 51
diff --git a/tools/perf/util/ui/browsers/hists.c b/tools/perf/util/ui/browsers/hists.c
index dafdf6775d77..5723091134ee 100644
--- a/tools/perf/util/ui/browsers/hists.c
+++ b/tools/perf/util/ui/browsers/hists.c
@@ -341,8 +341,8 @@ static int hist_browser__show_callchain_node_rb_tree(struct hist_browser *self,
341 *is_current_entry = true; 341 *is_current_entry = true;
342 } 342 }
343 343
344 SLsmg_set_color(color); 344 ui_browser__set_color(&self->b, color);
345 SLsmg_gotorc(self->b.y + row, self->b.x); 345 ui_browser__gotorc(&self->b, row, 0);
346 slsmg_write_nstring(" ", offset + extra_offset); 346 slsmg_write_nstring(" ", offset + extra_offset);
347 slsmg_printf("%c ", folded_sign); 347 slsmg_printf("%c ", folded_sign);
348 slsmg_write_nstring(str, width); 348 slsmg_write_nstring(str, width);
@@ -405,8 +405,8 @@ static int hist_browser__show_callchain_node(struct hist_browser *self,
405 } 405 }
406 406
407 s = callchain_list__sym_name(chain, ipstr, sizeof(ipstr)); 407 s = callchain_list__sym_name(chain, ipstr, sizeof(ipstr));
408 SLsmg_gotorc(self->b.y + row, self->b.x); 408 ui_browser__gotorc(&self->b, row, 0);
409 SLsmg_set_color(color); 409 ui_browser__set_color(&self->b, color);
410 slsmg_write_nstring(" ", offset); 410 slsmg_write_nstring(" ", offset);
411 slsmg_printf("%c ", folded_sign); 411 slsmg_printf("%c ", folded_sign);
412 slsmg_write_nstring(s, width - 2); 412 slsmg_write_nstring(s, width - 2);
@@ -484,8 +484,8 @@ static int hist_browser__show_entry(struct hist_browser *self,
484 color = HE_COLORSET_NORMAL; 484 color = HE_COLORSET_NORMAL;
485 } 485 }
486 486
487 SLsmg_set_color(color); 487 ui_browser__set_color(&self->b, color);
488 SLsmg_gotorc(self->b.y + row, self->b.x); 488 ui_browser__gotorc(&self->b, row, 0);
489 if (symbol_conf.use_callchain) { 489 if (symbol_conf.use_callchain) {
490 slsmg_printf("%c ", folded_sign); 490 slsmg_printf("%c ", folded_sign);
491 width -= 2; 491 width -= 2;
diff --git a/tools/perf/util/ui/browsers/map.c b/tools/perf/util/ui/browsers/map.c
index 142b825b42bf..733daba60cd4 100644
--- a/tools/perf/util/ui/browsers/map.c
+++ b/tools/perf/util/ui/browsers/map.c
@@ -56,9 +56,8 @@ static void map_browser__write(struct ui_browser *self, void *nd, int row)
56 struct symbol *sym = rb_entry(nd, struct symbol, rb_node); 56 struct symbol *sym = rb_entry(nd, struct symbol, rb_node);
57 struct map_browser *mb = container_of(self, struct map_browser, b); 57 struct map_browser *mb = container_of(self, struct map_browser, b);
58 bool current_entry = ui_browser__is_current_entry(self, row); 58 bool current_entry = ui_browser__is_current_entry(self, row);
59 int color = ui_browser__percent_color(0, current_entry);
60 59
61 SLsmg_set_color(color); 60 ui_browser__set_percent_color(self, 0, current_entry);
62 slsmg_printf("%*llx %*llx %c ", 61 slsmg_printf("%*llx %*llx %c ",
63 mb->addrlen, sym->start, mb->addrlen, sym->end, 62 mb->addrlen, sym->start, mb->addrlen, sym->end,
64 sym->binding == STB_GLOBAL ? 'g' : 63 sym->binding == STB_GLOBAL ? 'g' :