Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [RFC] Re: Profiling gdb?
       [not found] ` <3C4B8A6B.30407@cygnus.com>
@ 2003-01-05 22:27   ` Daniel Jacobowitz
  2003-01-06  4:39     ` Eli Zaretskii
  2003-01-06 14:17     ` Andrew Cagney
  0 siblings, 2 replies; 8+ messages in thread
From: Daniel Jacobowitz @ 2003-01-05 22:27 UTC (permalink / raw)
  To: gdb-patches

On Sun, Jan 20, 2002 at 10:26:35PM -0500, Andrew Cagney wrote:
> >What was the final status of the profiling patch?  It's a feature I'd
> >really like to see in (having it in means fewer local changes in my
> >tree when I'm testing the speed of something!).
> 
> 
> Interesting timing, I was just looking over the same thing.

And then neither of us did anything about it for a while.  Cue music, a
year later.

> My take is:
> 
> 
> Part 1: ``(gdb) maint set moncontrol {on,off}''
> 
> A home for the command doco (gdb.texinfo) has been created.
> 
> The necessary framework (maint set) has been added along with the 
> function to correctly implement a boolean command.  Note:
> http://sources.redhat.com/gdb/ari/#var_boolean
> 
> The command should always be present but the call should be wrapped in a 
> check that the function exits.  The function moncontrol() is in both the 
> libc and libc_p libraries (at least on correctly implemented systems :-) 
> so this is correct.

Check.

> Part 2: Add the --<what-was-that-profile-option>
> 
> Which adds the compile/link -gp flag.
> 
> Eli's comment that you don't need to link with -gp is correct.
> 
> Perhaphs the <what-was-that-profile-option> should let the user control 
> the compile and link flags.
> 
> Don't remember where the doco for this goes.

Check.  Without the extra bit of configurability for now.

> Part 3: (new) ``(gdb) maint set monstartup <lowpc> <highpc>
> 
> Can anyone think why we shouldn't make this visible.  Of course the user 
> will need to somehow obtain the magic addresses from somewhere.
> 
> Same as moncontrol().

Perhaps some other time.  I do _use_ monstartup, however.

This patch should address all comments from the last three times this
came up.  I chose to use monstartup/_mcleanup instead of using
moncontrol; when someone wants to use this on a system without those
functions, _then_ we can decide how to handle it.  That's just my
opinion though.  What I've done should work for at least GNU/Linux and
FreeBSD, and that's enough to be useful.  It only comes in if you
configure it on, anyway.

It works like a charm; absolutely beautifully.  Thoughts, all?

-- 
Daniel Jacobowitz
MontaVista Software                         Debian GNU/Linux Developer

2003-01-05  Daniel Jacobowitz  <drow@mvista.com>

	Original patch by Tom Tromey <tromey@cygnus.com>.
	* Makefile.in (PROFILE_CFLAGS): Substitute from configure.
	(INTERNAL_LDFLAGS): Don't include PROFILE_CFLAGS.
	* NEWS: Mention profiling.
	* configure.in (--enable-gdbtk): Fix typo.
	(--enable-profiling): New.  Set PROFILE_CFLAGS.  Define
	ENABLE_PROFILING.
	* maint.c (maintenance_set_profile_cmd): Remove NOTYET.
	Fill in function.
	(profiling_state): New variable.
	(mcleanup_wrapper): New function.
	(_initialize_maint): Remove NOTYET, fix call to
	add_setshow_boolean_cmd for "maint set profile".

2003-01-05  Daniel Jacobowitz  <drow@mvista.com>

	* gdb.texinfo (Maintenance Commands): Add "maint set profile"
	and "maint show profile".

Index: Makefile.in
===================================================================
RCS file: /cvs/src/src/gdb/Makefile.in,v
retrieving revision 1.309
diff -u -p -r1.309 Makefile.in
--- Makefile.in	5 Jan 2003 01:39:54 -0000	1.309
+++ Makefile.in	5 Jan 2003 22:13:53 -0000
@@ -318,7 +318,8 @@ 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".
@@ -345,7 +346,8 @@ LDFLAGS = @LDFLAGS@
 # Profiling options need to go here to work.
 # I think it's perfectly reasonable for a user to set -pg in CFLAGS
 # and have it work; that's why CFLAGS is here.
-INTERNAL_LDFLAGS = $(CFLAGS) $(GLOBAL_CFLAGS) $(PROFILE_CFLAGS) $(MH_LDFLAGS) $(LDFLAGS) $(CONFIG_LDFLAGS)
+# PROFILE_CFLAGS is _not_ included, however, because we use monstartup.
+INTERNAL_LDFLAGS = $(CFLAGS) $(GLOBAL_CFLAGS) $(MH_LDFLAGS) $(LDFLAGS) $(CONFIG_LDFLAGS)
 
 # If your system is missing alloca(), or, more likely, it's there but
 # it doesn't work, then refer to libiberty.
Index: NEWS
===================================================================
RCS file: /cvs/src/src/gdb/NEWS,v
retrieving revision 1.97
diff -u -p -r1.97 NEWS
--- NEWS	2 Jan 2003 14:27:26 -0000	1.97
+++ NEWS	5 Jan 2003 22:13:54 -0000
@@ -3,6 +3,13 @@
 
 *** Changes since GDB 5.3:
 
+* Profiling for gdb
+
+If gdb is configured with `--enable-profiling', then gdb is built with
+`-pg' and the `maint set profile' command is enabled.  This command can
+be used to enable or disable profiling, making it possible to profile a
+single command or set of commands.
+
 * Default MI syntax changed to "mi2".
 
 The default MI (machine interface) syntax, enabled by the command line
Index: configure.in
===================================================================
RCS file: /cvs/src/src/gdb/configure.in,v
retrieving revision 1.116
diff -u -p -r1.116 configure.in
--- configure.in	4 Jan 2003 23:47:12 -0000	1.116
+++ configure.in	5 Jan 2003 22:13:54 -0000
@@ -164,7 +164,7 @@ fi
 
 # Enable gdbtk.
 AC_ARG_ENABLE(gdbtk,
-[  --enable-gtk            enable gdbtk graphical user interface (GUI)],
+[  --enable-gdbtk          enable gdbtk graphical user interface (GUI)],
   [case $enableval in
     yes | no)
       ;;
@@ -183,6 +183,33 @@ case $host_os in
     enable_gdbtk=no ;;
 esac
 
+# Profiling support.
+AC_ARG_ENABLE(profiling,
+[  --enable-profiling      enable profiling of GDB],
+  [case $enableval in
+    yes | no)
+      ;;
+    *)
+      AC_MSG_ERROR([bad value $enableval for --enable-profile]) ;;
+  esac],
+ [enable_profiling=no])
+
+if test "$enable_profiling" = yes ; then
+  PROFILE_CFLAGS=-pg
+  OLD_CFLAGS="$CFLAGS"
+  CFLAGS="$CFLAGS $PROFILE_CFLAGS"
+
+  AC_CHECK_FUNC(monstartup, [],
+    AC_MSG_ERROR(monstartup necessary to use --enable-profiling.))
+
+  AC_CHECK_FUNC(_mcleanup, [],
+    AC_MSG_ERROR(_mcleanup necessary to use --enable-profiling.))
+
+  CFLAGS="$OLD_CFLAGS"
+  AC_DEFINE_UNQUOTED(ENABLE_PROFILING, 1,
+		     [Define if profiling support should be enabled.])
+fi
+
 # --------------------- #
 # Checks for programs.  #
 # --------------------- #
