Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754368AbZKPVaf (ORCPT ); Mon, 16 Nov 2009 16:30:35 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1754436AbZKPVae (ORCPT ); Mon, 16 Nov 2009 16:30:34 -0500 Received: from casper.infradead.org ([85.118.1.10]:55224 "EHLO casper.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754351AbZKPVae (ORCPT ); Mon, 16 Nov 2009 16:30:34 -0500 From: Arnaldo Carvalho de Melo To: Ingo Molnar Cc: linux-kernel@vger.kernel.org, Arnaldo Carvalho de Melo , Frederic Weisbecker , Mike Galbraith , Paul Mackerras , Peter Zijlstra Subject: [PATCH 2/2] perf top: Use all the lines in the screen Date: Mon, 16 Nov 2009 19:30:27 -0200 Message-Id: <1258407027-384-2-git-send-email-acme@infradead.org> X-Mailer: git-send-email 1.6.2.5 In-Reply-To: <1258407027-384-1-git-send-email-acme@infradead.org> References: <1258407027-384-1-git-send-email-acme@infradead.org> X-SRS-Rewrite: SMTP reverse-path rewritten from by casper.infradead.org See http://www.infradead.org/rpr.html Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2699 Lines: 97 From: Arnaldo Carvalho de Melo By querying the current number of rows, if the user specifies the number of entries, use that instead. If the user uses the 'e' command to change the number of lines 0 will mean do it automatically, any other number disables the auto resizing. Cc: Frederic Weisbecker Cc: Mike Galbraith Cc: Paul Mackerras Cc: Peter Zijlstra Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/builtin-top.c | 42 +++++++++++++++++++++++++++++++++++++++++- 1 files changed, 41 insertions(+), 1 deletions(-) diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c index 6613f98..3af9520 100644 --- a/tools/perf/builtin-top.c +++ b/tools/perf/builtin-top.c @@ -60,7 +60,7 @@ static int system_wide = 0; static int default_interval = 0; static int count_filter = 5; -static int print_entries = 15; +static int print_entries; static int target_pid = -1; static int inherit = 0; @@ -115,6 +115,36 @@ struct sym_entry { * Source functions */ +/* most GUI terminals set LINES (although some don't export it) */ +static int term_rows(void) +{ + char *lines_string = getenv("LINES"); + int n_lines; + + if (lines_string && (n_lines = atoi(lines_string)) > 0) + return n_lines; +#ifdef TIOCGWINSZ + else { + struct winsize ws; + if (!ioctl(1, TIOCGWINSZ, &ws) && ws.ws_row) + return ws.ws_row; + } +#endif + return 25; +} + +static void update_print_entries(void) +{ + print_entries = term_rows(); + if (print_entries > 9) + print_entries -= 9; +} + +static void sig_winch_handler(int sig __used) +{ + update_print_entries(); +} + static void parse_source(struct sym_entry *syme) { struct symbol *sym; @@ -668,6 +698,11 @@ static void handle_keypress(int c) break; case 'e': prompt_integer(&print_entries, "Enter display entries (lines)"); + if (print_entries == 0) { + update_print_entries(); + signal(SIGWINCH, sig_winch_handler); + } else + signal(SIGWINCH, SIG_DFL); break; case 'E': if (nr_counters > 1) { @@ -1228,5 +1263,10 @@ int cmd_top(int argc, const char **argv, const char *prefix __used) if (target_pid != -1 || profile_cpu != -1) nr_cpus = 1; + if (print_entries == 0) { + update_print_entries(); + signal(SIGWINCH, sig_winch_handler); + } + return __cmd_top(); } -- 1.6.2.5 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/