1*cdf0e10cSrcweir#!/usr/bin/perl -w 2*cdf0e10cSrcweir# 3*cdf0e10cSrcweir# $Id: gcov_resultinterpreter.pl,v 1.3 2005-11-02 17:24:12 kz Exp $ 4*cdf0e10cSrcweir# 5*cdf0e10cSrcweir 6*cdf0e10cSrcweir# GCOV_RESULTINTERPRETER 7*cdf0e10cSrcweir# 8*cdf0e10cSrcweir# Helper, to interpret the result 9*cdf0e10cSrcweir# 10*cdf0e10cSrcweir# Q: Why perl? 11*cdf0e10cSrcweir# A: regexp ;-) 12*cdf0e10cSrcweir# 13*cdf0e10cSrcweir 14*cdf0e10cSrcweiruse strict; 15*cdf0e10cSrcweiruse File::Basename; 16*cdf0e10cSrcweiruse Getopt::Long; 17*cdf0e10cSrcweir 18*cdf0e10cSrcweirour $version_info = 'gcov helper $Revision: 1.3 $ '; 19*cdf0e10cSrcweir 20*cdf0e10cSrcweirour $help; # Help option flag 21*cdf0e10cSrcweirour $version; # Version option flag 22*cdf0e10cSrcweir# our $infile; 23*cdf0e10cSrcweir 24*cdf0e10cSrcweirour $usedFunctions; # show all functions, which have a value > 0 25*cdf0e10cSrcweirour $nonusedFunctions; # show all functions, which have a value == 0 26*cdf0e10cSrcweirour $nPercent; # show all functions, which have a value > $nPercent 27*cdf0e10cSrcweirour $complete; # show all functions, which have a value == 100 28*cdf0e10cSrcweirour $incomplete; # show all functions, which have a value > 0 && < 100 29*cdf0e10cSrcweir 30*cdf0e10cSrcweir# Prototypes 31*cdf0e10cSrcweirsub print_usage(*); 32*cdf0e10cSrcweirsub read_gcov_function_file($); 33*cdf0e10cSrcweir 34*cdf0e10cSrcweir# Parse command line options 35*cdf0e10cSrcweirif (!GetOptions( 36*cdf0e10cSrcweir "usedfunctions" => \$usedFunctions, 37*cdf0e10cSrcweir "nonusedfunctions" => \$nonusedFunctions, 38*cdf0e10cSrcweir "percent=s" => \$nPercent, 39*cdf0e10cSrcweir "complete" => \$complete, 40*cdf0e10cSrcweir "incomplete" => \$incomplete, 41*cdf0e10cSrcweir "help" => \$help, 42*cdf0e10cSrcweir "version" => \$version 43*cdf0e10cSrcweir )) 44*cdf0e10cSrcweir{ 45*cdf0e10cSrcweir print_usage(*STDERR); 46*cdf0e10cSrcweir exit(1); 47*cdf0e10cSrcweir} 48*cdf0e10cSrcweir 49*cdf0e10cSrcweir# Check for help option 50*cdf0e10cSrcweirif ($help) 51*cdf0e10cSrcweir{ 52*cdf0e10cSrcweir print_usage(*STDOUT); 53*cdf0e10cSrcweir exit(0); 54*cdf0e10cSrcweir} 55*cdf0e10cSrcweir 56*cdf0e10cSrcweir# Check for version option 57*cdf0e10cSrcweirif ($version) 58*cdf0e10cSrcweir{ 59*cdf0e10cSrcweir print("$version_info\n"); 60*cdf0e10cSrcweir exit(0); 61*cdf0e10cSrcweir} 62*cdf0e10cSrcweir 63*cdf0e10cSrcweir# check if enough parameters 64*cdf0e10cSrcweirif ($#ARGV < 0) 65*cdf0e10cSrcweir{ 66*cdf0e10cSrcweir print("No input filename specified\n"); 67*cdf0e10cSrcweir print_usage(*STDERR); 68*cdf0e10cSrcweir exit(1); 69*cdf0e10cSrcweir} 70*cdf0e10cSrcweir 71*cdf0e10cSrcweirif ($complete) 72*cdf0e10cSrcweir{ 73*cdf0e10cSrcweir $nPercent = 100.00; 74*cdf0e10cSrcweir} 75*cdf0e10cSrcweir# ------------------------------------------------------------------------------ 76*cdf0e10cSrcweir 77*cdf0e10cSrcweirmy %list = read_gcov_function_file($ARGV[0]); 78*cdf0e10cSrcweir 79*cdf0e10cSrcweirmy $key; 80*cdf0e10cSrcweirmy $value; 81*cdf0e10cSrcweir 82*cdf0e10cSrcweirwhile (($key, $value) = each %list) 83*cdf0e10cSrcweir{ 84*cdf0e10cSrcweir # print "function: $key = $value\n"; 85*cdf0e10cSrcweir if ($nonusedFunctions) 86*cdf0e10cSrcweir { 87*cdf0e10cSrcweir if ($value <= 0.00) 88*cdf0e10cSrcweir { 89*cdf0e10cSrcweir print "$key\n"; 90*cdf0e10cSrcweir } 91*cdf0e10cSrcweir } 92*cdf0e10cSrcweir elsif ($usedFunctions) 93*cdf0e10cSrcweir { 94*cdf0e10cSrcweir if ($value != 0.00) 95*cdf0e10cSrcweir { 96*cdf0e10cSrcweir print "$key, $value\n"; 97*cdf0e10cSrcweir } 98*cdf0e10cSrcweir } 99*cdf0e10cSrcweir elsif ($nPercent) 100*cdf0e10cSrcweir { 101*cdf0e10cSrcweir if ($value >= $nPercent) 102*cdf0e10cSrcweir { 103*cdf0e10cSrcweir print "$key, $value\n"; 104*cdf0e10cSrcweir } 105*cdf0e10cSrcweir } 106*cdf0e10cSrcweir elsif ($incomplete) 107*cdf0e10cSrcweir { 108*cdf0e10cSrcweir if ($value > 0.00 && $value < 100.00) 109*cdf0e10cSrcweir { 110*cdf0e10cSrcweir print "$key, $value\n"; 111*cdf0e10cSrcweir } 112*cdf0e10cSrcweir } 113*cdf0e10cSrcweir else 114*cdf0e10cSrcweir { 115*cdf0e10cSrcweir print "$key, $value\n"; 116*cdf0e10cSrcweir } 117*cdf0e10cSrcweir} 118*cdf0e10cSrcweir 119*cdf0e10cSrcweir# -------------------------------------------------------------------------------- 120*cdf0e10cSrcweir# Read the gcov function (gcov -f) file 121*cdf0e10cSrcweir# and compare line by line with the export function list 122*cdf0e10cSrcweir# so we get a list of functions, which are only exported, and not all stuff. 123*cdf0e10cSrcweir 124*cdf0e10cSrcweirsub read_gcov_function_file($) 125*cdf0e10cSrcweir{ 126*cdf0e10cSrcweir local *INPUT_HANDLE; 127*cdf0e10cSrcweir my $file = $_[0]; 128*cdf0e10cSrcweir my %list; 129*cdf0e10cSrcweir my $line = ""; 130*cdf0e10cSrcweir 131*cdf0e10cSrcweir open(INPUT_HANDLE, $file) 132*cdf0e10cSrcweir or die("ERROR: cannot open $file!\n"); 133*cdf0e10cSrcweir 134*cdf0e10cSrcweir while ($line = <INPUT_HANDLE>) 135*cdf0e10cSrcweir { 136*cdf0e10cSrcweir chomp($line); 137*cdf0e10cSrcweir # sample line (for reg exp:) 138*cdf0e10cSrcweir # 100.00 rtl_ustr_toDouble 139*cdf0e10cSrcweir if ($line =~ /^(.*) (\w+)$/ ) 140*cdf0e10cSrcweir { 141*cdf0e10cSrcweir my $percent = $1; 142*cdf0e10cSrcweir my $value = $2; 143*cdf0e10cSrcweir 144*cdf0e10cSrcweir $list{$value} = $percent; 145*cdf0e10cSrcweir } 146*cdf0e10cSrcweir } 147*cdf0e10cSrcweir close(INPUT_HANDLE); 148*cdf0e10cSrcweir return %list; 149*cdf0e10cSrcweir} 150*cdf0e10cSrcweir 151*cdf0e10cSrcweir# ---------------------------------------------------------------------------- 152*cdf0e10cSrcweirsub print_usage(*) 153*cdf0e10cSrcweir{ 154*cdf0e10cSrcweir local *HANDLE = $_[0]; 155*cdf0e10cSrcweir my $tool_name = basename($0); 156*cdf0e10cSrcweir 157*cdf0e10cSrcweir print(HANDLE <<END_OF_USAGE); 158*cdf0e10cSrcweir 159*cdf0e10cSrcweirUsage: $tool_name [OPTIONS] INPUTFILE 160*cdf0e10cSrcweir 161*cdf0e10cSrcweir -u, --usedFunctions show all functions, which have a value > 0 162*cdf0e10cSrcweir -n, --nonusedFunctions show all functions, which have a value == 0 163*cdf0e10cSrcweir -p, --percent show all functions, which have a value > percent 164*cdf0e10cSrcweir -c, --complete show all functions, which have a value == 100 165*cdf0e10cSrcweir -i, --incomplete show all functions, which have a value > 0 && < 100 166*cdf0e10cSrcweir 167*cdf0e10cSrcweir -h, --help Print this help, then exit 168*cdf0e10cSrcweir -v, --version Print version number, then exit 169*cdf0e10cSrcweir 170*cdf0e10cSrcweirEND_OF_USAGE 171*cdf0e10cSrcweir ; 172*cdf0e10cSrcweir} 173