@@ -1132,6 +1162,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: maint.c
===================================================================
RCS file: /cvs/src/src/gdb/maint.c,v
retrieving revision 1.30
diff -u -p -r1.30 maint.c
--- maint.c	24 Dec 2002 03:57:58 -0000	1.30
+++ maint.c	5 Jan 2003 22:13:54 -0000
@@ -639,18 +639,57 @@ maintenance_show_cmd (char *args, int fr
   cmd_show_list (maintenance_show_cmdlist, from_tty, "");
 }
 
-#ifdef NOTYET
 /* Profiling support.  */
 
 static int maintenance_profile_p;
+static int profiling_state;
+
+static void
+mcleanup_wrapper (void)
+{
+  extern void _mcleanup (void);
+
+  if (profiling_state)
+    _mcleanup ();
+}
 
 static void
 maintenance_set_profile_cmd (char *args, int from_tty, struct cmd_list_element *c)
 {
+#ifdef ENABLE_PROFILING
+  if (maintenance_profile_p == profiling_state)
+    return;
+
+  profiling_state = maintenance_profile_p;
+
+  if (maintenance_profile_p)
+    {
+      static int profiling_initialized;
+
+      extern void monstartup (long, long);
+      extern char _etext;
+      extern int main();
+
+      if (!profiling_initialized)
+	{
+	  atexit (mcleanup_wrapper);
+	  profiling_initialized = 1;
+	}
+
+      /* "main" is now always the first function in the text segment, so use
+	 its address for monstartup.  */
+      monstartup ((long) &main, (long) &_etext);
+    }
+  else
+    {
+      extern void _mcleanup (void);
+      _mcleanup ();
+    }
+#else
   maintenance_profile_p = 0;
   warning ("\"maintenance set profile\" command not supported.\n");
-}
 #endif
