diff options
Diffstat (limited to 'tools/perf/util')
| -rw-r--r-- | tools/perf/util/include/linux/module.h | 6 | ||||
| -rw-r--r-- | tools/perf/util/ui/browser.c | 356 | ||||
| -rw-r--r-- | tools/perf/util/ui/browser.h | 52 | ||||
| -rw-r--r-- | tools/perf/util/ui/browsers/annotate.c | 302 | ||||
| -rw-r--r-- | tools/perf/util/ui/browsers/hists.c | 1138 | ||||
| -rw-r--r-- | tools/perf/util/ui/browsers/map.c | 156 | ||||
| -rw-r--r-- | tools/perf/util/ui/browsers/map.h | 6 | ||||
| -rw-r--r-- | tools/perf/util/ui/browsers/top.c | 212 | ||||
| -rw-r--r-- | tools/perf/util/ui/helpline.c | 72 | ||||
| -rw-r--r-- | tools/perf/util/ui/helpline.h | 11 | ||||
| -rw-r--r-- | tools/perf/util/ui/libslang.h | 27 | ||||
| -rw-r--r-- | tools/perf/util/ui/progress.c | 60 | ||||
| -rw-r--r-- | tools/perf/util/ui/progress.h | 11 | ||||
| -rw-r--r-- | tools/perf/util/ui/setup.c | 46 | ||||
| -rw-r--r-- | tools/perf/util/ui/ui.h | 8 | ||||
| -rw-r--r-- | tools/perf/util/ui/util.c | 130 | ||||
| -rw-r--r-- | tools/perf/util/ui/util.h | 10 |
17 files changed, 2603 insertions, 0 deletions
diff --git a/tools/perf/util/include/linux/module.h b/tools/perf/util/include/linux/module.h new file mode 100644 index 00000000000..b43e2dc21e0 --- /dev/null +++ b/tools/perf/util/include/linux/module.h | |||
| @@ -0,0 +1,6 @@ | |||
| 1 | #ifndef PERF_LINUX_MODULE_H | ||
| 2 | #define PERF_LINUX_MODULE_H | ||
| 3 | |||
| 4 | #define EXPORT_SYMBOL(name) | ||
| 5 | |||
| 6 | #endif | ||
diff --git a/tools/perf/util/ui/browser.c b/tools/perf/util/ui/browser.c new file mode 100644 index 00000000000..611219f8068 --- /dev/null +++ b/tools/perf/util/ui/browser.c | |||
| @@ -0,0 +1,356 @@ | |||
| 1 | #include "libslang.h" | ||
| 2 | #include "ui.h" | ||
| 3 | #include <linux/compiler.h> | ||
| 4 | #include <linux/list.h> | ||
| 5 | #include <linux/rbtree.h> | ||
| 6 | #include <stdlib.h> | ||
| 7 | #include <sys/ttydefaults.h> | ||
| 8 | #include "browser.h" | ||
| 9 | #include "helpline.h" | ||
| 10 | #include "../color.h" | ||
| 11 | #include "../util.h" | ||
| 12 | #include <stdio.h> | ||
| 13 | |||
| 14 | static int ui_browser__percent_color(double percent, bool current) | ||
| 15 | { | ||
| 16 | if (current) | ||
| 17 | return HE_COLORSET_SELECTED; | ||
| 18 | if (percent >= MIN_RED) | ||
| 19 | return HE_COLORSET_TOP; | ||
| 20 | if (percent >= MIN_GREEN) | ||
| 21 | return HE_COLORSET_MEDIUM; | ||
| 22 | return HE_COLORSET_NORMAL; | ||
| 23 | } | ||
| 24 | |||
| 25 | void ui_browser__set_color(struct ui_browser *self __used, int color) | ||
| 26 | { | ||
| 27 | SLsmg_set_color(color); | ||
| 28 | } | ||
| 29 | |||
| 30 | void ui_browser__set_percent_color(struct ui_browser *self, | ||
| 31 | double percent, bool current) | ||
| 32 | { | ||
| 33 | int color = ui_browser__percent_color(percent, current); | ||
| 34 | ui_browser__set_color(self, color); | ||
| 35 | } | ||
| 36 | |||
| 37 | void ui_browser__gotorc(struct ui_browser *self, int y, int x) | ||
| 38 | { | ||
| 39 | SLsmg_gotorc(self->y + y, self->x + x); | ||
| 40 | } | ||
| 41 | |||
| 42 | void ui_browser__list_head_seek(struct ui_browser *self, off_t offset, int whence) | ||
| 43 | { | ||
| 44 | struct list_head *head = self->entries; | ||
| 45 | struct list_head *pos; | ||
| 46 | |||
| 47 | switch (whence) { | ||
| 48 | case SEEK_SET: | ||
| 49 | pos = head->next; | ||
| 50 | break; | ||
| 51 | case SEEK_CUR: | ||
| 52 | pos = self->top; | ||
| 53 | break; | ||
| 54 | case SEEK_END: | ||
| 55 | pos = head->prev; | ||
| 56 | break; | ||
| 57 | default: | ||
| 58 | return; | ||
| 59 | } | ||
| 60 | |||
| 61 | if (offset > 0) { | ||
| 62 | while (offset-- != 0) | ||
| 63 | pos = pos->next; | ||
| 64 | } else { | ||
| 65 | while (offset++ != 0) | ||
| 66 | pos = pos->prev; | ||
| 67 | } | ||
| 68 | |||
| 69 | self->top = pos; | ||
| 70 | } | ||
| 71 | |||
| 72 | void ui_browser__rb_tree_seek(struct ui_browser *self, off_t offset, int whence) | ||
| 73 | { | ||
| 74 | struct rb_root *root = self->entries; | ||
| 75 | struct rb_node *nd; | ||
| 76 | |||
| 77 | switch (whence) { | ||
| 78 | case SEEK_SET: | ||
| 79 | nd = rb_first(root); | ||
| 80 | break; | ||
| 81 | case SEEK_CUR: | ||
| 82 | nd = self->top; | ||
| 83 | break; | ||
| 84 | case SEEK_END: | ||
| 85 | nd = rb_last(root); | ||
| 86 | break; | ||
| 87 | default: | ||
| 88 | return; | ||
| 89 | } | ||
| 90 | |||
| 91 | if (offset > 0) { | ||
| 92 | while (offset-- != 0) | ||
| 93 | nd = rb_next(nd); | ||
| 94 | } else { | ||
| 95 | while (offset++ != 0) | ||
| 96 | nd = rb_prev(nd); | ||
| 97 | } | ||
| 98 | |||
| 99 | self->top = nd; | ||
| 100 | } | ||
| 101 | |||
| 102 | unsigned int ui_browser__rb_tree_refresh(struct ui_browser *self) | ||
| 103 | { | ||
| 104 | struct rb_node *nd; | ||
| 105 | int row = 0; | ||
| 106 | |||
| 107 | if (self->top == NULL) | ||
| 108 | self->top = rb_first(self->entries); | ||
| 109 | |||
| 110 | nd = self->top; | ||
| 111 | |||
| 112 | while (nd != NULL) { | ||
| 113 | ui_browser__gotorc(self, row, 0); | ||
| 114 | self->write(self, nd, row); | ||
| 115 | if (++row == self->height) | ||
| 116 | break; | ||
| 117 | nd = rb_next(nd); | ||
| 118 | } | ||
| 119 | |||
| 120 | return row; | ||
| 121 | } | ||
| 122 | |||
| 123 | bool ui_browser__is_current_entry(struct ui_browser *self, unsigned row) | ||
| 124 | { | ||
| 125 | return self->top_idx + row == self->index; | ||
| 126 | } | ||
| 127 | |||
| 128 | void ui_browser__refresh_dimensions(struct ui_browser *self) | ||
| 129 | { | ||
| 130 | int cols, rows; | ||
| 131 | newtGetScreenSize(&cols, &rows); | ||
| 132 | |||
| 133 | self->width = cols - 1; | ||
| 134 | self->height = rows - 2; | ||
| 135 | self->y = 1; | ||
| 136 | self->x = 0; | ||
| 137 | } | ||
| 138 | |||
| 139 | void ui_browser__reset_index(struct ui_browser *self) | ||
| 140 | { | ||
| 141 | self->index = self->top_idx = 0; | ||
| 142 | self->seek(self, 0, SEEK_SET); | ||
| 143 | } | ||
| 144 | |||
| 145 | void ui_browser__add_exit_key(struct ui_browser *self, int key) | ||
| 146 | { | ||
| 147 | newtFormAddHotKey(self->form, key); | ||
| 148 | } | ||
| 149 | |||
| 150 | void ui_browser__add_exit_keys(struct ui_browser *self, int keys[]) | ||
| 151 | { | ||
| 152 | int i = 0; | ||
| 153 | |||
| 154 | while (keys[i] && i < 64) { | ||
| 155 | ui_browser__add_exit_key(self, keys[i]); | ||
| 156 | ++i; | ||
| 157 | } | ||
| 158 | } | ||
| 159 | |||
| 160 | void __ui_browser__show_title(struct ui_browser *browser, const char *title) | ||
| 161 | { | ||
| 162 | SLsmg_gotorc(0, 0); | ||
| 163 | ui_browser__set_color(browser, NEWT_COLORSET_ROOT); | ||
| 164 | slsmg_write_nstring(title, browser->width); | ||
| 165 | } | ||
| 166 | |||
| 167 | void ui_browser__show_title(struct ui_browser *browser, const char *title) | ||
| 168 | { | ||
| 169 | pthread_mutex_lock(&ui__lock); | ||
| 170 | __ui_browser__show_title(browser, title); | ||
| 171 | pthread_mutex_unlock(&ui__lock); | ||
| 172 | } | ||
| 173 | |||
| 174 | int ui_browser__show(struct ui_browser *self, const char *title, | ||
| 175 | const char *helpline, ...) | ||
| 176 | { | ||
| 177 | va_list ap; | ||
| 178 | int keys[] = { NEWT_KEY_UP, NEWT_KEY_DOWN, NEWT_KEY_PGUP, | ||
| 179 | NEWT_KEY_PGDN, NEWT_KEY_HOME, NEWT_KEY_END, ' ', | ||
| 180 | NEWT_KEY_LEFT, NEWT_KEY_ESCAPE, 'q', CTRL('c'), 0 }; | ||
| 181 | |||
| 182 | if (self->form != NULL) | ||
| 183 | newtFormDestroy(self->form); | ||
| 184 | |||
| 185 | ui_browser__refresh_dimensions(self); | ||
| 186 | self->form = newtForm(NULL, NULL, 0); | ||
| 187 | if (self->form == NULL) | ||
| 188 | return -1; | ||
| 189 | |||
| 190 | self->sb = newtVerticalScrollbar(self->width, 1, self->height, | ||
| 191 | HE_COLORSET_NORMAL, | ||
| 192 | HE_COLORSET_SELECTED); | ||
| 193 | if (self->sb | ||
