diff options
author | Doug Evans <dje@google.com> | 2013-03-21 17:37:30 +0000 |
---|---|---|
committer | Doug Evans <dje@google.com> | 2013-03-21 17:37:30 +0000 |
commit | bd712aed2f88ab824d403c55a212c2be3f41a335 (patch) | |
tree | 490fa4cc174545d0a4962ef985b39c00ffad42e3 /gdb/utils.c | |
parent | d76488d84eb95326e157d8deca0f626914036667 (diff) | |
download | gdb-bd712aed2f88ab824d403c55a212c2be3f41a335.zip gdb-bd712aed2f88ab824d403c55a212c2be3f41a335.tar.gz gdb-bd712aed2f88ab824d403c55a212c2be3f41a335.tar.bz2 |
New commands "mt set per-command {space,time,symtab} {on,off}".
* NEWS: Add entry.
* event-top.c: #include "maint.h".
* main.c: #include "maint.h".
* maint.c: #include <sys/time.h>, <time.h>, block.h, top.h,
timeval-utils.h, maint.h, cli/cli-setshow.h.
(per_command_time, per_command_space): New static globals.
(per_command_symtab): New static global.
(per_command_setlist, per_command_showlist): New static globals.
(struct cmd_stats): Move here from utils.c.
(set_per_command_time): Renamed from set_display_time in utils.c
and moved here. All callers updated.
(set_per_command_space): Renamed from set_display_space in utils.c
and moved here. All callers updated.
(count_symtabs_and_blocks): New function.
(report_command_stats): Moved here from utils.c. Add support for
printing symtab stats. Only print data if enabled before command
executed.
(make_command_stats_cleanup): Ditto.
(sert_per_command_cmd, show_per_command_cmd): New functions.
(_initialize_maint_cmds): Add new commands
mt set per-command {space,time,symtab} {on,off}.
* maint.h: New file.
* top.c: #include "maint.h".
* utils.c (reset_prompt_for_continue_wait_time): New function.
(get_prompt_for_continue_wait_time): New function.
* utils.h (reset_prompt_for_continue_wait_time): Declare
(get_prompt_for_continue_wait_time): Declare.
(make_command_stats_cleanup): Moved to maint.h.
(set_display_time, set_display_space): Moved to maint.h and renamed
to set_per_command_time, set_per_command_space.
* cli/cli-setshow.c (parse_cli_boolean_value): Renamed from
parse_binary_operation and made non-static. Don't call error,
just return an error marker. All callers updated.
* cli/cli-setshow.h (parse_cli_boolean_value): Declare.
doc/
* gdb.texinfo (Maintenance Commands): Add docs for
"mt set per-command {space,time,symtab} {on,off}".
testsuite/
* gdb.base/maint.exp: Update tests for per-command stats.
Diffstat (limited to 'gdb/utils.c')
-rw-r--r-- | gdb/utils.c | 129 |
1 files changed, 18 insertions, 111 deletions
diff --git a/gdb/utils.c b/gdb/utils.c index 4c2f08c..a28c782 100644 --- a/gdb/utils.c +++ b/gdb/utils.c @@ -544,117 +544,6 @@ free_current_contents (void *ptr) *location = NULL; } } - -/* 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_cpu_time; - struct timeval start_wall_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_cpu_time; - struct timeval now_wall_time, delta_wall_time; - - gettimeofday (&now_wall_time, NULL); - timeval_sub (&delta_wall_time, - &now_wall_time, &start_stats->start_wall_time); - - /* Subtract time spend in prompt_for_continue from walltime. */ - timeval_sub (&delta_wall_time, - &delta_wall_time, &prompt_for_continue_wait_time); - - printf_unfiltered (msg_type == 0 - ? _("Startup time: %ld.%06ld (cpu), %ld.%06ld (wall)\n") - : _("Command execution time: %ld.%06ld (cpu), %ld.%06ld (wall)\n"), - cmd_time / 1000000, cmd_time % 1000000, - (long) delta_wall_time.tv_sec, - (long) delta_wall_time.tv_usec); - } - - 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 (%s%ld during startup)\n") - : _("Space used: %ld (%s%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) -{ - static const struct timeval zero_timeval = { 0 }; - 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_cpu_time = get_run_time (); - gettimeofday (&new_stat->start_wall_time, NULL); - - /* Initalize timer to keep track of how long we waited for the user. */ - prompt_for_continue_wait_time = zero_timeval; - - return make_cleanup_dtor (report_command_stats, new_stat, xfree); -} @@ -1924,6 +1813,24 @@ prompt_for_continue (void) dont_repeat (); /* Forget prev cmd -- CR won't repeat it. */ } +/* Initalize timer to keep track of how long we waited for the user. */ + +void +reset_prompt_for_continue_wait_time (void) +{ + static const struct timeval zero_timeval = { 0 }; + + prompt_for_continue_wait_time = zero_timeval; +} + +/* Fetch the cumulative time spent in prompt_for_continue. */ + +struct timeval +get_prompt_for_continue_wait_time (void) +{ + return prompt_for_continue_wait_time; +} + /* Reinitialize filter; ie. tell it to reset to original values. */ void |