/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2005 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <stdlib.h>
#include "gprof.h"
/*
* add (or just increment) an arc
*/
void
{
#ifdef DEBUG
if (debug & TALLYDEBUG) {
(void) printf("[addarc] %lld arcs from %s to %s\n",
}
#endif /* DEBUG */
if (arcp != 0) {
/*
* a hit: just increment the count.
*/
#ifdef DEBUG
if (!Dflag) {
if (debug & TALLYDEBUG) {
(void) printf("[tally] hit %lld += %lld\n",
}
} else {
if (debug & TALLYDEBUG) {
(void) printf("[tally] hit %lld -= %lld\n",
}
}
#endif /* DEBUG */
if (!Dflag)
else {
}
return;
}
/*
* prepend this child to the children of this parent
*/
/*
* prepend this parent to the parents of this child
*/
}
/*
* the code below topologically sorts the graph (collapsing cycles),
* and propagates time bottom up and flags top down.
*/
/*
* the topologically sorted name list pointers
*/
static int
{
}
static void
{
double share;
double propshare;
return;
}
/*
* gather time from children of this parent.
*/
continue;
}
continue;
}
continue;
}
continue;
}
"[propagate] toporder botches\n");
}
} else {
"[propagate] toporder botches\n");
continue;
}
}
continue;
}
/*
* distribute time for this arc
*/
/*
* (1 - propfraction) gets lost along the way
*/
/*
* fix things for printing
*/
/*
* add this share to the parent's cycle header, if any.
*/
}
#ifdef DEBUG
(void) printf("[dotime] child \t");
(void) printf(" with %f %f %lld/%lld\n",
(void) printf("[dotime] parent\t");
}
#endif /* DEBUG */
}
}
static void
cycletime(void)
{
int cycle;
/*
* all members have the same propfraction
* except those that were excluded with -E
*/
continue;
}
}
}
}
static void
dotime(void)
{
int index;
cycletime();
}
}
static void
cyclelink(void)
{
int cycle;
/*
* Count the number of cycles, and initialize the cycle lists
*/
ncycle = 0;
/*
* this is how you find unattached cycles
*/
ncycle += 1;
}
}
}
/*
* cyclenl is indexed by cycle number:
* i.e. it is origin 1, not origin 0.
*/
if (cyclenl == 0) {
"%s: No room for %d bytes of cycle headers\n",
done();
}
/*
* now link cycles to true cycleheads,
* number them, accumulate the data for the cycle
*/
cycle = 0;
continue;
}
cycle += 1;
/* in children */
/* called */
/* to self */
/* propagates */
/* propagates */
/* time propagates */
/* printed? */
/* graph list */
/* top-sort order */
/* of cycle on */
/* of cycle */
#ifdef DEBUG
if (debug & CYCLEDEBUG) {
(void) printf("[cyclelink] ");
(void) printf(" is the head of cycle %d\n",
cycle);
}
#endif /* DEBUG */
/*
* link members to cycle header
*/
}
/*
* count calls from outside the cycle
* and those among cycle members
*/
continue;
cycle) {
} else
}
}
}
}
}
/*
* check if any parent of this child
* (or outside parents of this cycle)
* have their print flags on and set the
* print flag of the child (cycle) appropriately.
* similarly, deal with propagation fractions from parents.
*/
static void
{
/*
* just a regular child, check its parents
*/
continue;
}
/*
* if the child was never actually called
* (e.g. this arc is static (and all others
* are, too)) no time propagates along this arc.
*/
}
}
} else {
/*
* its a member of a cycle, look at all parents from
* outside the cycle
*/
continue;
}
/*
* if the cycle was never actually called
* (e.g. this arc is static (and all
* others are, too)) no time propagates
* along this arc.
*/
headp->propfraction +=
}
}
}
}
}
}
/*
* check here if *any* of its parents is printable
* then return true else return false
*/
static int
{
return (1);
return (1);
}
return (0);
}
/*
* check if the parents it passes time are *all* on
* the Elist in which case we do not pass the time
*/
static int
{
return (1);
return (1);
}
return (0);
}
/*
* in one top to bottom pass over the topologically sorted namelist
* propagate:
* printflag as the union of parents' printflags
* propfraction as the sum of fractional parents' propfractions
* and while we're here, sum time for functions.
*/
static void
doflags(void)
{
int index;
oldhead = 0;
/*
* if we haven't done this function or cycle,
* inherit things from parent.
* this way, we are linear in the number of arcs
* since we do all members of a cycle (and the
* cycle itself) as we hit the first member
* of the cycle.
*/
}
#ifdef DEBUG
(void) printf("[doflags] ");
(void) printf(
" inherits printflag %d and propfraction %f\n",
}
#endif /* DEBUG */
bool on_flist;
/*
* printflag is off
* it gets turned on by
* being on -f list,
* or there not being any -f list
* and not being on -e list.
*/
}
} else {
/*
* this function has printing parents:
* maybe someone wants to shut it up
* by putting it on -e list. (but favor -f
* over -e)
*/
}
}
/*
* no parents to pass time to.
* collect time from children if
* its on -F list,
* or there isn't any -F list and its not
* on -E list.
*/
}
} else {
/*
* it has parents to pass time to,
* but maybe someone wants to shut it up
* by putting it on -E list. (but favor -F
* over -E)
*/
if (check_parents(childp))
}
}
#ifdef DEBUG
(void) printf("[doflags] ");
(void) printf(" ends up with printflag %d and "
"propfraction %f\n",
(void) printf("time %f propself %f printtime %f\n",
}
#endif /* DEBUG */
}
}
nltype **
doarcs(void)
{
long i, index;
extern mod_info_t modules;
/*
* initialize various things:
* zero out child times.
* count self-recursive calls.
* indicate that nothing is on cycles.
*/
if (arcp != 0) {
} else {
}
/*
* Inspecting text space is valid only for
* the program executable.
*/
}
}
}
/*
* topologically order things
* if any node is unnumbered,
* number it and any of its descendents.
*/
}
}
}
/*
* link together nodes on the same cycle
*/
cyclelink();
/*
* Sort the symbol tables in reverse topological order
*/
if (topsortnlp == (nltype **) 0) {
"[doarcs] ran out of memory for topo sorting\n");
}
index = 0;
}
#ifdef DEBUG
(void) printf("[doarcs] topological sort listing\n");
(void) printf("[doarcs] ");
(void) printf("\n");
}
}
#endif /* DEBUG */
/*
* starting from the topological top,
* propagate print flags to children.
* also, calculate propagation fractions.
* this happens before time propagation
* since time propagation uses the fractions.
*/
doflags();
/*
* starting from the topological bottom,
* propogate children times up to parents.
*/
dotime();
/*
* Now, sort by propself + propchild.
* sorting both the regular function names
* and cycle headers.
*/
sizeof (nltype *));
if (timesortnlp == (nltype **) 0) {
"%s: ran out of memory for sorting\n", whoami);
}
index = 0;
}
return (timesortnlp);
}