+2010-06-25 Paul Hilfinger <hilfinger@adacore.com>
+
+ * defs.h (make_command_stats_cleanup): Declare.
+ (set_display_time): Declare.
+ (set_display_space): Declare.
+ * event-top.c (command_handler): Use make_command_stats_cleanup.
+ * 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.
+ * maint.c (maintenance_time_display): Use set_display_time.
+ (maintenance_space_display): Use set_display_space.
+ * top.c (execute_command): Remove obsolete 'maint time' code.
+ (command_loop): Use make_command_stats_cleanup.
+ * 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.
+
2010-06-25 Ulrich Weigand <uweigand@de.ibm.com>
* solib-spu.c (append_ocl_sos): Fix xsnprintf statement for
extern char *safe_strerror (int);
+extern void set_display_time (int);
+
+extern void set_display_space (int);
+
#define ALL_CLEANUPS ((struct cleanup *)0)
extern void do_cleanups (struct cleanup *);
extern void null_cleanup (void *);
+extern struct cleanup *make_command_stats_cleanup (int);
+
extern int myread (int, char *, int);
extern int query (const char *, ...) ATTRIBUTE_PRINTF (1, 2);
command_handler (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;
+ struct cleanup *stat_chain;
quit_flag = 0;
if (instream == stdin && stdin_is_tty)
execute_command ("quit", stdin == instream);
}
- 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
- }
+ stat_chain = make_command_stats_cleanup (1);
execute_command (command, instream == stdin);
/* Do any commands attached to breakpoint we stopped at. */
bpstat_do_actions ();
- 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 (%c%ld for this command)\n"),
- space_now,
- (space_diff >= 0 ? '+' : '-'),
- space_diff);
-#endif
- }
+ do_cleanups (stat_chain);
}
/* Handle a complete line of input. This is called by the callback
#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. */
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, "");
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. */
}
/* 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()
static void
maintenance_time_display (char *args, int from_tty)
{
- extern int display_time;
-
if (args == NULL || *args == '\0')
printf_unfiltered (_("\"maintenance time\" takes a numeric argument.\n"));
else
- display_time = strtol (args, NULL, 10);
+ set_display_time (strtol (args, NULL, 10));
}
static void
maintenance_space_display (char *args, int from_tty)
{
- extern int display_space;
-
if (args == NULL || *args == '\0')
printf_unfiltered ("\"maintenance space\" takes a numeric argument.\n");
else
- display_space = strtol (args, NULL, 10);
+ set_display_space (strtol (args, NULL, 10));
}
/* The "maintenance info" command is defined as a prefix, with
+2010-06-25 Paul Hilfinger <hilfinger@adacore.com>
+
+ * gdb.gdb/selftest.exp: Adjust expected message for
+ capturing start-up runtime.
+
2010-06-25 Tom Tromey <tromey@redhat.com>
PR python/10808:
set description "step over ttyarg initialization"
set command "step"
}
- -re ".*time_at_startup = get_run_time.*$gdb_prompt $" {
- set description "next over get_run_time and everything it calls"
+ -re ".*pre_stat_chain = make_command_stats_cleanup.*$gdb_prompt $" {
+ set description "next over make_command_stats_cleanup and everything it calls"
set command "next"
}
-re ".*START_PROGRESS.*$gdb_prompt $" {
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 ();
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))
{
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);
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
- }
}
}
\f
{
}
+/* If nonzero, display time usage both at startup and for each command. */
+
+static int display_time;
+
+/* If nonzero, display space usage both at startup and for each command. */
+
+static int display_space;
+
+/* Records a run time and space usage to be used as a base for
+ reporting elapsed time or change in space. In addition,
+ the msg_type field indicates whether the saved time is from the
+ beginning of GDB execution (0) or the beginning of an individual
+ command execution (1). */
+struct cmd_stats
+{
+ int msg_type;
+ long start_time;
+ long start_space;
+};
+
+/* Set whether to display time statistics to NEW_VALUE (non-zero
+ means true). */
+void
+set_display_time (int new_value)
+{
+ display_time = new_value;
+}
+
+/* Set whether to display space statistics to NEW_VALUE (non-zero
+ means true). */
+void
+set_display_space (int new_value)
+{
+ display_space = new_value;
+}
+
+/* As indicated by display_time and display_space, report GDB's elapsed time
+ and space usage from the base time and space provided in ARG, which
+ must be a pointer to a struct cmd_stat. This function is intended
+ to be called as a cleanup. */
+static void
+report_command_stats (void *arg)
+{
+ struct cmd_stats *start_stats = (struct cmd_stats *) arg;
+ int msg_type = start_stats->msg_type;
+
+ if (display_time)
+ {
+ long cmd_time = get_run_time () - start_stats->start_time;
+
+ printf_unfiltered (msg_type == 0
+ ? _("Startup time: %ld.%06ld\n")
+ : _("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 - start_stats->start_space;
+
+ printf_unfiltered (msg_type == 0
+ ? _("Space used: %ld (%c%ld during startup)\n")
+ : _("Space used: %ld (%c%ld for this command)\n"),
+ space_now,
+ (space_diff >= 0 ? '+' : '-'),
+ space_diff);
+#endif
+ }
+}
+
+/* Create a cleanup that reports time and space used since its
+ creation. Precise messages depend on MSG_TYPE:
+ 0: Initial time/space
+ 1: Individual command time/space. */
+struct cleanup *
+make_command_stats_cleanup (int msg_type)
+{
+ struct cmd_stats *new_stat = XMALLOC (struct cmd_stats);
+
+#ifdef HAVE_SBRK
+ char *lim = (char *) sbrk (0);
+ new_stat->start_space = lim - lim_at_start;
+#endif
+
+ new_stat->msg_type = msg_type;
+ new_stat->start_time = get_run_time ();
+
+ return make_cleanup_dtor (report_command_stats, new_stat, xfree);
+}
+
/* Continuations are implemented as cleanups internally. Inherit from
cleanups. */
struct continuation