#include <stdio.h>
#include "libiberty.h"
#include "gprof.h"
-#include "core.h"
+#include "corefile.h"
#include "gmon_io.h"
#include "gmon_out.h"
#include "hist.h"
#include "sym_ids.h"
#include "utils.h"
+#define UNITS_TO_CODE (offset_to_code / sizeof(UNIT))
+
+static void scale_and_align_entries PARAMS ((void));
+
/* declarations of automatically generated functions to output blurbs: */
extern void flat_blurb PARAMS ((FILE * fp));
if (fread (&hdr, sizeof (hdr), 1, ifp) != 1)
{
- fprintf (stderr, "%s: %s: unexpected end of file\n",
+ fprintf (stderr, _("%s: %s: unexpected end of file\n"),
whoami, filename);
done (1);
- } /* if */
+ }
n_lowpc = (bfd_vma) get_vma (core_bfd, (bfd_byte *) hdr.low_pc);
n_highpc = (bfd_vma) get_vma (core_bfd, (bfd_byte *) hdr.high_pc);
highpc = (bfd_vma) n_highpc / sizeof (UNIT);
hist_num_bins = ncnt;
hz = profrate;
- } /* if */
+ }
DBG (SAMPLEDEBUG,
printf ("[hist_read_rec] n_lowpc 0x%lx n_highpc 0x%lx ncnt %d\n",
- n_lowpc, n_highpc, ncnt);
+ (unsigned long) n_lowpc, (unsigned long) n_highpc, ncnt);
printf ("[hist_read_rec] s_lowpc 0x%lx s_highpc 0x%lx nsamples %d\n",
- s_lowpc, s_highpc, hist_num_bins);
+ (unsigned long) s_lowpc, (unsigned long) s_highpc,
+ hist_num_bins);
printf ("[hist_read_rec] lowpc 0x%lx highpc 0x%lx\n",
- lowpc, highpc));
+ (unsigned long) lowpc, (unsigned long) highpc));
if (n_lowpc != s_lowpc || n_highpc != s_highpc
|| ncnt != hist_num_bins || hz != profrate)
{
- fprintf (stderr, "%s: `%s' is incompatible with first gmon file\n",
+ fprintf (stderr, _("%s: `%s' is incompatible with first gmon file\n"),
whoami, filename);
done (1);
- } /* if */
+ }
if (!hist_sample)
{
hist_sample = (int *) xmalloc (hist_num_bins * sizeof (hist_sample[0]));
memset (hist_sample, 0, hist_num_bins * sizeof (hist_sample[0]));
- } /* if */
+ }
for (i = 0; i < hist_num_bins; ++i)
{
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 %d of %d samples\n"),
whoami, filename, i, hist_num_bins);
done (1);
- } /* if */
+ }
hist_sample[i] += bfd_get_16 (core_bfd, (bfd_byte *) & count[0]);
- } /* for */
-} /* hist_read_rec */
+ }
+}
/*
{
perror (filename);
done (1);
- } /* if */
+ }
for (i = 0; i < hist_num_bins; ++i)
{
{
perror (filename);
done (1);
- } /* if */
- } /* for */
-} /* hist_write_hist */
+ }
+ }
+}
/*
* next bin.
*/
static void
-DEFUN_VOID (scale_and_align_entries)
+scale_and_align_entries ()
{
Sym *sym;
-#if OFFSET_TO_CODE > 0
bfd_vma bin_of_entry;
bfd_vma bin_of_code;
-#endif
for (sym = symtab.base; sym < symtab.limit; sym++)
{
sym->hist.scaled_addr = sym->addr / sizeof (UNIT);
-#if OFFSET_TO_CODE > 0
bin_of_entry = (sym->hist.scaled_addr - lowpc) / hist_scale;
bin_of_code = (sym->hist.scaled_addr + UNITS_TO_CODE - lowpc) / hist_scale;
if (bin_of_entry < bin_of_code)
{
DBG (SAMPLEDEBUG,
printf ("[scale_and_align_entries] pushing 0x%lx to 0x%lx\n",
- sym->hist.scaled_addr, sym->aligned_addr + UNITS_TO_CODE));
- sym->aligned_addr += UNITS_TO_CODE;
- } /* if */
-#endif /* OFFSET_TO_CODE > 0 */
- } /* for */
-} /* scale_and_align_entries */
+ (unsigned long) sym->hist.scaled_addr,
+ (unsigned long) (sym->hist.scaled_addr
+ + UNITS_TO_CODE)));
+ sym->hist.scaled_addr += UNITS_TO_CODE;
+ }
+ }
+}
/*
bfd_vma bin_low_pc, bin_high_pc;
bfd_vma sym_low_pc, sym_high_pc;
bfd_vma overlap, addr;
- int bin_count, i, j;
+ int bin_count, i;
+ unsigned int j;
double time, credit;
/* read samples and assign to symbols: */
if (!bin_count)
{
continue;
- } /* if */
+ }
bin_low_pc = lowpc + (bfd_vma) (hist_scale * i);
bin_high_pc = lowpc + (bfd_vma) (hist_scale * (i + 1));
time = bin_count;
DBG (SAMPLEDEBUG,
printf (
"[assign_samples] bin_low_pc=0x%lx, bin_high_pc=0x%lx, bin_count=%d\n",
- sizeof (UNIT) * bin_low_pc, sizeof (UNIT) * bin_high_pc,
+ (unsigned long) (sizeof (UNIT) * bin_low_pc),
+ (unsigned long) (sizeof (UNIT) * bin_high_pc),
bin_count));
total_time += time;
if (bin_high_pc < sym_low_pc)
{
break;
- } /* if */
+ }
/*
* If low end of bin is above high end of symbol, go for
* next symbol.
if (bin_low_pc >= sym_high_pc)
{
continue;
- } /* if */
+ }
overlap =
MIN (bin_high_pc, sym_high_pc) - MAX (bin_low_pc, sym_low_pc);
if (overlap > 0)
DBG (SAMPLEDEBUG,
printf (
"[assign_samples] [0x%lx,0x%lx) %s gets %f ticks %ld overlap\n",
- symtab.base[j].addr, sizeof (UNIT) * sym_high_pc,
+ (unsigned long) symtab.base[j].addr,
+ (unsigned long) (sizeof (UNIT) * sym_high_pc),
symtab.base[j].name, overlap * time / hist_scale,
- overlap));
+ (long) overlap));
addr = symtab.base[j].addr;
credit = overlap * time / hist_scale;
/*
else
{
total_time -= credit;
- } /* if */
- } /* if */
- } /* if */
- } /* for */
+ }
+ }
+ }
+ }
DBG (SAMPLEDEBUG, printf ("[assign_samples] total_time %f\n",
total_time));
-} /* hist_assign_samples */
+}
/*
{
char unit[64];
- sprintf (unit, "%c%c/call", prefix, hist_dimension_abbrev);
+ sprintf (unit, _("%c%c/call"), prefix, hist_dimension_abbrev);
if (bsd_style_output)
{
- printf ("\ngranularity: each sample hit covers %ld byte(s)",
+ printf (_("\ngranularity: each sample hit covers %ld byte(s)"),
(long) hist_scale * sizeof (UNIT));
if (total_time > 0.0)
{
- printf (" for %.2f%% of %.2f %s\n\n",
+ printf (_(" for %.2f%% of %.2f %s\n\n"),
100.0 / total_time, total_time / hz, hist_dimension);
- } /* if */
+ }
}
else
{
- printf ("\nEach sample counts as %g %s.\n", 1.0 / hz, hist_dimension);
- } /* if */
+ printf (_("\nEach sample counts as %g %s.\n"), 1.0 / hz, hist_dimension);
+ }
if (total_time <= 0.0)
{
- printf (" no time accumulated\n\n");
+ printf (_(" no time accumulated\n\n"));
/* this doesn't hurt since all the numerators will be zero: */
total_time = 1.0;
- } /* if */
+ }
printf ("%5.5s %10.10s %8.8s %8.8s %8.8s %8.8s %-8.8s\n",
- "% ", "cumulative", "self ", "", "self ", "total ", "");
+ "% ", _("cumulative"), _("self "), "", _("self "), _("total "), "");
printf ("%5.5s %9.9s %8.8s %8.8s %8.8s %8.8s %-8.8s\n",
- "time", hist_dimension, hist_dimension, "calls", unit, unit,
- "name");
-} /* print_header */
+ _("time"), hist_dimension, hist_dimension, _("calls"), unit, unit,
+ _("name"));
+}
static void
if (ignore_zeros && sym->ncalls == 0 && sym->hist.time == 0)
{
return;
- } /* if */
+ }
accum_time += sym->hist.time;
if (bsd_style_output)
printf ("%6.2f %9.2f %8.2f",
total_time > 0.0 ? 100 * sym->hist.time / total_time : 0.0,
accum_time / hz, sym->hist.time / hz);
- } /* if */
- if (sym->ncalls)
+ }
+ if (sym->ncalls != 0)
{
- printf (" %8d %8.2f %8.2f ",
+ printf (" %8lu %8.2f %8.2f ",
sym->ncalls, scale * sym->hist.time / hz / sym->ncalls,
scale * (sym->hist.time + sym->cg.child_time) / hz / sym->ncalls);
}
else
{
printf (" %8.8s %8.8s %8.8s ", "", "", "");
- } /* if */
+ }
if (bsd_style_output)
{
print_name (sym);
else
{
print_name_only (sym);
- } /* if */
+ }
printf ("\n");
-} /* print_line */
+}
/*
const Sym *left = *(const Sym **) lp;
const Sym *right = *(const Sym **) rp;
double time_diff;
- long call_diff;
time_diff = right->hist.time - left->hist.time;
if (time_diff > 0.0)
{
return 1;
- } /* if */
+ }
if (time_diff < 0.0)
{
return -1;
- } /* if */
+ }
- call_diff = right->ncalls - left->ncalls;
- if (call_diff > 0)
+ if (right->ncalls > left->ncalls)
{
return 1;
- } /* if */
- if (call_diff < 0)
+ }
+ if (right->ncalls < left->ncalls)
{
return -1;
- } /* if */
+ }
return strcmp (left->name, right->name);
-} /* cmp_time */
+}
/*
DEFUN_VOID (hist_print)
{
Sym **time_sorted_syms, *top_dog, *sym;
- int index, log_scale;
+ unsigned int index;
+ int log_scale;
double top_time, time;
bfd_vma addr;
else
{
printf ("\f\n");
- } /* if */
+ }
accum_time = 0.0;
if (bsd_style_output)
{
if (print_descriptions)
{
- printf ("\n\n\nflat profile:\n");
+ printf (_("\n\n\nflat profile:\n"));
flat_blurb (stdout);
- } /* if */
+ }
}
else
{
- printf ("Flat profile:\n");
- } /* if */
+ printf (_("Flat profile:\n"));
+ }
/*
* Sort the symbol table by time (call-count and name as secondary
* and tertiary keys):
for (index = 0; index < symtab.len; ++index)
{
time_sorted_syms[index] = &symtab.base[index];
- } /* for */
+ }
qsort (time_sorted_syms, symtab.len, sizeof (Sym *), cmp_time);
if (bsd_style_output)
for (index = 0; index < symtab.len; ++index)
{
sym = time_sorted_syms[index];
- if (sym->ncalls)
+ if (sym->ncalls != 0)
{
time = (sym->hist.time + sym->cg.child_time) / sym->ncalls;
if (time > top_time)
{
top_dog = sym;
top_time = time;
- } /* if */
- } /* if */
- } /* for */
- if (top_dog && top_dog->ncalls && top_time > 0.0)
+ }
+ }
+ }
+ if (top_dog && top_dog->ncalls != 0 && top_time > 0.0)
{
top_time /= hz;
while (SItab[log_scale].scale * top_time < 1000.0
- && log_scale < sizeof (SItab) / sizeof (SItab[0]) - 1)
+ && ((size_t) log_scale
+ < sizeof (SItab) / sizeof (SItab[0]) - 1))
{
++log_scale;
- } /* while */
- } /* if */
- } /* if */
+ }
+ }
+ }
/*
* For now, the dimension is always seconds. In the future, we
&& !sym_lookup (&syms[EXCL_FLAT], addr)))
{
print_line (time_sorted_syms[index], SItab[log_scale].scale);
- } /* if */
- } /* for */
+ }
+ }
free (time_sorted_syms);
if (print_descriptions && !bsd_style_output)
{
flat_blurb (stdout);
- } /* if */
-} /* hist_print */
-
-/*** end of hist.c ***/
+ }
+}