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