summaryrefslogtreecommitdiff
path: root/report.pl
blob: 35af9486d2d1db35fcef0499a915a185e1b53073 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#!/usr/bin/env perl

my $before_name = $ARGV[0];
my $after_name  = $ARGV[1];

if ($#ARGV != 1) {
    printf("usage: report.pl <before> <after>\n");
}

open(BEFORE, $before_name) or die;
open(AFTER, $after_name) or die;

my %before = ();
my %after = ();

my $total_programs_before;

while (<BEFORE>) {
    my $line = $_;

    $line =~ /(.*):(.*)/;

    $before{$1} = $2;
    $total_programs_before++;
}

while (<AFTER>) {
    my $line = $_;

    $line =~ /(.*):(.*)/;

    $after{$1} = $2;
}

delete $before{"total"};
delete $after{"total"};

my $total_instructions_before = 0;
my $total_instructions_after = 0;
my $affected_programs_before = 0;
my $affected_instructions_before = 0;
my $affected_instructions_after = 0;

my %hurt_programs = ();

while (my ($prog, $before_count) = each(%before)) {
    my $after_count = $after{$prog};
    if ($after_count == "") {
	next;
    }

    $total_instructions_before += $before_count;
    $total_instructions_after += $after_count;

    if ($before_count == $after_count) {
	next;
    }

    if ($after_count > $before_count) {
	$hurt_programs{$prog} = 1;
    }

    printf("%s: %4d -> %4d\n",
	   $prog, $before_count, $after_count);

    $affected_instructions_before += $before_count;
    $affected_instructions_after += $after_count;

    $affected_programs_before++;
}

printf("\n");

printf("Total instructions: %d -> %d\n",
       $total_instructions_before, $total_instructions_after);

printf("%d/%d programs affected (%.1f%%)\n",
       $affected_programs_before, $total_programs_before,
    100 * $affected_programs_before / $total_programs_before);

if ($affected_instructions_after < $affected_instructions_before) {
    printf("%d -> %d instructions in affected programs (%.1f%% reduction)\n",
	   $affected_instructions_before,
	   $affected_instructions_after,
	   100 - (100 * $affected_instructions_after /
		  $affected_instructions_before));
}

if ($affected_instructions_after > $affected_instructions_before) {
    printf("%d -> %d instructions in affected programs (%.1f%% increase)\n",
	   $affected_instructions_before,
	   $affected_instructions_after,
	   (100 * $affected_instructions_after /
	    $affected_instructions_before) - 100);
}

my $header = 0;

if (keys(%hurt_programs) != 0) {
    printf("hurt programs:\n");

    while (my ($prog, $junk) = each(%hurt_programs)) {
	printf("%s\n", $prog);
    }
}