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