2 # This Source Code Form is subject to the terms of the Mozilla Public
3 # License, v. 2.0. If a copy of the MPL was not distributed with this
4 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
7 ################################################################################
11 # bloatdiff.pl - munges the output from
12 # XPCOM_MEM_BLOAT_LOG=1
13 # firefox-bin -P default resource:///res/bloatcycle.html
14 # so that it does some summary and stats stuff.
16 # To show leak test results for a set of changes, do something like this:
18 # XPCOM_MEM_BLOAT_LOG=1
19 # firefox-bin -P default resource:///res/bloatcycle.html > a.out
21 # firefox-bin -P default resource:///res/bloatcycle.html > b.out
22 # bloatdiff.pl a.out b.out
34 print "\nError: Previous log file not specified, does not exist, or is empty.\n\n";
42 print "\nError: Current log file not specified, does not exist, or is empty.\n\n";
48 my ($filename, $map, $prevMap) = @_;
52 ^\s
*(\d
+)\s
# Line number
56 (-?\d
+)\s
+ # Objects Total
57 (-?\d
+)\s
+ # Objects Rem
58 \
(\s
*(-?
[\d
.]+)\s
+ # Objects Mean
60 ([\w
.]+)\
)\s
+ # Objects StdDev
61 (-?\d
+)\s
+ # Reference Total
62 (-?\d
+)\s
+ # Reference Rem
63 \
(\s
*(-?
[\d
.]+)\s
+ # Reference Mean
65 ([\w\
.]+)\
) # Reference StdDev
67 $$map{$2} = { name
=> $2,
78 bloat
=> $3 * $5 # size * objTotal
81 # print "failed to parse: $_\n";
88 processFile
($OLDFILE, \
%oldMap);
91 processFile
($NEWFILE, \
%newMap);
93 ################################################################################
99 my $oldLeaks = $oldMap{$key}{leaked
} || 0;
100 my $newLeaks = $newMap{$key}{leaked
};
101 my $percentLeaks = 0;
102 if ($oldLeaks == 0) {
103 if ($newLeaks != 0) {
104 # there weren't any leaks before, but now there are!
105 $percentLeaks = $inf;
109 $percentLeaks = ($newLeaks - $oldLeaks) / $oldLeaks * 100;
111 # else we had no record of this class before
112 return ($newLeaks - $oldLeaks, $percentLeaks);
115 ################################################################################
119 my $newBloat = $newMap{$key}{bloat
};
120 my $percentBloat = 0;
121 my $oldSize = $oldMap{$key}{size
} || 0;
122 my $oldTotal = $oldMap{$key}{objTotal
} || 0;
123 my $oldBloat = $oldTotal * $oldSize;
124 if ($oldBloat == 0) {
125 if ($newBloat != 0) {
126 # this class wasn't used before, but now it is
127 $percentBloat = $inf;
131 $percentBloat = ($newBloat - $oldBloat) / $oldBloat * 100;
133 # else we had no record of this class before
134 return ($newBloat - $oldBloat, $percentBloat);
137 ################################################################################
139 foreach $key (keys %newMap) {
140 my ($newLeaks, $percentLeaks) = getLeaksDelta
($key);
141 my ($newBloat, $percentBloat) = getBloatDelta
($key);
142 $newMap{$key}{leakDelta
} = $newLeaks;
143 $newMap{$key}{leakPercent
} = $percentLeaks;
144 $newMap{$key}{bloatDelta
} = $newBloat;
145 $newMap{$key}{bloatPercent
} = $percentBloat;
148 ################################################################################
150 # Print a value of bytes out in a reasonable
151 # KB, MB, or GB form. Copied from build-seamonkey-util.pl, sorry. -mcafee
154 # print a number with 3 significant figures
159 $rv = sprintf "%.3f", ($num);
160 } elsif ($num < 10) {
161 $rv = sprintf "%.2f", ($num);
162 } elsif ($num < 100) {
163 $rv = sprintf "%.1f", ($num);
165 $rv = sprintf "%d", ($num);
171 if ($size > 1000000000) {
172 $rv = PrintNum
($size / 1000000000.0) . "G";
173 } elsif ($size > 1000000) {
174 $rv = PrintNum
($size / 1000000.0) . "M";
175 } elsif ($size > 1000) {
176 $rv = PrintNum
($size / 1000.0) . "K";
178 $rv = PrintNum
($size);
183 print "Bloat/Leak Delta Report\n";
184 print "--------------------------------------------------------------------------------------\n";
185 print "Current file: $NEWFILE\n";
186 print "Previous file: $OLDFILE\n";
187 print "----------------------------------------------leaks------leaks%------bloat------bloat%\n";
189 if (! $newMap{"TOTAL"} or
190 ! $newMap{"TOTAL"}{bloat
}) {
191 # It's OK if leaked or leakPercent are 0 (in fact, that would be good).
192 # If bloatPercent is zero, it is also OK, because we may have just had
193 # two runs exactly the same or with no new bloat.
194 print "\nError: unable to calculate bloat/leak data.\n";
195 print "There is no data present.\n\n";
196 print "HINT - Did your test run complete successfully?\n";
197 print "HINT - Are you pointing at the right log files?\n\n";
202 printf "%-40s %10s %10.2f%% %10s %10.2f%%\n",
204 $newMap{"TOTAL"}{leaked
}, $newMap{"TOTAL"}{leakPercent
},
205 $newMap{"TOTAL"}{bloat
}, $newMap{"TOTAL"}{bloatPercent
});
207 ################################################################################
215 return sprintf "%10.2f%%", $p;
220 @keys = sort { $newMap{$b}{leakPercent
} <=> $newMap{$a}{leakPercent
} } keys %newMap;
221 my $needsHeading = 1;
223 foreach $key (@keys) {
224 my $percentLeaks = $newMap{$key}{leakPercent
};
225 my $leaks = $newMap{$key}{leaked
};
226 if ($percentLeaks > 0 && $key !~ /TOTAL/) {
228 printf "--NEW-LEAKS-----------------------------------leaks------leaks%%-----------------------\n";
231 printf "%-40s %10s %10s\n", ($key, $leaks, percentStr
($percentLeaks));
235 if (!$needsHeading) {
236 printf "%-40s %10s\n", ("TOTAL", $total);
240 @keys = sort { $newMap{$b}{leakPercent
} <=> $newMap{$a}{leakPercent
} } keys %newMap;
243 foreach $key (@keys) {
244 my $percentLeaks = $newMap{$key}{leakPercent
};
245 my $leaks = $newMap{$key}{leaked
};
246 if ($percentLeaks < 0 && $key !~ /TOTAL/) {
248 printf "--FIXED-LEAKS---------------------------------leaks------leaks%%-----------------------\n";
251 printf "%-40s %10s %10s\n", ($key, $leaks, percentStr
($percentLeaks));
255 if (!$needsHeading) {
256 printf "%-40s %10s\n", ("TOTAL", $total);
260 @keys = sort { $newMap{$b}{bloatPercent
} <=> $newMap{$a}{bloatPercent
} } keys %newMap;
263 foreach $key (@keys) {
264 my $percentBloat = $newMap{$key}{bloatPercent
};
265 my $bloat = $newMap{$key}{bloat
};
266 if ($percentBloat > 0 && $key !~ /TOTAL/) {
268 printf "--NEW-BLOAT-----------------------------------bloat------bloat%%-----------------------\n";
271 printf "%-40s %10s %10s\n", ($key, $bloat, percentStr
($percentBloat));
275 if (!$needsHeading) {
276 printf "%-40s %10s\n", ("TOTAL", $total);
280 @keys = sort { $newMap{$b}{leaked
} <=> $newMap{$a}{leaked
} } keys %newMap;
283 foreach $key (@keys) {
284 my $leaks = $newMap{$key}{leaked
};
285 my $percentLeaks = $newMap{$key}{leakPercent
};
288 printf "--ALL-LEAKS-----------------------------------leaks------leaks%%-----------------------\n";
291 printf "%-40s %10s %10s\n", ($key, $leaks, percentStr
($percentLeaks));
292 if ($key !~ /TOTAL/) {
297 if (!$needsHeading) {
298 # printf "%-40s %10s\n", ("TOTAL", $total);
302 @keys = sort { $newMap{$b}{bloat
} <=> $newMap{$a}{bloat
} } keys %newMap;
305 foreach $key (@keys) {
306 my $bloat = $newMap{$key}{bloat
};
307 my $percentBloat = $newMap{$key}{bloatPercent
};
310 printf "--ALL-BLOAT-----------------------------------bloat------bloat%%-----------------------\n";
313 printf "%-40s %10s %10s\n", ($key, $bloat, percentStr
($percentBloat));
314 if ($key !~ /TOTAL/) {
319 if (!$needsHeading) {
320 # printf "%-40s %10s\n", ("TOTAL", $total);
324 @keys = sort { $newMap{$b}{bloatDelta
} <=> $newMap{$a}{bloatDelta
} } keys %newMap;
328 foreach $key (@keys) {
329 my $leaks = $newMap{$key}{leaked
};
330 my $bloat = $newMap{$key}{bloat
};
331 my $percentBloat = $newMap{$key}{bloatPercent
};
332 if ($percentBloat == $inf && $key !~ /TOTAL/) {
334 printf "--CLASSES-NOT-REPORTED-LAST-TIME--------------leaks------bloat------------------------\n";
337 printf "%-40s %10s %10s\n", ($key, $leaks, $bloat);
338 if ($key !~ /TOTAL/) {
344 if (!$needsHeading) {
345 printf "%-40s %10s %10s\n", ("TOTAL", $ltotal, $btotal);
349 @keys = sort { ($oldMap{$b}{bloat
} || 0) <=> ($oldMap{$a}{bloat
} || 0) } keys %oldMap;
353 foreach $key (@keys) {
354 if (!defined($newMap{$key})) {
355 my $leaks = $oldMap{$key}{leaked
};
356 my $bloat = $oldMap{$key}{bloat
};
358 printf "--CLASSES-THAT-WENT-AWAY----------------------leaks------bloat------------------------\n";
361 printf "%-40s %10s %10s\n", ($key, $leaks, $bloat);
362 if ($key !~ /TOTAL/) {
368 if (!$needsHeading) {
369 printf "%-40s %10s %10s\n", ("TOTAL", $ltotal, $btotal);
372 print "--------------------------------------------------------------------------------------\n";