add True Audio (TTA) codec
[kugel-rb.git] / tools / profile_reader / profile_comparator.pl
blobda5e3004c901186190860b0ceac5e225569f8f1c
1 #!/usr/bin/perl
2 sub error {
3 print("Error: @_\n");
4 exit(1);
6 sub usage {
7 if (@_) {
8 print STDERR ("Error: @_\n");
10 print STDERR ("USAGE:\n");
11 print STDERR ("$0 file1 file2 [showcalldiff]\n");
12 print STDERR
13 ("\tfile[12] output from profile_reader.pl to compare\n");
14 print STDERR
15 ("\tshowcalldiff show the percent change in calls instead of ticks\n");
16 exit(1);
18 if ($ARGV[0] =~ m/-(h|help|-help)/) {
19 usage();
21 if (@ARGV < 2) {
22 usage("Requires at least 2 arguments");
24 open(FILE1,shift) || error("Couldn't open file1");
25 my @file1 = <FILE1>;
26 close(FILE1);
27 open(FILE2,shift) || error("Couldn't open file2");
28 my @file2 = <FILE2>;
29 close(FILE2);
30 my $showcalldiff = shift;
31 my %calls1;
32 my %calls2;
33 my @calls = (\%calls1,\%calls2);
34 my $start = 0;
35 my @files = (\@file1,\@file2);
36 my @allcalls = (0,0);
37 my @allticks = (0,0);
38 for ( $i=0; $i <= $#files; $i++ ) {
39 my $file = $files[$i];
40 foreach $line(@$file) {
41 chomp($line);
42 if ( $line =~ m/By calls/ ) {
43 $start = 1;
44 next;
46 if ( $line =~ m/By ticks/ ) {
47 $start = 0;
48 last;
50 if ( $start == 1) {
51 my @line = split(/[[:space:]]+/,$line);
52 $allcalls[$i] += $line[1];
53 $allticks[$i] += $line[3];
54 $calls[$i]{$line[5]} = [($line[1],$line[3])];
58 printf("File one calls: %08ld, ticks: %08ld\n",$allcalls[0],$allticks[0]);
59 printf("File two calls: %08ld, ticks: %08ld\n",$allcalls[1],$allticks[1]);
60 printf("Percent change: %+7.2f%%, ticks: %+7.2f%%\n",
61 ($allcalls[1]-$allcalls[0])/$allcalls[0]*100,
62 ($allticks[1]-$allticks[0])/$allticks[0]*100);
63 my @allkeys = keys(%calls1);
64 push(@allkeys,keys(%calls2));
65 my %u = ();
66 my @keys = grep {defined} map {
67 if (exists $u{$_}) { undef; } else { $u{$_}=undef;$_; }
68 } @allkeys;
69 undef %u;
70 my %byticks;
71 my %bycalls;
72 foreach $key(@keys) {
73 my $values1 = $calls1{$key};
74 my $values2 = $calls2{$key};
75 my $calldiff = @$values2[0]-@$values1[0];
76 my $totalcalls = @$values2[0]+@$values1[0];
77 my $tickdiff = @$values2[1]-@$values1[1];
78 my $totalticks = @$values2[1]+@$values1[1];
79 my $pdiff;
80 my $result;
81 if ($showcalldiff) {
82 $pdiff = $calldiff/(@$values1[0]>0?@$values1[0]:1)*100;
83 $result = sprintf("%+7.2f%% Calls: %+09d Symbol: %s$key\n",
84 $pdiff, $calldiff,
85 (exists $calls1{$key} && exists $calls2{$key})?"":"LONE ");
86 } else {
87 $pdiff = $tickdiff/(@$values1[1]>0?@$values1[1]:1)*100;
88 $result = sprintf("%+7.2f%% Ticks: %+09d Symbol: %s$key\n",
89 $pdiff, $tickdiff,
90 (exists $calls1{$key} && exists $calls2{$key})?"":"LONE ");
92 $bycalls{sprintf("%08X$key",$totalcalls)} = $result;
93 $byticks{sprintf("%08X$key",$totalticks)} = $result;
95 my @calls = sort(keys(%bycalls));
96 print("By calls\n");
97 foreach $call(@calls) {
98 print($bycalls{$call});
100 my @ticks = sort(keys(%byticks));
101 print("By ticks\n");
102 foreach $tick(@ticks) {
103 print($byticks{$tick});