aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf/builtin-top.c
diff options
context:
space:
mode:
Diffstat (limited to 'tools/perf/builtin-top.c')
-rw-r--r--tools/perf/builtin-top.c42
1 files changed, 41 insertions, 1 deletions
diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c
index 6613f988a33e..3af95203208a 100644
--- a/tools/perf/builtin-top.c
+++ b/tools/perf/builtin-top.c
@@ -60,7 +60,7 @@ static int system_wide = 0;
60static int default_interval = 0; 60static int default_interval = 0;
61 61
62static int count_filter = 5; 62static int count_filter = 5;
63static int print_entries = 15; 63static int print_entries;
64 64
65static int target_pid = -1; 65static int target_pid = -1;
66static int inherit = 0; 66static int inherit = 0;
@@ -115,6 +115,36 @@ struct sym_entry {
115 * Source functions 115 * Source functions
116 */ 116 */
117 117
118/* most GUI terminals set LINES (although some don't export it) */
119static int term_rows(void)
120{
121 char *lines_string = getenv("LINES");
122 int n_lines;
123
124 if (lines_string && (n_lines = atoi(lines_string)) > 0)
125 return n_lines;
126#ifdef TIOCGWINSZ
127 else {
128 struct winsize ws;
129 if (!ioctl(1, TIOCGWINSZ, &ws) && ws.ws_row)
130 return ws.ws_row;
131 }
132#endif
133 return 25;
134}
135
136static void update_print_entries(void)
137{
138 print_entries = term_rows();
139 if (print_entries > 9)
140 print_entries -= 9;
141}
142
143static void sig_winch_handler(int sig __used)
144{
145 update_print_entries();
146}
147
118static void parse_source(struct sym_entry *syme) 148static void parse_source(struct sym_entry *syme)
119{ 149{
120 struct symbol *sym; 150 struct symbol *sym;
@@ -668,6 +698,11 @@ static void handle_keypress(int c)
668 break; 698 break;
669 case 'e': 699 case 'e':
670 prompt_integer(&print_entries, "Enter display entries (lines)"); 700 prompt_integer(&print_entries, "Enter display entries (lines)");
701 if (print_entries == 0) {
702 update_print_entries();
703 signal(SIGWINCH, sig_winch_handler);
704 } else
705 signal(SIGWINCH, SIG_DFL);
671 break; 706 break;
672 case 'E': 707 case 'E':
673 if (nr_counters > 1) { 708 if (nr_counters > 1) {
@@ -1228,5 +1263,10 @@ int cmd_top(int argc, const char **argv, const char *prefix __used)
1228 if (target_pid != -1 || profile_cpu != -1) 1263 if (target_pid != -1 || profile_cpu != -1)
1229 nr_cpus = 1; 1264 nr_cpus = 1;
1230 1265
1266 if (print_entries == 0) {
1267 update_print_entries();
1268 signal(SIGWINCH, sig_winch_handler);
1269 }
1270
1231 return __cmd_top(); 1271 return __cmd_top();
1232} 1272}