This is the mail archive of the
gdb-patches@sources.redhat.com
mailing list for the GDB project.
[RFA] patch to add 'maint profile-gdb' command
- To: gdb-patches at sources dot redhat dot com
- Subject: [RFA] patch to add 'maint profile-gdb' command
- From: Jason Molenda <jason-swarelist at molenda dot com>
- Date: Mon, 10 Sep 2001 00:30:22 -0700
- Cc: Tom Tromey <tromey at cygnus dot com>
This is a refresh of Tom Tromey's gdb profiling patch, originally here:
http://sources.redhat.com/ml/gdb-patches/2000-q1/msg00022.html
Instead of profiling all of gdb, Tom's patch lets you profile a
specific command (or commands). You enable profiling with the
'maint profile-gdb on' before the command(s) of interest, and
'maint profile-gdb off' (or exit) when you're finished.
configure and config.in both need to be regenerated after applying
this patch. Your build must be compiled with --enable-profiling
for this feature to be enabled.
My only comments on this patch are (1) the documentation entry
could note that your gmon.out file will be overwritten each time
gdb is started, even if you don't do a profile-gdb on command[1], and
(2) the configure.in check for $enable_profiling could be embedded
in the AC_ARG_ENABLE() autoconf call. It doesn't make any practical
difference, but it looks like tradition in gdb's configure.in is
to include this code inside the AC_ARG_ENABLE call.
[1] A bit of profiling happens before it can be turned
off in captured_main(). This initial profiling will overwrite
away any existing gmon.out. At least it does with the gprof
on Linux and FreeBSD systems.
No testsuite regressions are added with this patch.
This patch does not require approval for the 5.1 branch - it is
not something end users have cause to enable.
This patch does add a couple of ifdefs in main.c, aint.c to guard
the code, but this is necessary. Obviously you can't compile in
profiling all the time (performance, portability), and you can't
make calls to the profiling system calls if you aren't compiling
-pg.
Jason
2000-01-16 Tom Tromey <tromey@cygnus.com>
* maint.c (maint_profile_gdb): New function.
(_initialize_maint_cmds): Add `profile-gdb' command if profiling
enabled.
* main.c (captured_main): Call moncontrol if profiling enabled.
* config.in, configure: Rebuilt.
* configure.in: Added --enable-profiling. Define PROFILE_CFLAGS
and ENABLE_PROFILE as appropriate.
* acconfig.h (ENABLE_PROFILE): Added.
* Makefile.in (PROFILE_CFLAGS): Define as @PROFILE_CFLAGS@.
2000-01-16 Tom Tromey <tromey@cygnus.com>
* gdbint.texinfo (Profiling GDB): New node.
2000-01-16 Tom Tromey <tromey@cygnus.com>
* gdb.base/selftest.exp (do_steps_and_nexts): Account for
possible `moncontrol' call at startup.
Index: Makefile.in
===================================================================
RCS file: /cvs/src/src/gdb/Makefile.in,v
retrieving revision 1.115
diff -u -p -r1.115 Makefile.in
--- Makefile.in 2001/09/07 21:27:35 1.115
+++ Makefile.in 2001/09/10 07:14:48
@@ -314,7 +314,7 @@ GDB_CFLAGS = -I. -I$(srcdir) -I$(srcdir)
# M{H,T}_CFLAGS, if defined, have host- and target-dependent CFLAGS
# from the config directory.
GLOBAL_CFLAGS = $(MT_CFLAGS) $(MH_CFLAGS)
-#PROFILE_CFLAGS = -pg
+PROFILE_CFLAGS = @PROFILE_CFLAGS@
# CFLAGS is specifically reserved for setting from the command line
# when running make. I.E. "make CFLAGS=-Wmissing-prototypes".
Index: NEWS
===================================================================
RCS file: /cvs/src/src/gdb/NEWS,v
retrieving revision 1.32
diff -u -p -r1.32 NEWS
--- NEWS 2001/08/02 18:42:18 1.32
+++ NEWS 2001/09/10 07:14:50
@@ -112,6 +112,13 @@ name from a name of a function in that f
`set demangle-style' completes on available demangling styles.
+* Profiling for gdb
+
+If gdb is configured with `--enable-profiling', then gdb is built with
+`-pg' and a new `maintenance profile-gdb' command is created. This
+command can be used to enable or disable profiling, making it possible
+to profile a single command or set of commands.
+
* New platform-independent commands:
It is now possible to define a post-hook for a command as well as a
Index: acconfig.h
===================================================================
RCS file: /cvs/src/src/gdb/acconfig.h,v
retrieving revision 1.16
diff -u -p -r1.16 acconfig.h
--- acconfig.h 2001/03/31 18:09:02 1.16
+++ acconfig.h 2001/09/10 07:14:50
@@ -170,3 +170,6 @@
/* nativefile */
#undef GDB_NM_FILE
+
+/* Define if profiling support should be enabled. */
+#undef ENABLE_PROFILE
Index: configure.in
===================================================================
RCS file: /cvs/src/src/gdb/configure.in,v
retrieving revision 1.72
diff -u -p -r1.72 configure.in
--- configure.in 2001/09/06 20:59:18 1.72
+++ configure.in 2001/09/10 07:14:54
@@ -46,6 +46,7 @@ CONFIG_DEPS=
CONFIG_SRCS=
CONFIG_INITS=
ENABLE_CFLAGS=
+PROFILE_CFLAGS=
CONFIG_ALL=
CONFIG_CLEAN=
CONFIG_INSTALL=
@@ -654,6 +655,14 @@ if test $want_uiout = true; then
UIOUT_CFLAGS="-DUI_OUT=1"
fi
+AC_ARG_ENABLE(profiling,
+[ --enable-profiling Turn on profiling of gdb])
+
+if test "$enable_profiling" = yes; then
+ AC_DEFINE(ENABLE_PROFILE)
+ PROFILE_CFLAGS=-pg
+fi
+
AC_ARG_ENABLE(tui,
[ --enable-tui Enable full-screen terminal user interface],
[
@@ -1109,6 +1118,7 @@ AC_SUBST(IGNORE_SIM)
AC_SUBST(IGNORE_SIM_OBS)
AC_SUBST(ENABLE_CFLAGS)
+AC_SUBST(PROFILE_CFLAGS)
AC_SUBST(CONFIG_OBS)
AC_SUBST(CONFIG_LIB_OBS)
Index: main.c
===================================================================
RCS file: /cvs/src/src/gdb/main.c,v
retrieving revision 1.12
diff -u -p -r1.12 main.c
--- main.c 2001/07/14 18:59:07 1.12
+++ main.c 2001/09/10 07:14:55
@@ -158,6 +158,10 @@ captured_main (void *data)
long time_at_startup = get_run_time ();
+#ifdef ENABLE_PROFILE
+ moncontrol (0);
+#endif
+
START_PROGRESS (argv[0], 0);
#ifdef MPW
Index: maint.c
===================================================================
RCS file: /cvs/src/src/gdb/maint.c,v
retrieving revision 1.15
diff -u -p -r1.15 maint.c
--- maint.c 2001/04/11 01:01:04 1.15
+++ maint.c 2001/09/10 07:14:55
@@ -60,6 +60,11 @@ static void maintenance_print_command (c
static void maintenance_do_deprecate (char *, int);
+#ifdef ENABLE_PROFILE
+static void maint_profile_gdb PARAMS ((char *, int));
+#endif
+
+
/* Set this to the maximum number of seconds to wait instead of waiting forever
in target_wait(). If this timer times out, then it generates an error and
the command is aborted. This replaces most of the need for timeouts in the
@@ -266,6 +271,26 @@ maintenance_print_statistics (char *args
print_symbol_bcache_statistics ();
}
+/* "maintenance profile-gdb <on|off>" */
+static void
+maint_profile_gdb (char *arg, int from_tty)
+{
+#ifdef ENABLE_PROFILE
+ int val;
+ if (arg == NULL || ! *arg)
+ error ("requires argument (\"on\" or \"off\")");
+ if (! strcmp (arg, "on"))
+ val = 1;
+ else if (! strcmp (arg, "off"))
+ val = 0;
+ else
+ error ("unrecognized argument; must be \"on\" or \"off\"");
+ moncontrol (val);
+#else
+ error ("gdb was not configured with --enable-profiling");
+#endif
+}
+
void
maintenance_print_architecture (char *args, int from_tty)
{
@@ -512,6 +537,12 @@ itself a SIGQUIT signal.",
"Give GDB an internal error.\n\
Cause GDB to behave as if an internal error was detected.",
&maintenancelist);
+
+#ifdef ENABLE_PROFILE
+ add_cmd ("profile-gdb", class_maintenance, maint_profile_gdb,
+ "Enable or disable profiling.",
+ &maintenancelist);
+#endif
add_cmd ("demangle", class_maintenance, maintenance_demangle,
"Demangle a C++ mangled name.\n\
Index: doc/gdbint.texinfo
===================================================================
RCS file: /cvs/src/src/gdb/doc/gdbint.texinfo,v
retrieving revision 1.39
diff -u -p -r1.39 gdbint.texinfo
--- gdbint.texinfo 2001/09/08 10:53:45 1.39
+++ gdbint.texinfo 2001/09/10 07:15:00
@@ -4888,6 +4888,7 @@ appear anywhere else in the directory.
@menu
* Getting Started:: Getting started working on @value{GDBN}
* Debugging GDB:: Debugging @value{GDBN} with itself
+* Profiling GDB:: Profiling GDB
@end menu
@node Getting Started,,, Hints
@@ -4998,6 +4999,30 @@ routines for your local machine where th
Also, make sure that you've either compiled @value{GDBN} with your local cc, or
have run @code{fixincludes} if you are compiling with gcc.
+
+@node Profiling GDB,,, Hints
+
+@section Profiling GDB
+
+GDB contains some support for profiling itself. Currently this support
+is rudimentary.
+
+You can configure GDB with @samp{--enable-profiling}. This does two
+things. First, it arranges for GDB to be compiled and linked with
+@samp{-pg}. (This might not work on all platforms; feel free to submit
+patches to fix this for your platform.) Second, this configure flag
+arranges for the @code{maint profile-gdb} command to be enabled.
+
+@code{maint profile-gdb} takes a single argument, which must be
+@samp{on} or @samp{off}. This command enables or disables profiling of
+gdb, and can be used to limit profiling to a chosen set of user
+commands.
+
+Note that when configured this way, GDB disables profiling in
+@code{main}. If you want to profile GDB's initialization code, you will
+have to arrange to build GDB with @code{-pg} but without
+@samp{ENABLE_PROFILE} defined.
+
@section Submitting Patches
Index: testsuite/gdb.base/selftest.exp
===================================================================
RCS file: /cvs/src/src/gdb/testsuite/gdb.base/selftest.exp,v
retrieving revision 1.2
diff -u -p -r1.2 selftest.exp
--- selftest.exp 2001/03/06 08:21:51 1.2
+++ selftest.exp 2001/09/10 07:15:01
@@ -99,6 +99,10 @@ proc do_steps_and_nexts {} {
set description "next over get_run_time and everything it calls"
set command "next"
}
+ -re ".*moncontrol.*$gdb_prompt $" {
+ set description "next over moncontrol"
+ set command "next"
+ }
-re ".*START_PROGRESS.*$gdb_prompt $" {
set description "next over START_PROGRESS and everything it calls"
set command "next"