aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf
diff options
context:
space:
mode:
authorMike Galbraith <efault@gmx.de>2009-08-04 04:21:23 -0400
committerIngo Molnar <mingo@elte.hu>2009-08-09 06:54:31 -0400
commit091bd2e993fcb1094a23e36157285b62bc87afdf (patch)
tree6f6d88d3543ff3efcf1976b38b9ce90910cab22e /tools/perf
parent7b4b6658e152ed4568cfff48175d93645df081d1 (diff)
perf top: Improve interactive key handling
Pressing any key which is not currently mapped to functionality, based on startup command line options, displays currently mapped keys, and prompts for input. Pressing any unmapped key at the prompt returns the user to display mode with variables unchanged. eg, pressing ? <SPACE> <ESC> etc displays currently available keys, the value of the variable associated with that key, and prompts. Pressing same again aborts input. Signed-off-by: Mike Galbraith <efault@gmx.de> Cc: Peter Zijlstra <a.p.zijlstra@chello.nl> Signed-off-by: Ingo Molnar <mingo@elte.hu>
Diffstat (limited to 'tools/perf')
-rw-r--r--tools/perf/builtin-top.c108
1 files changed, 73 insertions, 35 deletions
diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c
index 4eef3465e837..7de28ce9ca26 100644
--- a/tools/perf/builtin-top.c
+++ b/tools/perf/builtin-top.c
@@ -595,25 +595,84 @@ out_free:
595 free(buf); 595 free(buf);
596} 596}
597 597
598static void print_known_keys(void) 598static void print_mapped_keys(void)
599{ 599{
600 fprintf(stdout, "\nknown keys:\n"); 600 char *name = NULL;
601 fprintf(stdout, "\t[d] select display delay.\n"); 601
602 fprintf(stdout, "\t[e] select display entries (lines).\n"); 602 if (sym_filter_entry) {
603 fprintf(stdout, "\t[E] active event counter. \t(%s)\n", event_name(sym_counter)); 603 struct symbol *sym = (struct symbol *)(sym_filter_entry+1);
604 fprintf(stdout, "\t[f] select normal display count filter.\n"); 604 name = sym->name;
605 fprintf(stdout, "\t[F] select annotation display count filter (percentage).\n"); 605 }
606 fprintf(stdout, "\t[qQ] quit.\n"); 606
607 fprintf(stdout, "\t[s] select annotation symbol and start annotation.\n"); 607 fprintf(stdout, "\nMapped keys:\n");
608 fprintf(stdout, "\t[S] stop annotation, revert to normal display.\n"); 608 fprintf(stdout, "\t[d] display refresh delay. \t(%d)\n", delay_secs);
609 fprintf(stdout, "\t[w] toggle display weighted/count[E]r. \t(%d)\n", display_weighted ? 1 : 0); 609 fprintf(stdout, "\t[e] display entries (lines). \t(%d)\n", print_entries);
610
611 if (nr_counters > 1)
612 fprintf(stdout, "\t[E] active event counter. \t(%s)\n", event_name(sym_counter));
613
614 fprintf(stdout, "\t[f] profile display filter (count). \t(%d)\n", count_filter);
615
616 if (vmlinux) {
617 fprintf(stdout, "\t[F] annotate display filter (percent). \t(%d%%)\n", sym_pcnt_filter);
618 fprintf(stdout, "\t[s] annotate symbol. \t(%s)\n", name?: "NULL");
619 fprintf(stdout, "\t[S] stop annotation.\n");
620 }
621
622 if (nr_counters > 1)
623 fprintf(stdout, "\t[w] toggle display weighted/count[E]r. \t(%d)\n", display_weighted ? 1 : 0);
624
610 fprintf(stdout, "\t[z] toggle sample zeroing. \t(%d)\n", zero ? 1 : 0); 625 fprintf(stdout, "\t[z] toggle sample zeroing. \t(%d)\n", zero ? 1 : 0);
626 fprintf(stdout, "\t[qQ] quit.\n");
627}
628
629static int key_mapped(int c)
630{
631 switch (c) {
632 case 'd':
633 case 'e':
634 case 'f':
635 case 'z':
636 case 'q':
637 case 'Q':
638 return 1;
639 case 'E':
640 case 'w':
641 return nr_counters > 1 ? 1 : 0;
642 case 'F':
643 case 's':
644 case 'S':
645 return vmlinux ? 1 : 0;
646 }
647
648 return 0;
611} 649}
612 650
613static void handle_keypress(int c) 651static void handle_keypress(int c)
614{ 652{
615 int once = 0; 653 if (!key_mapped(c)) {
616repeat: 654 struct pollfd stdin_poll = { .fd = 0, .events = POLLIN };
655 struct termios tc, save;
656
657 print_mapped_keys();
658 fprintf(stdout, "\nEnter selection, or unmapped key to continue: ");
659 fflush(stdout);
660
661 tcgetattr(0, &save);
662 tc = save;
663 tc.c_lflag &= ~(ICANON | ECHO);
664 tc.c_cc[VMIN] = 0;
665 tc.c_cc[VTIME] = 0;
666 tcsetattr(0, TCSANOW, &tc);
667
668 poll(&stdin_poll, 1, -1);
669 c = getc(stdin);
670
671 tcsetattr(0, TCSAFLUSH, &save);
672 if (!key_mapped(c))
673 return;
674 }
675
617 switch (c) { 676 switch (c) {
618 case 'd': 677 case 'd':
619 prompt_integer(&delay_secs, "Enter display delay"); 678 prompt_integer(&delay_secs, "Enter display delay");
@@ -669,28 +728,6 @@ repeat:
669 case 'z': 728 case 'z':
670 zero = ~zero; 729 zero = ~zero;
671 break; 730 break;
672 default: {
673 struct pollfd stdin_poll = { .fd = 0, .events = POLLIN };
674 struct termios tc, save;
675
676 if (!once) {
677 print_known_keys();
678 once++;
679 }
680
681 tcgetattr(0, &save);
682 tc = save;
683 tc.c_lflag &= ~(ICANON | ECHO);
684 tc.c_cc[VMIN] = 0;
685 tc.c_cc[VTIME] = 0;
686 tcsetattr(0, TCSANOW, &tc);
687
688 poll(&stdin_poll, 1, -1);
689 c = getc(stdin);
690
691 tcsetattr(0, TCSAFLUSH, &save);
692 goto repeat;
693 }
694 } 731 }
695} 732}
696 733
@@ -705,6 +742,7 @@ static void *display_thread(void *arg __used)
705 tc.c_lflag &= ~(ICANON | ECHO); 742 tc.c_lflag &= ~(ICANON | ECHO);
706 tc.c_cc[VMIN] = 0; 743 tc.c_cc[VMIN] = 0;
707 tc.c_cc[VTIME] = 0; 744 tc.c_cc[VTIME] = 0;
745
708repeat: 746repeat:
709 delay_msecs = delay_secs * 1000; 747 delay_msecs = delay_secs * 1000;
710 tcsetattr(0, TCSANOW, &tc); 748 tcsetattr(0, TCSANOW, &tc);