daily update
[deliverable/binutils-gdb.git] / gprof / hist.c
index 0d0df01007ca69f5544a7bf005ef103c1f30a75d..024f6653e662194638034a85a91a9b7c790901fd 100644 (file)
@@ -1,6 +1,7 @@
 /* hist.c  -  Histogram related operations.
 
-   Copyright 2000, 2001 Free Software Foundation, Inc.
+   Copyright 1999, 2000, 2001, 2002, 2004, 2005
+   Free Software Foundation, Inc.
 
    This file is part of GNU Binutils.
 
@@ -16,8 +17,8 @@
 
    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
-   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
-   02111-1307, USA.  */
+   Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
+   02110-1301, USA.  */
 \f
 #include "libiberty.h"
 #include "gprof.h"
 
 #define UNITS_TO_CODE (offset_to_code / sizeof(UNIT))
 
-static void scale_and_align_entries PARAMS ((void));
+static void scale_and_align_entries (void);
+static void print_header (int);
+static void print_line (Sym *, double);
+static int cmp_time (const PTR, const PTR);
 
 /* Declarations of automatically generated functions to output blurbs.  */
-extern void flat_blurb PARAMS ((FILE * fp));
+extern void flat_blurb (FILE * fp);
 
 bfd_vma s_lowpc;               /* Lowest address in .text.  */
 bfd_vma s_highpc = 0;          /* Highest address in .text.  */
 bfd_vma lowpc, highpc;         /* Same, but expressed in UNITs.  */
-int hist_num_bins = 0;         /* Number of histogram samples.  */
+unsigned int hist_num_bins = 0;        /* Number of histogram samples.  */
 int *hist_sample = 0;          /* Histogram samples (shorts in the file!).  */
 double hist_scale;
-char hist_dimension[16] = "seconds";
-char hist_dimension_abbrev = 's';
+static char hist_dimension[16] = "seconds";
+static char hist_dimension_abbrev = 's';
 
 static double accum_time;      /* Accumulated time so far for print_line(). */
 static double total_time;      /* Total time for all routines.  */
@@ -77,10 +81,10 @@ SItab[] =
    is provided for formatting error messages only.  */
 
 void
