#!/usr/bin/perl -n
#
#  $Id: trussfunccount,v 1.1 2002/07/12 05:26:28 dgregor Exp $
#
# A quick script for use with "truss -u a.out" to count function
# calls.  Useful for debugging why programs are slow when they are
# calling functions with poor performance like str[fp]time hundreds
# of times a second. 
#

chomp();

#m/^(\s+)(->)/ || m/^(\s+)(<-)/ || next;
#$num = length($1) / 2;
#$dir = $2;

m/(->)/ || m/(<-)/ || next;
$dir = $1;
m/^( +)/;
$num = length($1) / 2;

if ($dir eq "->") {
        $counts{$num} = 0;
#       foreach $i (1 .. $num - 1) {
#               $counts{$i}++;
#       }

        print "$_\n";
} else {
        print "$_ (made $counts{$num} calls)\n";
        $counts{$num - 1} += $counts{$num} + 1;
}