+}
 
 void
 _initialize_maint_cmds (void)
@@ -807,16 +846,12 @@ passes without a response from the targe
 		      &showlist);
 
 
-#ifdef NOTYET
-  /* FIXME: cagney/2002-06-15: A patch implementing profiling is
-     pending, this just sets up the framework.  */
-  tmpcmd = add_setshow_boolean_cmd ("profile", class_maintenance,
-				    var_boolean, &maintenance_profile_p, "\
-Set internal profiling.\n\
-When enabled GDB is profiled.", "\
-Show internal profiling.\n",
-				    maintenance_set_profile_cmd, NULL,
-				    &maintenance_set_cmdlist,
-				    &maintenance_show_cmdlist);
-#endif
+  add_setshow_boolean_cmd ("profile", class_maintenance,
+			   &maintenance_profile_p,
+			   "Set internal profiling.\n"
+			   "When enabled GDB is profiled.",
+			   "Show internal profiling.\n",
+			   maintenance_set_profile_cmd, NULL,
+			   &maintenance_set_cmdlist,
+			   &maintenance_show_cmdlist);
 }
Index: doc/gdb.texinfo
===================================================================
RCS file: /cvs/src/src/gdb/doc/gdb.texinfo,v
retrieving revision 1.136
diff -u -p -r1.136 gdb.texinfo
--- doc/gdb.texinfo	5 Jan 2003 04:34:39 -0000	1.136
+++ doc/gdb.texinfo	5 Jan 2003 22:13:59 -0000
@@ -14385,6 +14385,20 @@ cooked-registers} includes the (cooked) 
 
 Takes an optional file parameter.
 
