diff options
author | Brandon Low <lostlogic@rockbox.org> | 2006-01-18 20:54:13 +0000 |
---|---|---|
committer | Brandon Low <lostlogic@rockbox.org> | 2006-01-18 20:54:13 +0000 |
commit | 05dccc355144dc717b3cb9ef0074a9ab38a520f4 (patch) | |
tree | 0a36425cf1321817480a82ed05564a2790e2fca9 /tools/profile_reader/profile_comparator.pl | |
parent | 1060e447f83128a78dfaa8d59ba0baa642d15a4d (diff) | |
download | rockbox-05dccc355144dc717b3cb9ef0074a9ab38a520f4.tar.gz rockbox-05dccc355144dc717b3cb9ef0074a9ab38a520f4.zip |
Profiling support, tools and documentation.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@8375 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'tools/profile_reader/profile_comparator.pl')
-rwxr-xr-x | tools/profile_reader/profile_comparator.pl | 104 |
1 files changed, 104 insertions, 0 deletions
diff --git a/tools/profile_reader/profile_comparator.pl b/tools/profile_reader/profile_comparator.pl new file mode 100755 index 0000000000..da5e3004c9 --- /dev/null +++ b/tools/profile_reader/profile_comparator.pl | |||
@@ -0,0 +1,104 @@ | |||
1 | #!/usr/bin/perl | ||
2 | sub error { | ||
3 | print("Error: @_\n"); | ||
4 | exit(1); | ||
5 | } | ||
6 | sub usage { | ||
7 | if (@_) { | ||
8 | print STDERR ("Error: @_\n"); | ||
9 | } | ||
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); | ||
17 | } | ||
18 | if ($ARGV[0] =~ m/-(h|help|-help)/) { | ||
19 | usage(); | ||
20 | } | ||
21 | if (@ARGV < 2) { | ||
22 | usage("Requires at least 2 arguments"); | ||
23 | } | ||
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; | ||
45 | } | ||
46 | if ( $line =~ m/By ticks/ ) { | ||
47 | $start = 0; | ||
48 | last; | ||
49 | } | ||
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])]; | ||
55 | } | ||
56 | } | ||
57 | } | ||
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 "); | ||
91 | } | ||
92 | $bycalls{sprintf("%08X$key",$totalcalls)} = $result; | ||
93 | $byticks{sprintf("%08X$key",$totalticks)} = $result; | ||
94 | } | ||
95 | my @calls = sort(keys(%bycalls)); | ||
96 | print("By calls\n"); | ||
97 | foreach $call(@calls) { | ||
98 | print($bycalls{$call}); | ||
99 | } | ||
100 | my @ticks = sort(keys(%byticks)); | ||
101 | print("By ticks\n"); | ||
102 | foreach $tick(@ticks) { | ||
103 | print($byticks{$tick}); | ||
104 | } | ||