This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] Speed up "gdb -tui" output


On 02/04/2015 12:55 PM, Pedro Alves wrote:
> On 02/03/2015 06:52 PM, Pedro Alves wrote:
> 
>> I'm working on this now.
> 
> Turns out that flushing on every line like in my patch was still
> considerably (and noticeably) slower than delaying until an explicit
> gdb_flush is done, like in Doug's.  So I went with Doug's version.
> 
> The recent changes to unify CLI/TUI interface to readline tab
> completion made the patch even simpler.  Here's what I pushed
> to master.

And below's what I pushed to the 7.9 branch.  I noticed that here:

> @@ -425,6 +426,7 @@ tui_rl_display_match_list (char **matches, int len, int max)
>        if (get_y_or_n () == 0)
>  	{
>  	  tui_puts ("\n");
> +	  tui_refresh_cmd_win ();
>  	  return;
>  	}
>      }

get_y_or_n only flushes the output/question, if we're using the 
pipe trick:

/* Get a character from the command window.  This is called from the
   readline package.  */
int
tui_getc (FILE *fp)
{
  int ch;
  WINDOW *w;

  w = TUI_CMD_WIN->generic.handle;

#ifdef TUI_USE_PIPE_FOR_READLINE
  /* Flush readline output.  */
  tui_readline_output (0, 0);
#endif

so we must refresh before get_y_or_n too.

-------------
From: Doug Evans <dje@google.com>
Subject: [PATCH] Speed up GDB's TUI output

In the TUI mode, we call wrefresh after outputting every single
character.  This results in the I/O becoming very slow.  Fix this by
delaying refreshing the console window until an explicit flush of
gdb_stdout is requested, a write to any other (unbuffered) file is
done.

2015-02-04  Doug Evans  <dje@google.com>
	    Pedro Alves  <palves@redhat.com>
	    Eli Zaretskii  <eliz@gnu.org>

	PR tui/17810
	* tui/tui-command.c (tui_refresh_cmd_win): New function.
	* tui/tui-command.c (tui_refresh_cmd_win): Declare.
	* tui/tui-file.c: #include tui/tui-command.h.
	(tui_file_fputs): Refresh command window if stream is not gdb_stdout.
	(tui_file_flush): Refresh command window if stream is gdb_stdout.
	* tui/tui-io.c (tui_puts): Remove calls to wrefresh, fflush.
	(tui_readline_output): Call tui_refresh_cmd_win.
	(print_filename): Likewise.
	(tui_rl_display_match_list): Likewise.
---
 gdb/ChangeLog         | 15 +++++++++++++++
 gdb/tui/tui-command.c | 15 +++++++++++++++
 gdb/tui/tui-command.h |  3 +++
 gdb/tui/tui-file.c    | 10 +++++++++-
 gdb/tui/tui-io.c      | 14 +++++++++-----
 5 files changed, 51 insertions(+), 6 deletions(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 5cca93e..1f23daee 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,18 @@
+2015-02-04  Doug Evans  <dje@google.com>
+	    Pedro Alves  <palves@redhat.com>
+	    Eli Zaretskii  <eliz@gnu.org>
+
+	PR tui/17810
+	* tui/tui-command.c (tui_refresh_cmd_win): New function.
+	* tui/tui-command.c (tui_refresh_cmd_win): Declare.
+	* tui/tui-file.c: #include tui/tui-command.h.
+	(tui_file_fputs): Refresh command window if stream is not gdb_stdout.
+	(tui_file_flush): Refresh command window if stream is gdb_stdout.
+	* tui/tui-io.c (tui_puts): Remove calls to wrefresh, fflush.
+	(tui_readline_output): Call tui_refresh_cmd_win.
+	(print_filename): Likewise.
+	(tui_rl_display_match_list): Likewise.
+
 2015-02-03  Jan Kratochvil  <jan.kratochvil@redhat.com>
 
 	Filter out inferior gcc option -fpreprocessed.
diff --git a/gdb/tui/tui-command.c b/gdb/tui/tui-command.c
index d1a5ddb..3551063 100644
--- a/gdb/tui/tui-command.c
+++ b/gdb/tui/tui-command.c
@@ -129,3 +129,18 @@ tui_dispatch_ctrl_char (unsigned int ch)
       return c;
     }
 }
