forked from mozilla/gecko-dev
-
Notifications
You must be signed in to change notification settings - Fork 2
/
find-leakers.pl
executable file
·62 lines (48 loc) · 1.57 KB
/
find-leakers.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
#!/usr/bin/perl -w
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
use strict;
my %allocs;
my %classes;
my %counter;
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);
# for AddRef/Release $cnt is the refcount, for Ctor/Dtor it's the size
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});
}
elsif ($op eq 'Ctor') {
# Example: <PStreamNotifyParent> 0x08880BD0 8 Ctor (20)
$allocs{$obj} = ++$counter{$class};
$classes{$obj} = $class;
}
elsif ($op eq 'Dtor') {
# Example: <PStreamNotifyParent> 0x08880BD0 8 Dtor (20)
delete($allocs{$obj});
delete($classes{$obj});
}
}
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";
}