gcov.c (struct arcdata): Add hits and total, remove prob.
authorClinton Popetz <cpopetz@cygnus.com>
Wed, 10 Nov 1999 17:17:15 +0000 (17:17 +0000)
committerClinton Popetz <cpopetz@gcc.gnu.org>
Wed, 10 Nov 1999 17:17:15 +0000 (12:17 -0500)
* 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..

From-SVN: r30476

gcc/ChangeLog
gcc/gcov.c
gcc/gcov.texi

index 78815202b1bccd7392d6fac67030369dbd78a8cc..b72b02ea978b0bffdd6bb70c42c10393fb52414e 100644 (file)
@@ -1,3 +1,13 @@
+Wed Nov 10 10:57:22 1999  Clinton Popetz  <cpopetz@cygnus.com>
+
+       * 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..
+
 Wed Nov 10 01:10:41 1999  Philippe De Muyter  <phdm@macqel.be>
 
        * genoutput.c (output_insn_data): Cast `INSN_OUTPUT_FORMAT_MULTI' and
index 822531cce09bca349eeb3a306b338e2622f4a7e3..46e0c435c33bb9111aadb60ae53003642856d12e 100644 (file)
@@ -138,7 +138,8 @@ struct bb_info {
 
 struct arcdata
 {
-  int prob;
+  int hits;
+  int total;
   int call_insn;
   struct arcdata *next;
 };
@@ -213,6 +214,11 @@ static int output_function_summary = 0;
 
 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 **));
 static void open_files PROTO ((void));
@@ -314,6 +320,8 @@ process_args (argc, argv)
        {
          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);
          else if (argv[i][1] == 'n')
@@ -878,10 +886,11 @@ calculate_branch_probs (current_graph, block_num, branch_probs, last_line_num)
        continue;
                      
       a_ptr = (struct arcdata *) xmalloc (sizeof (struct arcdata));
+      a_ptr->total = total;
       if (total == 0)
-       a_ptr->prob = -1;
+          a_ptr->hits = 0;
       else
-       a_ptr->prob = ((arcptr->arc_count * 100) + (total >> 1)) / total;
+          a_ptr->hits = arcptr->arc_count;
       a_ptr->call_insn = arcptr->fake;
 
       if (output_function_summary)
@@ -889,15 +898,15 @@ calculate_branch_probs (current_graph, block_num, branch_probs, last_line_num)
          if (a_ptr->call_insn)
            {
              function_calls++;
-             if (a_ptr->prob != -1)
+             if (a_ptr->total != 0)
                function_calls_executed++;
            }
          else
            {
              function_branches++;
-             if (a_ptr->prob != -1)
+             if (a_ptr->total != 0)
                function_branches_executed++;
-             if (a_ptr->prob > 0)
+             if (a_ptr->hits > 0)
                function_branches_taken++;
            }
        }
@@ -1180,15 +1189,15 @@ output_data ()
                  if (a_ptr->call_insn)
                    {
                      total_calls++;
-                     if (a_ptr->prob != -1)
+                     if (a_ptr->total != 0)
                        total_calls_executed++;
                    }
                  else
                    {
                      total_branches++;
-                     if (a_ptr->prob != -1)
+                     if (a_ptr->total != 0)
                        total_branches_executed++;
-                     if (a_ptr->prob > 0)
+                     if (a_ptr->hits > 0)
                        total_branches_taken++;
                    }
                }
@@ -1336,24 +1345,43 @@ output_data ()
                    {
                      if (a_ptr->call_insn)
                        {
-                         if (a_ptr->prob == -1)
+                         if (a_ptr->total == 0)
                            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 (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->prob == -1)
+                         if (a_ptr->total == 0)
                            fnotice (gcov_file, "branch %d never executed\n",
                                     i);
                          else
-                           fnotice (gcov_file, "branch %d taken = %d%%\n", i,
-                                    a_ptr->prob);
+                           {
+                             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.  */
              if (retval == NULL)
index 9c6d77da7d4c80a88e45cceeab0cb79e6f5912a1..49de3f0545886f8fd0393e0489e5b5f25e49c83a 100644 (file)
@@ -81,7 +81,7 @@ compatible with any other profiling or test coverage mechanism.
 @section Invoking gcov
 
 @smallexample
-gcov [-b] [-v] [-n] [-l] [-f] [-o directory] @var{sourcefile}
+gcov [-b] [-c] [-v] [-n] [-l] [-f] [-o directory] @var{sourcefile}
 @end smallexample
 
 @table @code
@@ -90,6 +90,10 @@ Write branch frequencies to the output file, and write branch summary
 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
 Display the @code{gcov} version number (on the standard error stream).