diff options
Diffstat (limited to 'tools/perf')
| -rw-r--r-- | tools/perf/util/newt.c | 96 |
1 files changed, 88 insertions, 8 deletions
diff --git a/tools/perf/util/newt.c b/tools/perf/util/newt.c index 12b229bb9dc1..a3465a0ad70d 100644 --- a/tools/perf/util/newt.c +++ b/tools/perf/util/newt.c | |||
| @@ -28,6 +28,47 @@ static newtComponent newt_form__new(void) | |||
| 28 | return self; | 28 | return self; |
| 29 | } | 29 | } |
| 30 | 30 | ||
| 31 | static int popup_menu(int argc, const char *argv[]) | ||
| 32 | { | ||
| 33 | struct newtExitStruct es; | ||
| 34 | int i, rc = -1, max_len = 5; | ||
| 35 | newtComponent listbox, form = newt_form__new(); | ||
| 36 | |||
| 37 | if (form == NULL) | ||
| 38 | return -1; | ||
| 39 | |||
| 40 | listbox = newtListbox(0, 0, argc, NEWT_FLAG_RETURNEXIT); | ||
| 41 | if (listbox == NULL) | ||
| 42 | goto out_destroy_form; | ||
| 43 | |||
| 44 | newtFormAddComponents(form, listbox, NULL); | ||
| 45 | |||
| 46 | for (i = 0; i < argc; ++i) { | ||
| 47 | int len = strlen(argv[i]); | ||
| 48 | if (len > max_len) | ||
| 49 | max_len = len; | ||
| 50 | if (newtListboxAddEntry(listbox, argv[i], (void *)(long)i)) | ||
| 51 | goto out_destroy_form; | ||
| 52 | } | ||
| 53 | |||
| 54 | newtCenteredWindow(max_len, argc, NULL); | ||
| 55 | newtFormRun(form, &es); | ||
| 56 | rc = newtListboxGetCurrent(listbox) - NULL; | ||
| 57 | if (es.reason == NEWT_EXIT_HOTKEY) | ||
| 58 | rc = -1; | ||
| 59 | newtPopWindow(); | ||
| 60 | out_destroy_form: | ||
| 61 | newtFormDestroy(form); | ||
| 62 | return rc; | ||
| 63 | } | ||
| 64 | |||
| 65 | static bool dialog_yesno(const char *msg) | ||
| 66 | { | ||
| 67 | /* newtWinChoice should really be accepting const char pointers... */ | ||
| 68 | char yes[] = "Yes", no[] = "No"; | ||
| 69 | return newtWinChoice(NULL, no, yes, (char *)msg) == 2; | ||
| 70 | } | ||
| 71 | |||
| 31 | /* | 72 | /* |
| 32 | * When debugging newt problems it was useful to be able to "unroll" | 73 | * When debugging newt problems it was useful to be able to "unroll" |
| 33 | * the calls to newtCheckBoxTreeAdd{Array,Item}, so that we can generate | 74 | * the calls to newtCheckBoxTreeAdd{Array,Item}, so that we can generate |
| @@ -309,6 +350,19 @@ out_free_str: | |||
| 309 | free(str); | 350 | free(str); |
| 310 | } | 351 | } |
| 311 | 352 | ||
| 353 | static const void *newt__symbol_tree_get_current(newtComponent self) | ||
| 354 | { | ||
| 355 | if (symbol_conf.use_callchain) | ||
| 356 | return newtCheckboxTreeGetCurrent(self); | ||
| 357 | return newtListboxGetCurrent(self); | ||
| 358 | } | ||
| 359 | |||
| 360 | static void perf_session__selection(newtComponent self, void *data) | ||
| 361 | { | ||
| 362 | const struct symbol **symbol_ptr = data; | ||
| 363 | *symbol_ptr = newt__symbol_tree_get_current(self); | ||
| 364 | } | ||
| 365 | |||
| 312 | void perf_session__browse_hists(struct rb_root *hists, u64 session_total, | 366 | void perf_session__browse_hists(struct rb_root *hists, u64 session_total, |
| 313 | const char *helpline) | 367 | const char *helpline) |
| 314 | { | 368 | { |
| @@ -322,6 +376,7 @@ void perf_session__browse_hists(struct rb_root *hists, u64 session_total, | |||
| 322 | char str[1024]; | 376 | char str[1024]; |
| 323 | newtComponent form, tree; | 377 | newtComponent form, tree; |
| 324 | struct newtExitStruct es; | 378 | struct newtExitStruct es; |
| 379 | const struct symbol *selection; | ||
| 325 | 380 | ||
| 326 | snprintf(str, sizeof(str), "Samples: %Ld", session_total); | 381 | snprintf(str, sizeof(str), "Samples: %Ld", session_total); |
| 327 | newtDrawRootText(0, 0, str); | 382 | newtDrawRootText(0, 0, str); |
| @@ -336,6 +391,8 @@ void perf_session__browse_hists(struct rb_root *hists, u64 session_total, | |||
| 336 | tree = newtListbox(0, 0, rows - 5, (NEWT_FLAG_SCROLL | | 391 | tree = newtListbox(0, 0, rows - 5, (NEWT_FLAG_SCROLL | |
| 337 | NEWT_FLAG_RETURNEXIT)); | 392 | NEWT_FLAG_RETURNEXIT)); |
| 338 | 393 | ||
| 394 | newtComponentAddCallback(tree, perf_session__selection, &selection); | ||
| 395 | |||
| 339 | list_for_each_entry(se, &hist_entry__sort_list, list) { | 396 | list_for_each_entry(se, &hist_entry__sort_list, list) { |
| 340 | if (se->elide) | 397 | if (se->elide) |
| 341 | continue; | 398 | continue; |
| @@ -377,20 +434,43 @@ void perf_session__browse_hists(struct rb_root *hists, u64 session_total, | |||
| 377 | form = newt_form__new(); | 434 | form = newt_form__new(); |
| 378 | newtFormAddHotKey(form, 'A'); | 435 | newtFormAddHotKey(form, 'A'); |
| 379 | newtFormAddHotKey(form, 'a'); | 436 | newtFormAddHotKey(form, 'a'); |
| 437 | newtFormAddHotKey(form, NEWT_KEY_RIGHT); | ||
| 380 | newtFormAddComponents(form, tree, NULL); | 438 | newtFormAddComponents(form, tree, NULL); |
| 439 | selection = newt__symbol_tree_get_current(tree); | ||
| 381 | 440 | ||
| 382 | while (1) { | 441 | while (1) { |
| 383 | const struct symbol *selection; | 442 | char annotate[512]; |
| 443 | const char *options[2]; | ||
| 444 | int nr_options = 0, choice; | ||
| 384 | 445 | ||
| 385 | newtFormRun(form, &es); | 446 | newtFormRun(form, &es); |
| 386 | if (es.reason == NEWT_EXIT_HOTKEY && | 447 | if (es.reason == NEWT_EXIT_HOTKEY) { |
| 387 | toupper(es.u.key) != 'A') | 448 | if (toupper(es.u.key) == 'A') { |
| 449 | symbol__annotate_browser(selection); | ||
| 450 | continue; | ||
| 451 | } | ||
| 452 | if (es.u.key == NEWT_KEY_ESCAPE || | ||
| 453 | toupper(es.u.key) == 'Q' || | ||
| 454 | es.u.key == CTRL('c')) { | ||
| 455 | if (dialog_yesno("Do you really want to exit?")) | ||
| 456 | break; | ||
| 457 | else | ||
| 458 | continue; | ||
| 459 | } | ||
| 460 | } | ||
| 461 | |||
| 462 | if (selection != NULL) { | ||
| 463 | snprintf(annotate, sizeof(annotate), | ||
| 464 | "Annotate %s", selection->name); | ||
| 465 | options[nr_options++] = annotate; | ||
| 466 | } | ||
| 467 | |||
| 468 | options[nr_options++] = "Exit"; | ||
| 469 | choice = popup_menu(nr_options, options); | ||
| 470 | if (choice == nr_options - 1) | ||
| 388 | break; | 471 | break; |
| 389 | if (!symbol_conf.use_callchain) | 472 | else if (selection != NULL && choice >= 0) |
| 390 | selection = newtListboxGetCurrent(tree); | 473 | symbol__annotate_browser(selection); |
| 391 | else | ||
| 392 | selection = newtCheckboxTreeGetCurrent(tree); | ||
| 393 | symbol__annotate_browser(selection); | ||
| 394 | } | 474 | } |
| 395 | 475 | ||
| 396 | newtFormDestroy(form); | 476 | newtFormDestroy(form); |