+
+/* See tui-command.h.  */
+
+void
+tui_refresh_cmd_win (void)
+{
+  WINDOW *w = TUI_CMD_WIN->generic.handle;
+
+  wrefresh (w);
+
+  /* FIXME: It's not clear why this is here.
+     It was present in the original tui_puts code and is kept in order to
+     not introduce some subtle breakage.  */
+  fflush (stdout);
+}
diff --git a/gdb/tui/tui-command.h b/gdb/tui/tui-command.h
index 8cc5be4..ede2ecc 100644
--- a/gdb/tui/tui-command.h
+++ b/gdb/tui/tui-command.h
@@ -24,4 +24,7 @@
 
 extern unsigned int tui_dispatch_ctrl_char (unsigned int);
 
+/* Refresh the command window.  */
+extern void tui_refresh_cmd_win (void);
+
 #endif
diff --git a/gdb/tui/tui-file.c b/gdb/tui/tui-file.c
index b32cfa6..4b4b92c 100644
--- a/gdb/tui/tui-file.c
+++ b/gdb/tui/tui-file.c
@@ -20,7 +20,7 @@
 #include "ui-file.h"
 #include "tui/tui-file.h"
 #include "tui/tui-io.h"
-
+#include "tui/tui-command.h"
 #include "tui.h"
 
 /* A ``struct ui_file'' that is compatible with all the legacy
@@ -179,6 +179,10 @@ tui_file_fputs (const char *linebuffer, struct ui_file *file)
   else
     {
       tui_puts (linebuffer);
+      /* gdb_stdout is buffered, and the caller must gdb_flush it at
+	 appropriate times.  Other streams are not so buffered.  */
+      if (file != gdb_stdout)
+	tui_refresh_cmd_win ();
     }
 }
 
@@ -239,6 +243,10 @@ tui_file_flush (struct ui_file *file)
     case astring:
       break;
     case afile:
+      /* gdb_stdout is buffered.  Other files are always flushed on
+	 every write.  */
+      if (file == gdb_stdout)
+	tui_refresh_cmd_win ();
       fflush (stream->ts_filestream);
       break;
     }
diff --git a/gdb/tui/tui-io.c b/gdb/tui/tui-io.c
index 19e9485..13cc5fa 100644
--- a/gdb/tui/tui-io.c
+++ b/gdb/tui/tui-io.c
@@ -158,7 +158,10 @@ tui_putc (char c)
   tui_puts (buf);
 }
 
-/* Print the string in the curses command window.  */
+/* Print the string in the curses command window.
+   The output is buffered.  It is up to the caller to refresh the screen
+   if necessary.  */
+
 void
 tui_puts (const char *string)
 {
@@ -200,10 +203,6 @@ tui_puts (const char *string)
          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);
 }
 
 /* Readline callback.
@@ -342,6 +341,7 @@ tui_readline_output (int error, gdb_client_data data)
     {
       buf[size] = 0;
       tui_puts (buf);
+      tui_refresh_cmd_win ();
     }
 }
 #endif
@@ -393,6 +393,7 @@ print_filename (const char *to_print, const char *full_pathname)
     {
       PUTX (*s);
     }
+  tui_refresh_cmd_win ();
   return printed_len;
 }
 
@@ -448,9 +449,11 @@ 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_refresh_cmd_win ();
       if (get_y_or_n () == 0)
 	{
 	  tui_puts ("\n");
+	  tui_refresh_cmd_win ();
 	  return;
 	}
     }
@@ -522,6 +525,7 @@ tui_rl_display_match_list (char **matches, int len, int max)
 	}
       tui_putc ('\n');
     }
+  tui_refresh_cmd_win ();
 }
 
 /* Setup the IO for curses or non-curses mode.
-- 
1.9.3



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]