forked from mozilla/gecko-dev
-
Notifications
You must be signed in to change notification settings - Fork 2
/
analyze-timeline-log.pl
259 lines (241 loc) · 6.24 KB
/
analyze-timeline-log.pl
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
#
# perl file to get a list of files that we load from a timeline log
#
# Usage: perl getlines.pl < timline.log > file.log
# Configuration options
#
# Set this option to take all timings only upto the main window being visible
# All activity beyond main window being visible is ignored.
# default is 0. We take timings upto main1 finish
$stopWithVisibleWindow = 0;
# dlls loaded
my @dlls = ();
# Files of a particular extensions
my %ext = ();
# Number of files in a paticular extension. Used to sort them output by order of extension
my %extnum = ();
# List of all urls that either exist or are jar. Non dups.
my @allurls = ();
# List of nonexistent file urls
my @nonexistentfiles = ();
# Number of file urls
my $nfileurl = 0;
# Number of jar urls
my $njarurl = 0;
# Urls hash to figure out dups
my %seen = ();
# Number of dups per extension
my %extnumdups = ();
# interesting total times
my %breakdown = ();
# main1 cost
my $main1 = 0;
# when main window was visible
my $window = 0;
# pref files loaded
my @prefurl = ();
while (<>)
{
chomp;
# Computer breakdown of startup cost
if (/total:/) {
# This is a cumulative timer. Keep track of it.
/^[0-9\.: ]*(.*) total: ([0-9\.]*)/;
$breakdown{$1} = $2;
}
if (/InitXPCom\.\.\./) {
$breakdown{"Before InitXPCom"} = getTimelineStamp($_);
next;
}
if (/InitXPCOM done/) {
$breakdown{"InitXPCom"} = getTimelineStamp($_) - $breakdown{"Before InitXPCom"};
next;
}
# Find main1's cost to compute percentages
if (/\.\.\.main1/) {
$main1 = getTimelineStamp($_);
}
# find when we showed the window
if (/Navigator Window visible now/) {
$window = getTimelineStamp($_);
if ($stopWithVisibleWindow) {
$main1 = $window;
last;
}
}
# Find all files loaded
if (/PR_LoadLibrary/) {
my $dll = getdll($_);
push @dlls, $dll;
next;
}
if (/file:/) {
$url = getfileurl($_);
$e = getext($url);
if (!-f $url) {
push @nonexistentfiles, $url;
} else {
$seen{$url}++;
if ($seen{$url} > 1) {
$extnumdups{$e}++;
next;
}
push @allurls, $url;
if (exists $ext{$e}) {
$ext{$e} .= "---";
}
$ext{$e} .= $url;
$extnum{$e}++;
$nfileurl++;
}
next;
}
if (/jar:/) {
$url = getjarurl($_);
$e = getext($url);
$seen{$url}++;
if ($seen{$url} > 1) {
$extnumdups{$e}++;
next;
}
push @allurls, $url;
if (exists $ext{$e}) {
$ext{$e} .= "---";
}
$ext{$e} .= "$url";
$extnum{$e}++;
$njarurl++;
next;
}
if (/load pref file/) {
$url = getfile($_);
push @prefurl, $url;
}
}
# print results
print "SUMMARY\n";
print "----------------------------------------------------------------------\n";
print "Total startup time : $main1 sec\n";
printf "Main window visible: $window sec (%5.2f%%)\n", main1Percent($window);
print "dlls loaded : ", $#dlls+1, "\n";
print "Total unique: ", $#allurls+1, " [jar $njarurl, file $nfileurl]\n";
# print the # of files by extensions sorted
my @extsorted = sort { $extnum{$b} <=> $extnum{$a} } keys %extnum;
my $sep = " ";
foreach $i (@extsorted)
{
print "$sep.$i $extnum{$i}";
$sep = ", ";
}
print "\n";
# print number of dups per extension
my $sep = " dups: ";
foreach $i (@extsorted)
{
next unless exists($extnumdups{$i});
print "$sep.$i $extnumdups{$i}";
$sep = ", ";
}
print "\n";
print "Total non existent files : ", $#nonexistentfiles+1, "\n";
print "\n";
print "Cost Breakdown\n";
print "----------------------------------------------------------------------\n";
# sort by descending order of breakdown cost
my @breakdownsorted = sort { $breakdown{$b} <=> $breakdown{$a} } keys %breakdown;
my $totalAccounted = 0;
foreach $e (@breakdownsorted)
{
# ignore these breakdowns as they are already counted otherwise
next if ($e =~ /nsNativeComponentLoader::GetFactory/);
my $p = main1Percent($breakdown{$e});
#next if ($p == 0);
printf "%6.2f%% %s\n", $p, $e;
$totalAccounted += $p;
}
print "----------------------\n";
printf "%6.2f%% Total Accounted\n", $totalAccounted;
print "\n";
printf "[%d] List of dlls loaded:\n", $#dlls+1;
print "----------------------------------------------------------------------\n";
my $n = 1;
foreach $e (@dlls)
{
printf "%2d. %s\n", $n++, $e;
}
print "\n";
printf "[%d] List of existing unique files and jar urls by extension:\n", $#allurls+1;
print "----------------------------------------------------------------------\n";
foreach $e (@extsorted)
{
$n = 1;
print "[$extnum{$e}] .$e\n";
foreach $i (split("---", $ext{$e})) {
printf "%2d. %s", $n++, $i;
if ($seen{$i} > 1) {
printf " [%d]", $seen{$i}-1;
}
printf "\n";
}
print "\n";
}
#foreach $i (@allurls)
#{
# printf "%2d. %s\n", $n++, $i;
#}
print "\n";
printf "[%d] List of non existent file urls:\n", $#nonexistentfiles+1;
print "----------------------------------------------------------------------\n";
my $n = 1;
foreach $i (@nonexistentfiles)
{
printf "%2d. %s\n", $n++, $i;
}
# print prefs loaded
print "\n";
printf "[%d] List of pref files loaded:\n", $#prefurl+1;
print "----------------------------------------------------------------------\n";
$n = 1;
foreach $i (@prefurl)
{
printf "%2d. %s\n", $n++, $i;
}
# Subrouties
sub getTimelineStamp() {
my $line = shift;
$line =~ /^([0-9\.]*)/;
return $1+0;
}
sub getfileurl() {
my $f = shift;
$f =~ s/^.*file:\/*(.*)\).*$/\1/;
# unescape the url
$f =~ s/\|/:/;
$f =~ s/\%20/ /g;
return $f;
}
sub getjarurl() {
my $f = shift;
$f =~ s/^.*(jar:.*)\).*$/\1/;
return $f;
}
sub getdll() {
my $f = shift;
$f =~ s/^.*\((.*)\).*$/\1/;
return $f;
}
sub getext() {
my $f = shift;
$f =~ s/^.*\.([^\.]*)$/\1/;
return $f;
}
sub getfile() {
my $f = shift;
$f =~ s/^.*\((.*)\)$/\1/;
return $f;
}
# what % is this of startup
sub main1Percent() {
my $i = shift;
return $i/$main1 * 100;
}