aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorArnaldo Carvalho de Melo <acme@redhat.com>2011-10-14 11:27:54 -0400
committerArnaldo Carvalho de Melo <acme@redhat.com>2011-10-14 11:49:08 -0400
commit250611cfb60ff0c50ca189da7ca727dcd78e8cee (patch)
tree9983dca2ccca7edfb18218099c5bc64dc206ab5f /tools
parent7296d66aca60a71076a5f0ffab39730e7788590f (diff)
perf ui browser: Add filter method
Its becoming common to allow the user to filter out parts of the data structure being browsed, like already done in the hists browser and in the annotate browser in the next commit, so provide it directly in the ui_browser class list_head helpers. More work required to move the equivalent routines found now in the hists browser to the rb_tree helpers. Cc: David Ahern <dsahern@gmail.com> Cc: Frederic Weisbecker <fweisbec@gmail.com> Cc: Mike Galbraith <efault@gmx.de> Cc: Paul Mackerras <paulus@samba.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Stephane Eranian <eranian@google.com> Link: http://lkml.kernel.org/n/tip-jk7danyt1d9ji4e3o2xuthpn@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools')
-rw-r--r--tools/perf/util/ui/browser.c51
-rw-r--r--tools/perf/util/ui/browser.h1
2 files changed, 43 insertions, 9 deletions
diff --git a/tools/perf/util/ui/browser.c b/tools/perf/util/ui/browser.c
index 078ceaf5f8c..a54b926efe2 100644
--- a/tools/perf/util/ui/browser.c
+++ b/tools/perf/util/ui/browser.c
@@ -42,31 +42,62 @@ void ui_browser__gotorc(struct ui_browser *self, int y, int x)
42 SLsmg_gotorc(self->y + y, self->x + x); 42 SLsmg_gotorc(self->y + y, self->x + x);
43} 43}
44 44
45static struct list_head *
46ui_browser__list_head_filter_entries(struct ui_browser *browser,
47 struct list_head *pos)
48{
49 do {
50 if (!browser->filter || !browser->filter(browser, pos))
51 return pos;
52 pos = pos->next;
53 } while (pos != browser->entries);
54
55 return NULL;
56}
57
58static struct list_head *
59ui_browser__list_head_filter_prev_entries(struct ui_browser *browser,
60 struct list_head *pos)
61{
62 do {
63 if (!browser->filter || !browser->filter(browser, pos))
64 return pos;
65 pos = pos->prev;
66 } while (pos != browser->entries);
67
68 return NULL;
69}
70
45void ui_browser__list_head_seek(struct ui_browser *self, off_t offset, int whence) 71void ui_browser__list_head_seek(struct ui_browser *self, off_t offset, int whence)
46{ 72{
47 struct list_head *head = self->entries; 73 struct list_head *head = self->entries;
48 struct list_head *pos; 74 struct list_head *pos;
49 75
76 if (self->nr_entries == 0)
77 return;
78
50 switch (whence) { 79 switch (whence) {
51 case SEEK_SET: 80 case SEEK_SET:
52 pos = head->next; 81 pos = ui_browser__list_head_filter_entries(self, head->next);
53 break; 82 break;
54 case SEEK_CUR: 83 case SEEK_CUR:
55 pos = self->top; 84 pos = self->top;
56 break; 85 break;
57 case SEEK_END: 86 case SEEK_END:
58 pos = head->prev; 87 pos = ui_browser__list_head_filter_prev_entries(self, head->prev);
59 break; 88 break;
60 default: 89 default:
61 return; 90 return;
62 } 91 }
63 92
93 assert(pos != NULL);
94
64 if (offset > 0) { 95 if (offset > 0) {
65 while (offset-- != 0) 96 while (offset-- != 0)
66 pos = pos->next; 97 pos = ui_browser__list_head_filter_entries(self, pos->next);
67 } else { 98 } else {
68 while (offset++ != 0) 99 while (offset++ != 0)
69 pos = pos->prev; 100 pos = ui_browser__list_head_filter_prev_entries(self, pos->prev);
70 } 101 }
71 102
72 self->top = pos; 103 self->top = pos;
@@ -365,15 +396,17 @@ unsigned int ui_browser__list_head_refresh(struct ui_browser *self)
365 int row = 0; 396 int row = 0;
366 397
367 if (self->top == NULL || self->top == self->entries) 398 if (self->top == NULL || self->top == self->entries)
368 self->top = head->next; 399 self->top = ui_browser__list_head_filter_entries(self, head->next);
369 400
370 pos = self->top; 401 pos = self->top;
371 402
372 list_for_each_from(pos, head) { 403 list_for_each_from(pos, head) {
373 ui_browser__gotorc(self, row, 0); 404 if (!self->filter || !self->filter(self, pos)) {
374 self->write(self, pos, row); 405 ui_browser__gotorc(self, row, 0);
375 if (++row == self->height) 406 self->write(self, pos, row);
376 break; 407 if (++row == self->height)
408 break;
409 }
377 } 410 }
378 411
379 return row; 412 return row;
diff --git a/tools/perf/util/ui/browser.h b/tools/perf/util/ui/browser.h
index 7dd9d6107d1..351c006dd4b 100644
--- a/tools/perf/util/ui/browser.h
+++ b/tools/perf/util/ui/browser.h
@@ -21,6 +21,7 @@ struct ui_browser {
21 unsigned int (*refresh)(struct ui_browser *self); 21 unsigned int (*refresh)(struct ui_browser *self);
22 void (*write)(struct ui_browser *self, void *entry, int row); 22 void (*write)(struct ui_browser *self, void *entry, int row);
23 void (*seek)(struct ui_browser *self, off_t offset, int whence); 23 void (*seek)(struct ui_browser *self, off_t offset, int whence);
24 bool (*filter)(struct ui_browser *self, void *entry);
24 u32 nr_entries; 25 u32 nr_entries;
25}; 26};
26 27