public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Tom Tromey <tom@tromey.com>
To: gdb-patches@sourceware.org
Subject: [PATCH 14/26] Move psymtab statistics printing to psymtab.c
Date: Sun, 28 Feb 2021 13:37:51 -0700	[thread overview]
Message-ID: <20210228203803.1693413-15-tom@tromey.com> (raw)
In-Reply-To: <20210228203803.1693413-1-tom@tromey.com>

This moves all the psymtab statistics printing code form symmisc.c to
psymtab.c.  This changes the formatting of the output a little, but
considering that it is a maint command (and, I assume, a rarely used
one), this seems fine to me.

This change helps further dissociate the psymtab from the objfile.  In
the end there will be no direct connect -- only via the
quick_symbol_functions interface.

gdb/ChangeLog
2021-02-28  Tom Tromey  <tom@tromey.com>

	* dwarf2/read.c (dwarf2_base_index_functions::print_stats): Add
	print_bcache parameter.
	* symfile-debug.c (objfile::print_stats): Add print_bcache
	parameter.
	* quick-symbol.h (struct quick_symbol_functions)
	<print_stats>: Add print_bcache parameter.
	* symmisc.c (print_symbol_bcache_statistics, count_psyms): Move
	code to psymtab.c.
	(print_objfile_statistics): Move psymtab code to psymtab.c.
	* psymtab.c (count_psyms): Move from symmisc.c.
	(psymbol_functions::print_stats): Print partial symbol and bcache
	statistics.  Add print_bcache parameter.
	* objfiles.h (print_symbol_bcache_statistics): Don't declare.
	(struct objfile) <print_stats>: Add print_bcache parameter.
	* maint.c (maintenance_print_statistics): Update.

gdb/testsuite/ChangeLog
2021-02-28  Tom Tromey  <tom@tromey.com>

	* gdb.base/maint.exp: Update "maint print statistics" output.
---
 gdb/ChangeLog                    | 18 ++++++++++++
 gdb/dwarf2/read.c                |  8 ++++--
 gdb/maint.c                      |  1 -
 gdb/objfiles.h                   |  3 +-
 gdb/psympriv.h                   |  2 +-
 gdb/psymtab.c                    | 43 ++++++++++++++++++++++++----
 gdb/quick-symbol.h               |  6 ++--
 gdb/symfile-debug.c              |  8 +++---
 gdb/symmisc.c                    | 49 ++++++--------------------------
 gdb/testsuite/ChangeLog          |  4 +++
 gdb/testsuite/gdb.base/maint.exp |  2 +-
 11 files changed, 84 insertions(+), 60 deletions(-)

diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index 773e38d0dc5..4008e7dff2f 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -2456,7 +2456,7 @@ struct dwarf2_base_index_functions : public quick_symbol_functions
     return language_unknown;
   }
 
-  void print_stats (struct objfile *objfile) override;
+  void print_stats (struct objfile *objfile, bool print_bcache) override;
 
   void expand_all_symtabs (struct objfile *objfile) override;
 
@@ -3924,8 +3924,12 @@ dwarf2_gdb_index::lookup_symbol (struct objfile *objfile,
 }
 
 void
-dwarf2_base_index_functions::print_stats (struct objfile *objfile)
+dwarf2_base_index_functions::print_stats (struct objfile *objfile,
+					  bool print_bcache)
 {
+  if (print_bcache)
+    return;
+
   dwarf2_per_objfile *per_objfile = get_dwarf2_per_objfile (objfile);
   int total = (per_objfile->per_bfd->all_comp_units.size ()
 	       + per_objfile->per_bfd->all_type_units.size ());
diff --git a/gdb/maint.c b/gdb/maint.c
index bfdd1d5ca3e..5254cd6ed26 100644
--- a/gdb/maint.c
+++ b/gdb/maint.c
@@ -518,7 +518,6 @@ static void
 maintenance_print_statistics (const char *args, int from_tty)
 {
   print_objfile_statistics ();
-  print_symbol_bcache_statistics ();
 }
 
 static void
diff --git a/gdb/objfiles.h b/gdb/objfiles.h
index cd136eef788..ff60e18bca4 100644
--- a/gdb/objfiles.h
+++ b/gdb/objfiles.h
@@ -211,7 +211,6 @@ struct objstats
 #define OBJSTAT(objfile, expr) (objfile -> stats.expr)
 #define OBJSTATS struct objstats stats
 extern void print_objfile_statistics (void);
-extern void print_symbol_bcache_statistics (void);
 
 /* Number of entries in the minimal symbol hash table.  */
 #define MINIMAL_SYMBOL_HASH_SIZE 2039
@@ -568,7 +567,7 @@ struct objfile
 					 domain_enum domain);
 
   /* See quick_symbol_functions.  */
