18 if (!defined($ARGV[0])) {
19 print "No log file specified\n";
23 open(INFILE, $ARGV[0]);
24 while ($line = <INFILE>) {
25 if ($line =~ m/^(.*)\((.*):(\d+):(.*)\(\)\)/) {
26 @parsed = split(":", $1);
27 if (substr ($parsed[2], -1, 1) eq "F") {
31 if (!defined($cpu{$parsed[2]})) {
32 $cpu{$parsed[2]} = $parsed[3];
38 foreach $time (values %cpu) {
39 if ($start_time < $time) {
44 print "Starting analysis since $start_time\n";
47 while ($line = <INFILE>) {
49 my ($file, $func, $lno, $name, $size, $addr, $type);
50 if ($line =~ m/^(.*)\((.*):(\d+):(.*)\(\)\) (k|v|slab-)(.*) '(.*)': (\d+) at ([\da-f]+)/){
51 @parsed = split(":", $1);
52 if ($parsed[3] <= $start_time) {
64 # we can't dump the log after portals has exited, so skip "leaks"
65 # from memory freed in the portals module unloading.
66 if ($func eq 'portals_handle_init') {
69 printf("%8s %6d bytes at %s called %s (%s:%s:%d)\n", $type, $size,
70 $addr, $name, $file, $func, $lno);
75 if (index($type, 'alloced') >= 0) {
76 if (defined($memory->{$addr})) {
77 print STDERR "*** Two allocs with the same address ($size bytes at $addr, $file:$func:$lno)\n";
78 print STDERR " first malloc at $memory->{$addr}->{file}:$memory->{$addr}->{func}:$memory->{$addr}->{lno}, second at $file:$func:$lno\n";
82 $memory->{$addr}->{name} = $name;
83 $memory->{$addr}->{size} = $size;
84 $memory->{$addr}->{file} = $file;
85 $memory->{$addr}->{func} = $func;
86 $memory->{$addr}->{lno} = $lno;
87 $memory->{$addr}->{debug_line} = $debug_line;
94 if (!defined($memory->{$addr})) {
95 print STDERR "*** Free without malloc ($size bytes at $addr, $file:$func:$lno)\n";
98 my ($oldname, $oldsize, $oldfile, $oldfunc, $oldlno) = $memory->{$addr};
100 if ($memory->{$addr}->{size} != $size) {
101 print STDERR "*** Free different size ($memory->{$addr}->{size} alloced, $size freed).\n";
102 print STDERR " malloc at $memory->{$addr}->{file}:$memory->{$addr}->{func}:$memory->{$addr}->{lno}, free at $file:$func:$lno\n";
106 delete $memory->{$addr};
112 # Sort leak output by allocation time
114 return $memory->{$a}->{debug_line} <=> $memory->{$b}->{debug_line};
118 foreach $key (@sorted) {
119 my ($oldname, $oldsize, $oldfile, $oldfunc, $oldlno) = $memory->{$key};
120 print STDERR "*** Leak: $memory->{$key}->{size} bytes allocated at $key ($memory->{$key}->{file}:$memory->{$key}->{func}:$memory->{$key}->{lno}, debug file line $memory->{$key}->{debug_line})\n";
123 print STDERR "maximum used: $max, amount leaked: $total\n";