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