+@kindex maint set profile
+@kindex maint show profile
+@item maint set profile
+@itemx maint show profile
+Control profiling of @value{GDBN}.  These commands are only available if
+@samp{--enable-profiling} is used to build @value{GDBN}.
+
+Configuring with @samp{--enable-profiling} arranges for @value{GDBN} to
+be compiled with the @samp{-pg} compiler option.  Profiling will be disabled
+until you use the @samp{maint set profile} command to enable it.  When
+profiling is turned on, @value{GDBN} will overwrite the profiling log file
+(often called @file{gmon.out}).  If you have a record of important profiling
+data in a @file{gmon.out} file, be sure to move it to a safe location.
+
 @end table
 
 


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [RFC] Re: Profiling gdb?
  2003-01-05 22:27   ` [RFC] Re: Profiling gdb? Daniel Jacobowitz
@ 2003-01-06  4:39     ` Eli Zaretskii
  2003-01-06 14:17     ` Andrew Cagney
  1 sibling, 0 replies; 8+ messages in thread
From: Eli Zaretskii @ 2003-01-06  4:39 UTC (permalink / raw)
  To: drow; +Cc: gdb-patches

> Date: Sun, 5 Jan 2003 17:27:13 -0500
> From: Daniel Jacobowitz <drow@mvista.com>
> > 
> > Don't remember where the doco for this goes.
> 
> Check.  Without the extra bit of configurability for now.

The doco patch is approved, but please add a "@cindex profiling GDB"
index entry for this text.

Thanks.


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [RFC] Re: Profiling gdb?
  2003-01-05 22:27   ` [RFC] Re: Profiling gdb? Daniel Jacobowitz
  2003-01-06  4:39     ` Eli Zaretskii
@ 2003-01-06 14:17     ` Andrew Cagney
  2003-01-06 15:12       ` Daniel Jacobowitz
  1 sibling, 1 reply; 8+ messages in thread
From: Andrew Cagney @ 2003-01-06 14:17 UTC (permalink / raw)
  To: Daniel Jacobowitz; +Cc: gdb-patches

> 
> Perhaps some other time.  I do _use_ monstartup, however.
> 
> This patch should address all comments from the last three times this
> came up.  I chose to use monstartup/_mcleanup instead of using
> moncontrol; when someone wants to use this on a system without those
> functions, _then_ we can decide how to handle it.  That's just my
> opinion though.  What I've done should work for at least GNU/Linux and
> FreeBSD, and that's enough to be useful.  It only comes in if you
> configure it on, anyway.
> 
> It works like a charm; absolutely beautifully.  Thoughts, all?

(Unfortunatly, I've also leant a few things about how profiling works 
... :-().

I think the commands should always be present - conditional on the 
corresponding function being present.  Enabling / disabling the profiler 
is orthogonal to compiling with -pg.  I'm not sure about the unpublished 
_moncleanup() call.  Are you sure of monstartup()'s function signature 
(ari doesn't like the extern declarations but there isn't a header file 
:-().

I also suspect that more explict commands such as:

	moncontrol on/off
	monstartup [ <start> <end> ]

would be better.  The person using this feature will need to know how it 
is implemented anyway.

(Did Jason Molenda, have something to do with the original patch?)

Andrew



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [RFC] Re: Profiling gdb?
  2003-01-06 14:17     ` Andrew Cagney
@ 2003-01-06 15:12       ` Daniel Jacobowitz
  2003-01-06 16:04         ` Andrew Cagney
                           ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Daniel Jacobowitz @ 2003-01-06 15:12 UTC (permalink / raw)
  To: Andrew Cagney; +Cc: gdb-patches

On Mon, Jan 06, 2003 at 09:14:41AM -0500, Andrew Cagney wrote:
> >
> >Perhaps some other time.  I do _use_ monstartup, however.
> >
> >This patch should address all comments from the last three times this
> >came up.  I chose to use monstartup/_mcleanup instead of using
> >moncontrol; when someone wants to use this on a system without those
> >functions, _then_ we can decide how to handle it.  That's just my
> >opinion though.  What I've done should work for at least GNU/Linux and
> >FreeBSD, and that's enough to be useful.  It only comes in if you
> >configure it on, anyway.
> >
> >It works like a charm; absolutely beautifully.  Thoughts, all?
> 
> (Unfortunatly, I've also leant a few things about how profiling works 
> ... :-().

Learning is good :)  Let's take advantage of it!

> I think the commands should always be present - conditional on the 
> corresponding function being present.  Enabling / disabling the profiler 
> is orthogonal to compiling with -pg.  I'm not sure about the unpublished 

OK, I see how this works.  I'll make the configuration flag just add
-pg, and update the manual.