-  void print_stats ();
+  void print_stats (bool print_bcache);
 
   /* See quick_symbol_functions.  */
   void dump ();
diff --git a/gdb/psympriv.h b/gdb/psympriv.h
index 0f24c104aca..943d6c13919 100644
--- a/gdb/psympriv.h
+++ b/gdb/psympriv.h
@@ -496,7 +496,7 @@ struct psymbol_functions : public quick_symbol_functions
 					       domain_enum domain,
 					       bool *symbol_found_p) override;
 
-  void print_stats (struct objfile *objfile) override;
+  void print_stats (struct objfile *objfile, bool print_bcache) override;
 
   void dump (struct objfile *objfile) override;
 
diff --git a/gdb/psymtab.c b/gdb/psymtab.c
index 45a4db71c1f..867b71530eb 100644
--- a/gdb/psymtab.c
+++ b/gdb/psymtab.c
@@ -975,21 +975,52 @@ dump_psymtab (struct objfile *objfile, struct partial_symtab *psymtab,
   fprintf_filtered (outfile, "\n");
 }
 
+/* Count the number of partial symbols in OBJFILE.  */
+
+static int
+count_psyms (struct objfile *objfile)
+{
+  int count = 0;
+  for (partial_symtab *pst : objfile->psymtabs ())
+    {
+      count += pst->global_psymbols.size ();
+      count += pst->static_psymbols.size ();
+    }
+  return count;
+}
+
 /* Psymtab version of print_stats.  See its definition in
    the definition of quick_symbol_functions in symfile.h.  */
 
 void
-psymbol_functions::print_stats (struct objfile *objfile)
+psymbol_functions::print_stats (struct objfile *objfile, bool print_bcache)
 {
   int i;
 
-  i = 0;
-  for (partial_symtab *ps : require_partial_symbols (objfile, true))
+  if (!print_bcache)
+    {
+      int n_psyms = count_psyms (objfile);
+      if (n_psyms > 0)
+	printf_filtered (_("  Number of \"partial\" symbols read: %d\n"),
+			 n_psyms);
+
+      i = 0;
+      for (partial_symtab *ps : require_partial_symbols (objfile, true))
+	{
+	  if (!ps->readin_p (objfile))
+	    i++;
+	}
+      printf_filtered (_("  Number of psym tables (not yet expanded): %d\n"),
+		       i);
+      printf_filtered (_("  Total memory used for psymbol cache: %d\n"),
+		       objfile->partial_symtabs->psymbol_cache.memory_used ());
+    }
+  else
     {
-      if (!ps->readin_p (objfile))
-	i++;
+      printf_filtered (_("Psymbol byte cache statistics:\n"));
+      objfile->partial_symtabs->psymbol_cache.print_statistics
+	("partial symbol cache");
     }
-  printf_filtered (_("  Number of psym tables (not yet expanded): %d\n"), i);
 }
 
 /* Psymtab version of dump.  See its definition in
diff --git a/gdb/quick-symbol.h b/gdb/quick-symbol.h
index 319ffe681c8..315a97a49e0 100644
--- a/gdb/quick-symbol.h
+++ b/gdb/quick-symbol.h
@@ -126,8 +126,10 @@ struct quick_symbol_functions
 
   /* Print statistics about any indices loaded for OBJFILE.  The
      statistics should be printed to gdb_stdout.  This is used for
-     "maint print statistics".  */
-  virtual void print_stats (struct objfile *objfile) = 0;
+     "maint print statistics".  Statistics are printed in two
+     sections.  PRINT_BCACHE is false when printing the first section
+     of general statistics, and true when printing bcache statistics.  */
+  virtual void print_stats (struct objfile *objfile, bool print_bcache) = 0;
 
   /* Dump any indices loaded for OBJFILE.  The dump should go to
      gdb_stdout.  This is used for "maint print objfiles".  */
diff --git a/gdb/symfile-debug.c b/gdb/symfile-debug.c
index 55865ab03b0..406eac0b7d3 100644
--- a/gdb/symfile-debug.c
+++ b/gdb/symfile-debug.c
@@ -174,14 +174,14 @@ objfile::lookup_symbol (block_enum kind, const char *name, domain_enum domain)
 }
 
 void
-objfile::print_stats ()
+objfile::print_stats (bool print_bcache)
 {
   if (debug_symfile)
-    fprintf_filtered (gdb_stdlog, "qf->print_stats (%s)\n",
-		      objfile_debug_name (this));
+    fprintf_filtered (gdb_stdlog, "qf->print_stats (%s, %d)\n",
+		      objfile_debug_name (this), print_bcache);
 
   if (qf != nullptr)
-    qf->print_stats (this);
+    qf->print_stats (this, print_bcache);
 }
 
 void
