Things-to-keep:
.gdbinit
+__bb_exit_func.c
ChangeLog
Makefile.in
NOTES
+Mon Mar 13 21:44:24 1995 Ken Raeburn <raeburn@cujo.cygnus.com>
+
+ * __bb_exit_func.c: New file, from David Mosberger-Tang.
+
+ Thu Feb 9 16:56:07 1995 David Mosberger-Tang <davidm@piston.cs.arizona.edu>
+
+ * All *.c: More cleanup towards GNU format.
+
+ * gmon_out.h (struct gmon_hist_hdr, struct gmon_cg_arc_record):
+ replaced sizeof (bfd_vma) by size (char*) because Ken tells me
+ that bfd_vma is only guaranteed to be at least as big as a pointer.
+
+ (GMON_Record_tag): added explicit enumeration values to ensure
+ compatibility across compilers.
+
+ * gmon_io.c (get_vma, put_vma): replaced sizeof(bfd_vma) by
+ sizeof(char*).
+
Tue Feb 7 17:24:12 1995 Ken Raeburn <raeburn@cujo.cygnus.com>
* All *.c and *.h files: Ran "indent -gnu". Cleaned up a couple
-Sun Feb 5 16:27:32 1995
+Thu Feb 9 16:48:04 1995
- documentation
- optimize bfd_find_nearest_line_num() (or replace by different interface)
+- gmon_io.c cannot deal with target architecture that have a pointer size
+ that is different from the host architectures pointer size---fix this
+ (gmon_out.h, and gmon_io.c)
- add support for prof file format so that prof files can be displayed
at the line-level (this is useful for the uprofile tool under DEC's
OSF/1)
--- /dev/null
+/*
+ * Copyright (c) 1994 David Mosberger-Tang.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Library General Public License as
+ * published by the Free Software Foundation; either version 2, or (at
+ * your option) any later version.
+ *
+ * __bb_exit_func() dumps all the basic-block statistics linked into
+ * the bb_head chain to .d files.
+ */
+#include <stdio.h>
+#include <strings.h>
+#include "bfd.h"
+#include "gmon_out.h"
+
+/* structure emitted by -a */
+struct bb {
+ long zero_word;
+ const char *filename;
+ long *counts;
+ long ncounts;
+ struct bb *next;
+ const unsigned long *addresses;
+};
+
+struct bb *__bb_head = (struct bb *)0;
+
+
+void
+__bb_exit_func (void)
+{
+ const int version = GMON_VERSION;
+ struct gmon_hdr ghdr;
+ struct bb *ptr;
+ FILE *fp;
+ /*
+ * GEN_GMON_CNT_FILE should be defined on systems with mcleanup()
+ * functions that do not write basic-block to gmon.out. In such
+ * cases profiling with "-pg -a" would result in a gmon.out file
+ * without basic-block info (because the file written here would
+ * be overwritten. Thus, a separate file is generated instead.
+ * The two files can easily be combined by specifying them
+ * on gprof's command line (and possibly generating a gmon.sum
+ * file with "gprof -s").
+ */
+#ifndef GEN_GMON_CNT_FILE
+# define OUT_NAME "gmon.out"
+#else
+# define OUT_NAME "gmon.cnt"
+#endif
+ fp = fopen(OUT_NAME, "wb");
+ if (!fp) {
+ perror(OUT_NAME);
+ return;
+ } /* if */
+ bcopy(GMON_MAGIC, &ghdr.cookie[0], 4);
+ bcopy(&version, &ghdr.version, sizeof(version));
+ fwrite(&ghdr, sizeof(ghdr), 1, fp);
+
+ for (ptr = __bb_head; ptr != 0; ptr = ptr->next) {
+ u_int ncounts = ptr->ncounts;
+ u_char tag;
+ u_int i;
+
+ tag = GMON_TAG_BB_COUNT;
+ fwrite(&tag, sizeof(tag), 1, fp);
+ fwrite(&ncounts, sizeof(ncounts), 1, fp);
+
+ for (i = 0; i < ncounts; ++i) {
+ fwrite(&ptr->addresses[i], sizeof(ptr->addresses[0]), 1, fp);
+ fwrite(&ptr->counts[i], sizeof(ptr->counts[0]), 1, fp);
+ } /* for */
+ } /* for */
+ fclose (fp);
+} /* __bb_exit_func */
+
+ /*** end of __bb_exit_func.c ***/
indirect_child.name = "<indirect child>";
indirect_child.cg.prop.fract = 1.0;
indirect_child.cg.cyc.head = &indirect_child;
- } /* if */
+ }
if (!core_text_space)
{
return;
- } /* if */
+ }
if (p_lowpc < s_lowpc)
{
p_lowpc = s_lowpc;
- } /* if */
+ }
if (p_highpc > s_highpc)
{
p_highpc = s_highpc;
- } /* if */
+ }
DBG (CALLDEBUG, printf ("[find_call] %s: 0x%lx to 0x%lx\n",
parent->name, p_lowpc, p_highpc));
for (pc = (Instruction *) (p_lowpc + delta);
(bfd_vma) pc - delta,
pc->j.func == Jxx_FUNC_JSR ? "" : "_coroutine"));
arc_add (parent, &indirect_child, 0);
- } /* if */
+ }
break;
case OP_BSR:
/* a hit: */
arc_add (parent, child, 0);
continue;
- } /* if */
- } /* if */
+ }
+ }
/*
* Something funny going on.
*/
default:
break;
- } /* switch */
- } /* for */
-} /* find_call */
-/*** end of alpha.c ***/
+ }
+ }
+}
if (r)
{
return r;
- } /* if */
+ }
if (left->line_num != right->line_num)
{
return left->line_num - right->line_num;
- } /* if */
- } /* if */
+ }
+ }
if (left->addr < right->addr)
{
else
{
return 0;
- } /* if */
-} /* cmp_bb */
+ }
+}
/*
else if (!right)
{
return -1;
- } /* if */
+ }
if (right->ncalls != left->ncalls)
{
return right->ncalls - left->ncalls;
- } /* if */
+ }
return left->line_num - right->line_num;
-} /* cmp_ncalls */
+}
/*
if (ch == '\0')
{
break;
- } /* if */
- } /* if */
-} /* fskip_string */
+ }
+ }
+}
/*
{
fprintf (stderr, "%s: %s: unexpected end of file\n", whoami, filename);
done (1);
- } /* if */
+ }
nblocks = bfd_get_32 (core_bfd, (bfd_byte *) & nblocks);
if (gmon_file_version == 0)
{
fskip_string (ifp);
- } /* if */
+ }
for (b = 0; b < nblocks; ++b)
{
{
perror (filename);
done (1);
- } /* if */
+ }
}
else
{
{
perror (filename);
done (1);
- } /* if */
- } /* if */
+ }
+ }
/*
* Basic-block execution counts are meaningful only if we're
fprintf (stderr,
"%s: warning: ignoring basic-block exec counts (use -l or --line)\n",
whoami);
- } /* if */
- } /* if */
- } /* for */
+ }
+ }
+ }
return;
-} /* bb_read_rec */
+}
/*
if (sym->ncalls > 0)
{
++nblocks;
- } /* if */
- } /* for */
+ }
+ }
/* write header: */
bfd_put_32 (core_bfd, nblocks, (bfd_byte *) & nblocks);
{
perror (filename);
done (1);
- } /* if */
+ }
/* write counts: */
for (sym = symtab.base; sym < symtab.limit; ++sym)
if (sym->ncalls == 0)
{
continue;
- } /* if */
+ }
put_vma (core_bfd, sym->addr, (bfd_byte *) & addr);
bfd_put_32 (core_bfd, sym->ncalls, (bfd_byte *) & ncalls);
{
perror (filename);
done (1);
- } /* if */
- } /* for */
-} /* bb_write_blocks */
+ }
+ }
+}
/*
else
{
printf ("\f\n");
- } /* if */
+ }
/* sort basic-blocks according to function name and line number: */
&& !sym_lookup (&syms[EXCL_EXEC], sym->addr))))
{
sorted_bbs[len++] = sym;
- } /* if */
- } /* for */
+ }
+ }
qsort (sorted_bbs, len, sizeof (sorted_bbs[0]), cmp_bb);
/* output basic-blocks: */
printf ("%s:%d: (%s:0x%lx) %d executions\n",
sym->file ? sym->file->name : "<unknown>", sym->line_num,
sym->name, sym->addr, sym->ncalls);
- } /* for */
+ }
free (sorted_bbs);
-} /* print_exec_counts */
+}
/*
if (line_num == 1)
{
last_count = -1;
- } /* if */
+ }
b = 0;
if (line_num <= sf->num_lines)
{
b = sf->line[line_num - 1];
- } /* if */
+ }
if (!b)
{
cnt = -1;
{
++num_executable_lines;
cnt = b->ncalls;
- } /* if */
+ }
if (cnt > 0)
{
++num_lines_executed;
- } /* if */
+ }
if (cnt < 0 && bb_annotate_all_lines)
{
cnt = last_count;
- } /* if */
+ }
if (cnt < 0)
{
else
{
sprintf (buf, "%12ld -> ", cnt);
- } /* if */
+ }
last_count = cnt;
-} /* annotate_with_count */
+}
/*
&& !sym_lookup (&syms[EXCL_ANNO], sym->addr))))
{
sym->file->num_lines = sym->line_num;
- } /* if */
- } /* for */
+ }
+ }
/* allocate line descriptors: */
{
sf->line = (void *) xmalloc (sf->num_lines * sizeof (sf->line[0]));
memset (sf->line, 0, sf->num_lines * sizeof (sf->line[0]));
- } /* if */
- } /* for */
+ }
+ }
/* count executions per line: */
new_line->addr = 0;
new_line->ncalls += sym->ncalls;
sym->file->line[sym->line_num - 1] = new_line;
- } /* if */
- } /* if */
- } /* for */
+ }
+ }
+ }
/* plod over source files, annotating them: */
if (!sf->num_lines || (ignore_zeros && sf->ncalls == 0))
{
continue;
- } /* if */
+ }
num_executable_lines = num_lines_executed = 0;
ofp = annotate_source (sf, 16, annotate_with_count, sf);
if (!ofp)
{
continue;
- } /* if */
+ }
if (bb_table_length > 0)
{
if (table_len > sf->num_lines)
{
table_len = sf->num_lines;
- } /* if */
+ }
for (i = 0; i < table_len; ++i)
{
sym = sf->line[i];
if (!sym || sym->ncalls <= 0)
{
break;
- } /* if */
+ }
fprintf (ofp, "%9d %10d\n", sym->line_num, sym->ncalls);
- } /* for */
- } /* if */
+ }
+ }
free (sf->line);
sf->line = 0;
if (ofp != stdout)
{
fclose (ofp);
- } /* if */
- } /* for */
-} /* print_annotated_source */
-
-/*** end of basic_block.c ***/
+ }
+ }
+}
printf ("[cg_tally] arc from %s to %s traversed %d times\n",
parent->name, child->name, count));
arc_add (parent, child, count);
- } /* if */
-} /* cg_tally */
+ }
+}
/*
fprintf (stderr, "%s: %s: unexpected end of file\n",
whoami, filename);
done (1);
- } /* if */
+ }
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);
from_pc, self_pc, count));
/* add this arc: */
cg_tally (from_pc, self_pc, count);
-} /* cg_read_rec */
+}
/*
{
perror (filename);
done (1);
- } /* if */
+ }
DBG (SAMPLEDEBUG,
printf ("[cg_write_arcs] frompc 0x%lx selfpc 0x%lx count %d\n",
arc->parent->addr, arc->child->addr, arc->count));
- } /* for */
- } /* for */
-} /* cg_write_arcs */
-
-/*** end of call_graph.c ***/
+ }
+ }
+}
{
printf ("[arc_lookup] parent == 0 || child == 0\n");
return 0;
- } /* if */
+ }
DBG (LOOKUPDEBUG, printf ("[arc_lookup] parent %s child %s\n",
parent->name, child->name));
for (arc = parent->cg.children; arc; arc = arc->next_child)
&& child->end_addr <= arc->child->end_addr)
{
return arc;
- } /* if */
- } /* for */
+ }
+ }
return 0;
-} /* arc_lookup */
+}
/*
arc->count, count));
arc->count += count;
return;
- } /* if */
+ }
arc = (Arc *) xmalloc (sizeof (*arc));
arc->parent = parent;
arc->child = child;
/* prepend this parent to the parents of this child: */
arc->next_parent = child->cg.parents;
child->cg.parents = arc;
-} /* arc_add */
+}
static int
const Sym *right = *(const Sym **) rp;
return left->cg.top_order - right->cg.top_order;
-} /* cmp_topo */
+}
static void
if (parent->cg.prop.fract == 0.0)
{
return;
- } /* if */
+ }
/* gather time from children of this parent: */
if (arc->count == 0 || child == parent || child->cg.prop.fract == 0)
{
continue;
- } /* if */
+ }
if (child->cg.cyc.head != child)
{
if (parent->cg.cyc.num == child->cg.cyc.num)
{
continue;
- } /* if */
+ }
if (parent->cg.top_order <= child->cg.top_order)
{
fprintf (stderr, "[propagate] toporder botches\n");
- } /* if */
+ }
child = child->cg.cyc.head;
}
else
{
fprintf (stderr, "[propagate] toporder botches\n");
continue;
- } /* if */
- } /* if */
+ }
+ }
if (child->ncalls == 0)
{
continue;
- } /* if */
+ }
/* distribute time for this arc: */
arc->time = child->hist.time * (((double) arc->count)
{
parent->cg.cyc.head->cg.child_time += share;
parent->cg.cyc.head->cg.prop.child += prop_share;
- } /* if */
+ }
DBG (PROPDEBUG,
printf ("[prop_time] child \t");
print_name (child);
printf ("[prop_time] parent\t");
print_name (parent);
printf ("\n[prop_time] share %f\n", share));
- } /* for */
-} /* propagate_time */
+ }
+}
/*
* that were excluded with -E.
*/
continue;
- } /* if */
+ }
cyc->hist.time += member->hist.time;
- } /* for */
+ }
cyc->cg.prop.self = cyc->cg.prop.fract * cyc->hist.time;
- } /* for */
-} /* cycle_time */
+ }
+}
static void
if (sym->cg.cyc.head == sym && sym->cg.cyc.next)
{
++num_cycles;
- } /* if */
- } /* for */
+ }
+ }
/*
* cycle_header is indexed by cycle number: i.e. it is origin 1,
if (!(sym->cg.cyc.head == sym && sym->cg.cyc.next != 0))
{
continue;
- } /* if */
+ }
++num;
++cyc;
sym_init (cyc);
{
member->cg.cyc.num = num;
member->cg.cyc.head = cyc;
- } /* for */
+ }
/*
* Count calls from outside the cycle and those among cycle
if (arc->parent == member)
{
continue;
- } /* if */
+ }
if (arc->parent->cg.cyc.num == num)
{
cyc->cg.self_calls += arc->count;
else
{
cyc->ncalls += arc->count;
- } /* if */
- } /* for */
- } /* for */
- } /* for */
-} /* cycle_link */
+ }
+ }
+ }
+ }
+}
/*
if (child == parent)
{
continue;
- } /* if */
+ }
child->cg.print_flag |= parent->cg.print_flag;
/*
* If the child was never actually called (e.g., this arc
{
child->cg.prop.fract += parent->cg.prop.fract
* (((double) arc->count) / ((double) child->ncalls));
- } /* if */
- } /* for */
+ }
+ }
}
else
{
if (arc->parent->cg.cyc.head == head)
{
continue;
- } /* if */
+ }
parent = arc->parent;
head->cg.print_flag |= parent->cg.print_flag;
/*
{
head->cg.prop.fract += parent->cg.prop.fract
* (((double) arc->count) / ((double) head->ncalls));
- } /* if */
- } /* for */
- } /* for */
+ }
+ }
+ }
for (member = head; member; member = member->cg.cyc.next)
{
member->cg.print_flag = head->cg.print_flag;
member->cg.prop.fract = head->cg.prop.fract;
- } /* for */
- } /* if */
-} /* inherit_flags */
+ }
+ }
+}
/*
{
old_head = child->cg.cyc.head;
inherit_flags (child);
- } /* if */
+ }
DBG (PROPDEBUG,
printf ("[prop_flags] ");
print_name (child);
&& !sym_lookup (&syms[EXCL_GRAPH], child->addr)))
{
child->cg.print_flag = TRUE;
- } /* if */
+ }
}
else
{
&& sym_lookup (&syms[EXCL_GRAPH], child->addr))
{
child->cg.print_flag = FALSE;
- } /* if */
- } /* if */
+ }
+ }
if (child->cg.prop.fract == 0.0)
{
/*
&& !sym_lookup (&syms[EXCL_TIME], child->addr)))
{
child->cg.prop.fract = 1.0;
- } /* if */
+ }
}
else
{
&& sym_lookup (&syms[EXCL_TIME], child->addr))
{
child->cg.prop.fract = 0.0;
- } /* if */
- } /* if */
+ }
+ }
child->cg.prop.self = child->hist.time * child->cg.prop.fract;
print_time += child->cg.prop.self;
DBG (PROPDEBUG,
child->cg.print_flag, child->cg.prop.fract);
printf ("[prop_flags] time %f propself %f print_time %f\n",
child->hist.time, child->cg.prop.self, print_time));
- } /* if */
-} /* propagate_flags */
+ }
+}
/*
if (diff < 0.0)
{
return 1;
- } /* if */
+ }
if (diff > 0.0)
{
return -1;
- } /* if */
+ }
if (!left->name && left->cg.cyc.num != 0)
{
return -1;
- } /* if */
+ }
if (!right->name && right->cg.cyc.num != 0)
{
return 1;
- } /* if */
+ }
if (!left->name)
{
return -1;
- } /* if */
+ }
if (!right->name)
{
return 1;
- } /* if */
+ }
if (left->name[0] != '_' && right->name[0] == '_')
{
return -1;
- } /* if */
+ }
if (left->name[0] == '_' && right->name[0] != '_')
{
return 1;
- } /* if */
+ }
if (left->ncalls > right->ncalls)
{
return -1;
- } /* if */
+ }
if (left->ncalls < right->ncalls)
{
return 1;
- } /* if */
+ }
return strcmp (left->name, right->name);
-} /* cmp_total */
+}
/*
else
{
parent->cg.self_calls = 0;
- } /* if */
+ }
parent->cg.prop.fract = 0.0;
parent->cg.prop.self = 0.0;
parent->cg.prop.child = 0.0;
if (ignore_direct_calls)
{
find_call (parent, parent->addr, (parent + 1)->addr);
- } /* if */
- } /* for */
+ }
+ }
/*
* Topologically order things. If any node is unnumbered, number
* it and any of its descendents.
if (parent->cg.top_order == DFN_NAN)
{
cg_dfn (parent);
- } /* if */
- } /* for */
+ }
+ }
/* link together nodes on the same cycle: */
cycle_link ();
for (index = 0; index < symtab.len; ++index)
{
top_sorted_syms[index] = &symtab.base[index];
- } /* for */
+ }
qsort (top_sorted_syms, symtab.len, sizeof (Sym *), cmp_topo);
DBG (DFNDEBUG,
printf ("[cg_assemble] topological sort listing\n");
printf ("%d:", top_sorted_syms[index]->cg.top_order);
print_name (top_sorted_syms[index]);
printf ("\n");
- } /* for */
+ }
);
/*
* Starting from the topological top, propagate print flags to
for (index = 0; index < symtab.len; ++index)
{
propagate_time (top_sorted_syms[index]);
- } /* for */
+ }
free (top_sorted_syms);
for (index = 0; index < symtab.len; index++)
{
time_sorted_syms[index] = &symtab.base[index];
- } /* if */
+ }
for (index = 1; index <= num_cycles; index++)
{
time_sorted_syms[symtab.len + index - 1] = &cycle_header[index];
- } /* for */
+ }
qsort (time_sorted_syms, symtab.len + num_cycles, sizeof (Sym *),
cmp_total);
for (index = 0; index < symtab.len + num_cycles; index++)
{
time_sorted_syms[index]->cg.index = index + 1;
- } /* for */
+ }
return time_sorted_syms;
-} /* cg_assemble */
-
-/*** end of cg_arcs.c ***/
+}
DEFUN (is_numbered, (child), Sym * child)
{
return child->cg.top_order != DFN_NAN && child->cg.top_order != DFN_BUSY;
-} /* is_numbered */
+}
/*
if (child->cg.top_order == DFN_NAN)
{
return FALSE;
- } /* if */
+ }
return TRUE;
-} /* is_busy */
+}
/*
if (child == head)
{
break;
- } /* if */
+ }
if (child->cg.cyc.head != child && child->cg.cyc.head == head)
{
break;
- } /* if */
- } /* for */
+ }
+ }
if (cycle_top <= 0)
{
fprintf (stderr, "[find_cycle] couldn't find head of cycle\n");
done (1);
- } /* if */
+ }
#ifdef DEBUG
if (debug_level & DFNDEBUG)
{
else
{
printf ("<unknown>");
- } /* if */
+ }
printf ("\n");
}
#endif
printf ("[find_cycle] tail ");
print_name (tail);
printf ("\n"));
- } /* for */
+ }
/*
* If what we think is the top of the cycle has a cyclehead
* field, then it's not really the head of the cycle, which is
DBG (DFNDEBUG, printf ("[find_cycle] new cyclehead ");
print_name (head);
printf ("\n"));
- } /* if */
+ }
for (index = cycle_top + 1; index <= dfn_depth; ++index)
{
child = dfn_stack[index].sym;
printf (" onto ");
print_name (head);
printf ("\n"));
- } /* for */
+ }
}
else if (child->cg.cyc.head != head /* firewall */ )
{
fprintf (stderr, "[find_cycle] glommed, but not to head\n");
done (1);
- } /* if */
- } /* for */
- } /* if */
-} /* find_cycle */
+ }
+ }
+ }
+}
/*
{
fprintf (stderr, "[pre_visit] dfn_stack overflow\n");
done (1);
- } /* if */
+ }
dfn_stack[dfn_depth].sym = parent;
dfn_stack[dfn_depth].cycle_top = dfn_depth;
parent->cg.top_order = DFN_BUSY;
DBG (DFNDEBUG, printf ("[pre_visit]\t\t%d:", dfn_depth);
print_name (parent);
printf ("\n"));
-} /* pre_visit */
+}
/*
DBG (DFNDEBUG, printf ("[post_visit]\t\tmember ");
print_name (member);
printf ("-> cg.top_order = %d\n", dfn_counter));
- } /* for */
+ }
}
else
{
DBG (DFNDEBUG, printf ("[post_visit]\t\tis part of a cycle\n"));
- } /* if */
+ }
--dfn_depth;
-} /* post_visit */
+}
/*
if (is_numbered (parent))
{
return;
- } /* if */
+ }
/*
* If we're already busy, must be a cycle:
*/
{
find_cycle (parent);
return;
- } /* if */
+ }
pre_visit (parent);
/*
* Recursively visit children:
for (arc = parent->cg.children; arc; arc = arc->next_child)
{
cg_dfn (arc->child);
- } /* for */
+ }
post_visit (parent);
-} /* cg_dfn */
-
-/*** end of cg_dfn.c ***/
+}
else
{
printf ("\f\n");
- } /* if */
+ }
if (!bsd_style_output)
{
if (print_descriptions)
else
{
printf ("\t\t\tCall graph\n\n");
- } /* if */
- } /* if */
+ }
+ }
printf ("\ngranularity: each sample hit covers %ld byte(s)",
(long) hist_scale * sizeof (UNIT));
if (print_time > 0.0)
* This doesn't hurt, since all the numerators will be 0.0:
*/
print_time = 1.0;
- } /* if */
+ }
if (bsd_style_output)
{
printf ("%6.6s %5.5s %7.7s %11.11s %7.7s/%-7.7s %-8.8s\n",
else
{
printf ("index %% time self children called name\n");
- } /* if */
-} /* print_header */
+ }
+}
/*
else
{
printf (" %7.7s", "");
- } /* if */
+ }
printf (" <cycle %d as a whole>\t[%d]\n", cyc->cg.cyc.num, cyc->cg.index);
-} /* print_cycle */
+}
/*
if (left_time > right_time)
{
return GREATERTHAN;
- } /* if */
+ }
if (left_time < right_time)
{
return LESSTHAN;
- } /* if */
+ }
if (left_calls > right_calls)
{
return GREATERTHAN;
- } /* if */
+ }
if (left_calls < right_calls)
{
return LESSTHAN;
- } /* if */
+ }
return EQUALTO;
-} /* cmp_member */
+}
/*
if (cmp_member (doing, prev->cg.cyc.next) == GREATERTHAN)
{
break;
- } /* if */
- } /* for */
+ }
+ }
doing->cg.cyc.next = prev->cg.cyc.next;
prev->cg.cyc.next = doing;
- } /* for */
-} /* sort_members */
+ }
+}
/*
else
{
printf (" %7.7s", "");
- } /* if */
+ }
printf (" ");
print_name (member);
printf ("\n");
- } /* for */
-} /* print_members */
+ }
+}
/*
if (left_parent == left_child)
{
return LESSTHAN; /* left is a self call */
- } /* if */
+ }
if (right_parent == right_child)
{
return GREATERTHAN; /* right is a self call */
- } /* if */
+ }
if (left_parent->cg.cyc.num != 0 && left_child->cg.cyc.num != 0
&& left_parent->cg.cyc.num == left_child->cg.cyc.num)
if (left->count < right->count)
{
return LESSTHAN;
- } /* if */
+ }
if (left->count > right->count)
{
return GREATERTHAN;
- } /* if */
+ }
return EQUALTO;
}
else
{
/* right isn't a call within the cycle */
return LESSTHAN;
- } /* if */
+ }
}
else
{
if (left_time < right_time)
{
return LESSTHAN;
- } /* if */
+ }
if (left_time > right_time)
{
return GREATERTHAN;
- } /* if */
+ }
if (left->count < right->count)
{
return LESSTHAN;
- } /* if */
+ }
if (left->count > right->count)
{
return GREATERTHAN;
- } /* if */
+ }
return EQUALTO;
- } /* if */
- } /* if */
-} /* cmp_arc */
+ }
+ }
+}
static void
if (cmp_arc (arc, prev->next_parent) != GREATERTHAN)
{
break;
- } /* if */
- } /* for */
+ }
+ }
arc->next_parent = prev->next_parent;
prev->next_parent = arc;
- } /* for */
+ }
/* reattach sorted arcs to child: */
child->cg.parents = sorted.next_parent;
-} /* sort_parents */
+}
static void
else
{
cycle_head = child;
- } /* if */
+ }
if (!child->cg.parents)
{
printf (bsd_style_output
: "%6.6s %5.5s %7.7s %7.7s %7.7s %7.7s <spontaneous>\n",
"", "", "", "", "", "");
return;
- } /* if */
+ }
sort_parents (child);
for (arc = child->cg.parents; arc; arc = arc->next_parent)
{
arc->count, cycle_head->ncalls);
print_name (parent);
printf ("\n");
- } /* if */
- } /* for */
-} /* print_parents */
+ }
+ }
+}
static void
if (cmp_arc (arc, prev->next_child) != LESSTHAN)
{
break;
- } /* if */
- } /* for */
+ }
+ }
arc->next_child = prev->next_child;
prev->next_child = arc;
- } /* for */
+ }
/* reattach sorted children to parent: */
parent->cg.children = sorted.next_child;
-} /* sort_children */
+}
static void
arc->count, child->cg.cyc.head->ncalls);
print_name (child);
printf ("\n");
- } /* if */
- } /* for */
-} /* print_children */
+ }
+ }
+}
static void
else
{
printf (" %7.7s ", "");
- } /* if */
+ }
}
else
{
printf (" %7.7s %7.7s ", "", "");
- } /* if */
+ }
print_name (np);
printf ("\n");
-} /* print_line */
+}
/*
if (print_descriptions && bsd_style_output)
{
bsd_callg_blurb (stdout);
- } /* if */
+ }
print_header ();
|| !parent->cg.print_flag)
{
continue;
- } /* if */
+ }
if (!parent->name && parent->cg.cyc.num != 0)
{
/* cycle header: */
print_parents (parent);
print_line (parent);
print_children (parent);
- } /* if */
+ }
if (bsd_style_output)
printf ("\n");
printf ("-----------------------------------------------\n");
{
fsf_callg_blurb (stdout);
}
-} /* cg_print */
+}
static int
const Sym **npp2 = (const Sym **) right;
return strcmp ((*npp1)->name, (*npp2)->name);
-} /* cmp_name */
+}
void
&& symtab.base[index].hist.time == 0)
{
continue;
- } /* if */
+ }
name_sorted_syms[nnames++] = &symtab.base[index];
- } /* for */
+ }
qsort (name_sorted_syms, nnames, sizeof (Sym *), cmp_name);
for (index = 1, todo = nnames; index <= num_cycles; index++)
{
name_sorted_syms[todo++] = &cycle_header[index];
- } /* for */
+ }
printf ("\f\nIndex by function name\n\n");
index = (todo + 2) / 3;
for (i = 0; i < index; i++)
else
{
sprintf (buf, "(%d)", sym->cg.index);
- } /* if */
+ }
if (j < nnames)
{
if (bsd_style_output)
for (; col < starting_col + 5; ++col)
{
putchar (' ');
- } /* for */
+ }
printf (" %s ", buf);
col += print_name_only (sym);
if (!line_granularity && sym->is_static && sym->file)
else
{
filename = sym->file->name;
- } /* if */
- } /* if */
+ }
+ }
printf (" (%s)", filename);
col += strlen (filename) + 3;
- } /* if */
- } /* if */
+ }
+ }
}
else
{
printf ("%6.6s ", buf);
sprintf (buf, "<cycle %d>", sym->cg.cyc.num);
printf ("%-19.19s", buf);
- } /* if */
+ }
starting_col += column_width;
- } /* for */
+ }
printf ("\n");
- } /* for */
+ }
free (name_sorted_syms);
-} /* cg_print_index */
-
-/*** end of cg_print.c ***/
+}
{
perror (a_out_name);
done (1);
- } /* if */
+ }
if (!bfd_check_format (core_bfd, bfd_object))
{
fprintf (stderr, "%s: %s: not in a.out format\n", whoami, a_out_name);
done (1);
- } /* if */
+ }
/* get core's text section: */
core_text_sect = bfd_get_section_by_name (core_bfd, ".text");
fprintf (stderr, "%s: can't find .text section in %s\n",
whoami, a_out_name);
done (1);
- } /* if */
- } /* if */
+ }
+ }
/* read core's symbol table: */
fprintf (stderr, "%s: %s: %s\n", whoami, a_out_name,
bfd_errmsg (bfd_get_error ()));
done (1);
- } /* if */
+ }
core_syms = (asymbol **) xmalloc (core_num_syms);
core_num_syms = bfd_canonicalize_symtab (core_bfd, core_syms);
fprintf (stderr, "%s: %s: %s\n", whoami, a_out_name,
bfd_errmsg (bfd_get_error ()));
done (1);
- } /* if */
-} /* core_init */
+ }
+}
/*
fprintf (stderr, "%s: ran out room for %ld bytes of text space\n",
whoami, core_text_sect->_raw_size);
done (1);
- } /* if */
+ }
if (!bfd_get_section_contents (core_bfd, core_text_sect, core_text_space,
0, core_text_sect->_raw_size))
{
bfd_perror ("bfd_get_section_contents");
free (core_text_space);
core_text_space = 0;
- } /* if */
+ }
if (!core_text_space)
{
fprintf (stderr, "%s: can't do -c\n", whoami);
- } /* if */
-} /* core_get_text_space */
+ }
+}
/*
if (!sym->section)
{
return 0;
- } /* if */
+ }
if (ignore_static_funcs && (sym->flags & BSF_LOCAL))
{
DBG (AOUTDEBUG, printf ("[core_sym_class] %s: not a function\n",
sym->name));
return 0;
- } /* if */
+ }
bfd_get_symbol_info (core_bfd, sym, &syminfo);
i = syminfo.type;
if (i == 'T')
{
return i; /* it's a global symbol */
- } /* if */
+ }
if (i != 't')
{
DBG (AOUTDEBUG, printf ("[core_sym_class] %s is of class %c\n",
sym->name, i));
return 0;
- } /* if */
+ }
/* do some more filtering on static function-names: */
if (ignore_static_funcs)
{
return 0;
- } /* if */
+ }
/*
* Can't zero-length name or funny characters in name, where
* `funny' includes: `.' (.o file names) and `$' (Pascal labels).
if (!sym->name || sym->name[0] == '\0')
{
return 0;
- } /* if */
+ }
for (name = sym->name; *name; ++name)
{
if (*name == '.' || *name == '$')
{
return 0;
- } /* if */
- } /* if */
+ }
+ }
/*
* On systems where the C compiler adds an underscore to all
* names, static names without underscores seem usually to be
|| !strncmp (sym->name, "___gnu_compiled", 15))
{
return 0;
- } /* if */
+ }
return 't'; /* it's a static text symbol */
-} /* core_sym_class */
+}
/*
(long) addr, fname ? fname : "<unknown>", l,
func_name ? func_name : "<unknown>"));
return FALSE;
- } /* if */
-} /* get_src_info */
+ }
+}
/*
if (!core_sym_class (core_syms[i]))
{
continue;
- } /* if */
+ }
++symtab.len;
- } /* for */
+ }
if (symtab.len == 0)
{
fprintf (stderr, "%s: file `%s' has no symbols\n", whoami, a_out_name);
done (1);
- } /* if */
+ }
/* the "+ 2" is for the sentinels: */
symtab.base = (Sym *) xmalloc ((symtab.len + 2) * sizeof (Sym));
printf ("[core_create_function_syms] rejecting: 0x%lx %s\n",
core_syms[i]->value, core_syms[i]->name));
continue;
- } /* if */
+ }
sym_init (symtab.limit);
printf ("[core_create_function_syms: rej %s (maps to %s)\n",
symtab.limit->name, func_name));
continue;
- } /* if */
- } /* if */
+ }
+ }
#endif
symtab.limit->is_func = TRUE;
if (class == 't')
{
symtab.limit->is_static = TRUE;
- } /* if */
+ }
min_vma = MIN (symtab.limit->addr, min_vma);
max_vma = MAX (symtab.limit->addr, max_vma);
&& strcmp (symtab.limit->name, "main") == 0)
{
discard_underscores = 0;
- } /* if */
+ }
DBG (AOUTDEBUG, printf ("[core_create_function_syms] %ld %s 0x%lx\n",
(long) (symtab.limit - symtab.base),
symtab.limit->name, symtab.limit->addr));
++symtab.limit;
- } /* for */
+ }
/* create sentinels: */
symtab.len = symtab.limit - symtab.base;
symtab_finalize (&symtab);
-} /* core_create_function_syms */
+}
/*
&& strcmp (prev_filename, filename) == 0))
{
continue;
- } /* if */
+ }
++ltab.len;
prev_line_num = dummy.line_num;
if (offset - prev_offset < min_dist)
{
min_dist = offset - prev_offset;
- } /* if */
+ }
prev_offset = offset;
min_vma = MIN (vma, min_vma);
max_vma = MAX (vma, max_vma);
- } /* for */
+ }
DBG (AOUTDEBUG, printf ("[core_create_line_syms] min_dist=%lx\n", min_dist));
&& strcmp (prev->file->name, filename) == 0))
{
continue;
- } /* if */
+ }
/* make name pointer a malloc'ed string: */
ltab.limit->name = strdup (ltab.limit->name);
&& strcmp (ltab.limit->name, "main") == 0)
{
discard_underscores = 0;
- } /* if */
+ }
DBG (AOUTDEBUG, printf ("[core_create_line_syms] %d %s 0x%lx\n",
ltab.len, ltab.limit->name,
ltab.limit->addr));
++ltab.limit;
- } /* for */
+ }
/* update sentinels: */
&& min_vma <= sentinel->end_addr)
{
sentinel->end_addr = min_vma - 1;
- } /* if */
+ }
sentinel = sym_lookup (&symtab, ~0);
if (strcmp (sentinel->name, "<hicore>") == 0 && max_vma >= sentinel->addr)
{
sentinel->addr = max_vma + 1;
- } /* if */
+ }
/* copy in function symbols: */
memcpy (ltab.limit, symtab.base, symtab.len * sizeof (Sym));
"%s: somebody miscounted: ltab.len=%ld instead of %d\n",
whoami, (long) (ltab.limit - ltab.base), ltab.len);
done (1);
- } /* if */
+ }
/* finalize ltab and make it symbol table: */
}
while (sym->file == sym[-1].file &&
strcmp (sym->name, sym[-1].name) == 0);
- } /* if */
- } /* for */
-
-} /* core_create_line_syms */
+ }
+ }
-/*** end of core.c ***/
+}
{
fprintf (stderr, "%s: -c supported on this machine architecture\n",
whoami);
-} /* find_call */
-
-/*** end of dummy.c ***/
+}
bfd_vma
DEFUN (get_vma, (abfd, addr), bfd * abfd AND bfd_byte * addr)
{
- switch (sizeof (bfd_vma))
+ switch (sizeof (char*))
{
case 4:
return bfd_get_32 (abfd, addr);
return bfd_get_64 (abfd, addr);
default:
fprintf (stderr, "%s: bfd_vma has unexpected size of %ld bytes\n",
- whoami, (long) sizeof (bfd_vma));
+ whoami, (long) sizeof (char*));
done (1);
- } /* switch */
-} /* get_vma */
+ }
+}
/*
void
DEFUN (put_vma, (abfd, val, addr), bfd * abfd AND bfd_vma val AND bfd_byte * addr)
{
- switch (sizeof (bfd_vma))
+ switch (sizeof (char*))
{
case 4:
bfd_put_32 (abfd, val, addr);
break;
default:
fprintf (stderr, "%s: bfd_vma has unexpected size of %ld bytes\n",
- whoami, (long) sizeof (bfd_vma));
+ whoami, (long) sizeof (char*));
done (1);
- } /* switch */
-} /* put_vma */
+ }
+}
void
{
perror (filename);
done (1);
- } /* if */
- } /* if */
+ }
+ }
if (fread (&ghdr, sizeof (struct gmon_hdr), 1, ifp) != 1)
{
fprintf (stderr, "%s: file too short to be a gmon file\n",
filename);
done (1);
- } /* if */
+ }
if ((file_format == FF_MAGIC) ||
(file_format == FF_AUTO && !strncmp (&ghdr.cookie[0], GMON_MAGIC, 4)))
fprintf (stderr, "%s: file `%s' has bad magic cookie\n",
whoami, filename);
done (1);
- } /* if */
+ }
/* right magic, so it's probably really a new gmon.out file */
"%s: file `%s' has unsupported version %d\n",
whoami, filename, gmon_file_version);
done (1);
- } /* if */
+ }
/* read in all the records: */
while (fread (&tag, sizeof (tag), 1, ifp) == 1)
"%s: %s: found bad tag %d (file corrupted?)\n",
whoami, filename, tag);
done (1);
- } /* switch */
- } /* while */
+ }
+ }
}
else if (file_format == FF_AUTO || file_format == FF_BSD)
{
{
perror (filename);
done (1);
- } /* if */
+ }
if (fread (&raw, 1, sizeof (struct raw_phdr), ifp)
!= sizeof (struct raw_phdr))
{
fprintf (stderr, "%s: file too short to be a gmon file\n",
filename);
done (1);
- } /* if */
+ }
tmp.low_pc = get_vma (core_bfd, (bfd_byte *) & raw.low_pc[0]);
tmp.high_pc = get_vma (core_bfd, (bfd_byte *) & raw.high_pc[0]);
tmp.ncnt = bfd_get_32 (core_bfd, (bfd_byte *) & raw.ncnt[0]);
fprintf (stderr, "%s: incompatible with first gmon file\n",
filename);
done (1);
- } /* if */
+ }
h = tmp;
s_lowpc = (bfd_vma) h.low_pc;
s_highpc = (bfd_vma) h.high_pc;
if (hist_num_bins)
{
++nhist;
- } /* 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)
{
"%s: unexpected EOF after reading %d/%d bins\n",
whoami, --i, hist_num_bins);
done (1);
- } /* if */
+ }
hist_sample[i] += bfd_get_16 (core_bfd, (bfd_byte *) raw_bin_count);
- } /* for */
+ }
/*
* The rest of the file consists of a bunch of <from,self,count>
from_pc, self_pc, count));
/* add this arc: */
cg_tally (from_pc, self_pc, count);
- } /* while */
+ }
fclose (ifp);
if (hz == HZ_WRONG)
{
hz = 1;
fprintf (stderr, "time is in ticks, not seconds\n");
- } /* if */
- } /* if */
+ }
+ }
}
else
{
fprintf (stderr, "%s: don't know how to deal with file format %d\n",
whoami, file_format);
done (1);
- } /* if */
+ }
if (output_style & STYLE_GMON_INFO)
{
printf ("\t%d basic-block count record%s\n",
nbbs, nbbs == 1 ? "" : "s");
first_output = FALSE;
- } /* if */
-} /* gmon_out_read */
+ }
+}
void
{
perror (filename);
done (1);
- } /* if */
+ }
if (file_format == FF_AUTO || file_format == FF_MAGIC)
{
{
perror (filename);
done (1);
- } /* if */
+ }
/* write execution time histogram if we have one: */
if (gmon_input & INPUT_HISTOGRAM)
{
hist_write_hist (ofp, filename);
- } /* if */
+ }
/* write call graph arcs if we have any: */
if (gmon_input & INPUT_CALL_GRAPH)
{
cg_write_arcs (ofp, filename);
- } /* if */
+ }
/* write basic-block info if we have it: */
if (gmon_input & INPUT_BB_COUNTS)
{
bb_write_blocks (ofp, filename);
- } /* if */
+ }
}
else if (file_format == FF_BSD)
{
{
perror (filename);
done (1);
- } /* if */
+ }
/* dump the samples: */
{
perror (filename);
done (1);
- } /* if */
- } /* for */
+ }
+ }
/* dump the normalized raw arc information: */
{
perror (filename);
done (1);
- } /* if */
+ }
DBG (SAMPLEDEBUG,
printf ("[dumpsum] frompc 0x%lx selfpc 0x%lx count %d\n",
arc->parent->addr, arc->child->addr, arc->count));
- } /* for */
- } /* for */
+ }
+ }
fclose (ofp);
}
else
fprintf (stderr, "%s: don't know how to deal with file format %d\n",
whoami, file_format);
done (1);
- } /* if */
-} /* gmon_out_write */
-
-/*** gmon_out.c ***/
+ }
+}
/* types of records in this file: */
typedef enum
{
- GMON_TAG_TIME_HIST, GMON_TAG_CG_ARC, GMON_TAG_BB_COUNT
+ GMON_TAG_TIME_HIST = 0, GMON_TAG_CG_ARC = 1, GMON_TAG_BB_COUNT = 2
}
GMON_Record_Tag;
struct gmon_hist_hdr
{
- char low_pc[sizeof (bfd_vma)]; /* base pc address of sample buffer */
- char high_pc[sizeof (bfd_vma)]; /* max pc address of sampled buffer */
- char hist_size[4]; /* size of sample buffer */
- char prof_rate[4]; /* profiling clock rate */
- char dimen[15]; /* phys. dim., usually "seconds" */
- char dimen_abbrev; /* usually 's' for "seconds" */
+ char low_pc[sizeof (char*)]; /* base pc address of sample buffer */
+ char high_pc[sizeof (char*)]; /* max pc address of sampled buffer */
+ char hist_size[4]; /* size of sample buffer */
+ char prof_rate[4]; /* profiling clock rate */
+ char dimen[15]; /* phys. dim., usually "seconds" */
+ char dimen_abbrev; /* usually 's' for "seconds" */
};
struct gmon_cg_arc_record
{
- char from_pc[sizeof (bfd_vma)]; /* address within caller's body */
- char self_pc[sizeof (bfd_vma)]; /* address within callee's body */
- char count[4]; /* number of arc traversals */
+ char from_pc[sizeof (char*)]; /* address within caller's body */
+ char self_pc[sizeof (char*)]; /* address within callee's body */
+ char count[4]; /* number of arc traversals */
};
#endif /* gmon_out_h */
[image-file] [profile-file...]\n",
whoami);
done (status);
-} /* usage */
+}
int
if (optarg)
{
sym_id_add (optarg, INCL_ANNO);
- } /* if */
+ }
output_style |= STYLE_ANNOTATED_SOURCE;
user_specified |= STYLE_ANNOTATED_SOURCE;
break;
if (optarg)
{
sym_id_add (optarg, INCL_EXEC);
- } /* if */
+ }
output_style |= STYLE_EXEC_COUNTS;
user_specified |= STYLE_EXEC_COUNTS;
break;
else
{
debug_level = ~0;
- } /* if */
+ }
DBG (ANYDEBUG, printf ("[main] debug-level=0x%x\n", debug_level));
#ifndef DEBUG
printf ("%s: debugging not supported; -d ignored\n", whoami);
else
{
output_style &= ~STYLE_ANNOTATED_SOURCE;
- } /* if */
+ }
user_specified |= STYLE_ANNOTATED_SOURCE;
break;
case 'k':
fprintf (stderr, "%s: unknown file format %s\n",
optarg, whoami);
done (1);
- } /* switch */
+ }
break;
case 'p':
if (optarg)
{
sym_id_add (optarg, INCL_FLAT);
- } /* if */
+ }
output_style |= STYLE_FLAT_PROFILE;
user_specified |= STYLE_FLAT_PROFILE;
break;
else
{
output_style &= ~STYLE_FLAT_PROFILE;
- } /* if */
+ }
user_specified |= STYLE_FLAT_PROFILE;
break;
case 'q':
else
{
sym_id_add (optarg, INCL_GRAPH);
- } /* if */
- } /* if */
+ }
+ }
output_style |= STYLE_CALL_GRAPH;
user_specified |= STYLE_CALL_GRAPH;
break;
else
{
sym_id_add (optarg, EXCL_GRAPH);
- } /* if */
+ }
output_style |= STYLE_CALL_GRAPH;
}
else
{
output_style &= ~STYLE_CALL_GRAPH;
- } /* if */
+ }
user_specified |= STYLE_CALL_GRAPH;
break;
case 's':
if (bb_table_length < 0)
{
bb_table_length = 0;
- } /* if */
+ }
break;
case 'T':
bsd_style_output = TRUE;
if (output_width < 1)
{
output_width = 1;
- } /* if */
+ }
break;
case 'x':
bb_annotate_all_lines = TRUE;
else
{
output_style &= ~STYLE_EXEC_COUNTS;
- } /* if */
+ }
user_specified |= STYLE_ANNOTATED_SOURCE;
break;
default:
usage (stderr, 1);
- } /* switch */
- } /* while */
+ }
+ }
/* append value of GPROF_PATH to source search list if set: */
str = getenv ("GPROF_PATH");
if (str)
{
search_list_append (&src_search_list, str);
- } /* if */
+ }
if (optind < argc)
{
a_out_name = argv[optind++];
- } /* if */
+ }
if (optind < argc)
{
gmon_name = argv[optind++];
- } /* if */
+ }
/*
* Turn off default functions:
#ifdef __osf__
sym_id_add (*sp, EXCL_FLAT);
#endif
- } /* for */
+ }
/*
* For line-by-line profiling, also want to keep those
for (sp = &default_excluded_list[0]; *sp; sp++)
{
sym_id_add (*sp, EXCL_FLAT);
- } /* for */
- } /* if */
+ }
+ }
/*
* Read symbol table from core file:
if (ignore_direct_calls)
{
core_get_text_space (core_bfd);
- } /* if */
+ }
/*
* Create symbols from core image:
else
{
core_create_function_syms (core_bfd);
- } /* if */
+ }
/*
* Translate sym specs into syms:
if (optind < argc)
{
gmon_name = argv[optind];
- } /* if */
+ }
}
while (optind++ < argc);
#else
if (optind < argc)
{
gmon_name = argv[optind];
- } /* if */
+ }
}
while (optind++ < argc);
- } /* if */
+ }
/*
* If user did not specify output style, try to guess something
else
{
output_style = STYLE_EXEC_COUNTS;
- } /* if */
+ }
output_style &= ~user_specified;
- } /* if */
+ }
/*
* Dump a gmon.sum file if requested (before any other processing!):
if (output_style & STYLE_SUMMARY_FILE)
{
gmon_out_write (GMONSUM);
- } /* if */
+ }
if (gmon_input & INPUT_HISTOGRAM)
{
hist_assign_samples ();
- } /* if */
+ }
if (gmon_input & INPUT_CALL_GRAPH)
{
cg = cg_assemble ();
- } /* if */
+ }
/* do some simple sanity checks: */
{
fprintf (stderr, "%s: gmon.out file is missing histogram\n", whoami);
done (1);
- } /* if */
+ }
if ((output_style & STYLE_CALL_GRAPH) && !(gmon_input & INPUT_CALL_GRAPH))
{
fprintf (stderr,
"%s: gmon.out file is missing call-graph data\n", whoami);
done (1);
- } /* if */
+ }
/* output whatever user whishes to see: */
if (cg && (output_style & STYLE_CALL_GRAPH) && bsd_style_output)
{
cg_print (cg); /* print the dynamic profile */
- } /* if */
+ }
if (output_style & STYLE_FLAT_PROFILE)
{
hist_print (); /* print the flat profile */
- } /* if */
+ }
if (cg && (output_style & STYLE_CALL_GRAPH))
{
if (!bsd_style_output)
{
cg_print (cg); /* print the dynamic profile */
- } /* if */
+ }
cg_print_index ();
- } /* if */
+ }
if (output_style & STYLE_EXEC_COUNTS)
{
print_exec_counts ();
- } /* if */
+ }
if (output_style & STYLE_ANNOTATED_SOURCE)
{
print_annotated_source ();
- } /* if */
+ }
return 0;
}
if (tim.it_interval.tv_usec < 2)
{
return HZ_WRONG;
- } /* if */
+ }
return 1000000 / tim.it_interval.tv_usec;
#endif
-} /* hertz */
+}
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",
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)
{
"%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 */
+ }
+ }
+}
/*
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 */
+ }
+}
/*
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;
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)
else
{
total_time -= credit;
- } /* if */
- } /* if */
- } /* if */
- } /* for */
+ }
+ }
+ }
+ }
DBG (SAMPLEDEBUG, printf ("[assign_samples] total_time %f\n",
total_time));
-} /* hist_assign_samples */
+}
/*
{
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 */
+ }
if (total_time <= 0.0)
{
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 ", "");
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 */
+}
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)
{
printf (" %8d %8.2f %8.2f ",
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 */
+}
/*
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)
{
return 1;
- } /* if */
+ }
if (call_diff < 0)
{
return -1;
- } /* if */
+ }
return strcmp (left->name, right->name);
-} /* cmp_time */
+}
/*
else
{
printf ("\f\n");
- } /* if */
+ }
accum_time = 0.0;
if (bsd_style_output)
{
printf ("\n\n\nflat profile:\n");
flat_blurb (stdout);
- } /* if */
+ }
}
else
{
printf ("Flat profile:\n");
- } /* if */
+ }
/*
* 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)
{
top_dog = sym;
top_time = time;
- } /* if */
- } /* if */
- } /* for */
+ }
+ }
+ }
if (top_dog && top_dog->ncalls && top_time > 0.0)
{
top_time /= hz;
&& 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 ***/
+ }
+}
else
{
len = strlen (beg);
- } /* if */
+ }
new_el = (Search_List_Elem *) xmalloc (sizeof (*new_el) + len);
memcpy (new_el->path, beg, len);
new_el->path[len] = '\0';
else
{
list->head = new_el;
- } /* if */
+ }
list->tail = new_el;
}
while (colon);
-} /* search_list_append */
-
-/*** end of search_list.c ***/
+}
if (strcmp (path, sf->name) == 0)
{
break;
- } /* if */
- } /* for */
+ }
+ }
if (!sf)
{
/* create a new source file descriptor: */
sf->name = strdup (path);
sf->next = first_src_file;
first_src_file = sf;
- } /* if */
+ }
return sf;
-} /* source_file_lookup_path */
+}
Source_File *
else
{
fname = sf->name;
- } /* if */
+ }
if (strcmp (filename, fname) == 0)
{
break;
- } /* if */
- } /* for */
+ }
+ }
return sf;
-} /* source_file_lookup_name */
+}
FILE *
if (sf->name[0] == '/')
{
sle = 0; /* don't use search list for absolute paths */
- } /* if */
+ }
name_only = 0;
while (TRUE)
{
if (ifp)
{
break;
- } /* if */
+ }
if (!sle && !name_only)
{
name_only = strrchr (sf->name, '/');
/* try search-list again, but this time with name only: */
++name_only;
sle = src_search_list.head;
- } /* if */
- } /* if */
+ }
+ }
if (sle)
{
strcpy (fname, sle->path);
else
{
strcat (fname, sf->name);
- } /* if */
+ }
sle = sle->next;
}
else
else
{
perror (sf->name);
- } /* if */
+ }
return 0;
- } /* if */
- } /* while */
+ }
+ }
ofp = stdout;
if (create_annotation_files)
else
{
filename = sf->name;
- } /* if */
+ }
strcpy (fname, filename);
strcat (fname, EXT_ANNO);
{
perror (fname);
return 0;
- } /* if */
- } /* if */
+ }
+ }
/*
* Print file names if output goes to stdout and there are
else
{
fputc ('\n', ofp);
- } /* if */
+ }
if (first_output)
{
first_output = FALSE;
else
{
fprintf (ofp, "\f\n");
- } /* if */
+ }
fprintf (ofp, "*** File %s:\n", sf->name);
- } /* if */
+ }
annotation = xmalloc (max_width + 1);
line_num = 1;
fputs (annotation, ofp);
++line_num;
new_line = FALSE;
- } /* if */
+ }
new_line = (buf[i] == '\n');
fputc (buf[i], ofp);
- } /* for */
- } /* while */
+ }
+ }
free (annotation);
return ofp;
-} /* annotate_source */
-
-/*** end of source.c ***/
+}
if (core_text_space == 0)
{
return;
- } /* if */
+ }
if (p_lowpc < s_lowpc)
{
p_lowpc = s_lowpc;
- } /* if */
+ }
if (p_highpc > s_highpc)
{
p_highpc = s_highpc;
- } /* if */
+ }
DBG (CALLDEBUG, printf ("[find_call] %s: 0x%lx to 0x%lx\n",
parent->name, p_lowpc, p_highpc));
for (instr = (unsigned int *) (p_lowpc + delta);
/* a hit: */
arc_add (parent, child, 0);
continue;
- } /* if */
- } /* if */
+ }
+ }
/*
* Something funny going on.
*/
DBG (CALLDEBUG, printf ("\tbut it's a botch\n"));
- } /* if */
- } /* for */
-} /* find_call */
-/*** end of sparc.c ***/
+ }
+ }
+}
id->next = id_list;
id_list = id;
-} /* sym_id_add */
+}
/*
if (!sym->file)
{
sym->file = &non_existent_file;
- } /* if */
- } /* if */
+ }
+ }
spec = colon + 1;
if (strlen (spec))
{
else
{
sym->name = spec;
- } /* if */
- } /* if */
+ }
+ }
}
else if (strlen (spec))
{
if (!sym->file)
{
sym->file = &non_existent_file;
- } /* if */
+ }
}
else if (isdigit (*spec))
{
else if (strlen (spec))
{
sym->name = spec;
- } /* if */
- } /* if */
-} /* parse_spec */
+ }
+ }
+}
/*
parse_spec (slash + 1, &id->right.sym);
*slash = '\0';
id->has_right = TRUE;
- } /* if */
+ }
parse_spec (id->spec, &id->left.sym);
#ifdef DEBUG
else
{
printf ("*");
- } /* if */
+ }
if (id->has_right)
{
printf ("/%s:",
else
{
printf ("*");
- } /* if */
- } /* if */
+ }
+ }
printf ("\n");
}
#endif
-} /* parse_id */
+}
/*
return (pattern->file ? pattern->file == sym->file : TRUE)
&& (pattern->line_num ? pattern->line_num == sym->line_num : TRUE)
&& (pattern->name ? strcmp (pattern->name, sym->name) == 0 : TRUE);
-} /* match */
+}
static void
/* link match into match's chain: */
tab->base[tab->len].next = m->first_match;
m->first_match = &tab->base[tab->len];
- } /* if */
+ }
++tab->len;
- } /* if */
+ }
/* extend match to include this symbol: */
if (second_pass)
{
tab->base[m->prev_index].end_addr = sym->end_addr;
- } /* if */
+ }
m->prev_match = sym;
-} /* extend_match */
+}
/*
for (id = id_list; id; id = id->next)
{
parse_id (id);
- } /* for */
+ }
/* first determine size of each table: */
if (match (&id->left.sym, sym))
{
extend_match (&id->left, sym, &syms[id->which_table], FALSE);
- } /* if */
+ }
if (id->has_right && match (&id->right.sym, sym))
{
extend_match (&id->right, sym, &right_ids, FALSE);
- } /* if */
- } /* for */
- } /* for */
+ }
+ }
+ }
/* create tables of appropriate size and reset lengths: */
tab->base = (Sym *) xmalloc (tab->len * sizeof (Sym));
tab->limit = tab->base + tab->len;
tab->len = 0;
- } /* if */
- } /* for */
+ }
+ }
if (right_ids.len)
{
right_ids.base = (Sym *) xmalloc (right_ids.len * sizeof (Sym));
right_ids.limit = right_ids.base + right_ids.len;
right_ids.len = 0;
- } /* if */
+ }
/* make a second pass through symtab, creating syms as necessary: */
if (match (&id->left.sym, sym))
{
extend_match (&id->left, sym, &syms[id->which_table], TRUE);
- } /* if */
+ }
if (id->has_right && match (&id->right.sym, sym))
{
extend_match (&id->right, sym, &right_ids, TRUE);
- } /* if */
- } /* for */
- } /* for */
+ }
+ }
+ }
/* go through ids creating arcs as needed: */
right->end_addr,
table_name[id->which_table]));
arc_add (left, right, 0);
- } /* for */
- } /* for */
- } /* if */
- } /* for */
+ }
+ }
+ }
+ }
/* finally, we can sort the tables and we're done: */
DBG (IDDEBUG, printf ("[sym_id_parse] syms[%s]:\n",
table_name[tab - &syms[0]]));
symtab_finalize (tab);
- } /* for */
-} /* sym_id_parse */
+ }
+}
/*
&& arc_lookup (sym, to))
{
return TRUE;
- } /* if */
- } /* for */
+ }
+ }
return FALSE;
-} /* sym_id_arc_is_present */
-
-/*** end of sym_ids.h ***/
+}
sym->cg.prop.fract = 0.0;
sym->cg.prop.self = 0.0;
sym->cg.prop.child = 0.0;
-} /* sym_init */
+}
/*
else if (left->addr < right->addr)
{
return -1;
- } /* if */
+ }
if (left->is_func != right->is_func)
{
return right->is_func - left->is_func;
- } /* if */
+ }
return left->is_static - right->is_static;
-} /* cmp_addr */
+}
void
if (!tab->len)
{
return;
- } /* if */
+ }
/*
* Sort symbol table in order of increasing function addresses:
src->name, src->is_static ? 't' : 'T',
src->is_func ? 'F' : 'f');
printf (" (addr=%lx)\n", src->addr));
- } /* if */
+ }
}
else
{
if (dst > tab->base && dst[-1].end_addr == 0)
{
dst[-1].end_addr = src->addr - 1;
- } /* if */
+ }
/* retain sym only if it has a non-empty address range: */
if (!src->end_addr || src->addr <= src->end_addr)
{
*dst++ = *src;
prev_addr = src->addr;
- } /* if */
- } /* if */
- } /* if */
+ }
+ }
+ }
if (tab->len > 0 && dst[-1].end_addr == 0)
{
dst[-1].end_addr = core_text_sect->vma + core_text_sect->_raw_size - 1;
- } /* if */
+ }
DBG (AOUTDEBUG | IDDEBUG,
printf ("[symtab_finalize]: removed %d duplicate entries\n",
printf ("[symtab_finalize] 0x%lx-0x%lx\t%s\n",
(long) tab->base[j].addr, (long) tab->base[j].end_addr,
tab->base[j].name);
- } /* for */
+ }
);
-} /* symtab_finalize */
+}
#ifdef DEBUG
if (sym[mid].addr <= address && sym[mid + 1].addr > address)
{
return &sym[mid];
- } /* if */
+ }
if (sym[mid].addr > address)
{
high = mid;
else
{
low = mid + 1;
- } /* if */
- } /* for */
+ }
+ }
fprintf (stderr, "[sym_lookup] binary search fails???\n");
return 0;
-} /* dbg_sym_lookup */
+}
#endif /* DEBUG */
if (!symtab->len)
{
return 0;
- } /* if */
+ }
sym = symtab->base;
for (low = 0, high = symtab->len - 1; low != high;)
printf ("[sym_lookup] %d probes (symtab->len=%d)\n",
probes, symtab->len - 1));
return &sym[mid];
- } /* if */
- } /* if */
+ }
+ }
if (sym[mid].addr > address)
{
high = mid;
else
{
low = mid + 1;
- } /* if */
- } /* for */
+ }
+ }
if (sym[mid + 1].addr <= address)
{
if (address > sym[mid + 1].end_addr)
DBG (LOOKUPDEBUG, printf ("[sym_lookup] %d (%d) probes, fall off\n",
probes, symtab->len - 1));
return &sym[mid + 1];
- } /* if */
- } /* if */
+ }
+ }
return 0;
-} /* sym_lookup */
-
-/*** end of symtab.c ***/
+}
sym_init (&indirectchild);
indirectchild.cg.prop.fract = 1.0;
indirectchild.cg.cyc.head = &indirectchild;
- } /* if */
+ }
if (textspace == 0)
{
if (name[0] == '_' && name[1] && discard_underscores)
{
name++;
- } /* if */
+ }
demangled = cplus_demangle (name, DMGL_ANSI | DMGL_PARAMS);
if (demangled)
{
name = demangled;
- } /* if */
- } /* if */
+ }
+ }
printf ("%s", name);
size = strlen (name);
if (line_granularity && self->file)
else
{
filename = self->file->name;
- } /* if */
- } /* if */
+ }
+ }
sprintf (buf, " (%s:%d)", filename, self->line_num);
printf (buf);
size += strlen (buf);
- } /* if */
+ }
if (demangled)
{
free (demangled);
- } /* if */
+ }
DBG (DFNDEBUG, printf ("{%d} ", self->cg.top_order));
DBG (PROPDEBUG, printf ("%4.0f%% ", 100.0 * self->cg.prop.fract));
- } /* if */
+ }
return size;
-} /* print_name_only */
+}
void
if (self->cg.cyc.num != 0)
{
printf (" <cycle %d>", self->cg.cyc.num);
- } /* if */
+ }
if (self->cg.index != 0)
{
if (self->cg.print_flag)
else
{
printf (" (%d)", self->cg.index);
- } /* if */
- } /* if */
-} /* print_name */
-
-/*** end of utils.c ***/
+ }
+ }
+}
sym_init (&indirectchild);
indirectchild.cg.prop.fract = 1.0;
indirectchild.cg.cyc.head = &indirectchild;
- } /* if */
+ }
if (core_text_space == 0)
{