> _moncleanup() call.  Are you sure of monstartup()'s function signature 
> (ari doesn't like the extern declarations but there isn't a header file 
> :-().

_mcleanup() is no more or less published than monstartup(), as far as I
can tell; I'll submit a glibc patch to document these when I get around
to it.  I know both FreeBSD and GNU/Linux have these, because that's
how Emacs controls profiling.

Hmm, make that less documented, since FreeBSD has a man page for
monstartup.  They're both provided, however.

I am indeed sure of monstartup()'s function signature - well, at least
for GNU/Linux; I don't have access to a FreeBSD system but according to
the source for libc in FreeBSD 5.0 it'll work there too.  Although I
think it may leak memory in multiple runs, the way I use it.  It's
declared in a non-system-specific file as taking longs (unsigned, oops,
will fix).

> I also suspect that more explict commands such as:
> 
> 	moncontrol on/off
> 	monstartup [ <start> <end> ]
> 
> would be better.  The person using this feature will need to know how it 
> is implemented anyway.

No, they won't, IMO.  More explicit commands might be better, but I'm
going to leave that be for now, OK?  I don't see the benefit of being
able to do this - it would let you get combined profiling data for
multiple events into the same gmon.out, big deal, just profile the
stuff in the middle too.

> (Did Jason Molenda, have something to do with the original patch?)

No, but he had something to do with the revised version, I'll add him
to the ChangeLog.

Here's an updated patch, addressing your concerns and Eli's.  Like it
better?

-- 
Daniel Jacobowitz
MontaVista Software                         Debian GNU/Linux Developer

2003-01-06  Daniel Jacobowitz  <drow@mvista.com>

	Original patch by Tom Tromey <tromey@cygnus.com> and
	Jason Molenda <jmolenda@apple.com>.
	* Makefile.in (PROFILE_CFLAGS): Substitute from configure.
	(INTERNAL_LDFLAGS): Don't include PROFILE_CFLAGS.
	* NEWS: Mention profiling.
	* configure.in (--enable-gdbtk): Fix typo.
	(--enable-profiling): New.  Set PROFILE_CFLAGS.
	* maint.c (maintenance_set_profile_cmd): Remove NOTYET.
	Fill in function.
	(profiling_state): New variable.
	(mcleanup_wrapper): New function.
	(_initialize_maint): Remove NOTYET, fix call to
	add_setshow_boolean_cmd for "maint set profile".
	* configure: Regenerated.

2003-01-06  Daniel Jacobowitz  <drow@mvista.com>

	* gdb.texinfo (Maintenance Commands): Add "maint set profile"
	and "maint show profile".

Index: Makefile.in
===================================================================
RCS file: /cvs/src/src/gdb/Makefile.in,v
retrieving revision 1.309
diff -u -p -r1.309 Makefile.in
--- Makefile.in	5 Jan 2003 01:39:54 -0000	1.309
+++ Makefile.in	6 Jan 2003 15:04:01 -0000
@@ -318,7 +318,8 @@ 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".
@@ -345,7 +346,8 @@ LDFLAGS = @LDFLAGS@
 # Profiling options need to go here to work.
 # I think it's perfectly reasonable for a user to set -pg in CFLAGS
 # and have it work; that's why CFLAGS is here.
-INTERNAL_LDFLAGS = $(CFLAGS) $(GLOBAL_CFLAGS) $(PROFILE_CFLAGS) $(MH_LDFLAGS) $(LDFLAGS) $(CONFIG_LDFLAGS)
+# PROFILE_CFLAGS is _not_ included, however, because we use monstartup.
+INTERNAL_LDFLAGS = $(CFLAGS) $(GLOBAL_CFLAGS) $(MH_LDFLAGS) $(LDFLAGS) $(CONFIG_LDFLAGS)
 
 # If your system is missing alloca(), or, more likely, it's there but
 # it doesn't work, then refer to libiberty.
Index: NEWS
===================================================================
RCS file: /cvs/src/src/gdb/NEWS,v
retrieving revision 1.97
diff -u -p -r1.97 NEWS
--- NEWS	2 Jan 2003 14:27:26 -0000	1.97
+++ NEWS	6 Jan 2003 15:04:02 -0000
@@ -3,6 +3,14 @@
 
 *** Changes since GDB 5.3:
 
+* Profiling support
+
+A new command, "maint set profile on/off", has been added.  This command can
+be used to enable or disable profiling while running GDB, to profile a
+session or a set of commands.  In addition there is a new configure switch,
+"--enable-profiling", which will cause GDB to be compiled with profiling
+data, for more informative profiling results.
+
 * Default MI syntax changed to "mi2".
 
 The default MI (machine interface) syntax, enabled by the command line
Index: configure.in
===================================================================
RCS file: /cvs/src/src/gdb/configure.in,v
retrieving revision 1.116
diff -u -p -r1.116 configure.in
--- configure.in	4 Jan 2003 23:47:12 -0000	1.116
+++ configure.in	6 Jan 2003 15:04:04 -0000
@@ -164,7 +164,7 @@ fi
 
 # Enable gdbtk.
 AC_ARG_ENABLE(gdbtk,
-[  --enable-gtk            enable gdbtk graphical user interface (GUI)],
+[  --enable-gdbtk          enable gdbtk graphical user interface (GUI)],
   [case $enableval in
     yes | no)
       ;;
@@ -183,6 +183,31 @@ case $host_os in
     enable_gdbtk=no ;;
 esac
 
+# Profiling support.
+AC_ARG_ENABLE(profiling,
+[  --enable-profiling      enable profiling of GDB],
+  [case $enableval in
+    yes | no)
+      ;;
+    *)
+      AC_MSG_ERROR([bad value $enableval for --enable-profile]) ;;
+  esac],
+ [enable_profiling=no])
+
+if test "$enable_profiling" = yes ; then
+  PROFILE_CFLAGS=-pg
+  OLD_CFLAGS="$CFLAGS"
+  CFLAGS="$CFLAGS $PROFILE_CFLAGS"
+
+  AC_CHECK_FUNC(monstartup, [],
+    AC_MSG_ERROR(monstartup necessary to use --enable-profiling.))
+
+  AC_CHECK_FUNC(_mcleanup, [],
+    AC_MSG_ERROR(_mcleanup necessary to use --enable-profiling.))
+
+  CFLAGS="$OLD_CFLAGS"
+fi
+
 # --------------------- #
 # Checks for programs.  #
 # --------------------- #
