Bug 448600. Add prefs to disable Ogg and WAVE backends. r=doublec,sr=bzbarsky
[mozilla-central.git] / tools / footprint / heapmap.pl
blob38438d8b9f82a0e25ef0dfa3f96f1b6ef04d9a32
1 use strict;
2 my ($freeBytes, $freeCount);
3 my ($usedBytes, $usedCount);
4 my ($uncommFreeBytes, $uncommFreeCount);
5 my ($freeAtEndBytes, $freeAtEndCount);
6 my ($overheadBytes, $overheadCount);
7 my ($holeBytes, $holeCount, @hole);
8 my ($commBytes, $uncommBytes);
9 # track prev address of allocation to detect holes
10 # Track begin and end address of contiguous block
11 my ($nextAddr) = 0;
12 my $holeTolerance = 0;
14 # Heading for heap dump
15 my $heading;
17 # Notes the previous block size if it was a free to track freeAtEnd.
18 # If prev block was not a free, this would be set to zero.
19 my $prevFree = 0;
21 while(<>)
23 if (/BEGIN HEAPDUMP : (.*)$/) {
24 # Initialize all variables
25 ($freeBytes, $freeCount) = 0;
26 ($usedBytes, $usedCount) = 0;
27 ($uncommFreeBytes, $uncommFreeCount) = 0;
28 ($freeAtEndBytes, $freeAtEndCount) = 0;
29 ($overheadBytes, $overheadCount) = 0;
30 ($holeBytes, $holeCount) = 0;
31 ($commBytes, $uncommBytes) = 0;
32 $heading = $1;
33 @hole = ();
34 next;
36 if (/END HEAPDUMP/) {
37 # Print results of heapdump
38 results();
39 next;
41 # look for blocks that are used or free
42 if (/BEGIN heap/) {
43 next;
46 if (/END heap/) {
47 # Reset nextAddr for overhead detection
48 $nextAddr = 0;
50 # See if the previous heap ended with a free block
51 if ($prevFree) {
52 $freeAtEndBytes += $prevFree;
53 $freeAtEndCount++;
55 $prevFree = 0;
56 next;
59 if (/REGION ([0-9A-Fa-f]*) : *overhead ([0-9]*) committed ([0-9]*) uncommitted ([0-9]*)/) {
60 # Reset nextAddr for overhead detection
61 $nextAddr = 0;
63 # See if the previous heap ended with a free block
64 if ($prevFree) {
65 $freeAtEndBytes += $prevFree;
66 $freeAtEndCount++;
68 $prevFree = 0;
70 $commBytes += $3;
71 $uncommBytes += $4;
72 $overheadBytes += $2;
73 $overheadCount++;
74 next;
77 if (/ *FREE ([0-9A-Fa-f]*) : *([0-9]*) overhead *([0-9]*)/)
79 $freeCount++;
80 $freeBytes += $2;
81 $overheadCount++;
82 $overheadBytes += $3;
83 # This is a free. Notes it size. If the this is the end of the heap,
84 # this is a candidate for compaction.
85 $prevFree = $2;
87 elsif (/ *USED ([0-9A-Fa-f]*) : *([0-9]*) overhead *([0-9]*)/)
89 $usedCount++;
90 $usedBytes += $2;
91 $overheadCount++;
92 $overheadBytes += $3;
93 # This wasn't a free
94 $prevFree = 0;
96 elsif (/ *---- ([0-9A-Fa-f]*) : *([0-9]*) overhead *([0-9]*)/)
98 $uncommFreeCount++;
99 $uncommFreeBytes += $2;
100 # these won't have any overhead
101 # we shouldn't view this as a free as we could shed this and
102 # reduce our VmSize
103 $prevFree = $2;
105 else {
106 next;
108 my $addr = hex $1;
109 my $size = $2;
110 my $overhead = $3;
112 if ($nextAddr && $addr-$nextAddr > $holeTolerance) {
113 # found a hole. This is usally alignment overhead
114 $holeCount ++;
115 $holeBytes += $addr - $nextAddr;
117 $nextAddr = $addr + $size + $overhead;
120 sub results()
122 printf "Heap statistics : $heading\n";
123 printf "------------------------------------------------------------\n";
124 printf "USED : %8.2f K in %6d blocks\n", toK($usedBytes), $usedCount;
125 printf "FREE : %8.2f K in %6d blocks\n", toK($freeBytes), $freeCount;
126 printf "Uncommitted FREE : %8.2f K in %6d blocks\n", toK($uncommFreeBytes), $uncommFreeCount;
127 printf "Overhead : %8.2f K in %6d blocks\n", toK($overheadBytes), $overheadCount;
128 printf "Alignment overhead : %8.2f K in %6d blocks\n", toK($holeBytes), $holeCount;
129 printf " Total : %8.2f K\n", toK($freeBytes+$usedBytes+$uncommFreeBytes+$overheadBytes+$holeBytes);
130 printf "FREE at heap end : %8.2f K in %6d blocks - %5.2f%% of FREE\n", toK($freeAtEndBytes), $freeAtEndCount, $freeAtEndBytes/($freeBytes+$uncommFreeBytes)*100;
131 printf "\n";
132 printf "Total Commit : %8.2f K\n", toK($commBytes);
133 printf "Total Uncommit : %8.2f K\n", toK($uncommBytes);
134 printf " Total : %8.2f K\n", toK($uncommBytes + $commBytes);
137 sub toK()
139 my $bytes = shift;
140 return $bytes / 1024;