/* Read a basic-block record from file IFP. FILENAME is the name of
file IFP and is provided for formatting error-messages only. */
-extern void bb_read_rec (FILE *, const char *, bool);
+extern void bb_read_rec (FILE *, const char *, bool, const char *);
#endif /* basic_blocks_h */
#ifndef call_graph_h
#define call_graph_h
-extern void cg_tally (bfd_vma, bfd_vma, unsigned long);
+extern void cg_tally (bfd_vma, bfd_vma, unsigned long, const char *);
/* Read a record from file IFP describing an arc in the function
call-graph and the count of how many times the arc has been
traversed. FILENAME is the name of file IFP and is provided for
formatting error-messages only. */
-extern void cg_read_rec (FILE *, const char *);
+extern void cg_read_rec (FILE *, const char *, const char *);
#endif /* call_graph_h */
extern int offset_to_code; /* Offset (in bytes) of code from entry
address of routine. */
-extern int core_init (const char *);
-extern void symtab_init (void);
+extern int core_init (const char *, const char *);
+extern void symtab_init (const char *);
#endif /* corefile_h */
of file IFP and is provided for formatting error-messages only. */
void
-bb_read_rec (FILE *ifp, const char *filename, bool line_granularity)
+bb_read_rec (FILE *ifp, const char *filename,
+ bool line_granularity, const char *whoami)
{
unsigned int nblocks, b;
bfd_vma addr, ncalls;
done (1);
}
- symtab = get_symtab ();
+ symtab = get_symtab (whoami);
nblocks = bfd_get_32 (core_bfd, (bfd_byte *) & nblocks);
if (gmon_file_version == 0)
done (1);
}
}
- else if (gmon_io_read_vma (ifp, &addr)
- || gmon_io_read_vma (ifp, &ncalls))
+ else if (gmon_io_read_vma (ifp, &addr, whoami)
+ || gmon_io_read_vma (ifp, &ncalls, whoami))
{
perror (filename);
done (1);
#include "gmon_out.h"
void
-cg_tally (bfd_vma from_pc, bfd_vma self_pc, unsigned long count)
+cg_tally (bfd_vma from_pc, bfd_vma self_pc,
+ unsigned long count, const char *whoami)
{
Sym *parent;
Sym *child;
- Sym_Table *symtab = get_symtab ();
+ Sym_Table *symtab = get_symtab (whoami);
parent = sym_lookup (symtab, from_pc);
child = sym_lookup (symtab, self_pc);
formatting error-messages only. */
void
-cg_read_rec (FILE *ifp, const char *filename)
+cg_read_rec (FILE *ifp, const char *filename, const char *whoami)
{
bfd_vma from_pc, self_pc;
unsigned int count;
- if (gmon_io_read_vma (ifp, &from_pc)
- || gmon_io_read_vma (ifp, &self_pc)
+ if (gmon_io_read_vma (ifp, &from_pc, whoami)
+ || gmon_io_read_vma (ifp, &self_pc, whoami)
|| gmon_io_read_32 (ifp, &count))
{
fprintf (stderr, "%s: %s: unexpected end of file\n",
(unsigned long) from_pc, (unsigned long) self_pc,
(unsigned long) count));
/* Add this arc: */
- cg_tally (from_pc, self_pc, count);
+ cg_tally (from_pc, self_pc, count, whoami);
}
int
-core_init (const char * aout_name)
+core_init (const char * aout_name, const char *whoami)
{
int core_sym_bytes;
asymbol *synthsyms;
One symbol per function is entered. */
static void
-core_create_function_syms (void)
+core_create_function_syms (const char *whoami)
{
int cxxclass;
long i;
/* Initialize the symbol table. */
void
-symtab_init (void)
+symtab_init (const char *whoami)
{
- core_create_function_syms ();
+ core_create_function_syms (whoami);
}
typedef unsigned char UNIT[2]; /* unit of profiling */
#define UNITS_TO_CODE (offset_to_code / sizeof(UNIT))
-static void scale_and_align_entries (void);
+static long hz = 0;
/* Given a range of addresses for a symbol, find a histogram record
that intersects with this range, and clips the range to that
If no intersection is found, *P_LOWPC and *P_HIGHPC will be set to
one unspecified value. If more that one intersection is found,
an error is emitted. */
-static void hist_clip_symbol_address (bfd_vma *p_lowpc, bfd_vma *p_highpc);
+static void hist_clip_symbol_address (bfd_vma *p_lowpc,
+ bfd_vma *p_highpc, const char *whoami);
/* Declarations of automatically generated functions to output blurbs. */
static void
read_histogram_header (histogram *record,
FILE *ifp, const char *filename,
- int first)
+ int first, const char *whoami)
{
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)
+ if (gmon_io_read_vma (ifp, &record->lowpc, whoami)
+ || gmon_io_read_vma (ifp, &record->highpc, whoami)
|| gmon_io_read_32 (ifp, &record->num_bins)
|| gmon_io_read_32 (ifp, &profrate)
|| gmon_io_read (ifp, n_hist_dimension, 15)
is provided for formatting error messages only. */
void
-hist_read_rec (FILE * ifp, const char *filename)
+hist_read_rec (FILE * ifp, const char *filename, const char *whoami)
{
bfd_vma lowpc, highpc;
histogram n_record;
/* 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);
+ read_histogram_header (&n_record, ifp, filename, num_histograms == 0, whoami);
existing_record = find_histogram (n_record.lowpc, n_record.highpc);
if (existing_record)
record, it's an error. */
lowpc = n_record.lowpc;
highpc = n_record.highpc;
- hist_clip_symbol_address (&lowpc, &highpc);
+ hist_clip_symbol_address (&lowpc, &highpc, whoami);
if (lowpc != highpc)
{
fprintf (stderr,
next bin. */
static void
-scale_and_align_entries (void)
+scale_and_align_entries (const char *whoami)
{
Sym *sym;
bfd_vma bin_of_entry;
bfd_vma bin_of_code;
- Sym_Table *symtab = get_symtab ();
+ Sym_Table *symtab = get_symtab (whoami);
for (sym = symtab->base; sym < symtab->limit; sym++)
{
cases, above). */
static void
-hist_assign_samples_1 (histogram *r)
+hist_assign_samples_1 (histogram *r, const char *whoami)
{
bfd_vma bin_low_pc, bin_high_pc;
bfd_vma sym_low_pc, sym_high_pc;
unsigned int bin_count;
unsigned int i, j, k;
double count_time, credit;
- Sym_Table *symtab = get_symtab ();
+ Sym_Table *symtab = get_symtab (whoami);
bfd_vma lowpc = r->lowpc / sizeof (UNIT);
/* Calls 'hist_assign_samples_1' for all histogram records read so far. */
void
-hist_assign_samples (void)
+hist_assign_samples (const char *whoami)
{
unsigned i;
- scale_and_align_entries ();
+ scale_and_align_entries (whoami);
for (i = 0; i < num_histograms; ++i)
- hist_assign_samples_1 (&histograms[i]);
+ hist_assign_samples_1 (&histograms[i], whoami);
}
#define max(a,b) (((a)>(b)) ? (a) : (b))
#endif
-void
-hist_clip_symbol_address (bfd_vma *p_lowpc, bfd_vma *p_highpc)
+static void
+hist_clip_symbol_address (bfd_vma *p_lowpc,
+ bfd_vma *p_highpc, const char *whoami)
{
unsigned i;
int found = 0;
}
return 0;
}
+
+/* Return the profile rate in hz. */
+long
+hist_get_hz (void)
+{
+ return hz;
+}
ptr_unsigned
};
-static enum gmon_ptr_size gmon_get_ptr_size (void);
static enum gmon_ptr_signedness gmon_get_ptr_signedness (void);
static int gmon_io_read_64 (FILE *, uint64_t *);
int gmon_file_version = 0; /* 0 == old (non-versioned) file format. */
static enum gmon_ptr_size
-gmon_get_ptr_size (void)
+gmon_get_ptr_size (const char *whoami)
{
int size;
}
int
-gmon_io_read_vma (FILE *ifp, bfd_vma *valp)
+gmon_io_read_vma (FILE *ifp, bfd_vma *valp, const char *whoami)
{
unsigned int val32;
uint64_t val64;
- switch (gmon_get_ptr_size ())
+ switch (gmon_get_ptr_size (whoami))
{
case ptr_32bit:
if (gmon_io_read_32 (ifp, &val32))
}
int
-gmon_out_read (const char *filename, File_Format file_format)
+gmon_out_read (const char *filename,
+ File_Format file_format, const char *whoami)
{
FILE *ifp;
struct gmon_hdr ghdr;
case GMON_TAG_TIME_HIST:
++nhist;
gmon_input |= INPUT_HISTOGRAM;
- hist_read_rec (ifp, filename);
+ hist_read_rec (ifp, filename, whoami);
break;
case GMON_TAG_CG_ARC:
++narcs;
gmon_input |= INPUT_CALL_GRAPH;
- cg_read_rec (ifp, filename);
+ cg_read_rec (ifp, filename, whoami);
break;
case GMON_TAG_BB_COUNT:
++nbbs;
gmon_input |= INPUT_BB_COUNTS;
- bb_read_rec (ifp, filename, false);
+ bb_read_rec (ifp, filename, false, whoami);
break;
default:
extern int gmon_input; /* What input did we see? */
extern int gmon_file_version; /* File version are we dealing with. */
-extern int gmon_io_read_vma (FILE *ifp, bfd_vma *valp);
+extern int gmon_io_read_vma (FILE *ifp, bfd_vma *valp, const char *whoami);
extern int gmon_io_read_32 (FILE *ifp, unsigned int *valp);
extern int gmon_io_read (FILE *ifp, char *buf, size_t n);
-extern int gmon_out_read (const char *, File_Format);
+extern int gmon_out_read (const char *, File_Format, const char *);
#endif /* gmon_io_h */
initialized yet. */
Sym_Table *
-get_symtab (void)
+get_symtab (const char *whoami)
{
static Sym_Table *symtab_p;
if (!symtab_p)
{
- symtab_init ();
+ symtab_init (whoami);
symtab_p = &symtab;
}
int nticks; /* number of ticks in that state */
} ClockPacket;
-const char *whoami;
-long hz = HZ_WRONG;
-
static unsigned long *pc_array = NULL;
static char *base_folder;
static DFN_Stack *dfn_stack = NULL;
Mimimc a stack trace using a DF algorithm. */
static int
-cg_traverse_arcs (void)
+cg_traverse_arcs (const char *whoami)
{
Sym *sym;
- Sym_Table *symtab = get_symtab ();
+ Sym_Table *symtab = get_symtab (whoami);
for (sym = symtab->base; sym < symtab->limit; sym++)
{
logx = fopen (new_file_path, "w");
+ long hz = hist_get_hz ();
int gmon_interval = (hz == HZ_WRONG ? 1000 : hz * 100);
fprintf (logx, "<profile name=\"%s\" ptimer=\"%d\" numstates=\"%d\">\n",
}
/* Read the elf syms and the gmon file. */
- if (core_init (a_out_name) < 0)
+ if (core_init (a_out_name, whoami) < 0)
{
cc->remove_exp_dir ();
exit (1);
}
- if (gmon_out_read (gmon_name, FF_AUTO) < 0)
+ if (gmon_out_read (gmon_name, FF_AUTO, whoami) < 0)
{
cc->remove_exp_dir ();
exit (1);
}
/* Process the gmon file, and output the gprofng project files. */
- hist_assign_samples ();
- cg_traverse_arcs ();
+ hist_assign_samples (whoami);
+ cg_traverse_arcs (whoami);
gen_gmon_map (a_out_name);
gen_gmon_log ();
}
#define MAX(a,b) ((a) > (b) ? (a) : (b))
#endif
-extern const char *whoami;
#endif /* gp_gmon_h */
int *sample; /* Histogram samples (shorts in the file!). */
} histogram;
-extern long hz;
-
-extern void hist_read_rec (FILE *, const char *);
-extern void hist_assign_samples (void);
+extern void hist_read_rec (FILE *, const char *, const char *);
+extern void hist_assign_samples (const char *);
+extern long hist_get_hz (void);
#endif /* hist_h */
}
Sym_Table;
-extern Sym_Table *get_symtab (void);
+extern Sym_Table *get_symtab (const char *);
extern Sym_Table *get_symtab_direct (void);
extern void sym_init (Sym *);