@@ -1132,6 +1157,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: maint.c
===================================================================
RCS file: /cvs/src/src/gdb/maint.c,v
retrieving revision 1.30
diff -u -p -r1.30 maint.c
--- maint.c	24 Dec 2002 03:57:58 -0000	1.30
+++ maint.c	6 Jan 2003 15:04:04 -0000
@@ -639,18 +639,52 @@ maintenance_show_cmd (char *args, int fr
   cmd_show_list (maintenance_show_cmdlist, from_tty, "");
 }
 
-#ifdef NOTYET
 /* Profiling support.  */
 
 static int maintenance_profile_p;
+static int profiling_state;
+
+static void
+mcleanup_wrapper (void)
+{
+  extern void _mcleanup (void);
+
+  if (profiling_state)
+    _mcleanup ();
+}
 
 static void
 maintenance_set_profile_cmd (char *args, int from_tty, struct cmd_list_element *c)
 {
-  maintenance_profile_p = 0;
-  warning ("\"maintenance set profile\" command not supported.\n");
+  if (maintenance_profile_p == profiling_state)
+    return;
+
+  profiling_state = maintenance_profile_p;
+
+  if (maintenance_profile_p)
+    {
+      static int profiling_initialized;
+
+      extern void monstartup (unsigned long, unsigned long);
+      extern char _etext;
+      extern int main();
+
+      if (!profiling_initialized)
+	{
+	  atexit (mcleanup_wrapper);
+	  profiling_initialized = 1;
+	}
+
+      /* "main" is now always the first function in the text segment, so use
+	 its address for monstartup.  */
+      monstartup ((unsigned long) &main, (unsigned long) &_etext);
+    }
+  else
+    {
+      extern void _mcleanup (void);
+      _mcleanup ();
+    }
 }
-#endif
 
 void
 _initialize_maint_cmds (void)
@@ -807,16 +841,12 @@ passes without a response from the targe
 		      &showlist);
 
 
