public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Doug Evans <dje@google.com>
To: Pedro Alves <palves@redhat.com>
Cc: Jan Kratochvil <jan.kratochvil@redhat.com>,
	   eliz@gnu.org,    gdb-patches@sourceware.org
Subject: Re: [PATCH] Re: Regression for GDB global --statistics
Date: Sat, 12 Jul 2014 00:42:00 -0000	[thread overview]
Message-ID: <21440.24455.769287.540494@ruffy.mtv.corp.google.com> (raw)
In-Reply-To: <53BEC275.8000004@redhat.com>

Pedro Alves writes:
 > Hi Doug,
 > 
 > On 07/09/2014 10:10 PM, Doug Evans wrote:
 > > Here's a patch.
 > > 
 > > 2014-07-09  Doug Evans  <dje@google.com>
 > > 
 > > 	* maint.c (count_symtabs_and_blocks): Handle NULL
 > > 	current_program_space.
 > 
 > It's not obvious to me how this can be NULL, given we initialize
 > it so early.  If there's a good reason, could you please add
 > a comment here mentioning it?

2014-07-11  Doug Evans  <dje@google.com>

	* maint.c (count_symtabs_and_blocks): Handle NULL
	current_program_space.
	(report_command_stats): Check global enabled flag in addition to
	recorded enabled flag.
	(make_command_stats_cleanup): Handle msg_type == 0, startup.

	testsuite/
	* gdb.base/maint.exp: Update testing of per-command stats.

diff --git a/gdb/maint.c b/gdb/maint.c
index 5f34af3..c7a937c 100644
--- a/gdb/maint.c
+++ b/gdb/maint.c
@@ -830,13 +830,19 @@ count_symtabs_and_blocks (int *nr_symtabs_ptr, int *nr_primary_symtabs_ptr,
   int nr_primary_symtabs = 0;
   int nr_blocks = 0;
 
-  ALL_SYMTABS (o, s)
+  /* When collecting statistics during startup, this is called before
+     pretty much anything in gdb has been initialized, and thus
+     current_program_space may be NULL.  */
+  if (current_program_space != NULL)
     {
-      ++nr_symtabs;
-      if (s->primary)
+      ALL_SYMTABS (o, s)
 	{
-	  ++nr_primary_symtabs;
-	  nr_blocks += BLOCKVECTOR_NBLOCKS (BLOCKVECTOR (s));
+	  ++nr_symtabs;
+	  if (s->primary)
+	    {
+	      ++nr_primary_symtabs;
+	      nr_blocks += BLOCKVECTOR_NBLOCKS (BLOCKVECTOR (s));
+	    }
 	}
     }
 
@@ -856,7 +862,7 @@ report_command_stats (void *arg)
   struct cmd_stats *start_stats = (struct cmd_stats *) arg;
   int msg_type = start_stats->msg_type;
 
-  if (start_stats->time_enabled)
+  if (start_stats->time_enabled && per_command_time)
     {
       long cmd_time = get_run_time () - start_stats->start_cpu_time;
       struct timeval now_wall_time, delta_wall_time, wait_time;
@@ -877,7 +883,7 @@ report_command_stats (void *arg)
 			 (long) delta_wall_time.tv_usec);
     }
 
-  if (start_stats->space_enabled)
+  if (start_stats->space_enabled && per_command_space)
     {
 #ifdef HAVE_SBRK
       char *lim = (char *) sbrk (0);
@@ -894,7 +900,7 @@ report_command_stats (void *arg)
 #endif
     }
 
