1999-12-10 00:13:03 +03:00
|
|
|
#!/usr/bin/perl -w
|
1999-10-21 02:35:48 +04:00
|
|
|
|
2001-01-04 05:59:30 +03:00
|
|
|
#
|
|
|
|
# Munges the output from
|
|
|
|
# XPCOM_MEM_BLOAT_LOG=1; mozilla-bin -f bloaturls.txt
|
|
|
|
# so that it does some summary and stats stuff.
|
|
|
|
#
|
|
|
|
# To show leak test results for a set of changes, do something like this:
|
|
|
|
#
|
|
|
|
# XPCOM_MEM_BLOAT_LOG=1
|
|
|
|
# mozilla -f bloaturls.txt > a.out
|
|
|
|
# **make change**
|
|
|
|
# mozilla -f bloaturls.txt > b.out
|
|
|
|
# bloatdiff.pl a.out b.out
|
|
|
|
#
|
|
|
|
|
1999-10-21 02:35:48 +04:00
|
|
|
$OLDFILE = $ARGV[0];
|
|
|
|
$NEWFILE = $ARGV[1];
|
2001-12-05 12:27:28 +03:00
|
|
|
$LABEL = $ARGV[2];
|
1999-10-21 02:35:48 +04:00
|
|
|
|
|
|
|
sub processFile {
|
2000-05-15 22:10:46 +04:00
|
|
|
my ($filename, $map, $prevMap) = @_;
|
|
|
|
open(FH, $filename);
|
1999-10-21 02:35:48 +04:00
|
|
|
while (<FH>) {
|
2000-05-15 22:10:46 +04:00
|
|
|
if (m{
|
|
|
|
^\s*(\d+)\s # Line number
|
|
|
|
([\w:]+)\s+ # Name
|
|
|
|
(-?\d+)\s+ # Size
|
|
|
|
(-?\d+)\s+ # Leaked
|
|
|
|
(-?\d+)\s+ # Objects Total
|
|
|
|
(-?\d+)\s+ # Objects Rem
|
|
|
|
\(\s*(-?[\d.]+)\s+ # Objects Mean
|
|
|
|
\+/-\s+
|
|
|
|
([\w.]+)\)\s+ # Objects StdDev
|
|
|
|
(-?\d+)\s+ # Reference Total
|
|
|
|
(-?\d+)\s+ # Reference Rem
|
|
|
|
\(\s*(-?[\d.]+)\s+ # Reference Mean
|
|
|
|
\+/-\s+
|
|
|
|
([\w\.]+)\) # Reference StdDev
|
|
|
|
}x) {
|
|
|
|
$$map{$2} = { name => $2,
|
|
|
|
size => $3,
|
|
|
|
leaked => $4,
|
|
|
|
objTotal => $5,
|
|
|
|
objRem => $6,
|
|
|
|
objMean => $7,
|
|
|
|
objStdDev => $8,
|
|
|
|
refTotal => $9,
|
|
|
|
refRem => $10,
|
|
|
|
refMean => $11,
|
|
|
|
refStdDev => $12,
|
2000-05-15 23:04:27 +04:00
|
|
|
bloat => $3 * $5 # size * objTotal
|
2000-05-15 22:10:46 +04:00
|
|
|
};
|
|
|
|
} else {
|
1999-10-29 22:05:09 +04:00
|
|
|
# print "failed to parse: $_\n";
|
|
|
|
}
|
1999-10-21 02:35:48 +04:00
|
|
|
}
|
|
|
|
close(FH);
|
|
|
|
}
|
|
|
|
|
|
|
|
%oldMap = ();
|
|
|
|
processFile($OLDFILE, \%oldMap);
|
|
|
|
|
|
|
|
%newMap = ();
|
|
|
|
processFile($NEWFILE, \%newMap);
|
|
|
|
|
|
|
|
################################################################################
|
|
|
|
|
1999-10-28 22:57:37 +04:00
|
|
|
$inf = 9999999.99;
|
|
|
|
|
|
|
|
sub getLeaksDelta {
|
1999-10-21 09:16:54 +04:00
|
|
|
my ($key) = @_;
|
1999-10-28 22:57:37 +04:00
|
|
|
my $oldLeaks = $oldMap{$key}{leaked} || 0;
|
1999-10-21 09:16:54 +04:00
|
|
|
my $newLeaks = $newMap{$key}{leaked};
|
|
|
|
my $percentLeaks = 0;
|
1999-10-28 22:57:37 +04:00
|
|
|
if ($oldLeaks == 0) {
|
|
|
|
if ($newLeaks != 0) {
|
|
|
|
# there weren't any leaks before, but now there are!
|
|
|
|
$percentLeaks = $inf;
|
1999-10-21 02:35:48 +04:00
|
|
|
}
|
|
|
|
}
|
1999-10-28 22:57:37 +04:00
|
|
|
else {
|
|
|
|
$percentLeaks = ($newLeaks - $oldLeaks) / $oldLeaks * 100;
|
|
|
|
}
|
1999-10-21 02:35:48 +04:00
|
|
|
# else we had no record of this class before
|
1999-10-28 22:57:37 +04:00
|
|
|
return ($newLeaks - $oldLeaks, $percentLeaks);
|
1999-10-21 02:35:48 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
################################################################################
|
|
|
|
|
1999-10-28 22:57:37 +04:00
|
|
|
sub getBloatDelta {
|
1999-10-21 09:16:54 +04:00
|
|
|
my ($key) = @_;
|
1999-10-28 22:57:37 +04:00
|
|
|
my $newBloat = $newMap{$key}{bloat};
|
1999-10-21 09:16:54 +04:00
|
|
|
my $percentBloat = 0;
|
1999-10-28 22:57:37 +04:00
|
|
|
my $oldSize = $oldMap{$key}{size} || 0;
|
|
|
|
my $oldTotal = $oldMap{$key}{objTotal} || 0;
|
|
|
|
my $oldBloat = $oldTotal * $oldSize;
|
|
|
|
if ($oldBloat == 0) {
|
|
|
|
if ($newBloat != 0) {
|
|
|
|
# this class wasn't used before, but now it is
|
|
|
|
$percentBloat = $inf;
|
1999-10-21 02:35:48 +04:00
|
|
|
}
|
|
|
|
}
|
1999-10-28 22:57:37 +04:00
|
|
|
else {
|
|
|
|
$percentBloat = ($newBloat - $oldBloat) / $oldBloat * 100;
|
|
|
|
}
|
1999-10-21 02:35:48 +04:00
|
|
|
# else we had no record of this class before
|
1999-10-28 22:57:37 +04:00
|
|
|
return ($newBloat - $oldBloat, $percentBloat);
|
|
|
|
}
|
|
|
|
|
|
|
|
################################################################################
|
|
|
|
|
|
|
|
foreach $key (keys %newMap) {
|
|
|
|
my ($newLeaks, $percentLeaks) = getLeaksDelta($key);
|
|
|
|
my ($newBloat, $percentBloat) = getBloatDelta($key);
|
|
|
|
$newMap{$key}{leakDelta} = $newLeaks;
|
|
|
|
$newMap{$key}{leakPercent} = $percentLeaks;
|
|
|
|
$newMap{$key}{bloatDelta} = $newBloat;
|
|
|
|
$newMap{$key}{bloatPercent} = $percentBloat;
|
1999-10-21 02:35:48 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
################################################################################
|
|
|
|
|
2001-11-17 13:37:02 +03:00
|
|
|
# Print a value of bytes out in a reasonable
|
|
|
|
# KB, MB, or GB form. Copied from build-seamonkey-util.pl, sorry. -mcafee
|
|
|
|
sub PrintSize($) {
|
|
|
|
|
|
|
|
# print a number with 3 significant figures
|
|
|
|
sub PrintNum($) {
|
|
|
|
my ($num) = @_;
|
|
|
|
my $rv;
|
|
|
|
if ($num < 1) {
|
|
|
|
$rv = sprintf "%.3f", ($num);
|
|
|
|
} elsif ($num < 10) {
|
|
|
|
$rv = sprintf "%.2f", ($num);
|
|
|
|
} elsif ($num < 100) {
|
|
|
|
$rv = sprintf "%.1f", ($num);
|
|
|
|
} else {
|
|
|
|
$rv = sprintf "%d", ($num);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
my ($size) = @_;
|
|
|
|
my $rv;
|
|
|
|
if ($size > 1000000000) {
|
|
|
|
$rv = PrintNum($size / 1000000000.0) . "G";
|
|
|
|
} elsif ($size > 1000000) {
|
|
|
|
$rv = PrintNum($size / 1000000.0) . "M";
|
|
|
|
} elsif ($size > 1000) {
|
|
|
|
$rv = PrintNum($size / 1000.0) . "K";
|
|
|
|
} else {
|
2001-11-20 10:20:51 +03:00
|
|
|
$rv = PrintNum($size);
|
2001-11-17 13:37:02 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-10-21 09:16:54 +04:00
|
|
|
print "Bloat/Leak Delta Report\n";
|
2000-08-11 03:20:07 +04:00
|
|
|
print "--------------------------------------------------------------------------------------\n";
|
1999-10-21 09:16:54 +04:00
|
|
|
print "Current file: $NEWFILE\n";
|
|
|
|
print "Previous file: $OLDFILE\n";
|
2000-08-11 03:20:07 +04:00
|
|
|
print "----------------------------------------------leaks------leaks%------bloat------bloat%\n";
|
|
|
|
printf "%-40s %10s %10.2f%% %10s %10.2f%%\n",
|
1999-10-29 06:39:10 +04:00
|
|
|
("TOTAL",
|
|
|
|
$newMap{"TOTAL"}{leaked}, $newMap{"TOTAL"}{leakPercent},
|
|
|
|
$newMap{"TOTAL"}{bloat}, $newMap{"TOTAL"}{bloatPercent});
|
1999-10-28 22:57:37 +04:00
|
|
|
|
|
|
|
################################################################################
|
|
|
|
|
|
|
|
sub percentStr {
|
|
|
|
my ($p) = @_;
|
|
|
|
if ($p == $inf) {
|
|
|
|
return "-";
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return sprintf "%10.2f%%", $p;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# NEW LEAKS
|
|
|
|
@keys = sort { $newMap{$b}{leakPercent} <=> $newMap{$a}{leakPercent} } keys %newMap;
|
|
|
|
my $needsHeading = 1;
|
|
|
|
my $total = 0;
|
1999-10-21 02:35:48 +04:00
|
|
|
foreach $key (@keys) {
|
1999-10-28 22:57:37 +04:00
|
|
|
my $percentLeaks = $newMap{$key}{leakPercent};
|
|
|
|
my $leaks = $newMap{$key}{leaked};
|
|
|
|
if ($percentLeaks > 0 && $key !~ /TOTAL/) {
|
|
|
|
if ($needsHeading) {
|
2000-08-11 03:20:07 +04:00
|
|
|
printf "--NEW-LEAKS-----------------------------------leaks------leaks%%-----------------------\n";
|
1999-10-28 22:57:37 +04:00
|
|
|
$needsHeading = 0;
|
|
|
|
}
|
2000-08-11 03:20:07 +04:00
|
|
|
printf "%-40s %10s %10s\n", ($key, $leaks, percentStr($percentLeaks));
|
1999-10-28 22:57:37 +04:00
|
|
|
$total += $leaks;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!$needsHeading) {
|
2000-08-11 03:20:07 +04:00
|
|
|
printf "%-40s %10s\n", ("TOTAL", $total);
|
1999-10-21 02:35:48 +04:00
|
|
|
}
|
|
|
|
|
1999-10-28 22:57:37 +04:00
|
|
|
# FIXED LEAKS
|
|
|
|
@keys = sort { $newMap{$b}{leakPercent} <=> $newMap{$a}{leakPercent} } keys %newMap;
|
1999-10-29 03:24:39 +04:00
|
|
|
$needsHeading = 1;
|
|
|
|
$total = 0;
|
1999-10-28 22:57:37 +04:00
|
|
|
foreach $key (@keys) {
|
|
|
|
my $percentLeaks = $newMap{$key}{leakPercent};
|
|
|
|
my $leaks = $newMap{$key}{leaked};
|
|
|
|
if ($percentLeaks < 0 && $key !~ /TOTAL/) {
|
|
|
|
if ($needsHeading) {
|
2000-08-11 03:20:07 +04:00
|
|
|
printf "--FIXED-LEAKS---------------------------------leaks------leaks%%-----------------------\n";
|
1999-10-28 22:57:37 +04:00
|
|
|
$needsHeading = 0;
|
|
|
|
}
|
2000-08-11 03:20:07 +04:00
|
|
|
printf "%-40s %10s %10s\n", ($key, $leaks, percentStr($percentLeaks));
|
1999-10-28 22:57:37 +04:00
|
|
|
$total += $leaks;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!$needsHeading) {
|
2000-08-11 03:20:07 +04:00
|
|
|
printf "%-40s %10s\n", ("TOTAL", $total);
|
1999-10-28 22:57:37 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
# NEW BLOAT
|
|
|
|
@keys = sort { $newMap{$b}{bloatPercent} <=> $newMap{$a}{bloatPercent} } keys %newMap;
|
1999-10-29 03:24:39 +04:00
|
|
|
$needsHeading = 1;
|
|
|
|
$total = 0;
|
1999-10-28 22:57:37 +04:00
|
|
|
foreach $key (@keys) {
|
|
|
|
my $percentBloat = $newMap{$key}{bloatPercent};
|
|
|
|
my $bloat = $newMap{$key}{bloat};
|
|
|
|
if ($percentBloat > 0 && $key !~ /TOTAL/) {
|
|
|
|
if ($needsHeading) {
|
2000-08-11 03:20:07 +04:00
|
|
|
printf "--NEW-BLOAT-----------------------------------bloat------bloat%%-----------------------\n";
|
1999-10-28 22:57:37 +04:00
|
|
|
$needsHeading = 0;
|
|
|
|
}
|
2000-08-11 03:20:07 +04:00
|
|
|
printf "%-40s %10s %10s\n", ($key, $bloat, percentStr($percentBloat));
|
1999-10-28 22:57:37 +04:00
|
|
|
$total += $bloat;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!$needsHeading) {
|
2000-08-11 03:20:07 +04:00
|
|
|
printf "%-40s %10s\n", ("TOTAL", $total);
|
1999-10-28 22:57:37 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
# ALL LEAKS
|
|
|
|
@keys = sort { $newMap{$b}{leaked} <=> $newMap{$a}{leaked} } keys %newMap;
|
1999-10-29 03:24:39 +04:00
|
|
|
$needsHeading = 1;
|
|
|
|
$total = 0;
|
1999-10-28 22:57:37 +04:00
|
|
|
foreach $key (@keys) {
|
|
|
|
my $leaks = $newMap{$key}{leaked};
|
|
|
|
my $percentLeaks = $newMap{$key}{leakPercent};
|
|
|
|
if ($leaks > 0) {
|
|
|
|
if ($needsHeading) {
|
2000-08-11 03:20:07 +04:00
|
|
|
printf "--ALL-LEAKS-----------------------------------leaks------leaks%%-----------------------\n";
|
1999-10-28 22:57:37 +04:00
|
|
|
$needsHeading = 0;
|
|
|
|
}
|
2000-08-11 03:20:07 +04:00
|
|
|
printf "%-40s %10s %10s\n", ($key, $leaks, percentStr($percentLeaks));
|
1999-10-28 22:57:37 +04:00
|
|
|
if ($key !~ /TOTAL/) {
|
|
|
|
$total += $leaks;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!$needsHeading) {
|
2000-08-11 03:20:07 +04:00
|
|
|
# printf "%-40s %10s\n", ("TOTAL", $total);
|
1999-10-28 22:57:37 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
# ALL BLOAT
|
|
|
|
@keys = sort { $newMap{$b}{bloat} <=> $newMap{$a}{bloat} } keys %newMap;
|
1999-10-29 03:24:39 +04:00
|
|
|
$needsHeading = 1;
|
|
|
|
$total = 0;
|
1999-10-28 22:57:37 +04:00
|
|
|
foreach $key (@keys) {
|
|
|
|
my $bloat = $newMap{$key}{bloat};
|
|
|
|
my $percentBloat = $newMap{$key}{bloatPercent};
|
|
|
|
if ($bloat > 0) {
|
|
|
|
if ($needsHeading) {
|
2000-08-11 03:20:07 +04:00
|
|
|
printf "--ALL-BLOAT-----------------------------------bloat------bloat%%-----------------------\n";
|
1999-10-28 22:57:37 +04:00
|
|
|
$needsHeading = 0;
|
|
|
|
}
|
2000-08-11 03:20:07 +04:00
|
|
|
printf "%-40s %10s %10s\n", ($key, $bloat, percentStr($percentBloat));
|
1999-10-28 22:57:37 +04:00
|
|
|
if ($key !~ /TOTAL/) {
|
|
|
|
$total += $bloat;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!$needsHeading) {
|
2000-08-11 03:20:07 +04:00
|
|
|
# printf "%-40s %10s\n", ("TOTAL", $total);
|
1999-10-28 22:57:37 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
# NEW CLASSES
|
|
|
|
@keys = sort { $newMap{$b}{bloatDelta} <=> $newMap{$a}{bloatDelta} } keys %newMap;
|
2000-02-26 05:17:15 +03:00
|
|
|
$needsHeading = 1;
|
1999-10-28 22:57:37 +04:00
|
|
|
my $ltotal = 0;
|
|
|
|
my $btotal = 0;
|
|
|
|
foreach $key (@keys) {
|
|
|
|
my $leaks = $newMap{$key}{leaked};
|
|
|
|
my $bloat = $newMap{$key}{bloat};
|
|
|
|
my $percentBloat = $newMap{$key}{bloatPercent};
|
|
|
|
if ($percentBloat == $inf && $key !~ /TOTAL/) {
|
|
|
|
if ($needsHeading) {
|
2000-08-11 03:20:07 +04:00
|
|
|
printf "--CLASSES-NOT-REPORTED-LAST-TIME--------------leaks------bloat------------------------\n";
|
1999-10-28 22:57:37 +04:00
|
|
|
$needsHeading = 0;
|
|
|
|
}
|
2000-08-11 03:20:07 +04:00
|
|
|
printf "%-40s %10s %10s\n", ($key, $leaks, $bloat);
|
1999-10-28 22:57:37 +04:00
|
|
|
if ($key !~ /TOTAL/) {
|
|
|
|
$ltotal += $leaks;
|
|
|
|
$btotal += $bloat;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!$needsHeading) {
|
2000-08-11 03:20:07 +04:00
|
|
|
printf "%-40s %10s %10s\n", ("TOTAL", $ltotal, $btotal);
|
1999-10-28 22:57:37 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
# OLD CLASSES
|
|
|
|
@keys = sort { ($oldMap{$b}{bloat} || 0) <=> ($oldMap{$a}{bloat} || 0) } keys %oldMap;
|
2000-02-26 05:17:15 +03:00
|
|
|
$needsHeading = 1;
|
|
|
|
$ltotal = 0;
|
|
|
|
$btotal = 0;
|
1999-10-28 22:57:37 +04:00
|
|
|
foreach $key (@keys) {
|
|
|
|
if (!defined($newMap{$key})) {
|
|
|
|
my $leaks = $oldMap{$key}{leaked};
|
|
|
|
my $bloat = $oldMap{$key}{bloat};
|
|
|
|
if ($needsHeading) {
|
2000-08-11 03:20:07 +04:00
|
|
|
printf "--CLASSES-THAT-WENT-AWAY----------------------leaks------bloat------------------------\n";
|
1999-10-28 22:57:37 +04:00
|
|
|
$needsHeading = 0;
|
|
|
|
}
|
2000-08-11 03:20:07 +04:00
|
|
|
printf "%-40s %10s %10s\n", ($key, $leaks, $bloat);
|
1999-10-28 22:57:37 +04:00
|
|
|
if ($key !~ /TOTAL/) {
|
|
|
|
$ltotal += $leaks;
|
|
|
|
$btotal += $bloat;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!$needsHeading) {
|
2000-08-11 03:20:07 +04:00
|
|
|
printf "%-40s %10s %10s\n", ("TOTAL", $ltotal, $btotal);
|
1999-10-28 22:57:37 +04:00
|
|
|
}
|
1999-10-21 02:35:48 +04:00
|
|
|
|
2000-08-11 03:20:07 +04:00
|
|
|
print "--------------------------------------------------------------------------------------\n";
|