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