summaryrefslogtreecommitdiff
path: root/gdb/main.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/main.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/main.c')
-rw-r--r--gdb/main.c34
1 files changed, 4 insertions, 30 deletions
diff --git a/gdb/main.c b/gdb/main.c
index c5c712acff8..bfd12135738 100644
--- a/gdb/main.c
+++ b/gdb/main.c
@@ -43,14 +43,6 @@
#include "cli/cli-cmds.h"
#include "python/python.h"
-/* If nonzero, display time usage both at startup and for each command. */
-
-int display_time;
-
-/* If nonzero, display space usage both at startup and for each command. */
-
-int display_space;
-
/* The selected interpreter. This will be used as a set command
variable, so it should always be malloc'ed - since
do_setshow_command will free it. */
@@ -299,7 +291,7 @@ captured_main (void *data)
int i;
int save_auto_load;
- long time_at_startup = get_run_time ();
+ struct cleanup *pre_stat_chain = make_command_stats_cleanup (0);
#if defined (HAVE_SETLOCALE) && defined (HAVE_LC_MESSAGES)
setlocale (LC_MESSAGES, "");
@@ -485,8 +477,8 @@ captured_main (void *data)
break;
case OPT_STATISTICS:
/* Enable the display of both time and space usage. */
- display_time = 1;
- display_space = 1;
+ set_display_time (1);
+ set_display_space (1);
break;
case OPT_TUI:
/* --tui is equivalent to -i=tui. */
@@ -907,25 +899,7 @@ Can't attach to process and specify a core file at the same time."));
}
/* Show time and/or space usage. */
-
- if (display_time)
- {
- long init_time = get_run_time () - time_at_startup;
-
- printf_unfiltered (_("Startup time: %ld.%06ld\n"),
- init_time / 1000000, init_time % 1000000);
- }
-
- if (display_space)
- {
-#ifdef HAVE_SBRK
- extern char **environ;
- char *lim = (char *) sbrk (0);
-
- printf_unfiltered (_("Startup size: data size %ld\n"),
- (long) (lim - (char *) &environ));
-#endif
- }
+ do_cleanups (pre_stat_chain);
/* NOTE: cagney/1999-11-07: There is probably no reason for not
moving this loop and the code found in captured_command_loop()