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]

[patch] gcov branch statistics option



I'm committing the following, approved by Jim Wilson.  It adds an '-c' option
to gcov to display branch statistics as counts instead of percentages.

ChangeLog:

	* gcov.c (struct arcdata): Add hits and total, remove prob.
	(output_branch_counts): New.
	(process_args): Set output_branch_counts if -c.
	(calculate_branch_probs): Store hits and total instead of
	percentage.
	(output_data): Emit counts if output_branch_counts is true.
	* gcov.texi (Invoking Gcov): Document -c switch.


Index: gcov.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/gcov.c,v
retrieving revision 1.23
diff -c -2 -p -r1.23 gcov.c
*** gcov.c	1999/11/01 01:11:20	1.23
--- gcov.c	1999/11/10 17:05:30
*************** struct bb_info {
*** 139,143 ****
  struct arcdata
  {
!   int prob;
    int call_insn;
    struct arcdata *next;
--- 139,144 ----
  struct arcdata
  {
!   int hits;
!   int total;
    int call_insn;
    struct arcdata *next;
*************** static int output_function_summary = 0;
*** 214,217 ****
--- 215,223 ----
  static char *object_directory = 0;
  
+ /* Output the number of times a branch was taken as opposed to the percentage
+    of times it was taken.  Turned on by the -c option */
+    
+ static int output_branch_counts = 0;
+ 
  /* Forward declarations.  */
  static void process_args PROTO ((int, char **));
*************** process_args (argc, argv)
*** 315,318 ****
--- 321,326 ----
  	  if (argv[i][1] == 'b')
  	    output_branch_probs = 1;
+ 	  else if (argv[i][1] == 'c')
+ 	    output_branch_counts = 1;
  	  else if (argv[i][1] == 'v')
  	    fputs (gcov_version_string, stderr);
*************** calculate_branch_probs (current_graph, b
*** 879,886 ****
  		      
        a_ptr = (struct arcdata *) xmalloc (sizeof (struct arcdata));
        if (total == 0)
! 	a_ptr->prob = -1;
        else
! 	a_ptr->prob = ((arcptr->arc_count * 100) + (total >> 1)) / total;
        a_ptr->call_insn = arcptr->fake;
  
--- 887,895 ----
  		      
        a_ptr = (struct arcdata *) xmalloc (sizeof (struct arcdata));
+       a_ptr->total = total;
        if (total == 0)
!           a_ptr->hits = 0;
        else
!           a_ptr->hits = arcptr->arc_count;
        a_ptr->call_insn = arcptr->fake;
  
*************** calculate_branch_probs (current_graph, b
*** 890,894 ****
  	    {
  	      function_calls++;
! 	      if (a_ptr->prob != -1)
  		function_calls_executed++;
  	    }
--- 899,903 ----
  	    {
  	      function_calls++;
! 	      if (a_ptr->total != 0)
  		function_calls_executed++;
  	    }
*************** calculate_branch_probs (current_graph, b
*** 896,902 ****
  	    {
  	      function_branches++;
! 	      if (a_ptr->prob != -1)
  		function_branches_executed++;
! 	      if (a_ptr->prob > 0)
  		function_branches_taken++;
  	    }
--- 905,911 ----
  	    {
  	      function_branches++;
! 	      if (a_ptr->total != 0)
  		function_branches_executed++;
! 	      if (a_ptr->hits > 0)
  		function_branches_taken++;
  	    }
*************** output_data ()
*** 1181,1185 ****
  		    {
  		      total_calls++;
! 		      if (a_ptr->prob != -1)
  			total_calls_executed++;
  		    }
--- 1190,1194 ----
  		    {
  		      total_calls++;
! 		      if (a_ptr->total != 0)
  			total_calls_executed++;
  		    }
*************** output_data ()
*** 1187,1193 ****
  		    {
  		      total_branches++;
! 		      if (a_ptr->prob != -1)
  			total_branches_executed++;
! 		      if (a_ptr->prob > 0)
  			total_branches_taken++;
  		    }
--- 1196,1202 ----
  		    {
  		      total_branches++;
! 		      if (a_ptr->total != 0)
  			total_branches_executed++;
! 		      if (a_ptr->hits > 0)
  			total_branches_taken++;
  		    }
*************** output_data ()
*** 1337,1358 ****
  		      if (a_ptr->call_insn)
  			{
! 			  if (a_ptr->prob == -1)
  			    fnotice (gcov_file, "call %d never executed\n", i);
! 			  else
! 			    fnotice (gcov_file,
! 				     "call %d returns = %d%%\n",
! 				     i, 100 - a_ptr->prob);
  			}
  		      else
  			{
! 			  if (a_ptr->prob == -1)
  			    fnotice (gcov_file, "branch %d never executed\n",
  				     i);
  			  else
! 			    fnotice (gcov_file, "branch %d taken = %d%%\n", i,
! 				     a_ptr->prob);
  			}
! 		    }
! 		}
  
  	      /* Gracefully handle errors while reading the source file.  */
--- 1346,1386 ----
  		      if (a_ptr->call_insn)
  			{
! 			  if (a_ptr->total == 0)
  			    fnotice (gcov_file, "call %d never executed\n", i);
! 		            else
! 			      {
! 				if (output_branch_counts)
! 				  fnotice (gcov_file,
! 				           "call %d returns = %d\n",
! 				           i, a_ptr->total - a_ptr->hits);
! 			        else
!                                   fnotice (gcov_file,
! 				           "call %d returns = %d%%\n",
! 				            i, 100 - ((a_ptr->hits * 100) +
!                                            (a_ptr->total >> 1))/a_ptr->total);
! 			      }
  			}
  		      else
  			{
! 			  if (a_ptr->total == 0)
  			    fnotice (gcov_file, "branch %d never executed\n",
  				     i);
  			  else
! 			    {
! 			      if (output_branch_counts)
! 			        fnotice (gcov_file,
! 				         "branch %d taken = %d\n",
!                                          i, a_ptr->hits);
! 			      else
!                                 fnotice (gcov_file,
!                                          "branch %d taken = %d%%\n", i,
!                                          ((a_ptr->hits * 100) +
!                                           (a_ptr->total >> 1))/
!                                           a_ptr->total);
! 
! 			    }
  			}
! 		   }
! 	      }
  
  	      /* Gracefully handle errors while reading the source file.  */
Index: gcov.texi
===================================================================
RCS file: /cvs/gcc/egcs/gcc/gcov.texi,v
retrieving revision 1.3
diff -c -2 -p -r1.3 gcov.texi
*** gcov.texi	1998/12/16 20:56:07	1.3
--- gcov.texi	1999/11/10 17:05:32
*************** compatible with any other profiling or t
*** 82,86 ****
  
  @smallexample
! gcov [-b] [-v] [-n] [-l] [-f] [-o directory] @var{sourcefile}
  @end smallexample
  
--- 82,86 ----
  
  @smallexample
! gcov [-b] [-c] [-v] [-n] [-l] [-f] [-o directory] @var{sourcefile}
  @end smallexample
  
*************** Write branch frequencies to the output f
*** 90,93 ****
--- 90,97 ----
  info to the standard output.  This option allows you to see how often
  each branch in your program was taken.
+ 
+ @item -c
+ Write branch frequencies as the number of branches taken, rather than 
+ the percentage of branches taken.
  
  @item -v


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