1995-02-07 23:34:18 +01:00
|
|
|
#include "cg_arcs.h"
|
|
|
|
#include "call_graph.h"
|
|
|
|
#include "core.h"
|
|
|
|
#include "gmon_io.h"
|
|
|
|
#include "gmon_out.h"
|
|
|
|
#include "symtab.h"
|
|
|
|
#include "sym_ids.h"
|
|
|
|
|
|
|
|
extern void
|
1995-02-08 03:35:44 +01:00
|
|
|
DEFUN (cg_tally, (from_pc, self_pc, count),
|
|
|
|
bfd_vma from_pc AND bfd_vma self_pc AND int count)
|
1995-02-07 23:34:18 +01:00
|
|
|
{
|
1995-02-08 03:35:44 +01:00
|
|
|
Sym *parent;
|
|
|
|
Sym *child;
|
1995-02-07 23:34:18 +01:00
|
|
|
|
1995-02-08 03:35:44 +01:00
|
|
|
parent = sym_lookup (&symtab, from_pc);
|
|
|
|
child = sym_lookup (&symtab, self_pc);
|
1995-02-07 23:34:18 +01:00
|
|
|
|
1998-02-04 01:30:48 +01:00
|
|
|
if (child == NULL || parent == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* If we're doing line-by-line profiling, both the parent and the
|
|
|
|
child will probably point to line symbols instead of function
|
|
|
|
symbols. For the parent this is fine, since this identifies the
|
|
|
|
line number in the calling routing, but the child should always
|
|
|
|
point to a function entry point, so we back up in the symbol
|
|
|
|
table until we find it.
|
|
|
|
|
|
|
|
For normal profiling, is_func will be set on all symbols, so this
|
|
|
|
code will do nothing. */
|
|
|
|
|
|
|
|
while (child >= symtab.base && ! child->is_func)
|
|
|
|
--child;
|
|
|
|
|
|
|
|
if (child < symtab.base)
|
|
|
|
return;
|
|
|
|
|
1995-02-08 03:35:44 +01:00
|
|
|
/*
|
|
|
|
* Keep arc if it is on INCL_ARCS table or if the INCL_ARCS table
|
|
|
|
* is empty and it is not in the EXCL_ARCS table.
|
|
|
|
*/
|
|
|
|
if (sym_id_arc_is_present (&syms[INCL_ARCS], parent, child)
|
|
|
|
|| (syms[INCL_ARCS].len == 0
|
|
|
|
&& !sym_id_arc_is_present (&syms[EXCL_ARCS], parent, child)))
|
1995-02-07 23:34:18 +01:00
|
|
|
{
|
1995-02-08 03:35:44 +01:00
|
|
|
child->ncalls += count;
|
|
|
|
DBG (TALLYDEBUG,
|
1998-04-22 09:33:42 +02:00
|
|
|
printf (_("[cg_tally] arc from %s to %s traversed %d times\n"),
|
1995-02-07 23:34:18 +01:00
|
|
|
parent->name, child->name, count));
|
1995-02-08 03:35:44 +01:00
|
|
|
arc_add (parent, child, count);
|
1995-03-14 03:58:16 +01:00
|
|
|
}
|
|
|
|
}
|
1995-02-07 23:34:18 +01:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
void
|
1995-02-08 03:35:44 +01:00
|
|
|
DEFUN (cg_read_rec, (ifp, filename), FILE * ifp AND CONST char *filename)
|
1995-02-07 23:34:18 +01:00
|
|
|
{
|
1995-02-08 03:35:44 +01:00
|
|
|
bfd_vma from_pc, self_pc;
|
|
|
|
struct gmon_cg_arc_record arc;
|
|
|
|
int count;
|
1995-02-07 23:34:18 +01:00
|
|
|
|
1995-02-08 03:35:44 +01:00
|
|
|
if (fread (&arc, sizeof (arc), 1, ifp) != 1)
|
|
|
|
{
|
1998-04-22 09:33:42 +02:00
|
|
|
fprintf (stderr, _("%s: %s: unexpected end of file\n"),
|
1995-02-08 03:35:44 +01:00
|
|
|
whoami, filename);
|
|
|
|
done (1);
|
1995-03-14 03:58:16 +01:00
|
|
|
}
|
1995-02-08 03:35:44 +01:00
|
|
|
from_pc = get_vma (core_bfd, (bfd_byte *) arc.from_pc);
|
|
|
|
self_pc = get_vma (core_bfd, (bfd_byte *) arc.self_pc);
|
|
|
|
count = bfd_get_32 (core_bfd, (bfd_byte *) arc.count);
|
|
|
|
DBG (SAMPLEDEBUG,
|
|
|
|
printf ("[cg_read_rec] frompc 0x%lx selfpc 0x%lx count %d\n",
|
1995-02-07 23:34:18 +01:00
|
|
|
from_pc, self_pc, count));
|
1995-02-08 03:35:44 +01:00
|
|
|
/* add this arc: */
|
|
|
|
cg_tally (from_pc, self_pc, count);
|
1995-03-14 03:58:16 +01:00
|
|
|
}
|
1995-02-07 23:34:18 +01:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Write all the arcs in the call-graph to file OFP. FILENAME is
|
|
|
|
* the name of OFP and is provided for formatting error-messages
|
|
|
|
* only.
|
|
|
|
*/
|
|
|
|
void
|
1995-02-08 03:35:44 +01:00
|
|
|
DEFUN (cg_write_arcs, (ofp, filename), FILE * ofp AND const char *filename)
|
1995-02-07 23:34:18 +01:00
|
|
|
{
|
1995-02-08 03:35:44 +01:00
|
|
|
const unsigned char tag = GMON_TAG_CG_ARC;
|
|
|
|
struct gmon_cg_arc_record raw_arc;
|
|
|
|
Arc *arc;
|
|
|
|
Sym *sym;
|
1995-02-07 23:34:18 +01:00
|
|
|
|
1995-02-08 03:35:44 +01:00
|
|
|
for (sym = symtab.base; sym < symtab.limit; sym++)
|
|
|
|
{
|
|
|
|
for (arc = sym->cg.children; arc; arc = arc->next_child)
|
|
|
|
{
|
|
|
|
put_vma (core_bfd, arc->parent->addr, (bfd_byte *) raw_arc.from_pc);
|
|
|
|
put_vma (core_bfd, arc->child->addr, (bfd_byte *) raw_arc.self_pc);
|
|
|
|
bfd_put_32 (core_bfd, arc->count, (bfd_byte *) raw_arc.count);
|
|
|
|
if (fwrite (&tag, sizeof (tag), 1, ofp) != 1
|
|
|
|
|| fwrite (&raw_arc, sizeof (raw_arc), 1, ofp) != 1)
|
1995-02-07 23:34:18 +01:00
|
|
|
{
|
1995-02-08 03:35:44 +01:00
|
|
|
perror (filename);
|
|
|
|
done (1);
|
1995-03-14 03:58:16 +01:00
|
|
|
}
|
1995-02-08 03:35:44 +01:00
|
|
|
DBG (SAMPLEDEBUG,
|
|
|
|
printf ("[cg_write_arcs] frompc 0x%lx selfpc 0x%lx count %d\n",
|
|
|
|
arc->parent->addr, arc->child->addr, arc->count));
|
1995-03-14 03:58:16 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|