1#!/usr/bin/perl -w 2# ************************************************************* 3# 4# Licensed to the Apache Software Foundation (ASF) under one 5# or more contributor license agreements. See the NOTICE file 6# distributed with this work for additional information 7# regarding copyright ownership. The ASF licenses this file 8# to you under the Apache License, Version 2.0 (the 9# "License"); you may not use this file except in compliance 10# with the License. You may obtain a copy of the License at 11# 12# http://www.apache.org/licenses/LICENSE-2.0 13# 14# Unless required by applicable law or agreed to in writing, 15# software distributed under the License is distributed on an 16# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17# KIND, either express or implied. See the License for the 18# specific language governing permissions and limitations 19# under the License. 20# 21# ************************************************************* 22# 23# $Id: gcov_resultinterpreter.pl,v 1.3 2005-11-02 17:24:12 kz Exp $ 24# 25 26# GCOV_RESULTINTERPRETER 27# 28# Helper, to interpret the result 29# 30# Q: Why perl? 31# A: regexp ;-) 32# 33 34use strict; 35use File::Basename; 36use Getopt::Long; 37 38our $version_info = 'gcov helper $Revision: 1.3 $ '; 39 40our $help; # Help option flag 41our $version; # Version option flag 42# our $infile; 43 44our $usedFunctions; # show all functions, which have a value > 0 45our $nonusedFunctions; # show all functions, which have a value == 0 46our $nPercent; # show all functions, which have a value > $nPercent 47our $complete; # show all functions, which have a value == 100 48our $incomplete; # show all functions, which have a value > 0 && < 100 49 50# Prototypes 51sub print_usage(*); 52sub read_gcov_function_file($); 53 54# Parse command line options 55if (!GetOptions( 56 "usedfunctions" => \$usedFunctions, 57 "nonusedfunctions" => \$nonusedFunctions, 58 "percent=s" => \$nPercent, 59 "complete" => \$complete, 60 "incomplete" => \$incomplete, 61 "help" => \$help, 62 "version" => \$version 63 )) 64{ 65 print_usage(*STDERR); 66 exit(1); 67} 68 69# Check for help option 70if ($help) 71{ 72 print_usage(*STDOUT); 73 exit(0); 74} 75 76# Check for version option 77if ($version) 78{ 79 print("$version_info\n"); 80 exit(0); 81} 82 83# check if enough parameters 84if ($#ARGV < 0) 85{ 86 print("No input filename specified\n"); 87 print_usage(*STDERR); 88 exit(1); 89} 90 91if ($complete) 92{ 93 $nPercent = 100.00; 94} 95# ------------------------------------------------------------------------------ 96 97my %list = read_gcov_function_file($ARGV[0]); 98 99my $key; 100my $value; 101 102while (($key, $value) = each %list) 103{ 104 # print "function: $key = $value\n"; 105 if ($nonusedFunctions) 106 { 107 if ($value <= 0.00) 108 { 109 print "$key\n"; 110 } 111 } 112 elsif ($usedFunctions) 113 { 114 if ($value != 0.00) 115 { 116 print "$key, $value\n"; 117 } 118 } 119 elsif ($nPercent) 120 { 121 if ($value >= $nPercent) 122 { 123 print "$key, $value\n"; 124 } 125 } 126 elsif ($incomplete) 127 { 128 if ($value > 0.00 && $value < 100.00) 129 { 130 print "$key, $value\n"; 131 } 132 } 133 else 134 { 135 print "$key, $value\n"; 136 } 137} 138 139# -------------------------------------------------------------------------------- 140# Read the gcov function (gcov -f) file 141# and compare line by line with the export function list 142# so we get a list of functions, which are only exported, and not all stuff. 143 144sub read_gcov_function_file($) 145{ 146 local *INPUT_HANDLE; 147 my $file = $_[0]; 148 my %list; 149 my $line = ""; 150 151 open(INPUT_HANDLE, $file) 152 or die("ERROR: cannot open $file!\n"); 153 154 while ($line = <INPUT_HANDLE>) 155 { 156 chomp($line); 157 # sample line (for reg exp:) 158 # 100.00 rtl_ustr_toDouble 159 if ($line =~ /^(.*) (\w+)$/ ) 160 { 161 my $percent = $1; 162 my $value = $2; 163 164 $list{$value} = $percent; 165 } 166 } 167 close(INPUT_HANDLE); 168 return %list; 169} 170 171# ---------------------------------------------------------------------------- 172sub print_usage(*) 173{ 174 local *HANDLE = $_[0]; 175 my $tool_name = basename($0); 176 177 print(HANDLE <<END_OF_USAGE); 178 179Usage: $tool_name [OPTIONS] INPUTFILE 180 181 -u, --usedFunctions show all functions, which have a value > 0 182 -n, --nonusedFunctions show all functions, which have a value == 0 183 -p, --percent show all functions, which have a value > percent 184 -c, --complete show all functions, which have a value == 100 185 -i, --incomplete show all functions, which have a value > 0 && < 100 186 187 -h, --help Print this help, then exit 188 -v, --version Print version number, then exit 189 190END_OF_USAGE 191 ; 192} 193