-#ifdef NOTYET
-  /* FIXME: cagney/2002-06-15: A patch implementing profiling is
-     pending, this just sets up the framework.  */
-  tmpcmd = add_setshow_boolean_cmd ("profile", class_maintenance,
-				    var_boolean, &maintenance_profile_p, "\
-Set internal profiling.\n\
-When enabled GDB is profiled.", "\
-Show internal profiling.\n",
-				    maintenance_set_profile_cmd, NULL,
-				    &maintenance_set_cmdlist,
-				    &maintenance_show_cmdlist);
-#endif
+  add_setshow_boolean_cmd ("profile", class_maintenance,
+			   &maintenance_profile_p,
+			   "Set internal profiling.\n"
+			   "When enabled GDB is profiled.",
+			   "Show internal profiling.\n",
+			   maintenance_set_profile_cmd, NULL,
+			   &maintenance_set_cmdlist,
+			   &maintenance_show_cmdlist);
 }
Index: doc/gdb.texinfo
===================================================================
RCS file: /cvs/src/src/gdb/doc/gdb.texinfo,v
retrieving revision 1.136
diff -u -p -r1.136 gdb.texinfo
--- doc/gdb.texinfo	5 Jan 2003 04:34:39 -0000	1.136
+++ doc/gdb.texinfo	6 Jan 2003 15:04:09 -0000
@@ -14385,6 +14385,24 @@ cooked-registers} includes the (cooked) 
 
 Takes an optional file parameter.
 
+@kindex maint set profile
+@kindex maint show profile
+@cindex profiling GDB
+@item maint set profile
+@itemx maint show profile
+Control profiling of @value{GDBN}.
+
+Profiling will be disabled until you use the @samp{maint set profile}
+command to enable it.  When you enable profiling, the system will begin
+collecting timing and execution count data; when you disable profiling or
+exit @value{GDBN}, the results will be written to a log file.  Remember that
+if you use profiling, @value{GDBN} will overwrite the profiling log file
+(often called @file{gmon.out}).  If you have a record of important profiling
+data in a @file{gmon.out} file, be sure to move it to a safe location.
+
+Configuring with @samp{--enable-profiling} arranges for @value{GDBN} to be
+compiled with the @samp{-pg} compiler option. 
+
 @end table
 
 


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [RFC] Re: Profiling gdb?
  2003-01-06 15:12       ` Daniel Jacobowitz
@ 2003-01-06 16:04         ` Andrew Cagney
  2003-01-18  3:51           ` Daniel Jacobowitz
  2003-01-06 18:38         ` Eli Zaretskii
  2003-01-22 23:52         ` Daniel Jacobowitz
  2 siblings, 1 reply; 8+ messages in thread
From: Andrew Cagney @ 2003-01-06 16:04 UTC (permalink / raw)
  To: Daniel Jacobowitz; +Cc: gdb-patches

> 
> _mcleanup() is no more or less published than monstartup(), as far as I
> can tell; I'll submit a glibc patch to document these when I get around
> to it.  I know both FreeBSD and GNU/Linux have these, because that's
> how Emacs controls profiling.

Good old emacs - can always be relied on as the keeper of portability 
knowledge.

FYI,

They are all based on the same berkley code.  Looking at the Free/Net 
BSD man pages they document.

      moncontrol(int mode);

      monstartup(u_long *lowpc, u_long *highpc);

but not _mcleanup() (hence my comment about interfaces).  One thing, 
while the doco indicates pointers, the actual code matches your 
declaration.  So gess we stick with that.

http://www.opengroup.org doesn't mention any of this.

glibc recently modified its internal structures so that are incompatible 
with the other implementations.

FreeBSD also modified the internal structures but in a `forward 
compatible' way.

NetBSD hasn't touched the code in yonks (other than to fix portability 
problems).

> Hmm, make that less documented, since FreeBSD has a man page for
> monstartup.  They're both provided, however.
> 
> I am indeed sure of monstartup()'s function signature - well, at least
> for GNU/Linux; I don't have access to a FreeBSD system but according to
> the source for libc in FreeBSD 5.0 it'll work there too.  Although I
> think it may leak memory in multiple runs, the way I use it.  It's
> declared in a non-system-specific file as taking longs (unsigned, oops,
> will fix).

Andrew



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [RFC] Re: Profiling gdb?
  2003-01-06 15:12       ` Daniel Jacobowitz
  2003-01-06 16:04         ` Andrew Cagney
