summaryrefslogtreecommitdiff
path: root/gdb/top.c
diff options
context:
space:
mode:
authorPaul N. Hilfinger <hilfinger@adacore.com>2010-06-26 06:44:46 +0000
committerPaul N. Hilfinger <hilfinger@adacore.com>2010-06-26 06:44:46 +0000
commit21877d889fab20d373169bd4aa79001e28e793a0 (patch)
tree7a6f55dd808bcf0bff18d0a8ae503c9d112c4f6a /gdb/top.c
parent1063b4f43e24d344806244852745336c3014183f (diff)
downloadgdb-21877d889fab20d373169bd4aa79001e28e793a0.tar.gz
Refactor 'maint time' command statistics.
Consolidate code for displaying per-command time and space statistics to avoid duplication. Piggyback on cleanups so that statistics get printed even when commands terminate as a result of an error. Changelog * gdb/defs.h (make_command_stats_cleanup): Declare. (set_display_time): Declare. (set_display_space): Declare. * gdb/event-top.c (command_handler): Use make_command_stats_cleanup. * gdb/main.c (display_time, display_space): Move definitions to utils.c. (captured_main): Use make_command_stats_cleanup to get start-up statistics. Use set_display_time and set_display_space for processing OPT_STATISTICS case. * gdb/maint.c (maintenance_time_display): Use set_display_time. (maintenance_space_display): Use set_display_space. * gdb/top.c (execute_command): Remove obsolete 'maint time' code. (command_loop): Use make_command_stats_cleanup. * gdb/utils.c (struct cmd_stats): Structure for storing initial time and space usage. (display_time, display_space): Move definitions here from utils.c. (set_display_time): New function. (set_display_space): New function. (make_command_stats_cleanup): New function. (report_command_stats): New auxiliary function for make_command_stats_cleanup. * gdb/testsuite/gdb.gdb/selftest.exp: Adjust expected message for capturing start-up runtime.
Diffstat (limited to 'gdb/top.c')
-rw-r--r--gdb/top.c59
1 files changed, 1 insertions, 58 deletions
diff --git a/gdb/top.c b/gdb/top.c
index 3687cf7a6ec..93447fe9aa9 100644
--- a/gdb/top.c
+++ b/gdb/top.c
@@ -356,25 +356,6 @@ execute_command (char *p, int from_tty)
enum language flang;
static int warned = 0;
char *line;
- long time_at_cmd_start = 0;
-#ifdef HAVE_SBRK
- long space_at_cmd_start = 0;
-#endif
- extern int display_space;
-
- if (target_can_async_p ())
- {
- time_at_cmd_start = get_run_time ();
-
- if (display_space)
- {
-#ifdef HAVE_SBRK
- char *lim = (char *) sbrk (0);
-
- space_at_cmd_start = lim - lim_at_start;
-#endif
- }
- }
prepare_execute_command ();
@@ -486,12 +467,6 @@ command_loop (void)
struct cleanup *old_chain;
char *command;
int stdin_is_tty = ISATTY (stdin);
- long time_at_cmd_start;
-#ifdef HAVE_SBRK
- long space_at_cmd_start = 0;
-#endif
- extern int display_time;
- extern int display_space;
while (instream && !feof (instream))
{
@@ -510,16 +485,7 @@ command_loop (void)
if (command == 0)
return;
- time_at_cmd_start = get_run_time ();
-
- if (display_space)
- {
-#ifdef HAVE_SBRK
- char *lim = (char *) sbrk (0);
-
- space_at_cmd_start = lim - lim_at_start;
-#endif
- }
+ make_command_stats_cleanup (1);
execute_command (command, instream == stdin);
@@ -527,29 +493,6 @@ command_loop (void)
bpstat_do_actions ();
do_cleanups (old_chain);
-
- if (display_time)
- {
- long cmd_time = get_run_time () - time_at_cmd_start;
-
- printf_unfiltered (_("Command execution time: %ld.%06ld\n"),
- cmd_time / 1000000, cmd_time % 1000000);
- }
-
- if (display_space)
- {
-#ifdef HAVE_SBRK
- char *lim = (char *) sbrk (0);
-
- long space_now = lim - lim_at_start;
- long space_diff = space_now - space_at_cmd_start;
-
- printf_unfiltered (_("Space used: %ld (%s%ld for this command)\n"),
- space_now,
- (space_diff >= 0 ? "+" : ""),
- space_diff);
-#endif
- }
}
}