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_RESULTCOMPARE 24cdf0e10cSrcweir# 25cdf0e10cSrcweir# Helper, to compare two different results 26cdf0e10cSrcweir# 27cdf0e10cSrcweir# Q: Why perl? 28cdf0e10cSrcweir# A: regexp ;-) 29cdf0e10cSrcweir# 30cdf0e10cSrcweir 31cdf0e10cSrcweiruse strict; 32cdf0e10cSrcweiruse File::Basename; 33cdf0e10cSrcweiruse Getopt::Long; 34cdf0e10cSrcweir 35cdf0e10cSrcweirour $version_info = 'gcov_resultcompare $Revision: 1.2 $ '; 36cdf0e10cSrcweir 37cdf0e10cSrcweirour $help; # Help option flag 38cdf0e10cSrcweirour $version; # Version option flag 39cdf0e10cSrcweir# our $infile; 40cdf0e10cSrcweir 41cdf0e10cSrcweirour $orig; 42cdf0e10cSrcweirour $compare; 43cdf0e10cSrcweir 44cdf0e10cSrcweir# Prototypes 45cdf0e10cSrcweirsub print_usage(*); 46cdf0e10cSrcweirsub read_gcov_function_file($); 47cdf0e10cSrcweir 48cdf0e10cSrcweir# Parse command line options 49cdf0e10cSrcweirif (!GetOptions( 50cdf0e10cSrcweir "o=s" => \$orig, 51cdf0e10cSrcweir "c=s" => \$compare, 52cdf0e10cSrcweir "help" => \$help, 53cdf0e10cSrcweir "version" => \$version 54cdf0e10cSrcweir )) 55cdf0e10cSrcweir{ 56cdf0e10cSrcweir print_usage(*STDERR); 57cdf0e10cSrcweir exit(1); 58cdf0e10cSrcweir} 59cdf0e10cSrcweir 60cdf0e10cSrcweir# Check for help option 61cdf0e10cSrcweirif ($help) 62cdf0e10cSrcweir{ 63cdf0e10cSrcweir print_usage(*STDOUT); 64cdf0e10cSrcweir exit(0); 65cdf0e10cSrcweir} 66cdf0e10cSrcweir 67cdf0e10cSrcweir# Check for version option 68cdf0e10cSrcweirif ($version) 69cdf0e10cSrcweir{ 70cdf0e10cSrcweir print("$version_info\n"); 71cdf0e10cSrcweir exit(0); 72cdf0e10cSrcweir} 73cdf0e10cSrcweir 74cdf0e10cSrcweir# check if enough parameters 75cdf0e10cSrcweir# if ($#ARGV < 1) 76cdf0e10cSrcweir# { 77cdf0e10cSrcweir# print("No input filenames specified\n"); 78cdf0e10cSrcweir# print_usage(*STDERR); 79cdf0e10cSrcweir# exit(1); 80cdf0e10cSrcweir# } 81cdf0e10cSrcweir 82cdf0e10cSrcweirif (! $orig) 83cdf0e10cSrcweir{ 84cdf0e10cSrcweir print_usage(*STDOUT); 85cdf0e10cSrcweir exit(0); 86cdf0e10cSrcweir} 87cdf0e10cSrcweirif (! $compare) 88cdf0e10cSrcweir{ 89cdf0e10cSrcweir print_usage(*STDOUT); 90cdf0e10cSrcweir exit(0); 91cdf0e10cSrcweir} 92cdf0e10cSrcweir 93cdf0e10cSrcweir# ------------------------------------------------------------------------------ 94cdf0e10cSrcweir 95cdf0e10cSrcweirmy %origlist = read_gcov_function_file($orig); 96cdf0e10cSrcweirmy %cmplist = read_gcov_function_file($compare); 97cdf0e10cSrcweir 98cdf0e10cSrcweirmy $key; 99cdf0e10cSrcweirmy $value; 100cdf0e10cSrcweir 101cdf0e10cSrcweirwhile (($key, $value) = each %origlist) 102cdf0e10cSrcweir{ 103cdf0e10cSrcweir my $cmpvalue = $cmplist{$key}; 104cdf0e10cSrcweir 105cdf0e10cSrcweir if ($cmpvalue != 0.00) 106cdf0e10cSrcweir { 107cdf0e10cSrcweir if ($value < 100.00) 108cdf0e10cSrcweir { 109cdf0e10cSrcweir if ($cmpvalue > $value && $value < 90.0) 110cdf0e10cSrcweir { 111cdf0e10cSrcweir print "$key, $value, CMP:$cmpvalue\n"; 112cdf0e10cSrcweir } 113cdf0e10cSrcweir } 114cdf0e10cSrcweir } 115cdf0e10cSrcweir} 116cdf0e10cSrcweir 117cdf0e10cSrcweir# -------------------------------------------------------------------------------- 118cdf0e10cSrcweir# Read the gcov function (gcov -f) file 119cdf0e10cSrcweir# and compare line by line with the export function list 120cdf0e10cSrcweir# so we get a list of functions, which are only exported, and not all stuff. 121cdf0e10cSrcweir 122cdf0e10cSrcweirsub read_gcov_function_file($) 123cdf0e10cSrcweir{ 124cdf0e10cSrcweir local *INPUT_HANDLE; 125cdf0e10cSrcweir my $file = shift; 126cdf0e10cSrcweir my %list; 127cdf0e10cSrcweir my $line = ""; 128cdf0e10cSrcweir 129cdf0e10cSrcweir open(INPUT_HANDLE, $file) 130cdf0e10cSrcweir or die("ERROR: cannot open $file!\n"); 131cdf0e10cSrcweir 132cdf0e10cSrcweir while ($line = <INPUT_HANDLE>) 133cdf0e10cSrcweir { 134cdf0e10cSrcweir chomp($line); 135cdf0e10cSrcweir # sample line (for reg exp:) 136cdf0e10cSrcweir # 100.00 rtl_ustr_toDouble 137cdf0e10cSrcweir if ($line =~ /^(.{6}) (\w+)$/ ) 138cdf0e10cSrcweir { 139cdf0e10cSrcweir my $percent = $1; 140cdf0e10cSrcweir my $value = $2; 141cdf0e10cSrcweir 142cdf0e10cSrcweir $list{$value} = $percent; 143cdf0e10cSrcweir } 144cdf0e10cSrcweir } 145cdf0e10cSrcweir close(INPUT_HANDLE); 146cdf0e10cSrcweir return %list; 147cdf0e10cSrcweir} 148cdf0e10cSrcweir 149cdf0e10cSrcweir# ---------------------------------------------------------------------------- 150cdf0e10cSrcweirsub print_usage(*) 151cdf0e10cSrcweir{ 152cdf0e10cSrcweir local *HANDLE = $_[0]; 153cdf0e10cSrcweir my $tool_name = basename($0); 154cdf0e10cSrcweir 155cdf0e10cSrcweir print(HANDLE <<END_OF_USAGE); 156cdf0e10cSrcweir 157cdf0e10cSrcweirUsage: $tool_name [OPTIONS] INPUTFILE 158cdf0e10cSrcweir 159cdf0e10cSrcweir -o Original File, which gives the main values 160cdf0e10cSrcweir if here a value is smaller than in compare, the found value is a candidate for better check. 161cdf0e10cSrcweir -c Compare file. 162cdf0e10cSrcweir 163cdf0e10cSrcweir -h, --help Print this help, then exit 164cdf0e10cSrcweir -v, --version Print version number, then exit 165cdf0e10cSrcweir 166cdf0e10cSrcweirEND_OF_USAGE 167cdf0e10cSrcweir ; 168cdf0e10cSrcweir} 169