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