Bug 458256. Use LoadLibraryW instead of LoadLibrary (patch by DougT). r+sr=vlad
[wine-gecko.git] / tools / performance / startup / analyze-timeline-log.pl
blob11b4cd6f471de2fbaaf19d5af1bd1bef81f4eb96
2 # perl file to get a list of files that we load from a timeline log
4 # Usage: perl getlines.pl < timline.log > file.log
6 # Configuration options
8 # Set this option to take all timings only upto the main window being visible
9 # All activity beyond main window being visible is ignored.
10 # default is 0. We take timings upto main1 finish
11 $stopWithVisibleWindow = 0;
13 # dlls loaded
14 my @dlls = ();
15 # Files of a particular extensions
16 my %ext = ();
17 # Number of files in a paticular extension. Used to sort them output by order of extension
18 my %extnum = ();
19 # List of all urls that either exist or are jar. Non dups.
20 my @allurls = ();
21 # List of nonexistent file urls
22 my @nonexistentfiles = ();
23 # Number of file urls
24 my $nfileurl = 0;
25 # Number of jar urls
26 my $njarurl = 0;
27 # Urls hash to figure out dups
28 my %seen = ();
29 # Number of dups per extension
30 my %extnumdups = ();
31 # interesting total times
32 my %breakdown = ();
33 # main1 cost
34 my $main1 = 0;
35 # when main window was visible
36 my $window = 0;
37 # pref files loaded
38 my @prefurl = ();
39 while (<>)
41 chomp;
43 # Computer breakdown of startup cost
44 if (/total:/) {
45 # This is a cumulative timer. Keep track of it.
46 /^[0-9\.: ]*(.*) total: ([0-9\.]*)/;
47 $breakdown{$1} = $2;
49 if (/InitXPCom\.\.\./) {
50 $breakdown{"Before InitXPCom"} = getTimelineStamp($_);
51 next;
53 if (/InitXPCOM done/) {
54 $breakdown{"InitXPCom"} = getTimelineStamp($_) - $breakdown{"Before InitXPCom"};
55 next;
58 # Find main1's cost to compute percentages
59 if (/\.\.\.main1/) {
60 $main1 = getTimelineStamp($_);
62 # find when we showed the window
63 if (/Navigator Window visible now/) {
64 $window = getTimelineStamp($_);
65 if ($stopWithVisibleWindow) {
66 $main1 = $window;
67 last;
71 # Find all files loaded
72 if (/PR_LoadLibrary/) {
73 my $dll = getdll($_);
74 push @dlls, $dll;
75 next;
77 if (/file:/) {
78 $url = getfileurl($_);
79 $e = getext($url);
80 if (!-f $url) {
81 push @nonexistentfiles, $url;
82 } else {
83 $seen{$url}++;
84 if ($seen{$url} > 1) {
85 $extnumdups{$e}++;
86 next;
88 push @allurls, $url;
89 if (exists $ext{$e}) {
90 $ext{$e} .= "---";
92 $ext{$e} .= $url;
93 $extnum{$e}++;
94 $nfileurl++;
96 next;
98 if (/jar:/) {
99 $url = getjarurl($_);
100 $e = getext($url);
101 $seen{$url}++;
102 if ($seen{$url} > 1) {
103 $extnumdups{$e}++;
104 next;
106 push @allurls, $url;
107 if (exists $ext{$e}) {
108 $ext{$e} .= "---";
110 $ext{$e} .= "$url";
111 $extnum{$e}++;
112 $njarurl++;
113 next;
115 if (/load pref file/) {
116 $url = getfile($_);
117 push @prefurl, $url;
121 # print results
122 print "SUMMARY\n";
123 print "----------------------------------------------------------------------\n";
124 print "Total startup time : $main1 sec\n";
125 printf "Main window visible: $window sec (%5.2f%%)\n", main1Percent($window);
126 print "dlls loaded : ", $#dlls+1, "\n";
127 print "Total unique: ", $#allurls+1, " [jar $njarurl, file $nfileurl]\n";
128 # print the # of files by extensions sorted
129 my @extsorted = sort { $extnum{$b} <=> $extnum{$a} } keys %extnum;
130 my $sep = " ";
131 foreach $i (@extsorted)
133 print "$sep.$i $extnum{$i}";
134 $sep = ", ";
136 print "\n";
137 # print number of dups per extension
138 my $sep = " dups: ";
139 foreach $i (@extsorted)
141 next unless exists($extnumdups{$i});
142 print "$sep.$i $extnumdups{$i}";
143 $sep = ", ";
145 print "\n";
146 print "Total non existent files : ", $#nonexistentfiles+1, "\n";
148 print "\n";
149 print "Cost Breakdown\n";
150 print "----------------------------------------------------------------------\n";
151 # sort by descending order of breakdown cost
152 my @breakdownsorted = sort { $breakdown{$b} <=> $breakdown{$a} } keys %breakdown;
153 my $totalAccounted = 0;
154 foreach $e (@breakdownsorted)
156 # ignore these breakdowns as they are already counted otherwise
157 next if ($e =~ /nsNativeComponentLoader::GetFactory/);
158 my $p = main1Percent($breakdown{$e});
159 #next if ($p == 0);
160 printf "%6.2f%% %s\n", $p, $e;
161 $totalAccounted += $p;
163 print "----------------------\n";
164 printf "%6.2f%% Total Accounted\n", $totalAccounted;
166 print "\n";
167 printf "[%d] List of dlls loaded:\n", $#dlls+1;
168 print "----------------------------------------------------------------------\n";
169 my $n = 1;
170 foreach $e (@dlls)
172 printf "%2d. %s\n", $n++, $e;
175 print "\n";
176 printf "[%d] List of existing unique files and jar urls by extension:\n", $#allurls+1;
177 print "----------------------------------------------------------------------\n";
178 foreach $e (@extsorted)
180 $n = 1;
181 print "[$extnum{$e}] .$e\n";
182 foreach $i (split("---", $ext{$e})) {
183 printf "%2d. %s", $n++, $i;
184 if ($seen{$i} > 1) {
185 printf " [%d]", $seen{$i}-1;
187 printf "\n";
189 print "\n";
191 #foreach $i (@allurls)
193 # printf "%2d. %s\n", $n++, $i;
196 print "\n";
197 printf "[%d] List of non existent file urls:\n", $#nonexistentfiles+1;
198 print "----------------------------------------------------------------------\n";
199 my $n = 1;
200 foreach $i (@nonexistentfiles)
202 printf "%2d. %s\n", $n++, $i;
205 # print prefs loaded
206 print "\n";
207 printf "[%d] List of pref files loaded:\n", $#prefurl+1;
208 print "----------------------------------------------------------------------\n";
209 $n = 1;
210 foreach $i (@prefurl)
212 printf "%2d. %s\n", $n++, $i;
215 # Subrouties
216 sub getTimelineStamp() {
217 my $line = shift;
218 $line =~ /^([0-9\.]*)/;
219 return $1+0;
222 sub getfileurl() {
223 my $f = shift;
224 $f =~ s/^.*file:\/*(.*)\).*$/\1/;
225 # unescape the url
226 $f =~ s/\|/:/;
227 $f =~ s/\%20/ /g;
228 return $f;
231 sub getjarurl() {
232 my $f = shift;
233 $f =~ s/^.*(jar:.*)\).*$/\1/;
234 return $f;
237 sub getdll() {
238 my $f = shift;
239 $f =~ s/^.*\((.*)\).*$/\1/;
240 return $f;
243 sub getext() {
244 my $f = shift;
245 $f =~ s/^.*\.([^\.]*)$/\1/;
246 return $f;
249 sub getfile() {
250 my $f = shift;
251 $f =~ s/^.*\((.*)\)$/\1/;
252 return $f;
255 # what % is this of startup
256 sub main1Percent() {
257 my $i = shift;
258 return $i/$main1 * 100;