2000-07-24 22:59:04 +02:00
|
|
|
|
/* hist.c - Histogram related operations.
|
|
|
|
|
|
2015-01-01 15:15:26 +01:00
|
|
|
|
Copyright (C) 1999-2015 Free Software Foundation, Inc.
|
2000-07-24 22:59:04 +02:00
|
|
|
|
|
|
|
|
|
This file is part of GNU Binutils.
|
|
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU General Public License as published by
|
2007-07-06 12:40:34 +02:00
|
|
|
|
the Free Software Foundation; either version 3 of the License, or
|
2000-07-24 22:59:04 +02:00
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
|
along with this program; if not, write to the Free Software
|
2005-05-09 08:55:25 +02:00
|
|
|
|
Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
|
|
|
|
|
02110-1301, USA. */
|
2000-07-24 22:59:04 +02:00
|
|
|
|
|
1999-05-03 09:29:11 +02:00
|
|
|
|
#include "gprof.h"
|
2008-06-19 18:30:29 +02:00
|
|
|
|
#include "libiberty.h"
|
2002-01-31 13:56:08 +01:00
|
|
|
|
#include "search_list.h"
|
|
|
|
|
#include "source.h"
|
|
|
|
|
#include "symtab.h"
|
1999-05-03 09:29:11 +02:00
|
|
|
|
#include "corefile.h"
|
|
|
|
|
#include "gmon_io.h"
|
|
|
|
|
#include "gmon_out.h"
|
|
|
|
|
#include "hist.h"
|
|
|
|
|
#include "sym_ids.h"
|
|
|
|
|
#include "utils.h"
|
* hist.h (struct histogram)
(histograms, num_histograms): New.
* hist.c (find_histogram, find_histogram_for_pc)
(read_histogram_header): New.
(s_lowpc, s_highpc, lowpc, highpc, hist_num_bins)
(hist_sample): Remove.
(hist_read_rec): Use the above, and handle multiple
histogram records with disjoint address ranges.
(hist_write_hist): Support several histogram records.
(scale_and_align_entries): Adjust for multiple histograms.
(hist_assign_samples_1): New.
(hist_assign_samples): Use the above.
(hist_clip_symbol_address): New.
* hist.h (hist_check_address)
(hist_clip_symbol_address): Declare.
* gmon_io.c (gmon_out_read, gmon_out_write): Adjust handling
of legacy format for multiple histogram changes.
* corefile.c (find_call): Check for core_text_space and
clip symbol address range here.
* vax.c (vax_find_call): Don't check for
core_text_space, or clip the symbol's address range here.
Use hist_check_address to check call's target address.
* sparc.c: Likewise.
* tahoe.c: Likewise.
* i386.c: Likewise.
* mips.c: Likewise. Also use core_text_sect->vma as the base
address for code accesses, just like other machine-specific
routines do.
* gprof.texi: Adjust for the new logic.
2007-04-10 09:57:31 +02:00
|
|
|
|
#include "math.h"
|
|
|
|
|
#include "stdio.h"
|
|
|
|
|
#include "stdlib.h"
|
1999-05-03 09:29:11 +02:00
|
|
|
|
|
|
|
|
|
#define UNITS_TO_CODE (offset_to_code / sizeof(UNIT))
|
|
|
|
|
|
* alpha.c, basic_blocks.c, basic_blocks.h, bb_exit_func.c,
call_graph.c, call_graph.h, cg_arcs.c, cg_arcs.h, cg_dfn.c,
cg_dfn.h, cg_print.c, cg_print.h, corefile.c, corefile.h,
gmon_io.c, gmon_io.h, gprof.c, gprof.h, hertz.h, hist.c, hist.h,
i386.c, mips.c, search_list.c, search_list.h, source.c, source.h,
sparc.c, sym_ids.c, sym_ids.h, symtab.c, symtab.h, tahoe.c,
utils.c, utils.h, vax.c, gen-c-prog.awk: Convert K&R C to ANSI C.
2004-05-26 06:55:55 +02:00
|
|
|
|
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);
|
1999-05-03 09:29:11 +02:00
|
|
|
|
|
2000-07-24 22:59:04 +02:00
|
|
|
|
/* Declarations of automatically generated functions to output blurbs. */
|
* alpha.c, basic_blocks.c, basic_blocks.h, bb_exit_func.c,
call_graph.c, call_graph.h, cg_arcs.c, cg_arcs.h, cg_dfn.c,
cg_dfn.h, cg_print.c, cg_print.h, corefile.c, corefile.h,
gmon_io.c, gmon_io.h, gprof.c, gprof.h, hertz.h, hist.c, hist.h,
i386.c, mips.c, search_list.c, search_list.h, source.c, source.h,
sparc.c, sym_ids.c, sym_ids.h, symtab.c, symtab.h, tahoe.c,
utils.c, utils.h, vax.c, gen-c-prog.awk: Convert K&R C to ANSI C.
2004-05-26 06:55:55 +02:00
|
|
|
|
extern void flat_blurb (FILE * fp);
|
1999-05-03 09:29:11 +02:00
|
|
|
|
|
* hist.h (struct histogram)
(histograms, num_histograms): New.
* hist.c (find_histogram, find_histogram_for_pc)
(read_histogram_header): New.
(s_lowpc, s_highpc, lowpc, highpc, hist_num_bins)
(hist_sample): Remove.
(hist_read_rec): Use the above, and handle multiple
histogram records with disjoint address ranges.
(hist_write_hist): Support several histogram records.
(scale_and_align_entries): Adjust for multiple histograms.
(hist_assign_samples_1): New.
(hist_assign_samples): Use the above.
(hist_clip_symbol_address): New.
* hist.h (hist_check_address)
(hist_clip_symbol_address): Declare.
* gmon_io.c (gmon_out_read, gmon_out_write): Adjust handling
of legacy format for multiple histogram changes.
* corefile.c (find_call): Check for core_text_space and
clip symbol address range here.
* vax.c (vax_find_call): Don't check for
core_text_space, or clip the symbol's address range here.
Use hist_check_address to check call's target address.
* sparc.c: Likewise.
* tahoe.c: Likewise.
* i386.c: Likewise.
* mips.c: Likewise. Also use core_text_sect->vma as the base
address for code accesses, just like other machine-specific
routines do.
* gprof.texi: Adjust for the new logic.
2007-04-10 09:57:31 +02:00
|
|
|
|
static histogram *find_histogram (bfd_vma lowpc, bfd_vma highpc);
|
|
|
|
|
static histogram *find_histogram_for_pc (bfd_vma pc);
|
|
|
|
|
|
2009-09-25 11:57:50 +02:00
|
|
|
|
histogram * histograms;
|
|
|
|
|
unsigned num_histograms;
|
1999-05-03 09:29:11 +02:00
|
|
|
|
double hist_scale;
|
2005-04-23 19:13:31 +02:00
|
|
|
|
static char hist_dimension[16] = "seconds";
|
|
|
|
|
static char hist_dimension_abbrev = 's';
|
1999-05-03 09:29:11 +02:00
|
|
|
|
|
2001-03-14 04:14:56 +01:00
|
|
|
|
static double accum_time; /* Accumulated time so far for print_line(). */
|
2000-07-24 22:59:04 +02:00
|
|
|
|
static double total_time; /* Total time for all routines. */
|
|
|
|
|
|
|
|
|
|
/* Table of SI prefixes for powers of 10 (used to automatically
|
|
|
|
|
scale some of the values in the flat profile). */
|
1999-05-03 09:29:11 +02:00
|
|
|
|
const struct
|
|
|
|
|
{
|
|
|
|
|
char prefix;
|
|
|
|
|
double scale;
|
|
|
|
|
}
|
|
|
|
|
SItab[] =
|
|
|
|
|
{
|
2001-03-14 04:14:56 +01:00
|
|
|
|
{ 'T', 1e-12 }, /* tera */
|
|
|
|
|
{ 'G', 1e-09 }, /* giga */
|
|
|
|
|
{ 'M', 1e-06 }, /* mega */
|
|
|
|
|
{ 'K', 1e-03 }, /* kilo */
|
|
|
|
|
{ ' ', 1e-00 },
|
|
|
|
|
{ 'm', 1e+03 }, /* milli */
|
|
|
|
|
{ 'u', 1e+06 }, /* micro */
|
|
|
|
|
{ 'n', 1e+09 }, /* nano */
|
|
|
|
|
{ 'p', 1e+12 }, /* pico */
|
|
|
|
|
{ 'f', 1e+15 }, /* femto */
|
|
|
|
|
{ 'a', 1e+18 } /* ato */
|
1999-05-03 09:29:11 +02:00
|
|
|
|
};
|
|
|
|
|
|
* hist.h (struct histogram)
(histograms, num_histograms): New.
* hist.c (find_histogram, find_histogram_for_pc)
(read_histogram_header): New.
(s_lowpc, s_highpc, lowpc, highpc, hist_num_bins)
(hist_sample): Remove.
(hist_read_rec): Use the above, and handle multiple
histogram records with disjoint address ranges.
(hist_write_hist): Support several histogram records.
(scale_and_align_entries): Adjust for multiple histograms.
(hist_assign_samples_1): New.
(hist_assign_samples): Use the above.
(hist_clip_symbol_address): New.
* hist.h (hist_check_address)
(hist_clip_symbol_address): Declare.
* gmon_io.c (gmon_out_read, gmon_out_write): Adjust handling
of legacy format for multiple histogram changes.
* corefile.c (find_call): Check for core_text_space and
clip symbol address range here.
* vax.c (vax_find_call): Don't check for
core_text_space, or clip the symbol's address range here.
Use hist_check_address to check call's target address.
* sparc.c: Likewise.
* tahoe.c: Likewise.
* i386.c: Likewise.
* mips.c: Likewise. Also use core_text_sect->vma as the base
address for code accesses, just like other machine-specific
routines do.
* gprof.texi: Adjust for the new logic.
2007-04-10 09:57:31 +02:00
|
|
|
|
/* Reads just the header part of histogram record into
|
|
|
|
|
*RECORD from IFP. FILENAME is the name of IFP and
|
|
|
|
|
is provided for formatting error messages only.
|
2000-07-24 22:59:04 +02:00
|
|
|
|
|
* hist.h (struct histogram)
(histograms, num_histograms): New.
* hist.c (find_histogram, find_histogram_for_pc)
(read_histogram_header): New.
(s_lowpc, s_highpc, lowpc, highpc, hist_num_bins)
(hist_sample): Remove.
(hist_read_rec): Use the above, and handle multiple
histogram records with disjoint address ranges.
(hist_write_hist): Support several histogram records.
(scale_and_align_entries): Adjust for multiple histograms.
(hist_assign_samples_1): New.
(hist_assign_samples): Use the above.
(hist_clip_symbol_address): New.
* hist.h (hist_check_address)
(hist_clip_symbol_address): Declare.
* gmon_io.c (gmon_out_read, gmon_out_write): Adjust handling
of legacy format for multiple histogram changes.
* corefile.c (find_call): Check for core_text_space and
clip symbol address range here.
* vax.c (vax_find_call): Don't check for
core_text_space, or clip the symbol's address range here.
Use hist_check_address to check call's target address.
* sparc.c: Likewise.
* tahoe.c: Likewise.
* i386.c: Likewise.
* mips.c: Likewise. Also use core_text_sect->vma as the base
address for code accesses, just like other machine-specific
routines do.
* gprof.texi: Adjust for the new logic.
2007-04-10 09:57:31 +02:00
|
|
|
|
If FIRST is non-zero, sets global variables HZ, HIST_DIMENSION,
|
|
|
|
|
HIST_DIMENSION_ABBREV, HIST_SCALE. If FIRST is zero, checks
|
|
|
|
|
that the new histogram is compatible with already-set values
|
|
|
|
|
of those variables and emits an error if that's not so. */
|
|
|
|
|
static void
|
|
|
|
|
read_histogram_header (histogram *record,
|
|
|
|
|
FILE *ifp, const char *filename,
|
|
|
|
|
int first)
|
1999-05-03 09:29:11 +02:00
|
|
|
|
{
|
* hist.h (struct histogram)
(histograms, num_histograms): New.
* hist.c (find_histogram, find_histogram_for_pc)
(read_histogram_header): New.
(s_lowpc, s_highpc, lowpc, highpc, hist_num_bins)
(hist_sample): Remove.
(hist_read_rec): Use the above, and handle multiple
histogram records with disjoint address ranges.
(hist_write_hist): Support several histogram records.
(scale_and_align_entries): Adjust for multiple histograms.
(hist_assign_samples_1): New.
(hist_assign_samples): Use the above.
(hist_clip_symbol_address): New.
* hist.h (hist_check_address)
(hist_clip_symbol_address): Declare.
* gmon_io.c (gmon_out_read, gmon_out_write): Adjust handling
of legacy format for multiple histogram changes.
* corefile.c (find_call): Check for core_text_space and
clip symbol address range here.
* vax.c (vax_find_call): Don't check for
core_text_space, or clip the symbol's address range here.
Use hist_check_address to check call's target address.
* sparc.c: Likewise.
* tahoe.c: Likewise.
* i386.c: Likewise.
* mips.c: Likewise. Also use core_text_sect->vma as the base
address for code accesses, just like other machine-specific
routines do.
* gprof.texi: Adjust for the new logic.
2007-04-10 09:57:31 +02:00
|
|
|
|
unsigned int profrate;
|
|
|
|
|
char n_hist_dimension[15];
|
|
|
|
|
char n_hist_dimension_abbrev;
|
|
|
|
|
double n_hist_scale;
|
|
|
|
|
|
|
|
|
|
if (gmon_io_read_vma (ifp, &record->lowpc)
|
|
|
|
|
|| gmon_io_read_vma (ifp, &record->highpc)
|
|
|
|
|
|| gmon_io_read_32 (ifp, &record->num_bins)
|
2001-03-14 04:14:56 +01:00
|
|
|
|
|| gmon_io_read_32 (ifp, &profrate)
|
* hist.h (struct histogram)
(histograms, num_histograms): New.
* hist.c (find_histogram, find_histogram_for_pc)
(read_histogram_header): New.
(s_lowpc, s_highpc, lowpc, highpc, hist_num_bins)
(hist_sample): Remove.
(hist_read_rec): Use the above, and handle multiple
histogram records with disjoint address ranges.
(hist_write_hist): Support several histogram records.
(scale_and_align_entries): Adjust for multiple histograms.
(hist_assign_samples_1): New.
(hist_assign_samples): Use the above.
(hist_clip_symbol_address): New.
* hist.h (hist_check_address)
(hist_clip_symbol_address): Declare.
* gmon_io.c (gmon_out_read, gmon_out_write): Adjust handling
of legacy format for multiple histogram changes.
* corefile.c (find_call): Check for core_text_space and
clip symbol address range here.
* vax.c (vax_find_call): Don't check for
core_text_space, or clip the symbol's address range here.
Use hist_check_address to check call's target address.
* sparc.c: Likewise.
* tahoe.c: Likewise.
* i386.c: Likewise.
* mips.c: Likewise. Also use core_text_sect->vma as the base
address for code accesses, just like other machine-specific
routines do.
* gprof.texi: Adjust for the new logic.
2007-04-10 09:57:31 +02:00
|
|
|
|
|| gmon_io_read (ifp, n_hist_dimension, 15)
|
|
|
|
|
|| gmon_io_read (ifp, &n_hist_dimension_abbrev, 1))
|
1999-05-03 09:29:11 +02:00
|
|
|
|
{
|
|
|
|
|
fprintf (stderr, _("%s: %s: unexpected end of file\n"),
|
|
|
|
|
whoami, filename);
|
2001-03-14 04:14:56 +01:00
|
|
|
|
|
1999-05-03 09:29:11 +02:00
|
|
|
|
done (1);
|
|
|
|
|
}
|
|
|
|
|
|
* hist.h (struct histogram)
(histograms, num_histograms): New.
* hist.c (find_histogram, find_histogram_for_pc)
(read_histogram_header): New.
(s_lowpc, s_highpc, lowpc, highpc, hist_num_bins)
(hist_sample): Remove.
(hist_read_rec): Use the above, and handle multiple
histogram records with disjoint address ranges.
(hist_write_hist): Support several histogram records.
(scale_and_align_entries): Adjust for multiple histograms.
(hist_assign_samples_1): New.
(hist_assign_samples): Use the above.
(hist_clip_symbol_address): New.
* hist.h (hist_check_address)
(hist_clip_symbol_address): Declare.
* gmon_io.c (gmon_out_read, gmon_out_write): Adjust handling
of legacy format for multiple histogram changes.
* corefile.c (find_call): Check for core_text_space and
clip symbol address range here.
* vax.c (vax_find_call): Don't check for
core_text_space, or clip the symbol's address range here.
Use hist_check_address to check call's target address.
* sparc.c: Likewise.
* tahoe.c: Likewise.
* i386.c: Likewise.
* mips.c: Likewise. Also use core_text_sect->vma as the base
address for code accesses, just like other machine-specific
routines do.
* gprof.texi: Adjust for the new logic.
2007-04-10 09:57:31 +02:00
|
|
|
|
n_hist_scale = (double)((record->highpc - record->lowpc) / sizeof (UNIT))
|
|
|
|
|
/ record->num_bins;
|
|
|
|
|
|
|
|
|
|
if (first)
|
1999-05-03 09:29:11 +02:00
|
|
|
|
{
|
* hist.h (struct histogram)
(histograms, num_histograms): New.
* hist.c (find_histogram, find_histogram_for_pc)
(read_histogram_header): New.
(s_lowpc, s_highpc, lowpc, highpc, hist_num_bins)
(hist_sample): Remove.
(hist_read_rec): Use the above, and handle multiple
histogram records with disjoint address ranges.
(hist_write_hist): Support several histogram records.
(scale_and_align_entries): Adjust for multiple histograms.
(hist_assign_samples_1): New.
(hist_assign_samples): Use the above.
(hist_clip_symbol_address): New.
* hist.h (hist_check_address)
(hist_clip_symbol_address): Declare.
* gmon_io.c (gmon_out_read, gmon_out_write): Adjust handling
of legacy format for multiple histogram changes.
* corefile.c (find_call): Check for core_text_space and
clip symbol address range here.
* vax.c (vax_find_call): Don't check for
core_text_space, or clip the symbol's address range here.
Use hist_check_address to check call's target address.
* sparc.c: Likewise.
* tahoe.c: Likewise.
* i386.c: Likewise.
* mips.c: Likewise. Also use core_text_sect->vma as the base
address for code accesses, just like other machine-specific
routines do.
* gprof.texi: Adjust for the new logic.
2007-04-10 09:57:31 +02:00
|
|
|
|
/* We don't try to veryfy profrate is the same for all histogram
|
|
|
|
|
records. If we have two histogram records for the same
|
|
|
|
|
address range and profiling samples is done as often
|
|
|
|
|
as possible as opposed on timer, then the actual profrate will
|
|
|
|
|
be slightly different. Most of the time the difference does not
|
|
|
|
|
matter and insisting that profiling rate is exactly the same
|
|
|
|
|
will only create inconvenient. */
|
1999-05-03 09:29:11 +02:00
|
|
|
|
hz = profrate;
|
* hist.h (struct histogram)
(histograms, num_histograms): New.
* hist.c (find_histogram, find_histogram_for_pc)
(read_histogram_header): New.
(s_lowpc, s_highpc, lowpc, highpc, hist_num_bins)
(hist_sample): Remove.
(hist_read_rec): Use the above, and handle multiple
histogram records with disjoint address ranges.
(hist_write_hist): Support several histogram records.
(scale_and_align_entries): Adjust for multiple histograms.
(hist_assign_samples_1): New.
(hist_assign_samples): Use the above.
(hist_clip_symbol_address): New.
* hist.h (hist_check_address)
(hist_clip_symbol_address): Declare.
* gmon_io.c (gmon_out_read, gmon_out_write): Adjust handling
of legacy format for multiple histogram changes.
* corefile.c (find_call): Check for core_text_space and
clip symbol address range here.
* vax.c (vax_find_call): Don't check for
core_text_space, or clip the symbol's address range here.
Use hist_check_address to check call's target address.
* sparc.c: Likewise.
* tahoe.c: Likewise.
* i386.c: Likewise.
* mips.c: Likewise. Also use core_text_sect->vma as the base
address for code accesses, just like other machine-specific
routines do.
* gprof.texi: Adjust for the new logic.
2007-04-10 09:57:31 +02:00
|
|
|
|
memcpy (hist_dimension, n_hist_dimension, 15);
|
|
|
|
|
hist_dimension_abbrev = n_hist_dimension_abbrev;
|
|
|
|
|
hist_scale = n_hist_scale;
|
1999-05-03 09:29:11 +02:00
|
|
|
|
}
|
* hist.h (struct histogram)
(histograms, num_histograms): New.
* hist.c (find_histogram, find_histogram_for_pc)
(read_histogram_header): New.
(s_lowpc, s_highpc, lowpc, highpc, hist_num_bins)
(hist_sample): Remove.
(hist_read_rec): Use the above, and handle multiple
histogram records with disjoint address ranges.
(hist_write_hist): Support several histogram records.
(scale_and_align_entries): Adjust for multiple histograms.
(hist_assign_samples_1): New.
(hist_assign_samples): Use the above.
(hist_clip_symbol_address): New.
* hist.h (hist_check_address)
(hist_clip_symbol_address): Declare.
* gmon_io.c (gmon_out_read, gmon_out_write): Adjust handling
of legacy format for multiple histogram changes.
* corefile.c (find_call): Check for core_text_space and
clip symbol address range here.
* vax.c (vax_find_call): Don't check for
core_text_space, or clip the symbol's address range here.
Use hist_check_address to check call's target address.
* sparc.c: Likewise.
* tahoe.c: Likewise.
* i386.c: Likewise.
* mips.c: Likewise. Also use core_text_sect->vma as the base
address for code accesses, just like other machine-specific
routines do.
* gprof.texi: Adjust for the new logic.
2007-04-10 09:57:31 +02:00
|
|
|
|
else
|
1999-05-03 09:29:11 +02:00
|
|
|
|
{
|
* hist.h (struct histogram)
(histograms, num_histograms): New.
* hist.c (find_histogram, find_histogram_for_pc)
(read_histogram_header): New.
(s_lowpc, s_highpc, lowpc, highpc, hist_num_bins)
(hist_sample): Remove.
(hist_read_rec): Use the above, and handle multiple
histogram records with disjoint address ranges.
(hist_write_hist): Support several histogram records.
(scale_and_align_entries): Adjust for multiple histograms.
(hist_assign_samples_1): New.
(hist_assign_samples): Use the above.
(hist_clip_symbol_address): New.
* hist.h (hist_check_address)
(hist_clip_symbol_address): Declare.
* gmon_io.c (gmon_out_read, gmon_out_write): Adjust handling
of legacy format for multiple histogram changes.
* corefile.c (find_call): Check for core_text_space and
clip symbol address range here.
* vax.c (vax_find_call): Don't check for
core_text_space, or clip the symbol's address range here.
Use hist_check_address to check call's target address.
* sparc.c: Likewise.
* tahoe.c: Likewise.
* i386.c: Likewise.
* mips.c: Likewise. Also use core_text_sect->vma as the base
address for code accesses, just like other machine-specific
routines do.
* gprof.texi: Adjust for the new logic.
2007-04-10 09:57:31 +02:00
|
|
|
|
if (strncmp (n_hist_dimension, hist_dimension, 15) != 0)
|
|
|
|
|
{
|
|
|
|
|
fprintf (stderr,
|
|
|
|
|
_("%s: dimension unit changed between histogram records\n"
|
|
|
|
|
"%s: from '%s'\n"
|
|
|
|
|
"%s: to '%s'\n"),
|
|
|
|
|
whoami, whoami, hist_dimension, whoami, n_hist_dimension);
|
|
|
|
|
done (1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (n_hist_dimension_abbrev != hist_dimension_abbrev)
|
|
|
|
|
{
|
|
|
|
|
fprintf (stderr,
|
|
|
|
|
_("%s: dimension abbreviation changed between histogram records\n"
|
|
|
|
|
"%s: from '%c'\n"
|
|
|
|
|
"%s: to '%c'\n"),
|
|
|
|
|
whoami, whoami, hist_dimension_abbrev, whoami, n_hist_dimension_abbrev);
|
|
|
|
|
done (1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* The only reason we require the same scale for histograms is that
|
|
|
|
|
there's code (notably printing code), that prints units,
|
|
|
|
|
and it would be very confusing to have one unit mean different
|
|
|
|
|
things for different functions. */
|
|
|
|
|
if (fabs (hist_scale - n_hist_scale) > 0.000001)
|
|
|
|
|
{
|
|
|
|
|
fprintf (stderr,
|
|
|
|
|
_("%s: different scales in histogram records"),
|
|
|
|
|
whoami);
|
|
|
|
|
done (1);
|
|
|
|
|
}
|
1999-05-03 09:29:11 +02:00
|
|
|
|
}
|
* hist.h (struct histogram)
(histograms, num_histograms): New.
* hist.c (find_histogram, find_histogram_for_pc)
(read_histogram_header): New.
(s_lowpc, s_highpc, lowpc, highpc, hist_num_bins)
(hist_sample): Remove.
(hist_read_rec): Use the above, and handle multiple
histogram records with disjoint address ranges.
(hist_write_hist): Support several histogram records.
(scale_and_align_entries): Adjust for multiple histograms.
(hist_assign_samples_1): New.
(hist_assign_samples): Use the above.
(hist_clip_symbol_address): New.
* hist.h (hist_check_address)
(hist_clip_symbol_address): Declare.
* gmon_io.c (gmon_out_read, gmon_out_write): Adjust handling
of legacy format for multiple histogram changes.
* corefile.c (find_call): Check for core_text_space and
clip symbol address range here.
* vax.c (vax_find_call): Don't check for
core_text_space, or clip the symbol's address range here.
Use hist_check_address to check call's target address.
* sparc.c: Likewise.
* tahoe.c: Likewise.
* i386.c: Likewise.
* mips.c: Likewise. Also use core_text_sect->vma as the base
address for code accesses, just like other machine-specific
routines do.
* gprof.texi: Adjust for the new logic.
2007-04-10 09:57:31 +02:00
|
|
|
|
}
|
1999-05-03 09:29:11 +02:00
|
|
|
|
|
* hist.h (struct histogram)
(histograms, num_histograms): New.
* hist.c (find_histogram, find_histogram_for_pc)
(read_histogram_header): New.
(s_lowpc, s_highpc, lowpc, highpc, hist_num_bins)
(hist_sample): Remove.
(hist_read_rec): Use the above, and handle multiple
histogram records with disjoint address ranges.
(hist_write_hist): Support several histogram records.
(scale_and_align_entries): Adjust for multiple histograms.
(hist_assign_samples_1): New.
(hist_assign_samples): Use the above.
(hist_clip_symbol_address): New.
* hist.h (hist_check_address)
(hist_clip_symbol_address): Declare.
* gmon_io.c (gmon_out_read, gmon_out_write): Adjust handling
of legacy format for multiple histogram changes.
* corefile.c (find_call): Check for core_text_space and
clip symbol address range here.
* vax.c (vax_find_call): Don't check for
core_text_space, or clip the symbol's address range here.
Use hist_check_address to check call's target address.
* sparc.c: Likewise.
* tahoe.c: Likewise.
* i386.c: Likewise.
* mips.c: Likewise. Also use core_text_sect->vma as the base
address for code accesses, just like other machine-specific
routines do.
* gprof.texi: Adjust for the new logic.
2007-04-10 09:57:31 +02:00
|
|
|
|
/* Read the histogram from file IFP. FILENAME is the name of IFP and
|
|
|
|
|
is provided for formatting error messages only. */
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
hist_read_rec (FILE * ifp, const char *filename)
|
|
|
|
|
{
|
|
|
|
|
bfd_vma lowpc, highpc;
|
|
|
|
|
histogram n_record;
|
|
|
|
|
histogram *record, *existing_record;
|
|
|
|
|
unsigned i;
|
|
|
|
|
|
|
|
|
|
/* 1. Read the header and see if there's existing record for the
|
|
|
|
|
same address range and that there are no overlapping records. */
|
|
|
|
|
read_histogram_header (&n_record, ifp, filename, num_histograms == 0);
|
|
|
|
|
|
|
|
|
|
existing_record = find_histogram (n_record.lowpc, n_record.highpc);
|
|
|
|
|
if (existing_record)
|
1999-05-03 09:29:11 +02:00
|
|
|
|
{
|
* hist.h (struct histogram)
(histograms, num_histograms): New.
* hist.c (find_histogram, find_histogram_for_pc)
(read_histogram_header): New.
(s_lowpc, s_highpc, lowpc, highpc, hist_num_bins)
(hist_sample): Remove.
(hist_read_rec): Use the above, and handle multiple
histogram records with disjoint address ranges.
(hist_write_hist): Support several histogram records.
(scale_and_align_entries): Adjust for multiple histograms.
(hist_assign_samples_1): New.
(hist_assign_samples): Use the above.
(hist_clip_symbol_address): New.
* hist.h (hist_check_address)
(hist_clip_symbol_address): Declare.
* gmon_io.c (gmon_out_read, gmon_out_write): Adjust handling
of legacy format for multiple histogram changes.
* corefile.c (find_call): Check for core_text_space and
clip symbol address range here.
* vax.c (vax_find_call): Don't check for
core_text_space, or clip the symbol's address range here.
Use hist_check_address to check call's target address.
* sparc.c: Likewise.
* tahoe.c: Likewise.
* i386.c: Likewise.
* mips.c: Likewise. Also use core_text_sect->vma as the base
address for code accesses, just like other machine-specific
routines do.
* gprof.texi: Adjust for the new logic.
2007-04-10 09:57:31 +02:00
|
|
|
|
record = existing_record;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
/* If this record overlaps, but does not completely match an existing
|
|
|
|
|
record, it's an error. */
|
|
|
|
|
lowpc = n_record.lowpc;
|
|
|
|
|
highpc = n_record.highpc;
|
|
|
|
|
hist_clip_symbol_address (&lowpc, &highpc);
|
|
|
|
|
if (lowpc != highpc)
|
|
|
|
|
{
|
|
|
|
|
fprintf (stderr,
|
|
|
|
|
_("%s: overlapping histogram records\n"),
|
|
|
|
|
whoami);
|
|
|
|
|
done (1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* This is new record. Add it to global array and allocate space for
|
|
|
|
|
the samples. */
|
2009-09-11 17:27:38 +02:00
|
|
|
|
histograms = (struct histogram *)
|
|
|
|
|
xrealloc (histograms, sizeof (histogram) * (num_histograms + 1));
|
* hist.h (struct histogram)
(histograms, num_histograms): New.
* hist.c (find_histogram, find_histogram_for_pc)
(read_histogram_header): New.
(s_lowpc, s_highpc, lowpc, highpc, hist_num_bins)
(hist_sample): Remove.
(hist_read_rec): Use the above, and handle multiple
histogram records with disjoint address ranges.
(hist_write_hist): Support several histogram records.
(scale_and_align_entries): Adjust for multiple histograms.
(hist_assign_samples_1): New.
(hist_assign_samples): Use the above.
(hist_clip_symbol_address): New.
* hist.h (hist_check_address)
(hist_clip_symbol_address): Declare.
* gmon_io.c (gmon_out_read, gmon_out_write): Adjust handling
of legacy format for multiple histogram changes.
* corefile.c (find_call): Check for core_text_space and
clip symbol address range here.
* vax.c (vax_find_call): Don't check for
core_text_space, or clip the symbol's address range here.
Use hist_check_address to check call's target address.
* sparc.c: Likewise.
* tahoe.c: Likewise.
* i386.c: Likewise.
* mips.c: Likewise. Also use core_text_sect->vma as the base
address for code accesses, just like other machine-specific
routines do.
* gprof.texi: Adjust for the new logic.
2007-04-10 09:57:31 +02:00
|
|
|
|
memcpy (histograms + num_histograms,
|
|
|
|
|
&n_record, sizeof (histogram));
|
|
|
|
|
record = &histograms[num_histograms];
|
|
|
|
|
++num_histograms;
|
|
|
|
|
|
|
|
|
|
record->sample = (int *) xmalloc (record->num_bins
|
|
|
|
|
* sizeof (record->sample[0]));
|
|
|
|
|
memset (record->sample, 0, record->num_bins * sizeof (record->sample[0]));
|
1999-05-03 09:29:11 +02:00
|
|
|
|
}
|
|
|
|
|
|
* hist.h (struct histogram)
(histograms, num_histograms): New.
* hist.c (find_histogram, find_histogram_for_pc)
(read_histogram_header): New.
(s_lowpc, s_highpc, lowpc, highpc, hist_num_bins)
(hist_sample): Remove.
(hist_read_rec): Use the above, and handle multiple
histogram records with disjoint address ranges.
(hist_write_hist): Support several histogram records.
(scale_and_align_entries): Adjust for multiple histograms.
(hist_assign_samples_1): New.
(hist_assign_samples): Use the above.
(hist_clip_symbol_address): New.
* hist.h (hist_check_address)
(hist_clip_symbol_address): Declare.
* gmon_io.c (gmon_out_read, gmon_out_write): Adjust handling
of legacy format for multiple histogram changes.
* corefile.c (find_call): Check for core_text_space and
clip symbol address range here.
* vax.c (vax_find_call): Don't check for
core_text_space, or clip the symbol's address range here.
Use hist_check_address to check call's target address.
* sparc.c: Likewise.
* tahoe.c: Likewise.
* i386.c: Likewise.
* mips.c: Likewise. Also use core_text_sect->vma as the base
address for code accesses, just like other machine-specific
routines do.
* gprof.texi: Adjust for the new logic.
2007-04-10 09:57:31 +02:00
|
|
|
|
/* 2. We have either a new record (with zeroed histogram data), or an existing
|
|
|
|
|
record with some data in the histogram already. Read new data into the
|
|
|
|
|
record, adding hit counts. */
|
|
|
|
|
|
|
|
|
|
DBG (SAMPLEDEBUG,
|
|
|
|
|
printf ("[hist_read_rec] n_lowpc 0x%lx n_highpc 0x%lx ncnt %u\n",
|
|
|
|
|
(unsigned long) record->lowpc, (unsigned long) record->highpc,
|
|
|
|
|
record->num_bins));
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < record->num_bins; ++i)
|
1999-05-03 09:29:11 +02:00
|
|
|
|
{
|
* hist.h (struct histogram)
(histograms, num_histograms): New.
* hist.c (find_histogram, find_histogram_for_pc)
(read_histogram_header): New.
(s_lowpc, s_highpc, lowpc, highpc, hist_num_bins)
(hist_sample): Remove.
(hist_read_rec): Use the above, and handle multiple
histogram records with disjoint address ranges.
(hist_write_hist): Support several histogram records.
(scale_and_align_entries): Adjust for multiple histograms.
(hist_assign_samples_1): New.
(hist_assign_samples): Use the above.
(hist_clip_symbol_address): New.
* hist.h (hist_check_address)
(hist_clip_symbol_address): Declare.
* gmon_io.c (gmon_out_read, gmon_out_write): Adjust handling
of legacy format for multiple histogram changes.
* corefile.c (find_call): Check for core_text_space and
clip symbol address range here.
* vax.c (vax_find_call): Don't check for
core_text_space, or clip the symbol's address range here.
Use hist_check_address to check call's target address.
* sparc.c: Likewise.
* tahoe.c: Likewise.
* i386.c: Likewise.
* mips.c: Likewise. Also use core_text_sect->vma as the base
address for code accesses, just like other machine-specific
routines do.
* gprof.texi: Adjust for the new logic.
2007-04-10 09:57:31 +02:00
|
|
|
|
UNIT count;
|
1999-05-03 09:29:11 +02:00
|
|
|
|
if (fread (&count[0], sizeof (count), 1, ifp) != 1)
|
|
|
|
|
{
|
|
|
|
|
fprintf (stderr,
|
2005-02-22 13:59:21 +01:00
|
|
|
|
_("%s: %s: unexpected EOF after reading %u of %u samples\n"),
|
* hist.h (struct histogram)
(histograms, num_histograms): New.
* hist.c (find_histogram, find_histogram_for_pc)
(read_histogram_header): New.
(s_lowpc, s_highpc, lowpc, highpc, hist_num_bins)
(hist_sample): Remove.
(hist_read_rec): Use the above, and handle multiple
histogram records with disjoint address ranges.
(hist_write_hist): Support several histogram records.
(scale_and_align_entries): Adjust for multiple histograms.
(hist_assign_samples_1): New.
(hist_assign_samples): Use the above.
(hist_clip_symbol_address): New.
* hist.h (hist_check_address)
(hist_clip_symbol_address): Declare.
* gmon_io.c (gmon_out_read, gmon_out_write): Adjust handling
of legacy format for multiple histogram changes.
* corefile.c (find_call): Check for core_text_space and
clip symbol address range here.
* vax.c (vax_find_call): Don't check for
core_text_space, or clip the symbol's address range here.
Use hist_check_address to check call's target address.
* sparc.c: Likewise.
* tahoe.c: Likewise.
* i386.c: Likewise.
* mips.c: Likewise. Also use core_text_sect->vma as the base
address for code accesses, just like other machine-specific
routines do.
* gprof.texi: Adjust for the new logic.
2007-04-10 09:57:31 +02:00
|
|
|
|
whoami, filename, i, record->num_bins);
|
1999-05-03 09:29:11 +02:00
|
|
|
|
done (1);
|
|
|
|
|
}
|
* hist.h (struct histogram)
(histograms, num_histograms): New.
* hist.c (find_histogram, find_histogram_for_pc)
(read_histogram_header): New.
(s_lowpc, s_highpc, lowpc, highpc, hist_num_bins)
(hist_sample): Remove.
(hist_read_rec): Use the above, and handle multiple
histogram records with disjoint address ranges.
(hist_write_hist): Support several histogram records.
(scale_and_align_entries): Adjust for multiple histograms.
(hist_assign_samples_1): New.
(hist_assign_samples): Use the above.
(hist_clip_symbol_address): New.
* hist.h (hist_check_address)
(hist_clip_symbol_address): Declare.
* gmon_io.c (gmon_out_read, gmon_out_write): Adjust handling
of legacy format for multiple histogram changes.
* corefile.c (find_call): Check for core_text_space and
clip symbol address range here.
* vax.c (vax_find_call): Don't check for
core_text_space, or clip the symbol's address range here.
Use hist_check_address to check call's target address.
* sparc.c: Likewise.
* tahoe.c: Likewise.
* i386.c: Likewise.
* mips.c: Likewise. Also use core_text_sect->vma as the base
address for code accesses, just like other machine-specific
routines do.
* gprof.texi: Adjust for the new logic.
2007-04-10 09:57:31 +02:00
|
|
|
|
record->sample[i] += bfd_get_16 (core_bfd, (bfd_byte *) & count[0]);
|
2001-03-14 04:14:56 +01:00
|
|
|
|
DBG (SAMPLEDEBUG,
|
|
|
|
|
printf ("[hist_read_rec] 0x%lx: %u\n",
|
* hist.h (struct histogram)
(histograms, num_histograms): New.
* hist.c (find_histogram, find_histogram_for_pc)
(read_histogram_header): New.
(s_lowpc, s_highpc, lowpc, highpc, hist_num_bins)
(hist_sample): Remove.
(hist_read_rec): Use the above, and handle multiple
histogram records with disjoint address ranges.
(hist_write_hist): Support several histogram records.
(scale_and_align_entries): Adjust for multiple histograms.
(hist_assign_samples_1): New.
(hist_assign_samples): Use the above.
(hist_clip_symbol_address): New.
* hist.h (hist_check_address)
(hist_clip_symbol_address): Declare.
* gmon_io.c (gmon_out_read, gmon_out_write): Adjust handling
of legacy format for multiple histogram changes.
* corefile.c (find_call): Check for core_text_space and
clip symbol address range here.
* vax.c (vax_find_call): Don't check for
core_text_space, or clip the symbol's address range here.
Use hist_check_address to check call's target address.
* sparc.c: Likewise.
* tahoe.c: Likewise.
* i386.c: Likewise.
* mips.c: Likewise. Also use core_text_sect->vma as the base
address for code accesses, just like other machine-specific
routines do.
* gprof.texi: Adjust for the new logic.
2007-04-10 09:57:31 +02:00
|
|
|
|
(unsigned long) (record->lowpc
|
|
|
|
|
+ i * (record->highpc - record->lowpc)
|
|
|
|
|
/ record->num_bins),
|
|
|
|
|
record->sample[i]));
|
1999-05-03 09:29:11 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
* hist.h (struct histogram)
(histograms, num_histograms): New.
* hist.c (find_histogram, find_histogram_for_pc)
(read_histogram_header): New.
(s_lowpc, s_highpc, lowpc, highpc, hist_num_bins)
(hist_sample): Remove.
(hist_read_rec): Use the above, and handle multiple
histogram records with disjoint address ranges.
(hist_write_hist): Support several histogram records.
(scale_and_align_entries): Adjust for multiple histograms.
(hist_assign_samples_1): New.
(hist_assign_samples): Use the above.
(hist_clip_symbol_address): New.
* hist.h (hist_check_address)
(hist_clip_symbol_address): Declare.
* gmon_io.c (gmon_out_read, gmon_out_write): Adjust handling
of legacy format for multiple histogram changes.
* corefile.c (find_call): Check for core_text_space and
clip symbol address range here.
* vax.c (vax_find_call): Don't check for
core_text_space, or clip the symbol's address range here.
Use hist_check_address to check call's target address.
* sparc.c: Likewise.
* tahoe.c: Likewise.
* i386.c: Likewise.
* mips.c: Likewise. Also use core_text_sect->vma as the base
address for code accesses, just like other machine-specific
routines do.
* gprof.texi: Adjust for the new logic.
2007-04-10 09:57:31 +02:00
|
|
|
|
/* Write all execution histograms file OFP. FILENAME is the name
|
2000-07-24 22:59:04 +02:00
|
|
|
|
of OFP and is provided for formatting error-messages only. */
|
|
|
|
|
|
1999-05-03 09:29:11 +02:00
|
|
|
|
void
|
* alpha.c, basic_blocks.c, basic_blocks.h, bb_exit_func.c,
call_graph.c, call_graph.h, cg_arcs.c, cg_arcs.h, cg_dfn.c,
cg_dfn.h, cg_print.c, cg_print.h, corefile.c, corefile.h,
gmon_io.c, gmon_io.h, gprof.c, gprof.h, hertz.h, hist.c, hist.h,
i386.c, mips.c, search_list.c, search_list.h, source.c, source.h,
sparc.c, sym_ids.c, sym_ids.h, symtab.c, symtab.h, tahoe.c,
utils.c, utils.h, vax.c, gen-c-prog.awk: Convert K&R C to ANSI C.
2004-05-26 06:55:55 +02:00
|
|
|
|
hist_write_hist (FILE * ofp, const char *filename)
|
1999-05-03 09:29:11 +02:00
|
|
|
|
{
|
|
|
|
|
UNIT count;
|
* hist.h (struct histogram)
(histograms, num_histograms): New.
* hist.c (find_histogram, find_histogram_for_pc)
(read_histogram_header): New.
(s_lowpc, s_highpc, lowpc, highpc, hist_num_bins)
(hist_sample): Remove.
(hist_read_rec): Use the above, and handle multiple
histogram records with disjoint address ranges.
(hist_write_hist): Support several histogram records.
(scale_and_align_entries): Adjust for multiple histograms.
(hist_assign_samples_1): New.
(hist_assign_samples): Use the above.
(hist_clip_symbol_address): New.
* hist.h (hist_check_address)
(hist_clip_symbol_address): Declare.
* gmon_io.c (gmon_out_read, gmon_out_write): Adjust handling
of legacy format for multiple histogram changes.
* corefile.c (find_call): Check for core_text_space and
clip symbol address range here.
* vax.c (vax_find_call): Don't check for
core_text_space, or clip the symbol's address range here.
Use hist_check_address to check call's target address.
* sparc.c: Likewise.
* tahoe.c: Likewise.
* i386.c: Likewise.
* mips.c: Likewise. Also use core_text_sect->vma as the base
address for code accesses, just like other machine-specific
routines do.
* gprof.texi: Adjust for the new logic.
2007-04-10 09:57:31 +02:00
|
|
|
|
unsigned int i, r;
|
1999-05-03 09:29:11 +02:00
|
|
|
|
|
* hist.h (struct histogram)
(histograms, num_histograms): New.
* hist.c (find_histogram, find_histogram_for_pc)
(read_histogram_header): New.
(s_lowpc, s_highpc, lowpc, highpc, hist_num_bins)
(hist_sample): Remove.
(hist_read_rec): Use the above, and handle multiple
histogram records with disjoint address ranges.
(hist_write_hist): Support several histogram records.
(scale_and_align_entries): Adjust for multiple histograms.
(hist_assign_samples_1): New.
(hist_assign_samples): Use the above.
(hist_clip_symbol_address): New.
* hist.h (hist_check_address)
(hist_clip_symbol_address): Declare.
* gmon_io.c (gmon_out_read, gmon_out_write): Adjust handling
of legacy format for multiple histogram changes.
* corefile.c (find_call): Check for core_text_space and
clip symbol address range here.
* vax.c (vax_find_call): Don't check for
core_text_space, or clip the symbol's address range here.
Use hist_check_address to check call's target address.
* sparc.c: Likewise.
* tahoe.c: Likewise.
* i386.c: Likewise.
* mips.c: Likewise. Also use core_text_sect->vma as the base
address for code accesses, just like other machine-specific
routines do.
* gprof.texi: Adjust for the new logic.
2007-04-10 09:57:31 +02:00
|
|
|
|
for (r = 0; r < num_histograms; ++r)
|
1999-05-03 09:29:11 +02:00
|
|
|
|
{
|
* hist.h (struct histogram)
(histograms, num_histograms): New.
* hist.c (find_histogram, find_histogram_for_pc)
(read_histogram_header): New.
(s_lowpc, s_highpc, lowpc, highpc, hist_num_bins)
(hist_sample): Remove.
(hist_read_rec): Use the above, and handle multiple
histogram records with disjoint address ranges.
(hist_write_hist): Support several histogram records.
(scale_and_align_entries): Adjust for multiple histograms.
(hist_assign_samples_1): New.
(hist_assign_samples): Use the above.
(hist_clip_symbol_address): New.
* hist.h (hist_check_address)
(hist_clip_symbol_address): Declare.
* gmon_io.c (gmon_out_read, gmon_out_write): Adjust handling
of legacy format for multiple histogram changes.
* corefile.c (find_call): Check for core_text_space and
clip symbol address range here.
* vax.c (vax_find_call): Don't check for
core_text_space, or clip the symbol's address range here.
Use hist_check_address to check call's target address.
* sparc.c: Likewise.
* tahoe.c: Likewise.
* i386.c: Likewise.
* mips.c: Likewise. Also use core_text_sect->vma as the base
address for code accesses, just like other machine-specific
routines do.
* gprof.texi: Adjust for the new logic.
2007-04-10 09:57:31 +02:00
|
|
|
|
histogram *record = &histograms[r];
|
|
|
|
|
|
|
|
|
|
/* Write header. */
|
|
|
|
|
|
|
|
|
|
if (gmon_io_write_8 (ofp, GMON_TAG_TIME_HIST)
|
|
|
|
|
|| gmon_io_write_vma (ofp, record->lowpc)
|
|
|
|
|
|| gmon_io_write_vma (ofp, record->highpc)
|
|
|
|
|
|| gmon_io_write_32 (ofp, record->num_bins)
|
|
|
|
|
|| gmon_io_write_32 (ofp, hz)
|
|
|
|
|
|| gmon_io_write (ofp, hist_dimension, 15)
|
|
|
|
|
|| gmon_io_write (ofp, &hist_dimension_abbrev, 1))
|
1999-05-03 09:29:11 +02:00
|
|
|
|
{
|
|
|
|
|
perror (filename);
|
|
|
|
|
done (1);
|
|
|
|
|
}
|
* hist.h (struct histogram)
(histograms, num_histograms): New.
* hist.c (find_histogram, find_histogram_for_pc)
(read_histogram_header): New.
(s_lowpc, s_highpc, lowpc, highpc, hist_num_bins)
(hist_sample): Remove.
(hist_read_rec): Use the above, and handle multiple
histogram records with disjoint address ranges.
(hist_write_hist): Support several histogram records.
(scale_and_align_entries): Adjust for multiple histograms.
(hist_assign_samples_1): New.
(hist_assign_samples): Use the above.
(hist_clip_symbol_address): New.
* hist.h (hist_check_address)
(hist_clip_symbol_address): Declare.
* gmon_io.c (gmon_out_read, gmon_out_write): Adjust handling
of legacy format for multiple histogram changes.
* corefile.c (find_call): Check for core_text_space and
clip symbol address range here.
* vax.c (vax_find_call): Don't check for
core_text_space, or clip the symbol's address range here.
Use hist_check_address to check call's target address.
* sparc.c: Likewise.
* tahoe.c: Likewise.
* i386.c: Likewise.
* mips.c: Likewise. Also use core_text_sect->vma as the base
address for code accesses, just like other machine-specific
routines do.
* gprof.texi: Adjust for the new logic.
2007-04-10 09:57:31 +02:00
|
|
|
|
|
|
|
|
|
for (i = 0; i < record->num_bins; ++i)
|
|
|
|
|
{
|
|
|
|
|
bfd_put_16 (core_bfd, (bfd_vma) record->sample[i], (bfd_byte *) &count[0]);
|
|
|
|
|
|
|
|
|
|
if (fwrite (&count[0], sizeof (count), 1, ofp) != 1)
|
|
|
|
|
{
|
|
|
|
|
perror (filename);
|
|
|
|
|
done (1);
|
|
|
|
|
}
|
|
|
|
|
}
|
1999-05-03 09:29:11 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2000-07-24 22:59:04 +02:00
|
|
|
|
/* Calculate scaled entry point addresses (to save time in
|
|
|
|
|
hist_assign_samples), and, on architectures that have procedure
|
|
|
|
|
entry masks at the start of a function, possibly push the scaled
|
|
|
|
|
entry points over the procedure entry mask, if it turns out that
|
|
|
|
|
the entry point is in one bin and the code for a routine is in the
|
|
|
|
|
next bin. */
|
|
|
|
|
|
1999-05-03 09:29:11 +02:00
|
|
|
|
static void
|
|
|
|
|
scale_and_align_entries ()
|
|
|
|
|
{
|
|
|
|
|
Sym *sym;
|
|
|
|
|
bfd_vma bin_of_entry;
|
|
|
|
|
bfd_vma bin_of_code;
|
|
|
|
|
|
|
|
|
|
for (sym = symtab.base; sym < symtab.limit; sym++)
|
|
|
|
|
{
|
* hist.h (struct histogram)
(histograms, num_histograms): New.
* hist.c (find_histogram, find_histogram_for_pc)
(read_histogram_header): New.
(s_lowpc, s_highpc, lowpc, highpc, hist_num_bins)
(hist_sample): Remove.
(hist_read_rec): Use the above, and handle multiple
histogram records with disjoint address ranges.
(hist_write_hist): Support several histogram records.
(scale_and_align_entries): Adjust for multiple histograms.
(hist_assign_samples_1): New.
(hist_assign_samples): Use the above.
(hist_clip_symbol_address): New.
* hist.h (hist_check_address)
(hist_clip_symbol_address): Declare.
* gmon_io.c (gmon_out_read, gmon_out_write): Adjust handling
of legacy format for multiple histogram changes.
* corefile.c (find_call): Check for core_text_space and
clip symbol address range here.
* vax.c (vax_find_call): Don't check for
core_text_space, or clip the symbol's address range here.
Use hist_check_address to check call's target address.
* sparc.c: Likewise.
* tahoe.c: Likewise.
* i386.c: Likewise.
* mips.c: Likewise. Also use core_text_sect->vma as the base
address for code accesses, just like other machine-specific
routines do.
* gprof.texi: Adjust for the new logic.
2007-04-10 09:57:31 +02:00
|
|
|
|
histogram *r = find_histogram_for_pc (sym->addr);
|
|
|
|
|
|
2007-05-15 01:16:45 +02:00
|
|
|
|
sym->hist.scaled_addr = sym->addr / sizeof (UNIT);
|
|
|
|
|
|
* hist.h (struct histogram)
(histograms, num_histograms): New.
* hist.c (find_histogram, find_histogram_for_pc)
(read_histogram_header): New.
(s_lowpc, s_highpc, lowpc, highpc, hist_num_bins)
(hist_sample): Remove.
(hist_read_rec): Use the above, and handle multiple
histogram records with disjoint address ranges.
(hist_write_hist): Support several histogram records.
(scale_and_align_entries): Adjust for multiple histograms.
(hist_assign_samples_1): New.
(hist_assign_samples): Use the above.
(hist_clip_symbol_address): New.
* hist.h (hist_check_address)
(hist_clip_symbol_address): Declare.
* gmon_io.c (gmon_out_read, gmon_out_write): Adjust handling
of legacy format for multiple histogram changes.
* corefile.c (find_call): Check for core_text_space and
clip symbol address range here.
* vax.c (vax_find_call): Don't check for
core_text_space, or clip the symbol's address range here.
Use hist_check_address to check call's target address.
* sparc.c: Likewise.
* tahoe.c: Likewise.
* i386.c: Likewise.
* mips.c: Likewise. Also use core_text_sect->vma as the base
address for code accesses, just like other machine-specific
routines do.
* gprof.texi: Adjust for the new logic.
2007-04-10 09:57:31 +02:00
|
|
|
|
if (r)
|
1999-05-03 09:29:11 +02:00
|
|
|
|
{
|
* hist.h (struct histogram)
(histograms, num_histograms): New.
* hist.c (find_histogram, find_histogram_for_pc)
(read_histogram_header): New.
(s_lowpc, s_highpc, lowpc, highpc, hist_num_bins)
(hist_sample): Remove.
(hist_read_rec): Use the above, and handle multiple
histogram records with disjoint address ranges.
(hist_write_hist): Support several histogram records.
(scale_and_align_entries): Adjust for multiple histograms.
(hist_assign_samples_1): New.
(hist_assign_samples): Use the above.
(hist_clip_symbol_address): New.
* hist.h (hist_check_address)
(hist_clip_symbol_address): Declare.
* gmon_io.c (gmon_out_read, gmon_out_write): Adjust handling
of legacy format for multiple histogram changes.
* corefile.c (find_call): Check for core_text_space and
clip symbol address range here.
* vax.c (vax_find_call): Don't check for
core_text_space, or clip the symbol's address range here.
Use hist_check_address to check call's target address.
* sparc.c: Likewise.
* tahoe.c: Likewise.
* i386.c: Likewise.
* mips.c: Likewise. Also use core_text_sect->vma as the base
address for code accesses, just like other machine-specific
routines do.
* gprof.texi: Adjust for the new logic.
2007-04-10 09:57:31 +02:00
|
|
|
|
bin_of_entry = (sym->hist.scaled_addr - r->lowpc) / hist_scale;
|
|
|
|
|
bin_of_code = ((sym->hist.scaled_addr + UNITS_TO_CODE - r->lowpc)
|
|
|
|
|
/ hist_scale);
|
|
|
|
|
if (bin_of_entry < bin_of_code)
|
|
|
|
|
{
|
|
|
|
|
DBG (SAMPLEDEBUG,
|
|
|
|
|
printf ("[scale_and_align_entries] pushing 0x%lx to 0x%lx\n",
|
|
|
|
|
(unsigned long) sym->hist.scaled_addr,
|
|
|
|
|
(unsigned long) (sym->hist.scaled_addr
|
|
|
|
|
+ UNITS_TO_CODE)));
|
|
|
|
|
sym->hist.scaled_addr += UNITS_TO_CODE;
|
|
|
|
|
}
|
1999-05-03 09:29:11 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2000-07-24 22:59:04 +02:00
|
|
|
|
/* Assign samples to the symbol to which they belong.
|
2001-03-14 04:14:56 +01:00
|
|
|
|
|
2000-07-24 22:59:04 +02:00
|
|
|
|
Histogram bin I covers some address range [BIN_LOWPC,BIN_HIGH_PC)
|
|
|
|
|
which may overlap one more symbol address ranges. If a symbol
|
|
|
|
|
overlaps with the bin's address range by O percent, then O percent
|
|
|
|
|
of the bin's count is credited to that symbol.
|
2001-03-14 04:14:56 +01:00
|
|
|
|
|
2000-07-24 22:59:04 +02:00
|
|
|
|
There are three cases as to where BIN_LOW_PC and BIN_HIGH_PC can be
|
|
|
|
|
with respect to the symbol's address range [SYM_LOW_PC,
|
|
|
|
|
SYM_HIGH_PC) as shown in the following diagram. OVERLAP computes
|
|
|
|
|
the distance (in UNITs) between the arrows, the fraction of the
|
|
|
|
|
sample that is to be credited to the symbol which starts at
|
|
|
|
|
SYM_LOW_PC.
|
2001-03-14 04:14:56 +01:00
|
|
|
|
|
|
|
|
|
sym_low_pc sym_high_pc
|
|
|
|
|
| |
|
|
|
|
|
v v
|
|
|
|
|
|
|
|
|
|
+-----------------------------------------------+
|
|
|
|
|
| |
|
|
|
|
|
| ->| |<- ->| |<- ->| |<- |
|
|
|
|
|
| | | | | |
|
|
|
|
|
+---------+ +---------+ +---------+
|
|
|
|
|
|
|
|
|
|
^ ^ ^ ^ ^ ^
|
|
|
|
|
| | | | | |
|
2000-07-24 22:59:04 +02:00
|
|
|
|
bin_low_pc bin_high_pc bin_low_pc bin_high_pc bin_low_pc bin_high_pc
|
2001-03-14 04:14:56 +01:00
|
|
|
|
|
2000-07-24 22:59:04 +02:00
|
|
|
|
For the VAX we assert that samples will never fall in the first two
|
|
|
|
|
bytes of any routine, since that is the entry mask, thus we call
|
|
|
|
|
scale_and_align_entries() to adjust the entry points if the entry
|
|
|
|
|
mask falls in one bin but the code for the routine doesn't start
|
|
|
|
|
until the next bin. In conjunction with the alignment of routine
|
|
|
|
|
addresses, this should allow us to have only one sample for every
|
|
|
|
|
four bytes of text space and never have any overlap (the two end
|
|
|
|
|
cases, above). */
|
|
|
|
|
|
* hist.h (struct histogram)
(histograms, num_histograms): New.
* hist.c (find_histogram, find_histogram_for_pc)
(read_histogram_header): New.
(s_lowpc, s_highpc, lowpc, highpc, hist_num_bins)
(hist_sample): Remove.
(hist_read_rec): Use the above, and handle multiple
histogram records with disjoint address ranges.
(hist_write_hist): Support several histogram records.
(scale_and_align_entries): Adjust for multiple histograms.
(hist_assign_samples_1): New.
(hist_assign_samples): Use the above.
(hist_clip_symbol_address): New.
* hist.h (hist_check_address)
(hist_clip_symbol_address): Declare.
* gmon_io.c (gmon_out_read, gmon_out_write): Adjust handling
of legacy format for multiple histogram changes.
* corefile.c (find_call): Check for core_text_space and
clip symbol address range here.
* vax.c (vax_find_call): Don't check for
core_text_space, or clip the symbol's address range here.
Use hist_check_address to check call's target address.
* sparc.c: Likewise.
* tahoe.c: Likewise.
* i386.c: Likewise.
* mips.c: Likewise. Also use core_text_sect->vma as the base
address for code accesses, just like other machine-specific
routines do.
* gprof.texi: Adjust for the new logic.
2007-04-10 09:57:31 +02:00
|
|
|
|
static void
|
|
|
|
|
hist_assign_samples_1 (histogram *r)
|
1999-05-03 09:29:11 +02:00
|
|
|
|
{
|
|
|
|
|
bfd_vma bin_low_pc, bin_high_pc;
|
|
|
|
|
bfd_vma sym_low_pc, sym_high_pc;
|
|
|
|
|
bfd_vma overlap, addr;
|
2005-02-22 13:59:21 +01:00
|
|
|
|
unsigned int bin_count;
|
2011-10-25 18:46:46 +02:00
|
|
|
|
unsigned int i, j, k;
|
2009-12-11 14:42:17 +01:00
|
|
|
|
double count_time, credit;
|
1999-05-03 09:29:11 +02:00
|
|
|
|
|
* hist.h (struct histogram)
(histograms, num_histograms): New.
* hist.c (find_histogram, find_histogram_for_pc)
(read_histogram_header): New.
(s_lowpc, s_highpc, lowpc, highpc, hist_num_bins)
(hist_sample): Remove.
(hist_read_rec): Use the above, and handle multiple
histogram records with disjoint address ranges.
(hist_write_hist): Support several histogram records.
(scale_and_align_entries): Adjust for multiple histograms.
(hist_assign_samples_1): New.
(hist_assign_samples): Use the above.
(hist_clip_symbol_address): New.
* hist.h (hist_check_address)
(hist_clip_symbol_address): Declare.
* gmon_io.c (gmon_out_read, gmon_out_write): Adjust handling
of legacy format for multiple histogram changes.
* corefile.c (find_call): Check for core_text_space and
clip symbol address range here.
* vax.c (vax_find_call): Don't check for
core_text_space, or clip the symbol's address range here.
Use hist_check_address to check call's target address.
* sparc.c: Likewise.
* tahoe.c: Likewise.
* i386.c: Likewise.
* mips.c: Likewise. Also use core_text_sect->vma as the base
address for code accesses, just like other machine-specific
routines do.
* gprof.texi: Adjust for the new logic.
2007-04-10 09:57:31 +02:00
|
|
|
|
bfd_vma lowpc = r->lowpc / sizeof (UNIT);
|
1999-05-03 09:29:11 +02:00
|
|
|
|
|
2000-07-24 22:59:04 +02:00
|
|
|
|
/* Iterate over all sample bins. */
|
2011-10-25 18:46:46 +02:00
|
|
|
|
for (i = 0, k = 1; i < r->num_bins; ++i)
|
1999-05-03 09:29:11 +02:00
|
|
|
|
{
|
* hist.h (struct histogram)
(histograms, num_histograms): New.
* hist.c (find_histogram, find_histogram_for_pc)
(read_histogram_header): New.
(s_lowpc, s_highpc, lowpc, highpc, hist_num_bins)
(hist_sample): Remove.
(hist_read_rec): Use the above, and handle multiple
histogram records with disjoint address ranges.
(hist_write_hist): Support several histogram records.
(scale_and_align_entries): Adjust for multiple histograms.
(hist_assign_samples_1): New.
(hist_assign_samples): Use the above.
(hist_clip_symbol_address): New.
* hist.h (hist_check_address)
(hist_clip_symbol_address): Declare.
* gmon_io.c (gmon_out_read, gmon_out_write): Adjust handling
of legacy format for multiple histogram changes.
* corefile.c (find_call): Check for core_text_space and
clip symbol address range here.
* vax.c (vax_find_call): Don't check for
core_text_space, or clip the symbol's address range here.
Use hist_check_address to check call's target address.
* sparc.c: Likewise.
* tahoe.c: Likewise.
* i386.c: Likewise.
* mips.c: Likewise. Also use core_text_sect->vma as the base
address for code accesses, just like other machine-specific
routines do.
* gprof.texi: Adjust for the new logic.
2007-04-10 09:57:31 +02:00
|
|
|
|
bin_count = r->sample[i];
|
2000-07-24 22:59:04 +02:00
|
|
|
|
if (! bin_count)
|
|
|
|
|
continue;
|
|
|
|
|
|
1999-05-03 09:29:11 +02:00
|
|
|
|
bin_low_pc = lowpc + (bfd_vma) (hist_scale * i);
|
|
|
|
|
bin_high_pc = lowpc + (bfd_vma) (hist_scale * (i + 1));
|
2009-12-11 14:42:17 +01:00
|
|
|
|
count_time = bin_count;
|
2001-03-14 04:14:56 +01:00
|
|
|
|
|
1999-05-03 09:29:11 +02:00
|
|
|
|
DBG (SAMPLEDEBUG,
|
|
|
|
|
printf (
|
2005-02-22 13:59:21 +01:00
|
|
|
|
"[assign_samples] bin_low_pc=0x%lx, bin_high_pc=0x%lx, bin_count=%u\n",
|
1999-07-01 00:38:30 +02:00
|
|
|
|
(unsigned long) (sizeof (UNIT) * bin_low_pc),
|
|
|
|
|
(unsigned long) (sizeof (UNIT) * bin_high_pc),
|
1999-05-03 09:29:11 +02:00
|
|
|
|
bin_count));
|
2009-12-11 14:42:17 +01:00
|
|
|
|
total_time += count_time;
|
1999-05-03 09:29:11 +02:00
|
|
|
|
|
2011-10-26 11:51:57 +02:00
|
|
|
|
/* Credit all symbols that are covered by bin I.
|
|
|
|
|
|
|
|
|
|
PR gprof/13325: Make sure that K does not get decremented
|
|
|
|
|
and J will never be less than 0. */
|
2011-10-25 18:46:46 +02:00
|
|
|
|
for (j = k - 1; j < symtab.len; k = ++j)
|
1999-05-03 09:29:11 +02:00
|
|
|
|
{
|
|
|
|
|
sym_low_pc = symtab.base[j].hist.scaled_addr;
|
|
|
|
|
sym_high_pc = symtab.base[j + 1].hist.scaled_addr;
|
2001-03-14 04:14:56 +01:00
|
|
|
|
|
2000-07-24 22:59:04 +02:00
|
|
|
|
/* If high end of bin is below entry address,
|
|
|
|
|
go for next bin. */
|
1999-05-03 09:29:11 +02:00
|
|
|
|
if (bin_high_pc < sym_low_pc)
|
2011-10-25 18:46:46 +02:00
|
|
|
|
break;
|
2000-07-24 22:59:04 +02:00
|
|
|
|
|
|
|
|
|
/* If low end of bin is above high end of symbol,
|
|
|
|
|
go for next symbol. */
|
1999-05-03 09:29:11 +02:00
|
|
|
|
if (bin_low_pc >= sym_high_pc)
|
2000-07-24 22:59:04 +02:00
|
|
|
|
continue;
|
|
|
|
|
|
1999-05-03 09:29:11 +02:00
|
|
|
|
overlap =
|
|
|
|
|
MIN (bin_high_pc, sym_high_pc) - MAX (bin_low_pc, sym_low_pc);
|
|
|
|
|
if (overlap > 0)
|
|
|
|
|
{
|
|
|
|
|
DBG (SAMPLEDEBUG,
|
|
|
|
|
printf (
|
2001-03-14 04:14:56 +01:00
|
|
|
|
"[assign_samples] [0x%lx,0x%lx) %s gets %f ticks %ld overlap\n",
|
|
|
|
|
(unsigned long) symtab.base[j].addr,
|
|
|
|
|
(unsigned long) (sizeof (UNIT) * sym_high_pc),
|
2009-12-11 14:42:17 +01:00
|
|
|
|
symtab.base[j].name, overlap * count_time / hist_scale,
|
2001-03-14 04:14:56 +01:00
|
|
|
|
(long) overlap));
|
|
|
|
|
|
1999-05-03 09:29:11 +02:00
|
|
|
|
addr = symtab.base[j].addr;
|
2009-12-11 14:42:17 +01:00
|
|
|
|
credit = overlap * count_time / hist_scale;
|
2001-03-14 04:14:56 +01:00
|
|
|
|
|
2000-07-24 22:59:04 +02:00
|
|
|
|
/* Credit symbol if it appears in INCL_FLAT or that
|
2001-03-14 04:14:56 +01:00
|
|
|
|
table is empty and it does not appear it in
|
|
|
|
|
EXCL_FLAT. */
|
1999-05-03 09:29:11 +02:00
|
|
|
|
if (sym_lookup (&syms[INCL_FLAT], addr)
|
|
|
|
|
|| (syms[INCL_FLAT].len == 0
|
|
|
|
|
&& !sym_lookup (&syms[EXCL_FLAT], addr)))
|
|
|
|
|
{
|
|
|
|
|
symtab.base[j].hist.time += credit;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
total_time -= credit;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2001-03-14 04:14:56 +01:00
|
|
|
|
|
1999-05-03 09:29:11 +02:00
|
|
|
|
DBG (SAMPLEDEBUG, printf ("[assign_samples] total_time %f\n",
|
|
|
|
|
total_time));
|
|
|
|
|
}
|
|
|
|
|
|
* hist.h (struct histogram)
(histograms, num_histograms): New.
* hist.c (find_histogram, find_histogram_for_pc)
(read_histogram_header): New.
(s_lowpc, s_highpc, lowpc, highpc, hist_num_bins)
(hist_sample): Remove.
(hist_read_rec): Use the above, and handle multiple
histogram records with disjoint address ranges.
(hist_write_hist): Support several histogram records.
(scale_and_align_entries): Adjust for multiple histograms.
(hist_assign_samples_1): New.
(hist_assign_samples): Use the above.
(hist_clip_symbol_address): New.
* hist.h (hist_check_address)
(hist_clip_symbol_address): Declare.
* gmon_io.c (gmon_out_read, gmon_out_write): Adjust handling
of legacy format for multiple histogram changes.
* corefile.c (find_call): Check for core_text_space and
clip symbol address range here.
* vax.c (vax_find_call): Don't check for
core_text_space, or clip the symbol's address range here.
Use hist_check_address to check call's target address.
* sparc.c: Likewise.
* tahoe.c: Likewise.
* i386.c: Likewise.
* mips.c: Likewise. Also use core_text_sect->vma as the base
address for code accesses, just like other machine-specific
routines do.
* gprof.texi: Adjust for the new logic.
2007-04-10 09:57:31 +02:00
|
|
|
|
/* Calls 'hist_assign_sampes_1' for all histogram records read so far. */
|
|
|
|
|
void
|
|
|
|
|
hist_assign_samples ()
|
|
|
|
|
{
|
|
|
|
|
unsigned i;
|
|
|
|
|
|
|
|
|
|
scale_and_align_entries ();
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < num_histograms; ++i)
|
|
|
|
|
hist_assign_samples_1 (&histograms[i]);
|
|
|
|
|
|
|
|
|
|
}
|
1999-05-03 09:29:11 +02:00
|
|
|
|
|
2000-07-24 22:59:04 +02:00
|
|
|
|
/* Print header for flag histogram profile. */
|
|
|
|
|
|
1999-05-03 09:29:11 +02:00
|
|
|
|
static void
|
* alpha.c, basic_blocks.c, basic_blocks.h, bb_exit_func.c,
call_graph.c, call_graph.h, cg_arcs.c, cg_arcs.h, cg_dfn.c,
cg_dfn.h, cg_print.c, cg_print.h, corefile.c, corefile.h,
gmon_io.c, gmon_io.h, gprof.c, gprof.h, hertz.h, hist.c, hist.h,
i386.c, mips.c, search_list.c, search_list.h, source.c, source.h,
sparc.c, sym_ids.c, sym_ids.h, symtab.c, symtab.h, tahoe.c,
utils.c, utils.h, vax.c, gen-c-prog.awk: Convert K&R C to ANSI C.
2004-05-26 06:55:55 +02:00
|
|
|
|
print_header (int prefix)
|
1999-05-03 09:29:11 +02:00
|
|
|
|
{
|
|
|
|
|
char unit[64];
|
|
|
|
|
|
|
|
|
|
sprintf (unit, _("%c%c/call"), prefix, hist_dimension_abbrev);
|
|
|
|
|
|
|
|
|
|
if (bsd_style_output)
|
|
|
|
|
{
|
|
|
|
|
printf (_("\ngranularity: each sample hit covers %ld byte(s)"),
|
2007-07-12 09:16:41 +02:00
|
|
|
|
(long) hist_scale * (long) sizeof (UNIT));
|
1999-05-03 09:29:11 +02:00
|
|
|
|
if (total_time > 0.0)
|
|
|
|
|
{
|
|
|
|
|
printf (_(" for %.2f%% of %.2f %s\n\n"),
|
|
|
|
|
100.0 / total_time, total_time / hz, hist_dimension);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
printf (_("\nEach sample counts as %g %s.\n"), 1.0 / hz, hist_dimension);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (total_time <= 0.0)
|
|
|
|
|
{
|
|
|
|
|
printf (_(" no time accumulated\n\n"));
|
2001-03-14 04:14:56 +01:00
|
|
|
|
|
2000-07-24 22:59:04 +02:00
|
|
|
|
/* This doesn't hurt since all the numerators will be zero. */
|
1999-05-03 09:29:11 +02:00
|
|
|
|
total_time = 1.0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
printf ("%5.5s %10.10s %8.8s %8.8s %8.8s %8.8s %-8.8s\n",
|
2001-03-14 04:14:56 +01:00
|
|
|
|
"% ", _("cumulative"), _("self "), "", _("self "), _("total "),
|
|
|
|
|
"");
|
1999-05-03 09:29:11 +02:00
|
|
|
|
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"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
* alpha.c, basic_blocks.c, basic_blocks.h, bb_exit_func.c,
call_graph.c, call_graph.h, cg_arcs.c, cg_arcs.h, cg_dfn.c,
cg_dfn.h, cg_print.c, cg_print.h, corefile.c, corefile.h,
gmon_io.c, gmon_io.h, gprof.c, gprof.h, hertz.h, hist.c, hist.h,
i386.c, mips.c, search_list.c, search_list.h, source.c, source.h,
sparc.c, sym_ids.c, sym_ids.h, symtab.c, symtab.h, tahoe.c,
utils.c, utils.h, vax.c, gen-c-prog.awk: Convert K&R C to ANSI C.
2004-05-26 06:55:55 +02:00
|
|
|
|
print_line (Sym *sym, double scale)
|
1999-05-03 09:29:11 +02:00
|
|
|
|
{
|
|
|
|
|
if (ignore_zeros && sym->ncalls == 0 && sym->hist.time == 0)
|
2000-07-24 22:59:04 +02:00
|
|
|
|
return;
|
1999-05-03 09:29:11 +02:00
|
|
|
|
|
|
|
|
|
accum_time += sym->hist.time;
|
2001-03-14 04:14:56 +01:00
|
|
|
|
|
1999-05-03 09:29:11 +02:00
|
|
|
|
if (bsd_style_output)
|
2000-07-24 22:59:04 +02:00
|
|
|
|
printf ("%5.1f %10.2f %8.2f",
|
|
|
|
|
total_time > 0.0 ? 100 * sym->hist.time / total_time : 0.0,
|
|
|
|
|
accum_time / hz, sym->hist.time / hz);
|
1999-05-03 09:29:11 +02:00
|
|
|
|
else
|
2000-07-24 22:59:04 +02:00
|
|
|
|
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);
|
2001-03-14 04:14:56 +01:00
|
|
|
|
|
1999-05-03 09:29:11 +02:00
|
|
|
|
if (sym->ncalls != 0)
|
2000-07-24 22:59:04 +02:00
|
|
|
|
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);
|
1999-05-03 09:29:11 +02:00
|
|
|
|
else
|
2000-07-24 22:59:04 +02:00
|
|
|
|
printf (" %8.8s %8.8s %8.8s ", "", "", "");
|
2001-03-14 04:14:56 +01:00
|
|
|
|
|
1999-05-03 09:29:11 +02:00
|
|
|
|
if (bsd_style_output)
|
2000-07-24 22:59:04 +02:00
|
|
|
|
print_name (sym);
|
1999-05-03 09:29:11 +02:00
|
|
|
|
else
|
2000-07-24 22:59:04 +02:00
|
|
|
|
print_name_only (sym);
|
|
|
|
|
|
1999-05-03 09:29:11 +02:00
|
|
|
|
printf ("\n");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2000-07-24 22:59:04 +02:00
|
|
|
|
/* Compare LP and RP. The primary comparison key is execution time,
|
|
|
|
|
the secondary is number of invocation, and the tertiary is the
|
|
|
|
|
lexicographic order of the function names. */
|
|
|
|
|
|
1999-05-03 09:29:11 +02:00
|
|
|
|
static int
|
* alpha.c, basic_blocks.c, basic_blocks.h, bb_exit_func.c,
call_graph.c, call_graph.h, cg_arcs.c, cg_arcs.h, cg_dfn.c,
cg_dfn.h, cg_print.c, cg_print.h, corefile.c, corefile.h,
gmon_io.c, gmon_io.h, gprof.c, gprof.h, hertz.h, hist.c, hist.h,
i386.c, mips.c, search_list.c, search_list.h, source.c, source.h,
sparc.c, sym_ids.c, sym_ids.h, symtab.c, symtab.h, tahoe.c,
utils.c, utils.h, vax.c, gen-c-prog.awk: Convert K&R C to ANSI C.
2004-05-26 06:55:55 +02:00
|
|
|
|
cmp_time (const PTR lp, const PTR rp)
|
1999-05-03 09:29:11 +02:00
|
|
|
|
{
|
|
|
|
|
const Sym *left = *(const Sym **) lp;
|
|
|
|
|
const Sym *right = *(const Sym **) rp;
|
|
|
|
|
double time_diff;
|
|
|
|
|
|
|
|
|
|
time_diff = right->hist.time - left->hist.time;
|
2001-03-14 04:14:56 +01:00
|
|
|
|
|
1999-05-03 09:29:11 +02:00
|
|
|
|
if (time_diff > 0.0)
|
2000-07-24 22:59:04 +02:00
|
|
|
|
return 1;
|
2001-03-14 04:14:56 +01:00
|
|
|
|
|
1999-05-03 09:29:11 +02:00
|
|
|
|
if (time_diff < 0.0)
|
2000-07-24 22:59:04 +02:00
|
|
|
|
return -1;
|
1999-05-03 09:29:11 +02:00
|
|
|
|
|
|
|
|
|
if (right->ncalls > left->ncalls)
|
2000-07-24 22:59:04 +02:00
|
|
|
|
return 1;
|
|
|
|
|
|
1999-05-03 09:29:11 +02:00
|
|
|
|
if (right->ncalls < left->ncalls)
|
2000-07-24 22:59:04 +02:00
|
|
|
|
return -1;
|
1999-05-03 09:29:11 +02:00
|
|
|
|
|
|
|
|
|
return strcmp (left->name, right->name);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2000-07-24 22:59:04 +02:00
|
|
|
|
/* Print the flat histogram profile. */
|
|
|
|
|
|
1999-05-03 09:29:11 +02:00
|
|
|
|
void
|
2002-02-01 09:24:16 +01:00
|
|
|
|
hist_print ()
|
1999-05-03 09:29:11 +02:00
|
|
|
|
{
|
|
|
|
|
Sym **time_sorted_syms, *top_dog, *sym;
|
2009-12-11 14:42:17 +01:00
|
|
|
|
unsigned int sym_index;
|
2002-02-19 19:29:08 +01:00
|
|
|
|
unsigned log_scale;
|
2009-12-11 14:42:17 +01:00
|
|
|
|
double top_time;
|
1999-05-03 09:29:11 +02:00
|
|
|
|
bfd_vma addr;
|
|
|
|
|
|
|
|
|
|
if (first_output)
|
2002-11-30 09:39:46 +01:00
|
|
|
|
first_output = FALSE;
|
1999-05-03 09:29:11 +02:00
|
|
|
|
else
|
2000-07-24 22:59:04 +02:00
|
|
|
|
printf ("\f\n");
|
1999-05-03 09:29:11 +02:00
|
|
|
|
|
|
|
|
|
accum_time = 0.0;
|
2001-03-14 04:14:56 +01:00
|
|
|
|
|
1999-05-03 09:29:11 +02:00
|
|
|
|
if (bsd_style_output)
|
|
|
|
|
{
|
|
|
|
|
if (print_descriptions)
|
|
|
|
|
{
|
|
|
|
|
printf (_("\n\n\nflat profile:\n"));
|
|
|
|
|
flat_blurb (stdout);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
printf (_("Flat profile:\n"));
|
|
|
|
|
}
|
2001-03-14 04:14:56 +01:00
|
|
|
|
|
2000-07-24 22:59:04 +02:00
|
|
|
|
/* Sort the symbol table by time (call-count and name as secondary
|
|
|
|
|
and tertiary keys). */
|
1999-05-03 09:29:11 +02:00
|
|
|
|
time_sorted_syms = (Sym **) xmalloc (symtab.len * sizeof (Sym *));
|
2001-03-14 04:14:56 +01:00
|
|
|
|
|
2009-12-11 14:42:17 +01:00
|
|
|
|
for (sym_index = 0; sym_index < symtab.len; ++sym_index)
|
|
|
|
|
time_sorted_syms[sym_index] = &symtab.base[sym_index];
|
2000-07-24 22:59:04 +02:00
|
|
|
|
|
1999-05-03 09:29:11 +02:00
|
|
|
|
qsort (time_sorted_syms, symtab.len, sizeof (Sym *), cmp_time);
|
|
|
|
|
|
|
|
|
|
if (bsd_style_output)
|
|
|
|
|
{
|
2000-07-24 22:59:04 +02:00
|
|
|
|
log_scale = 5; /* Milli-seconds is BSD-default. */
|
1999-05-03 09:29:11 +02:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2000-07-24 22:59:04 +02:00
|
|
|
|
/* Search for symbol with highest per-call
|
|
|
|
|
execution time and scale accordingly. */
|
1999-05-03 09:29:11 +02:00
|
|
|
|
log_scale = 0;
|
|
|
|
|
top_dog = 0;
|
|
|
|
|
top_time = 0.0;
|
2001-03-14 04:14:56 +01:00
|
|
|
|
|
2009-12-11 14:42:17 +01:00
|
|
|
|
for (sym_index = 0; sym_index < symtab.len; ++sym_index)
|
1999-05-03 09:29:11 +02:00
|
|
|
|
{
|
2009-12-11 14:42:17 +01:00
|
|
|
|
sym = time_sorted_syms[sym_index];
|
2001-03-14 04:14:56 +01:00
|
|
|
|
|
1999-05-03 09:29:11 +02:00
|
|
|
|
if (sym->ncalls != 0)
|
|
|
|
|
{
|
2009-12-11 14:42:17 +01:00
|
|
|
|
double call_time;
|
2001-03-14 04:14:56 +01:00
|
|
|
|
|
2009-12-11 14:42:17 +01:00
|
|
|
|
call_time = (sym->hist.time + sym->cg.child_time) / sym->ncalls;
|
|
|
|
|
|
|
|
|
|
if (call_time > top_time)
|
1999-05-03 09:29:11 +02:00
|
|
|
|
{
|
|
|
|
|
top_dog = sym;
|
2009-12-11 14:42:17 +01:00
|
|
|
|
top_time = call_time;
|
1999-05-03 09:29:11 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2001-03-14 04:14:56 +01:00
|
|
|
|
|
1999-05-03 09:29:11 +02:00
|
|
|
|
if (top_dog && top_dog->ncalls != 0 && top_time > 0.0)
|
|
|
|
|
{
|
|
|
|
|
top_time /= hz;
|
2001-03-14 04:14:56 +01:00
|
|
|
|
|
2002-02-19 19:29:08 +01:00
|
|
|
|
for (log_scale = 0; log_scale < ARRAY_SIZE (SItab); log_scale ++)
|
1999-05-03 09:29:11 +02:00
|
|
|
|
{
|
2002-02-19 19:29:08 +01:00
|
|
|
|
double scaled_value = SItab[log_scale].scale * top_time;
|
|
|
|
|
|
|
|
|
|
if (scaled_value >= 1.0 && scaled_value < 1000.0)
|
|
|
|
|
break;
|
1999-05-03 09:29:11 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2000-07-24 22:59:04 +02:00
|
|
|
|
/* For now, the dimension is always seconds. In the future, we
|
|
|
|
|
may also want to support other (pseudo-)dimensions (such as
|
|
|
|
|
I-cache misses etc.). */
|
1999-05-03 09:29:11 +02:00
|
|
|
|
print_header (SItab[log_scale].prefix);
|
2001-03-14 04:14:56 +01:00
|
|
|
|
|
2009-12-11 14:42:17 +01:00
|
|
|
|
for (sym_index = 0; sym_index < symtab.len; ++sym_index)
|
1999-05-03 09:29:11 +02:00
|
|
|
|
{
|
2009-12-11 14:42:17 +01:00
|
|
|
|
addr = time_sorted_syms[sym_index]->addr;
|
2001-03-14 04:14:56 +01:00
|
|
|
|
|
2000-07-24 22:59:04 +02:00
|
|
|
|
/* Print symbol if its in INCL_FLAT table or that table
|
2001-03-14 04:14:56 +01:00
|
|
|
|
is empty and the symbol is not in EXCL_FLAT. */
|
1999-05-03 09:29:11 +02:00
|
|
|
|
if (sym_lookup (&syms[INCL_FLAT], addr)
|
|
|
|
|
|| (syms[INCL_FLAT].len == 0
|
|
|
|
|
&& !sym_lookup (&syms[EXCL_FLAT], addr)))
|
2009-12-11 14:42:17 +01:00
|
|
|
|
print_line (time_sorted_syms[sym_index], SItab[log_scale].scale);
|
1999-05-03 09:29:11 +02:00
|
|
|
|
}
|
2001-03-14 04:14:56 +01:00
|
|
|
|
|
1999-05-03 09:29:11 +02:00
|
|
|
|
free (time_sorted_syms);
|
|
|
|
|
|
|
|
|
|
if (print_descriptions && !bsd_style_output)
|
2000-07-24 22:59:04 +02:00
|
|
|
|
flat_blurb (stdout);
|
1999-05-03 09:29:11 +02:00
|
|
|
|
}
|
* hist.h (struct histogram)
(histograms, num_histograms): New.
* hist.c (find_histogram, find_histogram_for_pc)
(read_histogram_header): New.
(s_lowpc, s_highpc, lowpc, highpc, hist_num_bins)
(hist_sample): Remove.
(hist_read_rec): Use the above, and handle multiple
histogram records with disjoint address ranges.
(hist_write_hist): Support several histogram records.
(scale_and_align_entries): Adjust for multiple histograms.
(hist_assign_samples_1): New.
(hist_assign_samples): Use the above.
(hist_clip_symbol_address): New.
* hist.h (hist_check_address)
(hist_clip_symbol_address): Declare.
* gmon_io.c (gmon_out_read, gmon_out_write): Adjust handling
of legacy format for multiple histogram changes.
* corefile.c (find_call): Check for core_text_space and
clip symbol address range here.
* vax.c (vax_find_call): Don't check for
core_text_space, or clip the symbol's address range here.
Use hist_check_address to check call's target address.
* sparc.c: Likewise.
* tahoe.c: Likewise.
* i386.c: Likewise.
* mips.c: Likewise. Also use core_text_sect->vma as the base
address for code accesses, just like other machine-specific
routines do.
* gprof.texi: Adjust for the new logic.
2007-04-10 09:57:31 +02:00
|
|
|
|
|
|
|
|
|
int
|
|
|
|
|
hist_check_address (unsigned address)
|
|
|
|
|
{
|
|
|
|
|
unsigned i;
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < num_histograms; ++i)
|
|
|
|
|
if (histograms[i].lowpc <= address && address < histograms[i].highpc)
|
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#if ! defined(min)
|
|
|
|
|
#define min(a,b) (((a)<(b)) ? (a) : (b))
|
|
|
|
|
#endif
|
|
|
|
|
#if ! defined(max)
|
|
|
|
|
#define max(a,b) (((a)>(b)) ? (a) : (b))
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
hist_clip_symbol_address (bfd_vma *p_lowpc, bfd_vma *p_highpc)
|
|
|
|
|
{
|
|
|
|
|
unsigned i;
|
|
|
|
|
int found = 0;
|
|
|
|
|
|
|
|
|
|
if (num_histograms == 0)
|
|
|
|
|
{
|
|
|
|
|
*p_highpc = *p_lowpc;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < num_histograms; ++i)
|
|
|
|
|
{
|
|
|
|
|
bfd_vma common_low, common_high;
|
|
|
|
|
common_low = max (histograms[i].lowpc, *p_lowpc);
|
|
|
|
|
common_high = min (histograms[i].highpc, *p_highpc);
|
|
|
|
|
|
|
|
|
|
if (common_low < common_high)
|
|
|
|
|
{
|
|
|
|
|
if (found)
|
|
|
|
|
{
|
|
|
|
|
fprintf (stderr,
|
|
|
|
|
_("%s: found a symbol that covers "
|
2007-04-10 10:47:50 +02:00
|
|
|
|
"several histogram records"),
|
* hist.h (struct histogram)
(histograms, num_histograms): New.
* hist.c (find_histogram, find_histogram_for_pc)
(read_histogram_header): New.
(s_lowpc, s_highpc, lowpc, highpc, hist_num_bins)
(hist_sample): Remove.
(hist_read_rec): Use the above, and handle multiple
histogram records with disjoint address ranges.
(hist_write_hist): Support several histogram records.
(scale_and_align_entries): Adjust for multiple histograms.
(hist_assign_samples_1): New.
(hist_assign_samples): Use the above.
(hist_clip_symbol_address): New.
* hist.h (hist_check_address)
(hist_clip_symbol_address): Declare.
* gmon_io.c (gmon_out_read, gmon_out_write): Adjust handling
of legacy format for multiple histogram changes.
* corefile.c (find_call): Check for core_text_space and
clip symbol address range here.
* vax.c (vax_find_call): Don't check for
core_text_space, or clip the symbol's address range here.
Use hist_check_address to check call's target address.
* sparc.c: Likewise.
* tahoe.c: Likewise.
* i386.c: Likewise.
* mips.c: Likewise. Also use core_text_sect->vma as the base
address for code accesses, just like other machine-specific
routines do.
* gprof.texi: Adjust for the new logic.
2007-04-10 09:57:31 +02:00
|
|
|
|
whoami);
|
|
|
|
|
done (1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
found = 1;
|
|
|
|
|
*p_lowpc = common_low;
|
|
|
|
|
*p_highpc = common_high;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!found)
|
|
|
|
|
*p_highpc = *p_lowpc;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Find and return exising histogram record having the same lowpc and
|
|
|
|
|
highpc as passed via the parameters. Return NULL if nothing is found.
|
|
|
|
|
The return value is valid until any new histogram is read. */
|
|
|
|
|
static histogram *
|
|
|
|
|
find_histogram (bfd_vma lowpc, bfd_vma highpc)
|
|
|
|
|
{
|
|
|
|
|
unsigned i;
|
|
|
|
|
for (i = 0; i < num_histograms; ++i)
|
|
|
|
|
{
|
|
|
|
|
if (histograms[i].lowpc == lowpc && histograms[i].highpc == highpc)
|
|
|
|
|
return &histograms[i];
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Given a PC, return histogram record which address range include this PC.
|
|
|
|
|
Return NULL if there's no such record. */
|
|
|
|
|
static histogram *
|
|
|
|
|
find_histogram_for_pc (bfd_vma pc)
|
|
|
|
|
{
|
|
|
|
|
unsigned i;
|
|
|
|
|
for (i = 0; i < num_histograms; ++i)
|
|
|
|
|
{
|
|
|
|
|
if (histograms[i].lowpc <= pc && pc < histograms[i].highpc)
|
|
|
|
|
return &histograms[i];
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|