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