do chmod last in install
[unix-history] / usr / src / usr.bin / gprof / arcs.c
index 5920c83..e787373 100644 (file)
@@ -1,43 +1,64 @@
 #ifndef lint
 #ifndef lint
-    static     char *sccsid = "@(#)arcs.c      1.2 (Berkeley) %G%";
+    static     char *sccsid = "@(#)arcs.c      1.5 (Berkeley) %G%";
 #endif lint
 
 #include "gprof.h"
 
 #endif lint
 
 #include "gprof.h"
 
-topcmp( npp1 , npp2 )
-    nltype     **npp1;
-    nltype     **npp2;
+    /*
+     * add (or just increment) an arc
+     */
+addarc( parentp , childp , count )
+    nltype     *parentp;
+    nltype     *childp;
+    long       count;
 {
 {
-    return (*npp1) -> toporder - (*npp2) -> toporder;
+    arctype            *calloc();
+    arctype            *arcp;
+
+#   ifdef DEBUG
+       if ( debug & TALLYDEBUG ) {
+           printf( "[addarc] %d arcs from %s to %s\n" ,
+                   count , parentp -> name , childp -> name );
+       }
+#   endif DEBUG
+    arcp = arclookup( parentp , childp );
+    if ( arcp != 0 ) {
+           /*
+            *  a hit:  just increment the count.
+            */
+#      ifdef DEBUG
+           if ( debug & TALLYDEBUG ) {
+               printf( "[tally] hit %d += %d\n" ,
+                       arcp -> arc_count , count );
+           }
+#      endif DEBUG
+       arcp -> arc_count += count;
+       return;
+    }
+    arcp = calloc( 1 , sizeof *arcp );
+    arcp -> arc_parentp = parentp;
+    arcp -> arc_childp = childp;
+    arcp -> arc_count = count;
+       /*
+        *      prepend this child to the children of this parent
+        */
+    arcp -> arc_childlist = parentp -> children;
+    parentp -> children = arcp;
+       /*
+        *      prepend this parent to the parents of this child
+        */
+    arcp -> arc_parentlist = childp -> parents;
+    childp -> parents = arcp;
 }
 
 }
 
-    /*
-     * sort by decreasing total time (time+childtime)
-     * if times are equal, but one is a cycle header,
-     * say that's first (e.g. less)
-     */
-int
-totalcmp( npp1 , npp2 )
+topcmp( npp1 , npp2 )
     nltype     **npp1;
     nltype     **npp2;
 {
     nltype     **npp1;
     nltype     **npp2;
 {
-    register nltype    *np1 = *npp1;
-    register nltype    *np2 = *npp2;
-    double             diff;
-
-    diff =    ( np1 -> time + np1 -> childtime )
-           - ( np2 -> time + np2 -> childtime );
-    if ( diff < 0.0 )
-           return 1;
-    if ( diff > 0.0 )
-           return -1;
-    if ( np1 -> name == 0 && np1 -> cycleno != 0 ) 
-       return -1;
-    if ( np2 -> name == 0 && np1 -> cycleno != 0 )
-       return 1;
-    return 0;
+    return (*npp1) -> toporder - (*npp2) -> toporder;
 }
 
 }
 
+
 doarcs()
 {
     nltype     *parentp;
 doarcs()
 {
     nltype     *parentp;
@@ -62,6 +83,9 @@ doarcs()
        } else {
            parentp -> selfcalls = 0;
        }
        } else {
            parentp -> selfcalls = 0;
        }
+       if ( cflag ) {
+           findcalls( parentp , parentp -> value , (parentp+1) -> value );
+       }
        parentp -> toporder = 0;
        parentp -> cycleno = 0;
        parentp -> cyclehead = parentp;
        parentp -> toporder = 0;
        parentp -> cycleno = 0;
        parentp -> cyclehead = parentp;