tools/rb/find-leakers.pl

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rwxr-xr-x

Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

michael@0 1 #!/usr/bin/perl -w
michael@0 2 #
michael@0 3 # This Source Code Form is subject to the terms of the Mozilla Public
michael@0 4 # License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 5 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
michael@0 6
michael@0 7 use strict;
michael@0 8
michael@0 9 my %allocs;
michael@0 10 my %classes;
michael@0 11 my %counter;
michael@0 12
michael@0 13 LINE: while (<>) {
michael@0 14 next LINE if (! /^</);
michael@0 15
michael@0 16 my @fields = split(/ /, $_);
michael@0 17 my $class = shift(@fields);
michael@0 18 my $obj = shift(@fields);
michael@0 19 my $sno = shift(@fields);
michael@0 20 my $op = shift(@fields);
michael@0 21 my $cnt = shift(@fields);
michael@0 22
michael@0 23 # for AddRef/Release $cnt is the refcount, for Ctor/Dtor it's the size
michael@0 24
michael@0 25 if ($op eq 'AddRef' && $cnt == 1) {
michael@0 26 # Example: <nsStringBuffer> 0x01AFD3B8 1 AddRef 1
michael@0 27
michael@0 28 $allocs{$obj} = ++$counter{$class}; # the order of allocation
michael@0 29 $classes{$obj} = $class;
michael@0 30 }
michael@0 31 elsif ($op eq 'Release' && $cnt == 0) {
michael@0 32 # Example: <nsStringBuffer> 0x01AFD3B8 1 Release 0
michael@0 33
michael@0 34 delete($allocs{$obj});
michael@0 35 delete($classes{$obj});
michael@0 36 }
michael@0 37 elsif ($op eq 'Ctor') {
michael@0 38 # Example: <PStreamNotifyParent> 0x08880BD0 8 Ctor (20)
michael@0 39
michael@0 40 $allocs{$obj} = ++$counter{$class};
michael@0 41 $classes{$obj} = $class;
michael@0 42 }
michael@0 43 elsif ($op eq 'Dtor') {
michael@0 44 # Example: <PStreamNotifyParent> 0x08880BD0 8 Dtor (20)
michael@0 45
michael@0 46 delete($allocs{$obj});
michael@0 47 delete($classes{$obj});
michael@0 48 }
michael@0 49 }
michael@0 50
michael@0 51
michael@0 52 sub sort_by_value {
michael@0 53 my %x = @_;
michael@0 54 sub _by_value($) { my %x = @_; $x{$a} cmp $x{$b}; }
michael@0 55 sort _by_value keys(%x);
michael@0 56 }
michael@0 57
michael@0 58
michael@0 59 foreach my $key (&sort_by_value(%allocs)) {
michael@0 60 # Example: 0x03F1D818 (2078) @ <nsStringBuffer>
michael@0 61 print "$key (", $allocs{$key}, ") @ ", $classes{$key}, "\n";
michael@0 62 }

mercurial