Bug 449150 – In <find-leakers.pl>, fix code nits and add output sorting
authorSerge Gautherie <sgautherie.bz@free.fr>
Tue, 05 Aug 2008 04:05:50 +0200
changeset 17018 f6fb4a4be49947e767f34572958bfad63a45e9cf
parent 17017 6134148524680c48adfe513037b5705ebba846ec
child 17019 70f01c91c56280edae4906689b24c6ce24d3a252
push id1347
push userrobarnold@cmu.edu
push dateTue, 19 Aug 2008 00:03:21 +0000
treeherdermozilla-central@01b404e39936 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs449150
milestone1.9.1a2pre
Bug 449150 – In <find-leakers.pl>, fix code nits and add output sorting (Av1) <find-leakers.pl>
tools/rb/find-leakers.pl
--- a/tools/rb/find-leakers.pl
+++ b/tools/rb/find-leakers.pl
@@ -31,35 +31,50 @@
 # use your version of this file under the terms of the MPL, indicate your
 # decision by deleting the provisions above and replace them with the notice
 # and other provisions required by the GPL or the LGPL. If you do not delete
 # the provisions above, a recipient may use your version of this file under
 # the terms of any one of the MPL, the GPL or the LGPL.
 #
 # ***** END LICENSE BLOCK *****
 
+use strict;
+
 my %allocs;
+my %classes;
 my %counter;
-my $id = 0;
 
 LINE: while (<>) {
     next LINE if (! /^</);
+
     my @fields = split(/ /, $_);
-
     my $class = shift(@fields);
     my $obj   = shift(@fields);
     my $sno   = shift(@fields);
     my $op    = shift(@fields);
     my $cnt   = shift(@fields);
 
     if ($op eq 'AddRef' && $cnt == 1) {
+        # Example: <nsStringBuffer> 0x01AFD3B8 1 AddRef 1
+
         $allocs{$obj} = ++$counter{$class}; # the order of allocation
         $classes{$obj} = $class;
     }
     elsif ($op eq 'Release' && $cnt == 0) {
+        # Example: <nsStringBuffer> 0x01AFD3B8 1 Release 0
+
         delete($allocs{$obj});
+        delete($classes{$obj});
     }
 }
 
-foreach $key (keys(%allocs)) {
+
+sub sort_by_value {
+    my %x = @_;
+    sub _by_value($) { my %x = @_; $x{$a} cmp $x{$b}; } 
+    sort _by_value keys(%x);
+} 
+
+
+foreach my $key (&sort_by_value(%allocs)) {
+    # Example: 0x03F1D818 (2078) @ <nsStringBuffer>
     print "$key (", $allocs{$key}, ") @ ", $classes{$key}, "\n";
 }
-