diff options
author | zack <zack@138bc75d-0d04-0410-961f-82ee72b054a4> | 2000-08-29 20:57:11 +0000 |
---|---|---|
committer | zack <zack@138bc75d-0d04-0410-961f-82ee72b054a4> | 2000-08-29 20:57:11 +0000 |
commit | 2a8997e85cd4ad92644cad6932aa2b5e2115d610 (patch) | |
tree | 467a74cb03ab3a07329d87c25f28745ba9ed5e7f /gcc/ggc-simple.c | |
parent | 14da2a08382098d9b235ebe6ab1d02e5c3cb24d0 (diff) | |
download | gcc-2a8997e85cd4ad92644cad6932aa2b5e2115d610.tar.gz |
* flags.h (time_report, mem_report): New global flags.
* toplev.c: Define time_report and mem_report.
(f_options): Add -ftime-report and -fmem-report.
(compile_file): Turn on time_report if quiet_flag is off.
Call ggc_print_statistics at very end if mem_report is on.
* timevar.c (TIMEVAR_ENABLE): Examine time_report, not quiet_flag.
* ggc-common.c (ggc_print_statistics): Rename to
ggc_print_common_statistics; all callers changed. Scale
quantities above 10K to kilobytes and above 10M to megabytes.
* ggc-page.c (ggc_page_print_statistics): Rename to
ggc_print_statistics. Report memory consumed by internal data
structures for each allocation bucket. Scale quantities above
10K to kilobytes and above 10M to megabytes.
* ggc-simple.c: Prototype debug_ggc_tree to avoid warning.
Cast PTR_KEY(p) to unsigned long in fprintf call to avoid warning.
Define tally_leaves always.
(ggc_print_statistics): New function.
* ggc.h: Adjust for renamed functions.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@36049 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/ggc-simple.c')
-rw-r--r-- | gcc/ggc-simple.c | 52 |
1 files changed, 49 insertions, 3 deletions
diff --git a/gcc/ggc-simple.c b/gcc/ggc-simple.c index 86afaf17e12..7822bb916f3 100644 --- a/gcc/ggc-simple.c +++ b/gcc/ggc-simple.c @@ -137,10 +137,13 @@ static void clear_marks PARAMS ((struct ggc_mem *)); static void sweep_objs PARAMS ((struct ggc_mem **)); static void ggc_pop_context_1 PARAMS ((struct ggc_mem *, int)); +/* For use from debugger. */ +extern void debug_ggc_tree PARAMS ((struct ggc_mem *, int)); + #ifdef GGC_BALANCE extern void debug_ggc_balance PARAMS ((void)); -static void tally_leaves PARAMS ((struct ggc_mem *, int, size_t *, size_t *)); #endif +static void tally_leaves PARAMS ((struct ggc_mem *, int, size_t *, size_t *)); /* Insert V into the search tree. */ @@ -434,7 +437,7 @@ debug_ggc_tree (p, indent) for (i = 0; i < indent; ++i) putc (' ', stderr); - fprintf (stderr, "%lx %p\n", PTR_KEY (p), p); + fprintf (stderr, "%lx %p\n", (unsigned long)PTR_KEY (p), p); if (p->sub[1]) debug_ggc_tree (p->sub[1], indent + 1); @@ -460,7 +463,9 @@ debug_ggc_balance () (float)sumdepth / (float)nleaf, log ((double) G.objects) / M_LN2); } +#endif +/* Used by debug_ggc_balance, and also by ggc_print_statistics. */ static void tally_leaves (x, depth, nleaf, sumdepth) struct ggc_mem *x; @@ -481,4 +486,45 @@ tally_leaves (x, depth, nleaf, sumdepth) tally_leaves (x->sub[1], depth + 1, nleaf, sumdepth); } } -#endif + +#define SCALE(x) ((unsigned long) ((x) < 1024*10 \ + ? (x) \ + : ((x) < 1024*1024*10 \ + ? (x) / 1024 \ + : (x) / (1024*1024)))) +#define LABEL(x) ((x) < 1024*10 ? ' ' : ((x) < 1024*1024*10 ? 'k' : 'M')) + +/* Report on GC memory usage. */ +void +ggc_print_statistics () +{ + struct ggc_statistics stats; + size_t nleaf = 0, sumdepth = 0; + + /* Clear the statistics. */ + memset (&stats, 0, sizeof (stats)); + + /* Make sure collection will really occur. */ + G.allocated_last_gc = 0; + + /* Collect and print the statistics common across collectors. */ + ggc_print_common_statistics (stderr, &stats); + + /* Report on tree balancing. */ + tally_leaves (G.root, 0, &nleaf, &sumdepth); + + fprintf (stderr, "\n\ +Total internal data (bytes)\t%ld%c\n\ +Number of leaves in tree\t%d\n\ +Average leaf depth\t\t%.1f\n", + SCALE(G.objects * offsetof (struct ggc_mem, u)), + LABEL(G.objects * offsetof (struct ggc_mem, u)), + nleaf, (double)sumdepth / (double)nleaf); + + /* Report overall memory usage. */ + fprintf (stderr, "\n\ +Total objects allocated\t\t%d\n\ +Total memory in GC arena\t%ld%c\n", + G.objects, + SCALE(G.allocated), LABEL(G.allocated)); +} |