blob: 59a63e4405fc44feea4e1bd9d31dde31b3e2c42d [file] [log] [blame]
Arnaldo Carvalho de Melof9224c52010-03-11 20:12:44 -03001#define _GNU_SOURCE
2#include <stdio.h>
3#undef _GNU_SOURCE
4
Arnaldo Carvalho de Meloef7b93a2010-05-11 23:18:06 -03005#include <slang.h>
Arnaldo Carvalho de Melof9224c52010-03-11 20:12:44 -03006#include <stdlib.h>
7#include <newt.h>
Arnaldo Carvalho de Melo7081e082010-03-12 10:48:12 -03008#include <sys/ttydefaults.h>
Arnaldo Carvalho de Melof9224c52010-03-11 20:12:44 -03009
10#include "cache.h"
11#include "hist.h"
Arnaldo Carvalho de Melo3e1bbdc32010-05-14 20:05:21 -030012#include "pstack.h"
Arnaldo Carvalho de Melof9224c52010-03-11 20:12:44 -030013#include "session.h"
14#include "sort.h"
15#include "symbol.h"
16
Arnaldo Carvalho de Melo5f4d3f82010-03-26 21:16:22 -030017struct ui_progress {
18 newtComponent form, scale;
19};
20
21struct ui_progress *ui_progress__new(const char *title, u64 total)
22{
23 struct ui_progress *self = malloc(sizeof(*self));
24
25 if (self != NULL) {
26 int cols;
27 newtGetScreenSize(&cols, NULL);
28 cols -= 4;
29 newtCenteredWindow(cols, 1, title);
30 self->form = newtForm(NULL, NULL, 0);
31 if (self->form == NULL)
32 goto out_free_self;
33 self->scale = newtScale(0, 0, cols, total);
34 if (self->scale == NULL)
35 goto out_free_form;
Arnaldo Carvalho de Melo7f826452010-05-10 10:51:25 -030036 newtFormAddComponent(self->form, self->scale);
Arnaldo Carvalho de Melo5f4d3f82010-03-26 21:16:22 -030037 newtRefresh();
38 }
39
40 return self;
41
42out_free_form:
43 newtFormDestroy(self->form);
44out_free_self:
45 free(self);
46 return NULL;
47}
48
49void ui_progress__update(struct ui_progress *self, u64 curr)
50{
51 newtScaleSet(self->scale, curr);
52 newtRefresh();
53}
54
55void ui_progress__delete(struct ui_progress *self)
56{
57 newtFormDestroy(self->form);
58 newtPopWindow();
59 free(self);
60}
61
Arnaldo Carvalho de Melo3798ed72010-05-11 18:01:23 -030062static void ui_helpline__pop(void)
63{
64 newtPopHelpLine();
65}
66
67static void ui_helpline__push(const char *msg)
68{
69 newtPushHelpLine(msg);
70}
71
72static void ui_helpline__vpush(const char *fmt, va_list ap)
73{
74 char *s;
75
76 if (vasprintf(&s, fmt, ap) < 0)
77 vfprintf(stderr, fmt, ap);
78 else {
79 ui_helpline__push(s);
80 free(s);
81 }
82}
83
84static void ui_helpline__fpush(const char *fmt, ...)
85{
86 va_list ap;
87
88 va_start(ap, fmt);
89 ui_helpline__vpush(fmt, ap);
90 va_end(ap);
91}
92
93static void ui_helpline__puts(const char *msg)
94{
95 ui_helpline__pop();
96 ui_helpline__push(msg);
97}
98
Arnaldo Carvalho de Melo5f4d3f82010-03-26 21:16:22 -030099static char browser__last_msg[1024];
100
101int browser__show_help(const char *format, va_list ap)
102{
103 int ret;
104 static int backlog;
105
106 ret = vsnprintf(browser__last_msg + backlog,
107 sizeof(browser__last_msg) - backlog, format, ap);
108 backlog += ret;
109
110 if (browser__last_msg[backlog - 1] == '\n') {
Arnaldo Carvalho de Melo3798ed72010-05-11 18:01:23 -0300111 ui_helpline__puts(browser__last_msg);
Arnaldo Carvalho de Melo5f4d3f82010-03-26 21:16:22 -0300112 newtRefresh();
113 backlog = 0;
114 }
115
116 return ret;
117}
118
Arnaldo Carvalho de Melo7081e082010-03-12 10:48:12 -0300119static void newt_form__set_exit_keys(newtComponent self)
120{
Arnaldo Carvalho de Meloa308f3a2010-05-16 20:29:38 -0300121 newtFormAddHotKey(self, NEWT_KEY_LEFT);
Arnaldo Carvalho de Melo7081e082010-03-12 10:48:12 -0300122 newtFormAddHotKey(self, NEWT_KEY_ESCAPE);
123 newtFormAddHotKey(self, 'Q');
124 newtFormAddHotKey(self, 'q');
125 newtFormAddHotKey(self, CTRL('c'));
126}
127
128static newtComponent newt_form__new(void)
129{
130 newtComponent self = newtForm(NULL, NULL, 0);
131 if (self)
132 newt_form__set_exit_keys(self);
133 return self;
134}
135
Arnaldo Carvalho de Melo83753192010-04-03 16:30:44 -0300136static int popup_menu(int argc, char * const argv[])
Arnaldo Carvalho de Melo53c54012010-03-24 16:40:14 -0300137{
138 struct newtExitStruct es;
139 int i, rc = -1, max_len = 5;
140 newtComponent listbox, form = newt_form__new();
141
142 if (form == NULL)
143 return -1;
144
145 listbox = newtListbox(0, 0, argc, NEWT_FLAG_RETURNEXIT);
146 if (listbox == NULL)
147 goto out_destroy_form;
148
Arnaldo Carvalho de Melo7f826452010-05-10 10:51:25 -0300149 newtFormAddComponent(form, listbox);
Arnaldo Carvalho de Melo53c54012010-03-24 16:40:14 -0300150
151 for (i = 0; i < argc; ++i) {
152 int len = strlen(argv[i]);
153 if (len > max_len)
154 max_len = len;
155 if (newtListboxAddEntry(listbox, argv[i], (void *)(long)i))
156 goto out_destroy_form;
157 }
158
159 newtCenteredWindow(max_len, argc, NULL);
160 newtFormRun(form, &es);
161 rc = newtListboxGetCurrent(listbox) - NULL;
162 if (es.reason == NEWT_EXIT_HOTKEY)
163 rc = -1;
164 newtPopWindow();
165out_destroy_form:
166 newtFormDestroy(form);
167 return rc;
168}
169
170static bool dialog_yesno(const char *msg)
171{
172 /* newtWinChoice should really be accepting const char pointers... */
173 char yes[] = "Yes", no[] = "No";
Arnaldo Carvalho de Meloc0ed55d2010-04-05 12:04:23 -0300174 return newtWinChoice(NULL, yes, no, (char *)msg) == 1;
Arnaldo Carvalho de Melo53c54012010-03-24 16:40:14 -0300175}
176
Arnaldo Carvalho de Meloef7b93a2010-05-11 23:18:06 -0300177#define HE_COLORSET_TOP 50
178#define HE_COLORSET_MEDIUM 51
179#define HE_COLORSET_NORMAL 52
180#define HE_COLORSET_SELECTED 53
181#define HE_COLORSET_CODE 54
182
183static int ui_browser__percent_color(double percent, bool current)
184{
185 if (current)
186 return HE_COLORSET_SELECTED;
187 if (percent >= MIN_RED)
188 return HE_COLORSET_TOP;
189 if (percent >= MIN_GREEN)
190 return HE_COLORSET_MEDIUM;
191 return HE_COLORSET_NORMAL;
192}
193
194struct ui_browser {
195 newtComponent form, sb;
196 u64 index, first_visible_entry_idx;
197 void *first_visible_entry, *entries;
198 u16 top, left, width, height;
199 void *priv;
200 u32 nr_entries;
201};
202
203static void ui_browser__refresh_dimensions(struct ui_browser *self)
204{
205 int cols, rows;
206 newtGetScreenSize(&cols, &rows);
207
208 if (self->width > cols - 4)
209 self->width = cols - 4;
210 self->height = rows - 5;
211 if (self->height > self->nr_entries)
212 self->height = self->nr_entries;
213 self->top = (rows - self->height) / 2;
214 self->left = (cols - self->width) / 2;
215}
216
217static void ui_browser__reset_index(struct ui_browser *self)
218{
219 self->index = self->first_visible_entry_idx = 0;
220 self->first_visible_entry = NULL;
221}
222
223static int objdump_line__show(struct objdump_line *self, struct list_head *head,
224 int width, struct hist_entry *he, int len,
225 bool current_entry)
226{
227 if (self->offset != -1) {
228 struct symbol *sym = he->ms.sym;
229 unsigned int hits = 0;
230 double percent = 0.0;
231 int color;
232 struct sym_priv *priv = symbol__priv(sym);
233 struct sym_ext *sym_ext = priv->ext;
234 struct sym_hist *h = priv->hist;
235 s64 offset = self->offset;
236 struct objdump_line *next = objdump__get_next_ip_line(head, self);
237
238 while (offset < (s64)len &&
239 (next == NULL || offset < next->offset)) {
240 if (sym_ext) {
241 percent += sym_ext[offset].percent;
242 } else
243 hits += h->ip[offset];
244
245 ++offset;
246 }
247
248 if (sym_ext == NULL && h->sum)
249 percent = 100.0 * hits / h->sum;
250
251 color = ui_browser__percent_color(percent, current_entry);
252 SLsmg_set_color(color);
253 SLsmg_printf(" %7.2f ", percent);
254 if (!current_entry)
255 SLsmg_set_color(HE_COLORSET_CODE);
256 } else {
257 int color = ui_browser__percent_color(0, current_entry);
258 SLsmg_set_color(color);
259 SLsmg_write_nstring(" ", 9);
260 }
261
262 SLsmg_write_char(':');
263 SLsmg_write_nstring(" ", 8);
264 if (!*self->line)
265 SLsmg_write_nstring(" ", width - 18);
266 else
267 SLsmg_write_nstring(self->line, width - 18);
268
269 return 0;
270}
271
272static int ui_browser__refresh_entries(struct ui_browser *self)
273{
274 struct objdump_line *pos;
275 struct list_head *head = self->entries;
276 struct hist_entry *he = self->priv;
277 int row = 0;
278 int len = he->ms.sym->end - he->ms.sym->start;
279
280 if (self->first_visible_entry == NULL || self->first_visible_entry == self->entries)
281 self->first_visible_entry = head->next;
282
283 pos = list_entry(self->first_visible_entry, struct objdump_line, node);
284
285 list_for_each_entry_from(pos, head, node) {
286 bool current_entry = (self->first_visible_entry_idx + row) == self->index;
287 SLsmg_gotorc(self->top + row, self->left);
288 objdump_line__show(pos, head, self->width,
289 he, len, current_entry);
290 if (++row == self->height)
291 break;
292 }
293
294 SLsmg_set_color(HE_COLORSET_NORMAL);
295 SLsmg_fill_region(self->top + row, self->left,
296 self->height - row, self->width, ' ');
297
298 return 0;
299}
300
301static int ui_browser__run(struct ui_browser *self, const char *title,
302 struct newtExitStruct *es)
303{
304 if (self->form) {
305 newtFormDestroy(self->form);
306 newtPopWindow();
307 }
308
309 ui_browser__refresh_dimensions(self);
310 newtCenteredWindow(self->width + 2, self->height, title);
311 self->form = newt_form__new();
312 if (self->form == NULL)
313 return -1;
314
315 self->sb = newtVerticalScrollbar(self->width + 1, 0, self->height,
316 HE_COLORSET_NORMAL,
317 HE_COLORSET_SELECTED);
318 if (self->sb == NULL)
319 return -1;
320
321 newtFormAddHotKey(self->form, NEWT_KEY_UP);
322 newtFormAddHotKey(self->form, NEWT_KEY_DOWN);
323 newtFormAddHotKey(self->form, NEWT_KEY_PGUP);
324 newtFormAddHotKey(self->form, NEWT_KEY_PGDN);
325 newtFormAddHotKey(self->form, NEWT_KEY_HOME);
326 newtFormAddHotKey(self->form, NEWT_KEY_END);
327
328 if (ui_browser__refresh_entries(self) < 0)
329 return -1;
330 newtFormAddComponent(self->form, self->sb);
331
332 while (1) {
333 unsigned int offset;
334
335 newtFormRun(self->form, es);
336
337 if (es->reason != NEWT_EXIT_HOTKEY)
338 break;
339 switch (es->u.key) {
340 case NEWT_KEY_DOWN:
341 if (self->index == self->nr_entries - 1)
342 break;
343 ++self->index;
344 if (self->index == self->first_visible_entry_idx + self->height) {
345 struct list_head *pos = self->first_visible_entry;
346 ++self->first_visible_entry_idx;
347 self->first_visible_entry = pos->next;
348 }
349 break;
350 case NEWT_KEY_UP:
351 if (self->index == 0)
352 break;
353 --self->index;
354 if (self->index < self->first_visible_entry_idx) {
355 struct list_head *pos = self->first_visible_entry;
356 --self->first_visible_entry_idx;
357 self->first_visible_entry = pos->prev;
358 }
359 break;
360 case NEWT_KEY_PGDN:
361 if (self->first_visible_entry_idx + self->height > self->nr_entries - 1)
362 break;
363
364 offset = self->height;
365 if (self->index + offset > self->nr_entries - 1)
366 offset = self->nr_entries - 1 - self->index;
367 self->index += offset;
368 self->first_visible_entry_idx += offset;
369
370 while (offset--) {
371 struct list_head *pos = self->first_visible_entry;
372 self->first_visible_entry = pos->next;
373 }
374
375 break;
376 case NEWT_KEY_PGUP:
377 if (self->first_visible_entry_idx == 0)
378 break;
379
380 if (self->first_visible_entry_idx < self->height)
381 offset = self->first_visible_entry_idx;
382 else
383 offset = self->height;
384
385 self->index -= offset;
386 self->first_visible_entry_idx -= offset;
387
388 while (offset--) {
389 struct list_head *pos = self->first_visible_entry;
390 self->first_visible_entry = pos->prev;
391 }
392 break;
393 case NEWT_KEY_HOME:
394 ui_browser__reset_index(self);
395 break;
396 case NEWT_KEY_END: {
397 struct list_head *head = self->entries;
398 offset = self->height - 1;
399
400 if (offset > self->nr_entries)
401 offset = self->nr_entries;
402
403 self->index = self->first_visible_entry_idx = self->nr_entries - 1 - offset;
404 self->first_visible_entry = head->prev;
405 while (offset-- != 0) {
406 struct list_head *pos = self->first_visible_entry;
407 self->first_visible_entry = pos->prev;
408 }
409 }
410 break;
411 case NEWT_KEY_ESCAPE:
Arnaldo Carvalho de Melo60553902010-05-15 20:40:34 -0300412 case NEWT_KEY_LEFT:
Arnaldo Carvalho de Meloef7b93a2010-05-11 23:18:06 -0300413 case CTRL('c'):
414 case 'Q':
415 case 'q':
416 return 0;
417 default:
418 continue;
419 }
420 if (ui_browser__refresh_entries(self) < 0)
421 return -1;
422 }
423 return 0;
424}
425
Arnaldo Carvalho de Melo4ded2b22010-03-22 17:52:49 -0300426/*
427 * When debugging newt problems it was useful to be able to "unroll"
428 * the calls to newtCheckBoxTreeAdd{Array,Item}, so that we can generate
429 * a source file with the sequence of calls to these methods, to then
430 * tweak the arrays to get the intended results, so I'm keeping this code
431 * here, may be useful again in the future.
432 */
433#undef NEWT_DEBUG
434
435static void newt_checkbox_tree__add(newtComponent tree, const char *str,
436 void *priv, int *indexes)
Arnaldo Carvalho de Melof9224c52010-03-11 20:12:44 -0300437{
Arnaldo Carvalho de Melo4ded2b22010-03-22 17:52:49 -0300438#ifdef NEWT_DEBUG
439 /* Print the newtCheckboxTreeAddArray to tinker with its index arrays */
440 int i = 0, len = 40 - strlen(str);
441
442 fprintf(stderr,
443 "\tnewtCheckboxTreeAddItem(tree, %*.*s\"%s\", (void *)%p, 0, ",
444 len, len, " ", str, priv);
445 while (indexes[i] != NEWT_ARG_LAST) {
446 if (indexes[i] != NEWT_ARG_APPEND)
447 fprintf(stderr, " %d,", indexes[i]);
448 else
449 fprintf(stderr, " %s,", "NEWT_ARG_APPEND");
450 ++i;
451 }
452 fprintf(stderr, " %s", " NEWT_ARG_LAST);\n");
453 fflush(stderr);
454#endif
455 newtCheckboxTreeAddArray(tree, str, priv, 0, indexes);
456}
457
458static char *callchain_list__sym_name(struct callchain_list *self,
459 char *bf, size_t bfsize)
460{
Arnaldo Carvalho de Melob3c9ac02010-03-24 16:40:18 -0300461 if (self->ms.sym)
462 return self->ms.sym->name;
Arnaldo Carvalho de Melo4ded2b22010-03-22 17:52:49 -0300463
464 snprintf(bf, bfsize, "%#Lx", self->ip);
465 return bf;
466}
467
468static void __callchain__append_graph_browser(struct callchain_node *self,
469 newtComponent tree, u64 total,
470 int *indexes, int depth)
471{
472 struct rb_node *node;
473 u64 new_total, remaining;
474 int idx = 0;
475
476 if (callchain_param.mode == CHAIN_GRAPH_REL)
477 new_total = self->children_hit;
478 else
479 new_total = total;
480
481 remaining = new_total;
482 node = rb_first(&self->rb_root);
483 while (node) {
484 struct callchain_node *child = rb_entry(node, struct callchain_node, rb_node);
485 struct rb_node *next = rb_next(node);
486 u64 cumul = cumul_hits(child);
487 struct callchain_list *chain;
488 int first = true, printed = 0;
489 int chain_idx = -1;
490 remaining -= cumul;
491
492 indexes[depth] = NEWT_ARG_APPEND;
493 indexes[depth + 1] = NEWT_ARG_LAST;
494
495 list_for_each_entry(chain, &child->val, list) {
496 char ipstr[BITS_PER_LONG / 4 + 1],
497 *alloc_str = NULL;
498 const char *str = callchain_list__sym_name(chain, ipstr, sizeof(ipstr));
499
500 if (first) {
501 double percent = cumul * 100.0 / new_total;
502
503 first = false;
504 if (asprintf(&alloc_str, "%2.2f%% %s", percent, str) < 0)
505 str = "Not enough memory!";
506 else
507 str = alloc_str;
508 } else {
509 indexes[depth] = idx;
510 indexes[depth + 1] = NEWT_ARG_APPEND;
511 indexes[depth + 2] = NEWT_ARG_LAST;
512 ++chain_idx;
513 }
Arnaldo Carvalho de Melod5679ae2010-03-24 16:40:19 -0300514 newt_checkbox_tree__add(tree, str, &chain->ms, indexes);
Arnaldo Carvalho de Melo4ded2b22010-03-22 17:52:49 -0300515 free(alloc_str);
516 ++printed;
517 }
518
519 indexes[depth] = idx;
520 if (chain_idx != -1)
521 indexes[depth + 1] = chain_idx;
522 if (printed != 0)
523 ++idx;
524 __callchain__append_graph_browser(child, tree, new_total, indexes,
525 depth + (chain_idx != -1 ? 2 : 1));
526 node = next;
527 }
528}
529
530static void callchain__append_graph_browser(struct callchain_node *self,
531 newtComponent tree, u64 total,
532 int *indexes, int parent_idx)
533{
534 struct callchain_list *chain;
535 int i = 0;
536
537 indexes[1] = NEWT_ARG_APPEND;
538 indexes[2] = NEWT_ARG_LAST;
539
540 list_for_each_entry(chain, &self->val, list) {
541 char ipstr[BITS_PER_LONG / 4 + 1], *str;
542
543 if (chain->ip >= PERF_CONTEXT_MAX)
544 continue;
545
546 if (!i++ && sort__first_dimension == SORT_SYM)
547 continue;
548
549 str = callchain_list__sym_name(chain, ipstr, sizeof(ipstr));
Arnaldo Carvalho de Melod5679ae2010-03-24 16:40:19 -0300550 newt_checkbox_tree__add(tree, str, &chain->ms, indexes);
Arnaldo Carvalho de Melo4ded2b22010-03-22 17:52:49 -0300551 }
552
553 indexes[1] = parent_idx;
554 indexes[2] = NEWT_ARG_APPEND;
555 indexes[3] = NEWT_ARG_LAST;
556 __callchain__append_graph_browser(self, tree, total, indexes, 2);
557}
558
559static void hist_entry__append_callchain_browser(struct hist_entry *self,
560 newtComponent tree, u64 total, int parent_idx)
561{
562 struct rb_node *rb_node;
563 int indexes[1024] = { [0] = parent_idx, };
564 int idx = 0;
565 struct callchain_node *chain;
566
567 rb_node = rb_first(&self->sorted_chain);
568 while (rb_node) {
569 chain = rb_entry(rb_node, struct callchain_node, rb_node);
570 switch (callchain_param.mode) {
571 case CHAIN_FLAT:
572 break;
573 case CHAIN_GRAPH_ABS: /* falldown */
574 case CHAIN_GRAPH_REL:
575 callchain__append_graph_browser(chain, tree, total, indexes, idx++);
576 break;
577 case CHAIN_NONE:
578 default:
579 break;
580 }
581 rb_node = rb_next(rb_node);
582 }
583}
584
Arnaldo Carvalho de Melo4ded2b22010-03-22 17:52:49 -0300585static size_t hist_entry__append_browser(struct hist_entry *self,
586 newtComponent tree, u64 total)
587{
Arnaldo Carvalho de Meloa4e3b952010-03-31 11:33:40 -0300588 char s[256];
589 size_t ret;
Arnaldo Carvalho de Melof9224c52010-03-11 20:12:44 -0300590
591 if (symbol_conf.exclude_other && !self->parent)
592 return 0;
593
Arnaldo Carvalho de Meloa4e3b952010-03-31 11:33:40 -0300594 ret = hist_entry__snprintf(self, s, sizeof(s), NULL,
595 false, 0, false, total);
Arnaldo Carvalho de Melo4ded2b22010-03-22 17:52:49 -0300596 if (symbol_conf.use_callchain) {
597 int indexes[2];
598
599 indexes[0] = NEWT_ARG_APPEND;
600 indexes[1] = NEWT_ARG_LAST;
Arnaldo Carvalho de Melod5679ae2010-03-24 16:40:19 -0300601 newt_checkbox_tree__add(tree, s, &self->ms, indexes);
Arnaldo Carvalho de Melo4ded2b22010-03-22 17:52:49 -0300602 } else
Arnaldo Carvalho de Melod5679ae2010-03-24 16:40:19 -0300603 newtListboxAppendEntry(tree, s, &self->ms);
Arnaldo Carvalho de Melo4ded2b22010-03-22 17:52:49 -0300604
Arnaldo Carvalho de Meloa4e3b952010-03-31 11:33:40 -0300605 return ret;
Arnaldo Carvalho de Melof9224c52010-03-11 20:12:44 -0300606}
607
Arnaldo Carvalho de Meloef7b93a2010-05-11 23:18:06 -0300608static void hist_entry__annotate_browser(struct hist_entry *self)
Arnaldo Carvalho de Melof9224c52010-03-11 20:12:44 -0300609{
Arnaldo Carvalho de Meloef7b93a2010-05-11 23:18:06 -0300610 struct ui_browser browser;
Arnaldo Carvalho de Melof9224c52010-03-11 20:12:44 -0300611 struct newtExitStruct es;
Arnaldo Carvalho de Meloef7b93a2010-05-11 23:18:06 -0300612 struct objdump_line *pos, *n;
613 LIST_HEAD(head);
Arnaldo Carvalho de Melof9224c52010-03-11 20:12:44 -0300614
Arnaldo Carvalho de Meloef7b93a2010-05-11 23:18:06 -0300615 if (self->ms.sym == NULL)
Arnaldo Carvalho de Melof9224c52010-03-11 20:12:44 -0300616 return;
617
Arnaldo Carvalho de Meloef7b93a2010-05-11 23:18:06 -0300618 if (hist_entry__annotate(self, &head) < 0)
Arnaldo Carvalho de Melof9224c52010-03-11 20:12:44 -0300619 return;
620
Arnaldo Carvalho de Melo60553902010-05-15 20:40:34 -0300621 ui_helpline__push("Press <- or ESC to exit");
Arnaldo Carvalho de Melof9224c52010-03-11 20:12:44 -0300622
Arnaldo Carvalho de Meloef7b93a2010-05-11 23:18:06 -0300623 memset(&browser, 0, sizeof(browser));
624 browser.entries = &head;
625 browser.priv = self;
626 list_for_each_entry(pos, &head, node) {
627 size_t line_len = strlen(pos->line);
628 if (browser.width < line_len)
629 browser.width = line_len;
630 ++browser.nr_entries;
Arnaldo Carvalho de Melof9224c52010-03-11 20:12:44 -0300631 }
Arnaldo Carvalho de Melof9224c52010-03-11 20:12:44 -0300632
Arnaldo Carvalho de Meloef7b93a2010-05-11 23:18:06 -0300633 browser.width += 18; /* Percentage */
634 ui_browser__run(&browser, self->ms.sym->name, &es);
635 newtFormDestroy(browser.form);
Arnaldo Carvalho de Melof9224c52010-03-11 20:12:44 -0300636 newtPopWindow();
Arnaldo Carvalho de Meloef7b93a2010-05-11 23:18:06 -0300637 list_for_each_entry_safe(pos, n, &head, node) {
638 list_del(&pos->node);
639 objdump_line__free(pos);
640 }
Arnaldo Carvalho de Melo3798ed72010-05-11 18:01:23 -0300641 ui_helpline__pop();
Arnaldo Carvalho de Melof9224c52010-03-11 20:12:44 -0300642}
643
Arnaldo Carvalho de Melo53c54012010-03-24 16:40:14 -0300644static const void *newt__symbol_tree_get_current(newtComponent self)
645{
646 if (symbol_conf.use_callchain)
647 return newtCheckboxTreeGetCurrent(self);
648 return newtListboxGetCurrent(self);
649}
650
Arnaldo Carvalho de Meloe65713e2010-04-03 11:25:56 -0300651static void hist_browser__selection(newtComponent self, void *data)
Arnaldo Carvalho de Melo53c54012010-03-24 16:40:14 -0300652{
Arnaldo Carvalho de Melod5679ae2010-03-24 16:40:19 -0300653 const struct map_symbol **symbol_ptr = data;
Arnaldo Carvalho de Melo53c54012010-03-24 16:40:14 -0300654 *symbol_ptr = newt__symbol_tree_get_current(self);
655}
656
Arnaldo Carvalho de Meloe65713e2010-04-03 11:25:56 -0300657struct hist_browser {
658 newtComponent form, tree;
Arnaldo Carvalho de Melod5679ae2010-03-24 16:40:19 -0300659 const struct map_symbol *selection;
Arnaldo Carvalho de Meloe65713e2010-04-03 11:25:56 -0300660};
661
662static struct hist_browser *hist_browser__new(void)
663{
664 struct hist_browser *self = malloc(sizeof(*self));
665
Arnaldo Carvalho de Melo83753192010-04-03 16:30:44 -0300666 if (self != NULL)
667 self->form = NULL;
Arnaldo Carvalho de Meloe65713e2010-04-03 11:25:56 -0300668
669 return self;
670}
671
672static void hist_browser__delete(struct hist_browser *self)
673{
674 newtFormDestroy(self->form);
675 newtPopWindow();
676 free(self);
677}
678
Arnaldo Carvalho de Melob09e0192010-05-11 11:10:15 -0300679static int hist_browser__populate(struct hist_browser *self, struct hists *hists,
680 const char *title)
Arnaldo Carvalho de Meloe65713e2010-04-03 11:25:56 -0300681{
682 int max_len = 0, idx, cols, rows;
Arnaldo Carvalho de Melo5f4d3f82010-03-26 21:16:22 -0300683 struct ui_progress *progress;
Arnaldo Carvalho de Meloe65713e2010-04-03 11:25:56 -0300684 struct rb_node *nd;
685 u64 curr_hist = 0;
Arnaldo Carvalho de Meloc82ee822010-05-14 14:19:35 -0300686 char seq[] = ".", unit;
Arnaldo Carvalho de Melo83753192010-04-03 16:30:44 -0300687 char str[256];
Arnaldo Carvalho de Meloc82ee822010-05-14 14:19:35 -0300688 unsigned long nr_events = hists->stats.nr_events[PERF_RECORD_SAMPLE];
Arnaldo Carvalho de Melo83753192010-04-03 16:30:44 -0300689
690 if (self->form) {
691 newtFormDestroy(self->form);
692 newtPopWindow();
693 }
694
Arnaldo Carvalho de Meloc82ee822010-05-14 14:19:35 -0300695 nr_events = convert_unit(nr_events, &unit);
696 snprintf(str, sizeof(str), "Events: %lu%c ",
697 nr_events, unit);
Arnaldo Carvalho de Melo83753192010-04-03 16:30:44 -0300698 newtDrawRootText(0, 0, str);
699
700 newtGetScreenSize(NULL, &rows);
701
702 if (symbol_conf.use_callchain)
703 self->tree = newtCheckboxTreeMulti(0, 0, rows - 5, seq,
704 NEWT_FLAG_SCROLL);
705 else
706 self->tree = newtListbox(0, 0, rows - 5,
707 (NEWT_FLAG_SCROLL |
708 NEWT_FLAG_RETURNEXIT));
709
710 newtComponentAddCallback(self->tree, hist_browser__selection,
711 &self->selection);
Arnaldo Carvalho de Melo5f4d3f82010-03-26 21:16:22 -0300712
Arnaldo Carvalho de Melob09e0192010-05-11 11:10:15 -0300713 progress = ui_progress__new("Adding entries to the browser...",
714 hists->nr_entries);
Arnaldo Carvalho de Melo5f4d3f82010-03-26 21:16:22 -0300715 if (progress == NULL)
716 return -1;
Arnaldo Carvalho de Melof9224c52010-03-11 20:12:44 -0300717
Arnaldo Carvalho de Melo4ded2b22010-03-22 17:52:49 -0300718 idx = 0;
Arnaldo Carvalho de Melob09e0192010-05-11 11:10:15 -0300719 for (nd = rb_first(&hists->entries); nd; nd = rb_next(nd)) {
Arnaldo Carvalho de Melof9224c52010-03-11 20:12:44 -0300720 struct hist_entry *h = rb_entry(nd, struct hist_entry, rb_node);
Arnaldo Carvalho de Melo83753192010-04-03 16:30:44 -0300721 int len;
722
723 if (h->filtered)
724 continue;
725
Arnaldo Carvalho de Melocee75ac2010-05-14 13:16:55 -0300726 len = hist_entry__append_browser(h, self->tree, hists->stats.total_period);
Arnaldo Carvalho de Melof9224c52010-03-11 20:12:44 -0300727 if (len > max_len)
728 max_len = len;
Arnaldo Carvalho de Melod5679ae2010-03-24 16:40:19 -0300729 if (symbol_conf.use_callchain)
Arnaldo Carvalho de Meloe65713e2010-04-03 11:25:56 -0300730 hist_entry__append_callchain_browser(h, self->tree,
Arnaldo Carvalho de Melocee75ac2010-05-14 13:16:55 -0300731 hists->stats.total_period, idx++);
Arnaldo Carvalho de Melo5f4d3f82010-03-26 21:16:22 -0300732 ++curr_hist;
733 if (curr_hist % 5)
734 ui_progress__update(progress, curr_hist);
Arnaldo Carvalho de Melof9224c52010-03-11 20:12:44 -0300735 }
736
Arnaldo Carvalho de Melo5f4d3f82010-03-26 21:16:22 -0300737 ui_progress__delete(progress);
738
Arnaldo Carvalho de Meloe65713e2010-04-03 11:25:56 -0300739 newtGetScreenSize(&cols, &rows);
740
Arnaldo Carvalho de Melo4ded2b22010-03-22 17:52:49 -0300741 if (max_len > cols)
742 max_len = cols - 3;
743
744 if (!symbol_conf.use_callchain)
Arnaldo Carvalho de Meloe65713e2010-04-03 11:25:56 -0300745 newtListboxSetWidth(self->tree, max_len);
Arnaldo Carvalho de Melo4ded2b22010-03-22 17:52:49 -0300746
747 newtCenteredWindow(max_len + (symbol_conf.use_callchain ? 5 : 0),
Arnaldo Carvalho de Melo6e7ab4c2010-04-05 12:02:18 -0300748 rows - 5, title);
Arnaldo Carvalho de Meloe65713e2010-04-03 11:25:56 -0300749 self->form = newt_form__new();
Arnaldo Carvalho de Melo83753192010-04-03 16:30:44 -0300750 if (self->form == NULL)
751 return -1;
752
Arnaldo Carvalho de Meloe65713e2010-04-03 11:25:56 -0300753 newtFormAddHotKey(self->form, 'A');
754 newtFormAddHotKey(self->form, 'a');
Arnaldo Carvalho de Melo9d192e12010-05-15 21:15:01 -0300755 newtFormAddHotKey(self->form, 'D');
756 newtFormAddHotKey(self->form, 'd');
757 newtFormAddHotKey(self->form, 'T');
758 newtFormAddHotKey(self->form, 't');
Arnaldo Carvalho de Meloe65713e2010-04-03 11:25:56 -0300759 newtFormAddHotKey(self->form, NEWT_KEY_RIGHT);
760 newtFormAddComponents(self->form, self->tree, NULL);
761 self->selection = newt__symbol_tree_get_current(self->tree);
762
763 return 0;
764}
765
Arnaldo Carvalho de Meloef7b93a2010-05-11 23:18:06 -0300766static struct hist_entry *hist_browser__selected_entry(struct hist_browser *self)
Arnaldo Carvalho de Meloa5e29ac2010-04-03 22:44:37 -0300767{
768 int *indexes;
769
770 if (!symbol_conf.use_callchain)
771 goto out;
772
773 indexes = newtCheckboxTreeFindItem(self->tree, (void *)self->selection);
774 if (indexes) {
775 bool is_hist_entry = indexes[1] == NEWT_ARG_LAST;
776 free(indexes);
777 if (is_hist_entry)
778 goto out;
779 }
780 return NULL;
781out:
Arnaldo Carvalho de Meloef7b93a2010-05-11 23:18:06 -0300782 return container_of(self->selection, struct hist_entry, ms);
783}
784
785static struct thread *hist_browser__selected_thread(struct hist_browser *self)
786{
787 struct hist_entry *he = hist_browser__selected_entry(self);
788 return he ? he->thread : NULL;
Arnaldo Carvalho de Meloa5e29ac2010-04-03 22:44:37 -0300789}
790
Arnaldo Carvalho de Melo6e7ab4c2010-04-05 12:02:18 -0300791static int hist_browser__title(char *bf, size_t size, const char *input_name,
792 const struct dso *dso, const struct thread *thread)
793{
794 int printed = 0;
795
796 if (thread)
797 printed += snprintf(bf + printed, size - printed,
798 "Thread: %s(%d)",
799 (thread->comm_set ? thread->comm : ""),
800 thread->pid);
801 if (dso)
802 printed += snprintf(bf + printed, size - printed,
803 "%sDSO: %s", thread ? " " : "",
804 dso->short_name);
805 return printed ?: snprintf(bf, size, "Report: %s", input_name);
806}
807
Arnaldo Carvalho de Melob09e0192010-05-11 11:10:15 -0300808int hists__browse(struct hists *self, const char *helpline, const char *input_name)
Arnaldo Carvalho de Meloe65713e2010-04-03 11:25:56 -0300809{
Arnaldo Carvalho de Meloe65713e2010-04-03 11:25:56 -0300810 struct hist_browser *browser = hist_browser__new();
Arnaldo Carvalho de Melo3e1bbdc32010-05-14 20:05:21 -0300811 struct pstack *fstack = pstack__new(2);
Arnaldo Carvalho de Melo6e7ab4c2010-04-05 12:02:18 -0300812 const struct thread *thread_filter = NULL;
813 const struct dso *dso_filter = NULL;
814 struct newtExitStruct es;
815 char msg[160];
816 int err = -1;
Arnaldo Carvalho de Meloe65713e2010-04-03 11:25:56 -0300817
818 if (browser == NULL)
819 return -1;
820
Arnaldo Carvalho de Melo3e1bbdc32010-05-14 20:05:21 -0300821 fstack = pstack__new(2);
822 if (fstack == NULL)
823 goto out;
824
Arnaldo Carvalho de Melo3798ed72010-05-11 18:01:23 -0300825 ui_helpline__push(helpline);
Arnaldo Carvalho de Meloe65713e2010-04-03 11:25:56 -0300826
Arnaldo Carvalho de Melo6e7ab4c2010-04-05 12:02:18 -0300827 hist_browser__title(msg, sizeof(msg), input_name,
828 dso_filter, thread_filter);
Arnaldo Carvalho de Melob09e0192010-05-11 11:10:15 -0300829 if (hist_browser__populate(browser, self, msg) < 0)
Arnaldo Carvalho de Melo3e1bbdc32010-05-14 20:05:21 -0300830 goto out_free_stack;
Arnaldo Carvalho de Melof9224c52010-03-11 20:12:44 -0300831
832 while (1) {
Arnaldo Carvalho de Meloa5e29ac2010-04-03 22:44:37 -0300833 const struct thread *thread;
Arnaldo Carvalho de Melo6e7ab4c2010-04-05 12:02:18 -0300834 const struct dso *dso;
Arnaldo Carvalho de Melo83753192010-04-03 16:30:44 -0300835 char *options[16];
836 int nr_options = 0, choice = 0, i,
Arnaldo Carvalho de Meloa5e29ac2010-04-03 22:44:37 -0300837 annotate = -2, zoom_dso = -2, zoom_thread = -2;
Arnaldo Carvalho de Melof9224c52010-03-11 20:12:44 -0300838
Arnaldo Carvalho de Meloe65713e2010-04-03 11:25:56 -0300839 newtFormRun(browser->form, &es);
Arnaldo Carvalho de Melo9d192e12010-05-15 21:15:01 -0300840
841 thread = hist_browser__selected_thread(browser);
842 dso = browser->selection->map ? browser->selection->map->dso : NULL;
843
Arnaldo Carvalho de Melo53c54012010-03-24 16:40:14 -0300844 if (es.reason == NEWT_EXIT_HOTKEY) {
Arnaldo Carvalho de Melo9d192e12010-05-15 21:15:01 -0300845 switch (toupper(es.u.key)) {
846 case 'A':
Arnaldo Carvalho de Melod5679ae2010-03-24 16:40:19 -0300847 goto do_annotate;
Arnaldo Carvalho de Melo9d192e12010-05-15 21:15:01 -0300848 case 'D':
849 goto zoom_dso;
850 case 'T':
851 goto zoom_thread;
852 default:;
853 }
Arnaldo Carvalho de Melo29351db2010-05-15 21:06:58 -0300854 if (toupper(es.u.key) == 'Q' ||
855 es.u.key == CTRL('c'))
856 break;
857 if (es.u.key == NEWT_KEY_ESCAPE) {
Arnaldo Carvalho de Melo53c54012010-03-24 16:40:14 -0300858 if (dialog_yesno("Do you really want to exit?"))
859 break;
860 else
861 continue;
862 }
Arnaldo Carvalho de Melo3e1bbdc32010-05-14 20:05:21 -0300863
864 if (es.u.key == NEWT_KEY_LEFT) {
865 const void *top;
866
867 if (pstack__empty(fstack))
868 continue;
869 top = pstack__pop(fstack);
870 if (top == &dso_filter)
871 goto zoom_out_dso;
872 if (top == &thread_filter)
873 goto zoom_out_thread;
874 continue;
875 }
Arnaldo Carvalho de Melo53c54012010-03-24 16:40:14 -0300876 }
877
Arnaldo Carvalho de Melo83753192010-04-03 16:30:44 -0300878 if (browser->selection->sym != NULL &&
879 asprintf(&options[nr_options], "Annotate %s",
880 browser->selection->sym->name) > 0)
881 annotate = nr_options++;
Arnaldo Carvalho de Melo53c54012010-03-24 16:40:14 -0300882
Arnaldo Carvalho de Meloa5e29ac2010-04-03 22:44:37 -0300883 if (thread != NULL &&
884 asprintf(&options[nr_options], "Zoom %s %s(%d) thread",
Arnaldo Carvalho de Melo6e7ab4c2010-04-05 12:02:18 -0300885 (thread_filter ? "out of" : "into"),
886 (thread->comm_set ? thread->comm : ""),
887 thread->pid) > 0)
Arnaldo Carvalho de Meloa5e29ac2010-04-03 22:44:37 -0300888 zoom_thread = nr_options++;
889
Arnaldo Carvalho de Melo6e7ab4c2010-04-05 12:02:18 -0300890 if (dso != NULL &&
891 asprintf(&options[nr_options], "Zoom %s %s DSO",
892 (dso_filter ? "out of" : "into"),
893 (dso->kernel ? "the Kernel" : dso->short_name)) > 0)
894 zoom_dso = nr_options++;
895
Arnaldo Carvalho de Melo83753192010-04-03 16:30:44 -0300896 options[nr_options++] = (char *)"Exit";
897
Arnaldo Carvalho de Melo53c54012010-03-24 16:40:14 -0300898 choice = popup_menu(nr_options, options);
Arnaldo Carvalho de Melo83753192010-04-03 16:30:44 -0300899
900 for (i = 0; i < nr_options - 1; ++i)
901 free(options[i]);
902
Arnaldo Carvalho de Melo53c54012010-03-24 16:40:14 -0300903 if (choice == nr_options - 1)
Arnaldo Carvalho de Melof9224c52010-03-11 20:12:44 -0300904 break;
Arnaldo Carvalho de Meloa5e29ac2010-04-03 22:44:37 -0300905
906 if (choice == -1)
907 continue;
Arnaldo Carvalho de Meloc1ec5fe2010-05-15 20:45:31 -0300908
Arnaldo Carvalho de Melo83753192010-04-03 16:30:44 -0300909 if (choice == annotate) {
Arnaldo Carvalho de Meloef7b93a2010-05-11 23:18:06 -0300910 struct hist_entry *he;
Arnaldo Carvalho de Meloc1ec5fe2010-05-15 20:45:31 -0300911do_annotate:
Arnaldo Carvalho de Meloe65713e2010-04-03 11:25:56 -0300912 if (browser->selection->map->dso->origin == DSO__ORIG_KERNEL) {
Arnaldo Carvalho de Melo3798ed72010-05-11 18:01:23 -0300913 ui_helpline__puts("No vmlinux file found, can't "
Arnaldo Carvalho de Melod5679ae2010-03-24 16:40:19 -0300914 "annotate with just a "
915 "kallsyms file");
916 continue;
917 }
Arnaldo Carvalho de Meloef7b93a2010-05-11 23:18:06 -0300918
919 he = hist_browser__selected_entry(browser);
920 if (he == NULL)
921 continue;
922
923 hist_entry__annotate_browser(he);
Arnaldo Carvalho de Meloa5e29ac2010-04-03 22:44:37 -0300924 } else if (choice == zoom_dso) {
Arnaldo Carvalho de Melo9d192e12010-05-15 21:15:01 -0300925zoom_dso:
Arnaldo Carvalho de Melo6e7ab4c2010-04-05 12:02:18 -0300926 if (dso_filter) {
Arnaldo Carvalho de Melo3e1bbdc32010-05-14 20:05:21 -0300927 pstack__remove(fstack, &dso_filter);
928zoom_out_dso:
Arnaldo Carvalho de Melo3798ed72010-05-11 18:01:23 -0300929 ui_helpline__pop();
Arnaldo Carvalho de Melo6e7ab4c2010-04-05 12:02:18 -0300930 dso_filter = NULL;
931 } else {
Arnaldo Carvalho de Melo9d192e12010-05-15 21:15:01 -0300932 if (dso == NULL)
933 continue;
Arnaldo Carvalho de Melo3e1bbdc32010-05-14 20:05:21 -0300934 ui_helpline__fpush("To zoom out press <- or -> + \"Zoom out of %s DSO\"",
Arnaldo Carvalho de Melo3798ed72010-05-11 18:01:23 -0300935 dso->kernel ? "the Kernel" : dso->short_name);
Arnaldo Carvalho de Melo6e7ab4c2010-04-05 12:02:18 -0300936 dso_filter = dso;
Arnaldo Carvalho de Melo3e1bbdc32010-05-14 20:05:21 -0300937 pstack__push(fstack, &dso_filter);
Arnaldo Carvalho de Melo6e7ab4c2010-04-05 12:02:18 -0300938 }
Arnaldo Carvalho de Melob09e0192010-05-11 11:10:15 -0300939 hists__filter_by_dso(self, dso_filter);
Arnaldo Carvalho de Melo6e7ab4c2010-04-05 12:02:18 -0300940 hist_browser__title(msg, sizeof(msg), input_name,
941 dso_filter, thread_filter);
Arnaldo Carvalho de Melob09e0192010-05-11 11:10:15 -0300942 if (hist_browser__populate(browser, self, msg) < 0)
Arnaldo Carvalho de Melo83753192010-04-03 16:30:44 -0300943 goto out;
Arnaldo Carvalho de Meloa5e29ac2010-04-03 22:44:37 -0300944 } else if (choice == zoom_thread) {
Arnaldo Carvalho de Melo9d192e12010-05-15 21:15:01 -0300945zoom_thread:
Arnaldo Carvalho de Melo6e7ab4c2010-04-05 12:02:18 -0300946 if (thread_filter) {
Arnaldo Carvalho de Melo3e1bbdc32010-05-14 20:05:21 -0300947 pstack__remove(fstack, &thread_filter);
948zoom_out_thread:
Arnaldo Carvalho de Melo3798ed72010-05-11 18:01:23 -0300949 ui_helpline__pop();
Arnaldo Carvalho de Melo6e7ab4c2010-04-05 12:02:18 -0300950 thread_filter = NULL;
951 } else {
Arnaldo Carvalho de Melo3e1bbdc32010-05-14 20:05:21 -0300952 ui_helpline__fpush("To zoom out press <- or -> + \"Zoom out of %s(%d) thread\"",
Arnaldo Carvalho de Melo3798ed72010-05-11 18:01:23 -0300953 thread->comm_set ? thread->comm : "",
954 thread->pid);
Arnaldo Carvalho de Melo6e7ab4c2010-04-05 12:02:18 -0300955 thread_filter = thread;
Arnaldo Carvalho de Melo3e1bbdc32010-05-14 20:05:21 -0300956 pstack__push(fstack, &thread_filter);
Arnaldo Carvalho de Melo6e7ab4c2010-04-05 12:02:18 -0300957 }
Arnaldo Carvalho de Melob09e0192010-05-11 11:10:15 -0300958 hists__filter_by_thread(self, thread_filter);
Arnaldo Carvalho de Melo6e7ab4c2010-04-05 12:02:18 -0300959 hist_browser__title(msg, sizeof(msg), input_name,
960 dso_filter, thread_filter);
Arnaldo Carvalho de Melob09e0192010-05-11 11:10:15 -0300961 if (hist_browser__populate(browser, self, msg) < 0)
Arnaldo Carvalho de Meloa5e29ac2010-04-03 22:44:37 -0300962 goto out;
Arnaldo Carvalho de Melod5679ae2010-03-24 16:40:19 -0300963 }
Arnaldo Carvalho de Melof9224c52010-03-11 20:12:44 -0300964 }
Arnaldo Carvalho de Meloe65713e2010-04-03 11:25:56 -0300965 err = 0;
Arnaldo Carvalho de Melo3e1bbdc32010-05-14 20:05:21 -0300966out_free_stack:
967 pstack__delete(fstack);
Arnaldo Carvalho de Meloe65713e2010-04-03 11:25:56 -0300968out:
969 hist_browser__delete(browser);
970 return err;
Arnaldo Carvalho de Melof9224c52010-03-11 20:12:44 -0300971}
972
Arnaldo Carvalho de Meloef7b93a2010-05-11 23:18:06 -0300973static struct newtPercentTreeColors {
974 const char *topColorFg, *topColorBg;
975 const char *mediumColorFg, *mediumColorBg;
976 const char *normalColorFg, *normalColorBg;
977 const char *selColorFg, *selColorBg;
978 const char *codeColorFg, *codeColorBg;
979} defaultPercentTreeColors = {
980 "red", "lightgray",
981 "green", "lightgray",
982 "black", "lightgray",
983 "lightgray", "magenta",
984 "blue", "lightgray",
985};
986
Arnaldo Carvalho de Melof9224c52010-03-11 20:12:44 -0300987void setup_browser(void)
988{
Arnaldo Carvalho de Meloef7b93a2010-05-11 23:18:06 -0300989 struct newtPercentTreeColors *c = &defaultPercentTreeColors;
Arnaldo Carvalho de Melof9224c52010-03-11 20:12:44 -0300990 if (!isatty(1))
991 return;
992
993 use_browser = true;
994 newtInit();
995 newtCls();
Arnaldo Carvalho de Melo3798ed72010-05-11 18:01:23 -0300996 ui_helpline__puts(" ");
Arnaldo Carvalho de Meloef7b93a2010-05-11 23:18:06 -0300997 SLtt_set_color(HE_COLORSET_TOP, NULL, c->topColorFg, c->topColorBg);
998 SLtt_set_color(HE_COLORSET_MEDIUM, NULL, c->mediumColorFg, c->mediumColorBg);
999 SLtt_set_color(HE_COLORSET_NORMAL, NULL, c->normalColorFg, c->normalColorBg);
1000 SLtt_set_color(HE_COLORSET_SELECTED, NULL, c->selColorFg, c->selColorBg);
1001 SLtt_set_color(HE_COLORSET_CODE, NULL, c->codeColorFg, c->codeColorBg);
Arnaldo Carvalho de Melof9224c52010-03-11 20:12:44 -03001002}
1003
Arnaldo Carvalho de Melof3a1f0e2010-03-22 13:10:25 -03001004void exit_browser(bool wait_for_ok)
Arnaldo Carvalho de Melof9224c52010-03-11 20:12:44 -03001005{
Arnaldo Carvalho de Melof3a1f0e2010-03-22 13:10:25 -03001006 if (use_browser) {
1007 if (wait_for_ok) {
1008 char title[] = "Fatal Error", ok[] = "Ok";
1009 newtWinMessage(title, ok, browser__last_msg);
1010 }
Arnaldo Carvalho de Melof9224c52010-03-11 20:12:44 -03001011 newtFinished();
Arnaldo Carvalho de Melof3a1f0e2010-03-22 13:10:25 -03001012 }
Arnaldo Carvalho de Melof9224c52010-03-11 20:12:44 -03001013}