diff --git a/gdb/symmisc.c b/gdb/symmisc.c
index 0aab30d08ab..9ea5cb55d0f 100644
--- a/gdb/symmisc.c
+++ b/gdb/symmisc.c
@@ -38,9 +38,6 @@
 #include "source.h"
 #include "readline/tilde.h"
 
-#include "psymtab.h"
-#include "psympriv.h"
-
 /* Prototypes for local functions */
 
 static int block_depth (const struct block *);
@@ -49,35 +46,6 @@ static void print_symbol (struct gdbarch *gdbarch, struct symbol *symbol,
 			  int depth, ui_file *outfile);
 \f
 
-void
-print_symbol_bcache_statistics (void)
-{
-  for (struct program_space *pspace : program_spaces)
-    for (objfile *objfile : pspace->objfiles ())
-      {
-	QUIT;
-	printf_filtered (_("Byte cache statistics for '%s':\n"),
-			 objfile_name (objfile));
-	objfile->partial_symtabs->psymbol_cache.print_statistics
-	  ("partial symbol cache");
-	objfile->per_bfd->string_cache.print_statistics ("string cache");
-      }
-}
-
-/* Count the number of partial symbols in OBJFILE.  */
-
-static int
-count_psyms (struct objfile *objfile)
-{
-  int count = 0;
-  for (partial_symtab *pst : objfile->psymtabs ())
-    {
-      count += pst->global_psymbols.size ();
-      count += pst->static_psymbols.size ();
-    }
-  return count;
-}
-
 void
 print_objfile_statistics (void)
 {
@@ -94,18 +62,13 @@ print_objfile_statistics (void)
 	if (objfile->per_bfd->n_minsyms > 0)
 	  printf_filtered (_("  Number of \"minimal\" symbols read: %d\n"),
 			   objfile->per_bfd->n_minsyms);
-
-	int n_psyms = count_psyms (objfile);
-	if (n_psyms > 0)
-	  printf_filtered (_("  Number of \"partial\" symbols read: %d\n"),
-			   n_psyms);
 	if (OBJSTAT (objfile, n_syms) > 0)
 	  printf_filtered (_("  Number of \"full\" symbols read: %d\n"),
 			   OBJSTAT (objfile, n_syms));
 	if (OBJSTAT (objfile, n_types) > 0)
 	  printf_filtered (_("  Number of \"types\" defined: %d\n"),
 			   OBJSTAT (objfile, n_types));
-	objfile->print_stats ();
+
 	i = linetables = 0;
 	for (compunit_symtab *cu : objfile->compunits ())
 	  {
@@ -124,6 +87,8 @@ print_objfile_statistics (void)
 	printf_filtered (_("  Number of symbol tables with blockvectors: %d\n"),
 			 blockvectors);
 
+	objfile->print_stats (false);
+
 	if (OBJSTAT (objfile, sz_strtab) > 0)
 	  printf_filtered (_("  Space used by string tables: %d\n"),
 			   OBJSTAT (objfile, sz_strtab));
@@ -133,11 +98,13 @@ print_objfile_statistics (void)
 	printf_filtered (_("  Total memory used for BFD obstack: %s\n"),
 			 pulongest (obstack_memory_used (&objfile->per_bfd
 							 ->storage_obstack)));
-	printf_filtered
-	  (_("  Total memory used for psymbol cache: %d\n"),
-	   objfile->partial_symtabs->psymbol_cache.memory_used ());
+
 	printf_filtered (_("  Total memory used for string cache: %d\n"),
 			 objfile->per_bfd->string_cache.memory_used ());
+	printf_filtered (_("Byte cache statistics for '%s':\n"),
+			 objfile_name (objfile));
+	objfile->per_bfd->string_cache.print_statistics ("string cache");
+	objfile->print_stats (true);
       }
 }
 