-  if (start_stats->symtab_enabled)
+  if (start_stats->symtab_enabled && per_command_symtab)
     {
       int nr_symtabs, nr_primary_symtabs, nr_blocks;
 
@@ -920,8 +926,14 @@ make_command_stats_cleanup (int msg_type)
 {
   struct cmd_stats *new_stat;
 
-  /* Early exit if we're not reporting any stats.  */
-  if (!per_command_time
+  /* Early exit if we're not reporting any stats.  It can be expensive to
+     compute the pre-command values so don't collect them at all if we're
+     not reporting stats.  Alas this doesn't work in the startup case because
+     we don't know yet whether we will be reporting the stats.  For the
+     startup case collect the data anyway (it should be cheap at this point),
+     and leave it to the reporter to decide whether to print them.  */
+  if (msg_type != 0
+      && !per_command_time
       && !per_command_space
       && !per_command_symtab)
     return make_cleanup (null_cleanup, 0);
@@ -930,7 +942,7 @@ make_command_stats_cleanup (int msg_type)
 
   new_stat->msg_type = msg_type;
 
-  if (per_command_space)
+  if (msg_type == 0 || per_command_space)
     {
 #ifdef HAVE_SBRK
       char *lim = (char *) sbrk (0);
@@ -939,14 +951,14 @@ make_command_stats_cleanup (int msg_type)
 #endif
     }
 
-  if (per_command_time)
+  if (msg_type == 0 || per_command_time)
     {
       new_stat->start_cpu_time = get_run_time ();
       gettimeofday (&new_stat->start_wall_time, NULL);
       new_stat->time_enabled = 1;
     }
 
-  if (per_command_symtab)
+  if (msg_type == 0 || per_command_symtab)
     {
       int nr_symtabs, nr_primary_symtabs, nr_blocks;
 
diff --git a/gdb/testsuite/gdb.base/maint.exp b/gdb/testsuite/gdb.base/maint.exp
index 64753b7..21d0a31 100644
--- a/gdb/testsuite/gdb.base/maint.exp
+++ b/gdb/testsuite/gdb.base/maint.exp
@@ -130,10 +130,11 @@ gdb_expect  {
 # tests here!!
 gdb_test_no_output "maint check-symtabs"
 
+# Test per-command stats.
 gdb_test_no_output "maint set per-command on"
-
-gdb_test "maint set per-command off" \
+gdb_test "pwd" \
     "Command execution time: \[0-9.\]+ \\(cpu\\), \[0-9.\]+ \\(wall\\)\[\r\n\]+Space used: $decimal \\(\\+$decimal for this command\\)\[\r\n\]+#symtabs: $decimal \\(\\+$decimal\\), #primary symtabs: $decimal \\(\\+$decimal\\), #blocks: $decimal \\(\\+$decimal\\)"
+gdb_test_no_output "maint set per-command off"
 
 gdb_test "maint demangle" \
     "\"maintenance demangle\" takes an argument to demangle\\."

  reply	other threads:[~2014-07-11 22:05 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-03-15 23:44 [doc RFA] New commands: mt set per-command on|off Doug Evans
2013-03-17 19:04 ` Eli Zaretskii
     [not found]   ` <20807.35450.682935.524373@ruffy2.mtv.corp.google.com>
2013-03-20 17:24     ` Eli Zaretskii
2013-03-21 17:54       ` Doug Evans
2013-03-28 23:27     ` doc/ build regression with texinfo-5.1 [Re: [doc RFA] New commands: mt set per-command on|off] Jan Kratochvil
2013-03-29  0:27       ` Eli Zaretskii
2013-03-29 16:50         ` Jan Kratochvil
2013-03-29 16:57           ` Doug Evans
2013-03-29 16:58             ` Jan Kratochvil
2013-03-29 21:50               ` Eli Zaretskii
2014-06-30 17:13 ` Regression for GDB global --statistics " Jan Kratochvil
2014-07-09 21:11   ` [PATCH] Re: Regression for GDB global --statistics Doug Evans
2014-07-10 16:42     ` Pedro Alves
2014-07-12  0:42       ` Doug Evans [this message]
2014-07-15  9:43         ` Pedro Alves
2014-07-17 12:02           ` Doug Evans
2014-07-11 21:33     ` Jan Kratochvil
2014-07-11 22:05       ` Doug Evans
2014-07-12 20:25         ` [testsuite patch] " Jan Kratochvil
     [not found]           ` <CADPb22SxWYQ-6tK85p2koVQjxrFF0o3OtmEd79R0q-_xWcJ+Mg@mail.gmail.com>
2014-07-17 12:23             ` [testsuite commit] " Jan Kratochvil

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=21440.24455.769287.540494@ruffy.mtv.corp.google.com \
    --to=dje@google.com \
    --cc=eliz@gnu.org \
    --cc=gdb-patches@sourceware.org \
    --cc=jan.kratochvil@redhat.com \
    --cc=palves@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).