-DEFUN (hist_read_rec, (ifp, filename), FILE * ifp AND const char *filename)
+hist_read_rec (FILE * ifp, const char *filename)
 {
   bfd_vma n_lowpc, n_highpc;
-  int i, ncnt, profrate;
+  unsigned int i, ncnt, profrate;
   UNIT count;
 
   if (gmon_io_read_vma (ifp, &n_lowpc)
@@ -108,16 +112,16 @@ DEFUN (hist_read_rec, (ifp, filename), FILE * ifp AND const char *filename)
     }
 
   DBG (SAMPLEDEBUG,
-       printf ("[hist_read_rec] n_lowpc 0x%lx n_highpc 0x%lx ncnt %d\n",
+       printf ("[hist_read_rec] n_lowpc 0x%lx n_highpc 0x%lx ncnt %u\n",
               (unsigned long) n_lowpc, (unsigned long) n_highpc, ncnt);
-       printf ("[hist_read_rec] s_lowpc 0x%lx s_highpc 0x%lx nsamples %d\n",
+       printf ("[hist_read_rec] s_lowpc 0x%lx s_highpc 0x%lx nsamples %u\n",
               (unsigned long) s_lowpc, (unsigned long) s_highpc,
               hist_num_bins);
        printf ("[hist_read_rec]   lowpc 0x%lx   highpc 0x%lx\n",
               (unsigned long) lowpc, (unsigned long) highpc));
 
   if (n_lowpc != s_lowpc || n_highpc != s_highpc
-      || ncnt != hist_num_bins || hz != profrate)
+      || ncnt != hist_num_bins || hz != (int) profrate)
     {
       fprintf (stderr, _("%s: `%s' is incompatible with first gmon file\n"),
               whoami, filename);
@@ -135,7 +139,7 @@ DEFUN (hist_read_rec, (ifp, filename), FILE * ifp AND const char *filename)
       if (fread (&count[0], sizeof (count), 1, ifp) != 1)
        {
          fprintf (stderr,
-                 _("%s: %s: unexpected EOF after reading %d of %d samples\n"),
+                 _("%s: %s: unexpected EOF after reading %u of %u samples\n"),
                   whoami, filename, i, hist_num_bins);
          done (1);
        }
@@ -152,10 +156,10 @@ DEFUN (hist_read_rec, (ifp, filename), FILE * ifp AND const char *filename)
    of OFP and is provided for formatting error-messages only.  */
 
 void
-DEFUN (hist_write_hist, (ofp, filename), FILE * ofp AND const char *filename)
+hist_write_hist (FILE * ofp, const char *filename)
 {
   UNIT count;
-  int i;
+  unsigned int i;
 
   /* Write header.  */
 
@@ -173,7 +177,7 @@ DEFUN (hist_write_hist, (ofp, filename), FILE * ofp AND const char *filename)
 
   for (i = 0; i < hist_num_bins; ++i)
     {
-      bfd_put_16 (core_bfd, hist_sample[i], (bfd_byte *) & count[0]);
+      bfd_put_16 (core_bfd, (bfd_vma) hist_sample[i], (bfd_byte *) &count[0]);
 
       if (fwrite (&count[0], sizeof (count), 1, ofp) != 1)
        {
@@ -255,13 +259,13 @@ scale_and_align_entries ()
    cases, above).  */
 
 void
-DEFUN_VOID (hist_assign_samples)
+hist_assign_samples ()
 {
   bfd_vma bin_low_pc, bin_high_pc;
   bfd_vma sym_low_pc, sym_high_pc;
   bfd_vma overlap, addr;
-  int bin_count, i;
-  unsigned int j;
+  unsigned int bin_count;
+  unsigned int i, j;
   double time, credit;
 
   /* Read samples and assign to symbols.  */
@@ -282,7 +286,7 @@ DEFUN_VOID (hist_assign_samples)
 
       DBG (SAMPLEDEBUG,
           printf (
-      "[assign_samples] bin_low_pc=0x%lx, bin_high_pc=0x%lx, bin_count=%d\n",
+      "[assign_samples] bin_low_pc=0x%lx, bin_high_pc=0x%lx, bin_count=%u\n",
                    (unsigned long) (sizeof (UNIT) * bin_low_pc),
                    (unsigned long) (sizeof (UNIT) * bin_high_pc),
                    bin_count));
@@ -344,7 +348,7 @@ DEFUN_VOID (hist_assign_samples)
 /* Print header for flag histogram profile.  */
 
 static void
-DEFUN (print_header, (prefix), const char prefix)
+print_header (int prefix)
 {
   char unit[64];
 
@@ -383,7 +387,7 @@ DEFUN (print_header, (prefix), const char prefix)
 
 
 static void
-DEFUN (print_line, (sym, scale), Sym * sym AND double scale)
+print_line (Sym *sym, double scale)
 {
   if (ignore_zeros && sym->ncalls == 0 && sym->hist.time == 0)
     return;
@@ -420,7 +424,7 @@ DEFUN (print_line, (sym, scale), Sym * sym AND double scale)
    lexicographic order of the function names.  */
 
 static int
-DEFUN (cmp_time, (lp, rp), const PTR lp AND const PTR rp)
+cmp_time (const PTR lp, const PTR rp)
 {
   const Sym *left = *(const Sym **) lp;
   const Sym *right = *(const Sym **) rp;
@@ -447,16 +451,16 @@ DEFUN (cmp_time, (lp, rp), const PTR lp AND const PTR rp)
 /* Print the flat histogram profile.  */
 
 void
-DEFUN_VOID (hist_print)
+hist_print ()
 {
   Sym **time_sorted_syms, *top_dog, *sym;
   unsigned int index;
-  int log_scale;
+  unsigned log_scale;
   double top_time, time;
   bfd_vma addr;
 
   if (first_output)
-    first_output = false;
+    first_output = FALSE;
   else
     printf ("\f\n");
 
@@ -516,11 +520,12 @@ DEFUN_VOID (hist_print)
        {
          top_time /= hz;
 
-         while (SItab[log_scale].scale * top_time < 1000.0
-                && ((size_t) log_scale
-                    < sizeof (SItab) / sizeof (SItab[0]) - 1))
+         for (log_scale = 0; log_scale < ARRAY_SIZE (SItab); log_scale ++)
            {
-             ++log_scale;
+             double scaled_value = SItab[log_scale].scale * top_time;
+
+             if (scaled_value >= 1.0 && scaled_value < 1000.0) 
+               break;
            }
        }
     }
This page took 0.026502 seconds and 4 git commands to generate.