diff --git a/gdb/testsuite/gdb.base/maint.exp b/gdb/testsuite/gdb.base/maint.exp
index b418c023d73..e72392220cc 100644
--- a/gdb/testsuite/gdb.base/maint.exp
+++ b/gdb/testsuite/gdb.base/maint.exp
@@ -193,7 +193,7 @@ if [istarget "*-*-cygwin*"] {
 
 send_gdb "maint print statistics\n"
 gdb_expect  {
-    -re "Statistics for\[^\n\r\]*maint\[^\n\r\]*:\r\n  Number of \"minimal\" symbols read: $decimal\r\n(  Number of \"partial\" symbols read: $decimal\r\n)?  Number of \"full\" symbols read: $decimal\r\n  Number of \"types\" defined: $decimal\r\n(  Number of psym tables \\(not yet expanded\\): $decimal\r\n)?(  Number of read CUs: $decimal\r\n  Number of unread CUs: $decimal\r\n)?  Number of symbol tables: $decimal\r\n  Number of symbol tables with line tables: $decimal\r\n  Number of symbol tables with blockvectors: $decimal\r\n  Total memory used for objfile obstack: $decimal\r\n  Total memory used for BFD obstack: $decimal\r\n  Total memory used for psymbol cache: $decimal\r\n  Total memory used for string cache: $decimal\r\n" {
+    -re "Statistics for\[^\n\r\]*maint\[^\n\r\]*:\r\n  Number of \"minimal\" symbols read: $decimal\r\n  Number of \"full\" symbols read: $decimal\r\n  Number of \"types\" defined: $decimal\r\n(  Number of read CUs: $decimal\r\n  Number of unread CUs: $decimal\r\n)?  Number of symbol tables: $decimal\r\n  Number of symbol tables with line tables: $decimal\r\n  Number of symbol tables with blockvectors: $decimal\r\n(  Number of \"partial\" symbols read: $decimal\r\n)?(  Number of psym tables \\(not yet expanded\\): $decimal\r\n)?  Total memory used for psymbol cache: $decimal\r\n  Total memory used for objfile obstack: $decimal\r\n  Total memory used for BFD obstack: $decimal\r\n  Total memory used for string cache: $decimal\r\n" {
 	gdb_expect {
 	    -re "$gdb_prompt $" {
 		pass "maint print statistics"
-- 
2.26.2


  parent reply	other threads:[~2021-02-28 20:38 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-28 20:37 [PATCH 00/26] Allow multiple "partial" symtab readers per objfile Tom Tromey
2021-02-28 20:37 ` [PATCH 01/26] Move some DWARF code out of symfile.h Tom Tromey
2021-02-28 20:37 ` [PATCH 02/26] Introduce dwarf2/public.h Tom Tromey
2021-02-28 20:37 ` [PATCH 03/26] Change objfile_has_partial_symbols to a method Tom Tromey
2021-02-28 20:37 ` [PATCH 04/26] Change objfile::has_partial_symbols to return bool Tom Tromey
2021-02-28 20:37 ` [PATCH 05/26] Introduce method wrappers for quick_symbol_functions Tom Tromey
2021-03-22 13:52   ` Simon Marchi
2021-02-28 20:37 ` [PATCH 06/26] Move quick_symbol_functions to a new header Tom Tromey
2021-02-28 20:37 ` [PATCH 07/26] Move sym_fns::qf to objfile Tom Tromey
2021-02-28 20:37 ` [PATCH 08/26] Convert quick_symbol_functions to use methods Tom Tromey
2021-02-28 20:37 ` [PATCH 09/26] Move psymbol_map out of objfile Tom Tromey
2021-02-28 20:37 ` [PATCH 10/26] Change how some psymbol readers access the psymtab storage Tom Tromey
2021-02-28 20:37 ` [PATCH 11/26] Do not pass objfile to psymtab_discarder Tom Tromey
2021-02-28 20:37 ` [PATCH 12/26] Set per_bfd->partial_symtabs earlier Tom Tromey
2021-02-28 20:37 ` [PATCH 13/26] Change how DWARF indices use addrmap Tom Tromey
2021-02-28 20:37 ` Tom Tromey [this message]
2021-02-28 20:37 ` [PATCH 15/26] Change how DWARF index writer finds address map Tom Tromey
2021-02-28 20:37 ` [PATCH 16/26] Reference psymtabs via per_bfd in DWARF reader Tom Tromey
2021-02-28 20:37 ` [PATCH 17/26] Attach partial symtab storage to psymbol_functions Tom Tromey
2021-02-28 20:37 ` [PATCH 18/26] Rearrange psymtab_storage construction Tom Tromey
2021-02-28 20:37 ` [PATCH 19/26] Remove sym_fns::sym_read_psymbols Tom Tromey
2021-02-28 20:37 ` [PATCH 20/26] Introduce objfile::require_partial_symbols Tom Tromey
2021-02-28 20:37 ` [PATCH 21/26] Add partial_symtabs parameter to psymtab construction functions Tom Tromey
2021-02-28 20:37 ` [PATCH 22/26] Remove last objfile partial_symtab references from psymtab.c Tom Tromey
2021-02-28 20:38 ` [PATCH 23/26] Change count_psyms to be a method on psymbol_functions Tom Tromey
2021-02-28 20:38 ` [PATCH 24/26] Remove objfile::psymtabs Tom Tromey
2021-02-28 20:38 ` [PATCH 25/26] Switch objfile to hold a list of psymbol readers Tom Tromey
2021-02-28 20:38 ` [PATCH 26/26] Allow multiple partial symbol readers per objfile Tom Tromey
2021-03-20 23:33 ` [PATCH 00/26] Allow multiple "partial" symtab " Tom Tromey
2021-03-22 14:13   ` Simon Marchi

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=20210228203803.1693413-15-tom@tromey.com \
    --to=tom@tromey.com \
    --cc=gdb-patches@sourceware.org \
    /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).