Update contrib.
1 # Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
3 # This component and the accompanying materials are made available
4 # under the terms of the License "Eclipse Public License v1.0"
5 # which accompanies this distribution, and is available
6 # at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 # Initial Contributors:
9 # Nokia Corporation - initial contribution.
14 # e32utils\trace\btrace_syslock.pl
15 # Process runtests btrace log file to determine the maximum time the system
17 # Example commands to generate a runtests btrace log file with system lock
18 # tracing analysis when running e32test.auto.bat and 10MB btrace buffer:
19 # 1 - btrace -f4,17 -m1 -b10480
20 # 2 - runtests e32test.auto.bat -a OR use
22 # after running what ever is being tested
24 # perl btrace_syslock.pl <inputfile> [<symbolfile> [<maxsymbols]]
25 # If <maxsymbols> is given, this is how many of the last (i.e. slowest)
26 # results to look up in the symbol file. Defaults to 1.
33 my $oldfh = select(STDERR); $| = 1; select($oldfh);
35 print STDERR "\nTHIS TOOL IS UNOFFICIAL, UNSUPPORTED AND SUBJECT TO CHANGE WITHOUT NOTICE!\n\n";
38 my $usage = "$0: usage: perl $0 <logfile> [<symbolfile> [<maxsymbols>]]\n";
40 my ($infile, $symbolfile, $howmany) = @ARGV;
42 die($usage) if !($infile && -f $infile) || ($symbolfile && ! -f $symbolfile);
44 my $symbols = new SymbolTable($symbolfile);
46 open(my $in, "<", $infile) || die("$0: $infile: $!\n");
57 if (/BTRACE BUFFER IS FULL/)
62 if (/^RUNTESTS: Test/)
64 $testnames->{$lockinfo} = $_ if $lockinfo;
68 if (/^<FM/ && /System lock/i)
72 $bufferfulls++ if $berror;
78 @wanted = sort @wanted;
83 $howmany = 1 if $howmany < 1;
84 $howmany = scalar(@wanted) if $howmany > scalar(@wanted);
86 print @wanted[0 .. $#wanted - $howmany];
88 for my $line (@wanted[$#wanted - $howmany + 1 .. $#wanted])
92 # MaxTime AveTime HeldCount MaxPC MaxTimestamp TraceId Name
93 # <FM000000> 71 7 104631 f8023ddc 300257957 640005a4 'Sys
95 my @fields = split(" ", $line);
96 my $maxpc = $fields[4];
99 $symbols->lookup($maxpc);
102 $testnames->{$line} if $testnames->{$line};
110 printf(STDERR "%d buffer %s found\n", $bufferfulls,
111 $bufferfulls == 1 ? "overflow was" : "overflows were") if $bufferfulls;
114 # ========================================================================
120 my ($proto, $filename) = @_;
122 return undef if ! $filename;
126 open(my $in, "<", $filename) || die("$0: $filename: $!\n");
128 print STDERR "Loading symbols...";
132 # f800c040 0000 btrace_fiq k_entry_.o(.emb_text)
133 if (/^[0-9a-f]{8}\s/i) # Have a symbol table entry
135 # Ensure the address is in lowercase
136 $_ = lc(substr($_, 0, 8)) . substr($_, 8);
143 my $symbols = [sort @symbols];
145 my $class = ref($proto) || $proto;
147 bless($symbols, $class);
149 print STDERR " done\n";
154 # lookup() is an implementation of the binary search algorithm below,
155 # retrieved from wikipedia on 10/9/07
157 # BinarySearch(A[0..N-1], value) {
160 # while (low <= high) {
161 # mid = (low + high) / 2
162 # if (A[mid] > value)
164 # else if (A[mid] < value)
174 my ($symbols, $addr) = @_;
176 return "BAD ADDRESS $addr\n" unless $addr =~ /^[0-9a-f]{8}$/i;
179 my ($low, $high) = (0, $#$symbols);
181 while ($low <= $high)
183 my $mid = int(($low + $high) / 2);
184 my $mid_value = substr($symbols->[$mid], 0, 8);
185 ## print "low: $low, high: $high, mid: $mid, mid_value: $mid_value\n";
186 if ($mid_value gt $addr)
190 elsif ($mid_value lt $addr)
196 # Found an exact match
197 return($symbols->[$mid]);
201 # We didn't find an exact match. We want the largest value that is
202 # less than the input address. This will be the value at either
205 return $symbols->[$low] if $low <= $#$symbols &&
206 $symbols->[$low] lt $addr;
207 return "NO SYMBOL FOUND\n" if $high < 0;
208 return $symbols->[$high] if $symbols->[$high] lt $addr;
209 return "THIS SHOULDN'T HAPPEN\n";