update readme and add gitignore
[client-tools.git] / tools / memoryReport.pl
bloba588480bc4af304d8d7cc11d6ae23a206ec1a069
1 die "usage: perl memoryReport.pl [-c (sort by count) | -a (sort by allocated amount)] [-l] logFile.txt" if (@ARGV < 1 || $ARGV[0] eq "-h");
3 $sortMethod = 0; # 0 = using sort by allocated amount, 1 = sort by allocation count
5 if ($ARGV[0] eq "-c")
7 shift @ARGV;
8 $sortMethod = 1;
11 if ($ARGV[0] eq "-a")
13 shift @ARGV;
14 $sortMethod = 0;
18 if ($ARGV[0] eq "-l")
20 shift @ARGV;
21 $lines = 1;
24 sub sortAllocated
26 return -($allocated{$a} <=> $allocated{$b});
29 sub sortCount
31 return -($count{$a} <=> $count{$b});
34 while (<>)
36 chomp;
38 if (/memory allocation/ || /memory leak/)
40 s/.*[\/\\]//;
41 s/^.*unknown/unknown/;
42 s/:.*,//;
43 s/bytes$//;
44 s/\(.*\)// if (! $lines);
45 ($file, $size) = split;
46 $allocated{$file} += $size;
47 $count{$file} += 1;
49 elsif (s/: alloc / /)
51 s/=.*//;
52 s/\(.*\)// if (! $lines);
53 ($file, $size) = split;
54 $allocated{$file} += $size;
55 $count{$file} += 1;
59 if ($sortMethod == 0)
61 # print sorted by allocated amount
62 foreach (sort sortAllocated keys %allocated)
64 print $count{$_}, "\t", $allocated{$_}, "\t", $_, "\n";
67 else
69 # print sorted by # allocations
70 foreach (sort sortCount keys %count)
72 print $count{$_}, "\t", $allocated{$_}, "\t", $_, "\n";