From patchwork Wed Jan 7 22:29:51 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pedro Alves X-Patchwork-Id: 4557 Received: (qmail 10632 invoked by alias); 7 Jan 2015 22:30:08 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 10617 invoked by uid 89); 7 Jan 2015 22:30:07 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.0 required=5.0 tests=AWL, BAYES_00, SPF_HELO_PASS, SPF_PASS, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Wed, 07 Jan 2015 22:30:05 +0000 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id t07MU1eZ010865 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Wed, 7 Jan 2015 17:30:01 -0500 Received: from [127.0.0.1] (ovpn01.gateway.prod.ext.ams2.redhat.com [10.39.146.11]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t07MTrlo011172; Wed, 7 Jan 2015 17:29:56 -0500 Message-ID: <54ADB35F.7050200@redhat.com> Date: Wed, 07 Jan 2015 22:29:51 +0000 From: Pedro Alves User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.3.0 MIME-Version: 1.0 To: Eli Zaretskii , Doug Evans CC: gdb-patches@sourceware.org Subject: Re: [PATCH] Speed up "gdb -tui" output References: <83zj9v7urq.fsf@gnu.org> <54AD4E22.1010106@redhat.com> <83mw5u79t7.fsf@gnu.org> <83fvbm784e.fsf@gnu.org> <83a91u75fe.fsf@gnu.org> In-Reply-To: <83a91u75fe.fsf@gnu.org> On 01/07/2015 07:32 PM, Eli Zaretskii wrote: > So? How does this help? The stderr problem is simple, but what do > you do with stdout and stdlog? Especially when tui_file_fputs is > called one character at a time in most cases. I'm confused on that the confusion is. :-) I think something like this should work. I'm not really seeing a point for those fflush(stdout)'s, btw. Note that tui_stream->ts_filestream is only ever used in tui_file_isatty; it's never written to. From 2b4d8cfb56d67f9eded113a120dc5c18ea3781cc Mon Sep 17 00:00:00 2001 From: Pedro Alves Date: Wed, 7 Jan 2015 19:50:48 +0000 Subject: [PATCH] TUI emulate line buffering when printing to stdout, only refresh the console window when either a new line is seen or when an explicit flush is requested. --- gdb/tui/tui-file.c | 5 +++-- gdb/tui/tui-io.c | 53 +++++++++++++++++++++++++++++++++++++++++++++-------- gdb/tui/tui-io.h | 10 ++++++++-- 3 files changed, 56 insertions(+), 12 deletions(-) diff --git a/gdb/tui/tui-file.c b/gdb/tui/tui-file.c index b32cfa6..932df46 100644 --- a/gdb/tui/tui-file.c +++ b/gdb/tui/tui-file.c @@ -178,7 +178,7 @@ tui_file_fputs (const char *linebuffer, struct ui_file *file) } else { - tui_puts (linebuffer); + tui_puts_file (file, linebuffer); } } @@ -239,7 +239,8 @@ tui_file_flush (struct ui_file *file) case astring: break; case afile: - fflush (stream->ts_filestream); + if (file == tui_stdout) + tui_flush_stdout (); break; } } diff --git a/gdb/tui/tui-io.c b/gdb/tui/tui-io.c index 233e7a6..e7c5583 100644 --- a/gdb/tui/tui-io.c +++ b/gdb/tui/tui-io.c @@ -118,7 +118,7 @@ key_is_command_char (int ch) /* #undef TUI_USE_PIPE_FOR_READLINE */ /* TUI output files. */ -static struct ui_file *tui_stdout; +struct ui_file *tui_stdout; static struct ui_file *tui_stderr; struct ui_out *tui_out; @@ -148,6 +148,17 @@ static char *tui_rl_saved_prompt; static unsigned int tui_handle_resize_during_io (unsigned int); +static void tui_puts (const char *string); + +void +tui_flush_stdout (void) +{ + WINDOW *w; + + w = TUI_CMD_WIN->generic.handle; + wrefresh (w); +} + static void tui_putc (char c) { @@ -158,9 +169,13 @@ tui_putc (char c) tui_puts (buf); } -/* Print the string in the curses command window. */ -void -tui_puts (const char *string) +/* Print the string in the curses command window. If LINEBUFFERED, + we're printing to stdout, and so like stdio, should only flush when + we see a new line. If LINEBUFFERED is false, we'll flush after + printing the whole string. */ + +static void +tui_puts_maybe_buffered (const char *string, int linebuffered) { static int tui_skip_line = -1; char c; @@ -182,15 +197,36 @@ tui_puts (const char *string) } else if (c == '\n') tui_skip_line = -1; + + if (linebuffered && c == '\n') + wrefresh (w); } getyx (w, TUI_CMD_WIN->detail.command_info.cur_line, TUI_CMD_WIN->detail.command_info.curch); TUI_CMD_WIN->detail.command_info.start_line = TUI_CMD_WIN->detail.command_info.cur_line; - /* We could defer the following. */ - wrefresh (w); - fflush (stdout); + if (!linebuffered) + wrefresh (w); +} + +/* Print the string in the curses command window, as if printing to + stdout. */ + +static void +tui_puts (const char *string) +{ + tui_puts_maybe_buffered (string, 1); +} + +/* Print the string in the curses command window. FILE indicates + which file the caller is printing to. If gdb_stdout, then emulate + line buffering. */ + +void +tui_puts_file (struct ui_file *file, const char *string) +{ + tui_puts_maybe_buffered (string, file == tui_stdout); } /* Readline callback. @@ -279,7 +315,6 @@ tui_redisplay_readline (void) TUI_CMD_WIN->detail.command_info.start_line -= height - 1; wrefresh (w); - fflush(stdout); } /* Readline callback to prepare the terminal. It is called once each @@ -412,6 +447,7 @@ tui_rl_display_match_list (char **matches, int len, int max) /* Screen dimension correspond to the TUI command window. */ int screenwidth = TUI_CMD_WIN->generic.width; + WINDOW *w = TUI_CMD_WIN->generic.handle; /* If there are many items, then ask the user if she really wants to see them all. */ @@ -422,6 +458,7 @@ tui_rl_display_match_list (char **matches, int len, int max) xsnprintf (msg, sizeof (msg), "\nDisplay all %d possibilities? (y or n)", len); tui_puts (msg); + tui_flush_stdout (); if (get_y_or_n () == 0) { tui_puts ("\n"); diff --git a/gdb/tui/tui-io.h b/gdb/tui/tui-io.h index 8f96cfe..81d4337 100644 --- a/gdb/tui/tui-io.h +++ b/gdb/tui/tui-io.h @@ -24,8 +24,13 @@ struct ui_out; -/* Print the string in the curses command window. */ -extern void tui_puts (const char *); +/* Print the string in the curses command window. FILE indicates + which file the caller is printing to. If gdb_stdout, then emulate + line buffering. */ +extern void tui_puts_file (struct ui_file *file, const char *string); + +/* Flush console output. */ +extern void tui_flush_stdout (void); /* Setup the IO for curses or non-curses mode. */ extern void tui_setup_io (int mode); @@ -41,6 +46,7 @@ extern int tui_getc (FILE *); changed the edited text. */ extern void tui_redisplay_readline (void); +extern struct ui_file *tui_stdout; extern struct ui_out *tui_out; extern struct ui_out *tui_old_uiout;