@ 2003-01-06 18:38         ` Eli Zaretskii
  2003-01-22 23:52         ` Daniel Jacobowitz
  2 siblings, 0 replies; 8+ messages in thread
From: Eli Zaretskii @ 2003-01-06 18:38 UTC (permalink / raw)
  To: drow; +Cc: ac131313, gdb-patches

> Date: Mon, 6 Jan 2003 10:10:54 -0500
> From: Daniel Jacobowitz <drow@mvista.com>
> 
> Here's an updated patch, addressing your concerns and Eli's.  Like it
> better?

I'm happy with the doco patch, thanks.


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [RFC] Re: Profiling gdb?
  2003-01-06 16:04         ` Andrew Cagney
@ 2003-01-18  3:51           ` Daniel Jacobowitz
  0 siblings, 0 replies; 8+ messages in thread
From: Daniel Jacobowitz @ 2003-01-18  3:51 UTC (permalink / raw)
  To: gdb-patches

On Mon, Jan 06, 2003 at 11:04:27AM -0500, Andrew Cagney wrote:
> >
> >_mcleanup() is no more or less published than monstartup(), as far as I
> >can tell; I'll submit a glibc patch to document these when I get around
> >to it.  I know both FreeBSD and GNU/Linux have these, because that's
> >how Emacs controls profiling.
> 
> Good old emacs - can always be relied on as the keeper of portability 
> knowledge.

Andrew,

Did I resolve your remaining concerns about this patch?

-- 
Daniel Jacobowitz
MontaVista Software                         Debian GNU/Linux Developer


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [RFC] Re: Profiling gdb?
  2003-01-06 15:12       ` Daniel Jacobowitz
  2003-01-06 16:04         ` Andrew Cagney
  2003-01-06 18:38         ` Eli Zaretskii
@ 2003-01-22 23:52         ` Daniel Jacobowitz
  2 siblings, 0 replies; 8+ messages in thread
From: Daniel Jacobowitz @ 2003-01-22 23:52 UTC (permalink / raw)
  To: gdb-patches

On Mon, Jan 06, 2003 at 10:10:54AM -0500, Daniel Jacobowitz wrote:
> Here's an updated patch, addressing your concerns and Eli's.  Like it
> better?

It's [finally] in.

> 2003-01-06  Daniel Jacobowitz  <drow@mvista.com>
> 
> 	Original patch by Tom Tromey <tromey@cygnus.com> and
> 	Jason Molenda <jmolenda@apple.com>.
> 	* Makefile.in (PROFILE_CFLAGS): Substitute from configure.
> 	(INTERNAL_LDFLAGS): Don't include PROFILE_CFLAGS.
> 	* NEWS: Mention profiling.
> 	* configure.in (--enable-gdbtk): Fix typo.
> 	(--enable-profiling): New.  Set PROFILE_CFLAGS.
> 	* maint.c (maintenance_set_profile_cmd): Remove NOTYET.
> 	Fill in function.
> 	(profiling_state): New variable.
> 	(mcleanup_wrapper): New function.
> 	(_initialize_maint): Remove NOTYET, fix call to
> 	add_setshow_boolean_cmd for "maint set profile".
> 	* configure: Regenerated.
> 
> 2003-01-06  Daniel Jacobowitz  <drow@mvista.com>
> 
> 	* gdb.texinfo (Maintenance Commands): Add "maint set profile"
> 	and "maint show profile".

-- 
Daniel Jacobowitz
MontaVista Software                         Debian GNU/Linux Developer


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2003-01-22 23:52 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <20020120210343.A22638@nevyn.them.org>
     [not found] ` <3C4B8A6B.30407@cygnus.com>
2003-01-05 22:27   ` [RFC] Re: Profiling gdb? Daniel Jacobowitz
2003-01-06  4:39     ` Eli Zaretskii
2003-01-06 14:17     ` Andrew Cagney
2003-01-06 15:12       ` Daniel Jacobowitz
2003-01-06 16:04         ` Andrew Cagney
2003-01-18  3:51           ` Daniel Jacobowitz
2003-01-06 18:38         ` Eli Zaretskii
2003-01-22 23:52         ` Daniel Jacobowitz

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox