This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[patch] Include memory consumption in timevar reports


Hello,

this patch includes information about amount of ggc memory allocated
for each timevar, e.g. (passes with >2% ggc for ./cc1 -O2 combine.i)

 parser                :   0.44 ( 2%) usr   0.00 ( 0%) sys   0.45 ( 2%) wall    6429 kB (14%) ggc
 tree gimplify         :   0.35 ( 2%) usr   0.00 ( 0%) sys   0.35 ( 2%) wall    1718 kB ( 4%) ggc
 tree CFG construction :   0.04 ( 0%) usr   0.00 ( 0%) sys   0.04 ( 0%) wall    2527 kB ( 6%) ggc
 tree PHI insertion    :   0.05 ( 0%) usr   0.00 ( 0%) sys   0.05 ( 0%) wall    1443 kB ( 3%) ggc
 tree SSA rewrite      :   0.27 ( 2%) usr   0.00 ( 0%) sys   0.27 ( 1%) wall    1621 kB ( 4%) ggc
 dominator optimization:   1.30 ( 7%) usr   0.00 ( 0%) sys   1.32 ( 7%) wall    4121 kB ( 9%) ggc
 tree split crit edges :   0.04 ( 0%) usr   0.00 ( 0%) sys   0.04 ( 0%) wall    1952 kB ( 4%) ggc
 tree redundant PHIs   :   0.18 ( 1%) usr   0.00 ( 0%) sys   0.18 ( 1%) wall    2906 kB ( 6%) ggc
 tree SSA to normal    :   0.24 ( 1%) usr   0.00 ( 0%) sys   0.24 ( 1%) wall    1710 kB ( 4%) ggc
 expand                :   0.59 ( 3%) usr   0.00 ( 0%) sys   0.59 ( 3%) wall    5411 kB (12%) ggc
 TOTAL                 :  17.99             0.21            18.32               45890 kB
 
(some of the numbers are really interesting; I would not suspect
splitting critical edges to take that much memory)

This has several advantages over the memory reports available with
GATHER_STATISTICS:

1) It is always available, without need to compile gcc with special
   flags and slow it down. so it is easier to spot possible problems
   with memory consumption.
2) The memory consumption is shown for passes rather than source code
   locations.  So passes cannot "hide" using allocating memory on
   many different places or through shared functions -- it is clear
   who is responsible for the memory consumption.

Bootstrapped & regtested on i686.

Zdenek

	* ggc-page.c (ggc_alloc_stat): Record amount of memory allocated.
	* ggc-zone.c (ggc_alloc_zone_1): Ditto.
	* timevar.c (timevar_ggc_mem_total): New variable.
	(GGC_MEM_BOUND): New constant.
	(get_time): Record ggc memory status.
	(timevar_accumulate): Accumulate amount of ggc memory.
	(timevar_print): Print consumption of ggc memory.
	* timevar.def (TV_FIND_REFERENCED_VARS, TV_TREE_REDPHI,
	TV_TREE_LOOP_BOUNDS, TV_TREE_LOOP_IVCANON, TV_TREE_VECTORIZATION,
	TV_TREE_LINEAR_TRANSFORM): Shorten strings to fit in 22 characters.
	* timevar.h (struct timevar_time_def): Add ggc_mem field.
	(timevar_ggc_mem_total): Declare.

Index: ggc-page.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/ggc-page.c,v
retrieving revision 1.98
diff -c -3 -p -r1.98 ggc-page.c
*** ggc-page.c	18 Jan 2005 11:36:14 -0000	1.98
--- ggc-page.c	21 Jan 2005 21:48:06 -0000
*************** ggc_alloc_stat (size_t size MEM_STAT_DEC
*** 1215,1220 ****
--- 1215,1223 ----
       information is used in deciding when to collect.  */
    G.allocated += object_size;
  
+   /* For timevar statistics.  */
+   timevar_ggc_mem_total += object_size;
+ 
  #ifdef GATHER_STATISTICS
    {
      size_t overhead = object_size - size;
Index: ggc-zone.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/ggc-zone.c,v
retrieving revision 2.20
diff -c -3 -p -r2.20 ggc-zone.c
*** ggc-zone.c	9 Sep 2004 13:54:00 -0000	2.20
--- ggc-zone.c	21 Jan 2005 21:48:06 -0000
*************** ggc_alloc_zone_1 (size_t orig_size, stru
*** 720,725 ****
--- 720,727 ----
    /* Keep track of how many bytes are being allocated.  This
       information is used in deciding when to collect.  */
    zone->allocated += size;
+   
+   timevar_ggc_mem_total += (size + CHUNK_OVERHEAD);
  
  #ifdef GATHER_STATISTICS
    ggc_record_overhead (orig_size, size + CHUNK_OVERHEAD - orig_size PASS_MEM_STAT);
Index: timevar.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/timevar.c,v
retrieving revision 1.37
diff -c -3 -p -r1.37 timevar.c
*** timevar.c	4 Nov 2004 02:34:07 -0000	1.37
--- timevar.c	21 Jan 2005 21:48:07 -0000
*************** static double clocks_to_msec;
*** 115,120 ****
--- 115,129 ----
  
  bool timevar_enable;
  
+ /* Total amount of memory allocated by garbage collector.  */
+ 
+ size_t timevar_ggc_mem_total;
+ 
+ /* The amount of memory that will cause us to report the timevar even
+    if the time spent is not significant.  */
+ 
+ #define GGC_MEM_BOUND (1 << 20)
+ 
  /* See timevar.h for an explanation of timing variables.  */
  
  /* A timing variable.  */
*************** get_time (struct timevar_time_def *now)
*** 183,188 ****
--- 192,198 ----
    now->user = 0;
    now->sys  = 0;
    now->wall = 0;
+   now->ggc_mem = timevar_ggc_mem_total;
  
    if (!timevar_enable)
      return;
*************** timevar_accumulate (struct timevar_time_
*** 216,221 ****
--- 226,232 ----
    timer->user += stop_time->user - start_time->user;
    timer->sys += stop_time->sys - start_time->sys;
    timer->wall += stop_time->wall - start_time->wall;
+   timer->ggc_mem += stop_time->ggc_mem - start_time->ggc_mem;
  }
  
  /* Initialize timing variables.  */
*************** timevar_print (FILE *fp)
*** 417,423 ****
           zeroes.  */
        if (tv->elapsed.user < tiny
  	  && tv->elapsed.sys < tiny
! 	  && tv->elapsed.wall < tiny)
  	continue;
  
        /* The timing variable name.  */
--- 428,435 ----
           zeroes.  */
        if (tv->elapsed.user < tiny
  	  && tv->elapsed.sys < tiny
! 	  && tv->elapsed.wall < tiny
! 	  && tv->elapsed.ggc_mem < GGC_MEM_BOUND)
  	continue;
  
        /* The timing variable name.  */
*************** timevar_print (FILE *fp)
*** 444,449 ****
--- 456,468 ----
  	       (total->wall == 0 ? 0 : tv->elapsed.wall / total->wall) * 100);
  #endif /* HAVE_WALL_TIME */
  
+       /* Print the amount of ggc memory allocated.  */
+       fprintf (fp, "%8u kB (%2.0f%%) ggc",
+ 	       (unsigned) (tv->elapsed.ggc_mem >> 10),
+ 	       (total->ggc_mem == 0
+ 		? 0
+ 		: (float) tv->elapsed.ggc_mem / total->ggc_mem) * 100);
+ 
        putc ('\n', fp);
      }
  
*************** timevar_print (FILE *fp)
*** 456,463 ****
    fprintf (fp, "%7.2f          ", total->sys);
  #endif
  #ifdef HAVE_WALL_TIME
!   fprintf (fp, "%7.2f\n", total->wall);
  #endif
  
  #ifdef ENABLE_CHECKING
    fprintf (fp, "Extra diagnostic checks enabled; compiler may run slowly.\n");
--- 475,483 ----
    fprintf (fp, "%7.2f          ", total->sys);
  #endif
  #ifdef HAVE_WALL_TIME
!   fprintf (fp, "%7.2f           ", total->wall);
  #endif
+   fprintf (fp, "%8u kB\n", (unsigned) (total->ggc_mem >> 10));
  
  #ifdef ENABLE_CHECKING
    fprintf (fp, "Extra diagnostic checks enabled; compiler may run slowly.\n");
Index: timevar.def
===================================================================
RCS file: /cvs/gcc/gcc/gcc/timevar.def,v
retrieving revision 1.42
diff -c -3 -p -r1.42 timevar.def
*** timevar.def	20 Jan 2005 19:20:22 -0000	1.42
--- timevar.def	21 Jan 2005 21:48:07 -0000
*************** DEFTIMEVAR (TV_TREE_GIMPLIFY	     , "tre
*** 64,70 ****
  DEFTIMEVAR (TV_TREE_EH		     , "tree eh")
  DEFTIMEVAR (TV_TREE_CFG		     , "tree CFG construction")
  DEFTIMEVAR (TV_TREE_CLEANUP_CFG	     , "tree CFG cleanup")
! DEFTIMEVAR (TV_FIND_REFERENCED_VARS  , "tree find referenced vars")
  DEFTIMEVAR (TV_TREE_PTA		     , "tree PTA")
  DEFTIMEVAR (TV_TREE_MAY_ALIAS        , "tree alias analysis")
  DEFTIMEVAR (TV_TREE_INSERT_PHI_NODES , "tree PHI insertion")
--- 64,70 ----
  DEFTIMEVAR (TV_TREE_EH		     , "tree eh")
  DEFTIMEVAR (TV_TREE_CFG		     , "tree CFG construction")
  DEFTIMEVAR (TV_TREE_CLEANUP_CFG	     , "tree CFG cleanup")
! DEFTIMEVAR (TV_FIND_REFERENCED_VARS  , "tree find ref. vars")
  DEFTIMEVAR (TV_TREE_PTA		     , "tree PTA")
  DEFTIMEVAR (TV_TREE_MAY_ALIAS        , "tree alias analysis")
  DEFTIMEVAR (TV_TREE_INSERT_PHI_NODES , "tree PHI insertion")
*************** DEFTIMEVAR (TV_TREE_SRA              , "
*** 76,82 ****
  DEFTIMEVAR (TV_TREE_CCP		     , "tree CCP")
  DEFTIMEVAR (TV_TREE_SPLIT_EDGES      , "tree split crit edges")
  DEFTIMEVAR (TV_TREE_PRE		     , "tree PRE")
! DEFTIMEVAR (TV_TREE_REDPHI	     , "tree remove redundant PHIs")
  DEFTIMEVAR (TV_TREE_FRE		     , "tree FRE")
  DEFTIMEVAR (TV_TREE_PHIOPT	     , "tree linearize phis")
  DEFTIMEVAR (TV_TREE_FORWPROP	     , "tree forward propagate")
--- 76,82 ----
  DEFTIMEVAR (TV_TREE_CCP		     , "tree CCP")
  DEFTIMEVAR (TV_TREE_SPLIT_EDGES      , "tree split crit edges")
  DEFTIMEVAR (TV_TREE_PRE		     , "tree PRE")
! DEFTIMEVAR (TV_TREE_REDPHI	     , "tree redundant PHIs")
  DEFTIMEVAR (TV_TREE_FRE		     , "tree FRE")
  DEFTIMEVAR (TV_TREE_PHIOPT	     , "tree linearize phis")
  DEFTIMEVAR (TV_TREE_FORWPROP	     , "tree forward propagate")
*************** DEFTIMEVAR (TV_TREE_CD_DCE	     , "tree 
*** 85,97 ****
  DEFTIMEVAR (TV_TREE_DSE		     , "tree DSE")
  DEFTIMEVAR (TV_TREE_MERGE_PHI	     , "PHI merge")
  DEFTIMEVAR (TV_TREE_LOOP	     , "tree loop optimization")
! DEFTIMEVAR (TV_TREE_LOOP_BOUNDS	     , "tree record loop bounds")
  DEFTIMEVAR (TV_LIM                   , "loop invariant motion")
! DEFTIMEVAR (TV_TREE_LOOP_IVCANON     , "tree canonical iv creation")
  DEFTIMEVAR (TV_TREE_LOOP_UNSWITCH    , "tree loop unswitching")
  DEFTIMEVAR (TV_COMPLETE_UNROLL       , "complete unrolling")
! DEFTIMEVAR (TV_TREE_VECTORIZATION    , "tree loop vectorization")
! DEFTIMEVAR (TV_TREE_LINEAR_TRANSFORM , "tree loop linear transforms")
  DEFTIMEVAR (TV_TREE_LOOP_IVOPTS	     , "tree iv optimization")
  DEFTIMEVAR (TV_TREE_LOOP_INIT	     , "tree loop init")
  DEFTIMEVAR (TV_TREE_LOOP_FINI	     , "tree loop fini")
--- 85,97 ----
  DEFTIMEVAR (TV_TREE_DSE		     , "tree DSE")
  DEFTIMEVAR (TV_TREE_MERGE_PHI	     , "PHI merge")
  DEFTIMEVAR (TV_TREE_LOOP	     , "tree loop optimization")
! DEFTIMEVAR (TV_TREE_LOOP_BOUNDS	     , "tree loop bounds")
  DEFTIMEVAR (TV_LIM                   , "loop invariant motion")
! DEFTIMEVAR (TV_TREE_LOOP_IVCANON     , "tree canonical iv")
  DEFTIMEVAR (TV_TREE_LOOP_UNSWITCH    , "tree loop unswitching")
  DEFTIMEVAR (TV_COMPLETE_UNROLL       , "complete unrolling")
! DEFTIMEVAR (TV_TREE_VECTORIZATION    , "tree vectorization")
! DEFTIMEVAR (TV_TREE_LINEAR_TRANSFORM , "tree loop linear")
  DEFTIMEVAR (TV_TREE_LOOP_IVOPTS	     , "tree iv optimization")
  DEFTIMEVAR (TV_TREE_LOOP_INIT	     , "tree loop init")
  DEFTIMEVAR (TV_TREE_LOOP_FINI	     , "tree loop fini")
Index: timevar.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/timevar.h,v
retrieving revision 1.16
diff -c -3 -p -r1.16 timevar.h
*** timevar.h	4 Nov 2004 02:34:07 -0000	1.16
--- timevar.h	21 Jan 2005 21:48:07 -0000
*************** struct timevar_time_def
*** 61,66 ****
--- 61,69 ----
  
    /* Wall clock time.  */
    double wall;
+ 
+   /* Garbage collector memory.  */
+   unsigned ggc_mem;
  };
  
  /* An enumeration of timing variable identifiers.  Constructed from
*************** extern void print_time (const char *, lo
*** 93,96 ****
--- 96,101 ----
  
  extern bool timevar_enable;
  
+ extern size_t timevar_ggc_mem_total;
+ 
  #endif /* ! GCC_TIMEVAR_H */


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]