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