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
12 my $holeTolerance = 0;
14 # Heading for heap dump
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.
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;
37 # Print results of heapdump
41 # look for blocks that are used or free
47 # Reset nextAddr for overhead detection
50 # See if the previous heap ended with a free block
52 $freeAtEndBytes += $prevFree;
59 if (/REGION ([0-9A-Fa-f]*) : *overhead ([0-9]*) committed ([0-9]*) uncommitted ([0-9]*)/) {
60 # Reset nextAddr for overhead detection
63 # See if the previous heap ended with a free block
65 $freeAtEndBytes += $prevFree;
77 if (/ *FREE ([0-9A-Fa-f]*) : *([0-9]*) overhead *([0-9]*)/)
83 # This is a free. Notes it size. If the this is the end of the heap,
84 # this is a candidate for compaction.
87 elsif (/ *USED ([0-9A-Fa-f]*) : *([0-9]*) overhead *([0-9]*)/)
96 elsif (/ *---- ([0-9A-Fa-f]*) : *([0-9]*) overhead *([0-9]*)/)
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
112 if ($nextAddr && $addr-$nextAddr > $holeTolerance) {
113 # found a hole. This is usally alignment overhead
115 $holeBytes += $addr - $nextAddr;
117 $nextAddr = $addr + $size + $overhead;
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;
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);
140 return $bytes / 1024;