Merge pull request #5714 from alexischr/update_bockbuild
[mono.git] / scripts / mono-heapviz
index cb8a034f977d72894dea262fab819c2be873928a..27b6f7f60235790c7c55fbd5748b9698f25de6a8 100755 (executable)
@@ -8,7 +8,7 @@
 from __future__ import print_function
 import sys, os
 import Image, ImageDraw
-from xml.sax import ContentHandler, saxutils, make_parser
+from xml.sax import ContentHandler, make_parser
 from xml.sax.handler import feature_namespaces
 from optparse import OptionParser
 
@@ -92,8 +92,11 @@ class SmallSectionHandler (SectionHandler):
         assert kind == 'old'
         if self.width <= 0:
             self.width = (size + chunk_size - 1) / chunk_size
-        else:
-            assert self.width == (size + chunk_size - 1) / chunk_size
+            if self.width < 128:
+                self.width = 512
+                self.current_section_size = size
+            else:
+                self.current_section_size = self.width * chunk_size
         self.size += size
 
     def add_object (self, klass, offset, size):
@@ -103,14 +106,14 @@ class SmallSectionHandler (SectionHandler):
         SectionHandler.add_occupied (self, self.offset + offset, size)
 
     def end_section (self):
-        self.offset += self.width * chunk_size
+        self.offset += self.current_section_size
 
     def header (self):
         return 'old sections'
 
 class LargeSectionHandler (SectionHandler):
     def __init__ (self):
-        SectionHandler.__init__ (self, 500)
+        SectionHandler.__init__ (self, 512)
 
     def start_section (self, kind, size):
         self.kind = kind
@@ -124,7 +127,7 @@ class LargeSectionHandler (SectionHandler):
     def header (self):
         return self.kind + ' section'
 
-class DocHandler (saxutils.DefaultHandler):
+class DocHandler (ContentHandler):
     def start (self):
         self.collection_index = 0
         self.index_file = open ('index.html', 'w')
@@ -153,6 +156,7 @@ class DocHandler (saxutils.DefaultHandler):
             self.usage = {}
             self.los_usage = {}
             self.pinned_usage = {}
+            self.occupancies = {}
             self.in_los = False
             self.in_pinned = False
             self.heap_used = 0
@@ -166,6 +170,13 @@ class DocHandler (saxutils.DefaultHandler):
             kind = attrs.get('type', None)
             bytes = int(attrs.get('bytes', None))
             print ('Pinned from %s: %d kB<br>' % (kind, bytes / 1024), file = self.collection_file)
+        elif name == 'occupancy':
+            size = int (attrs.get ('size', None))
+            available = int (attrs.get ('available', None))
+            used = int (attrs.get ('used', None))
+            unused = available - used
+
+            print ('Occupancy of %d byte slots: %d / %d (%d kB / %d%% wasted)<br>' % (size, used, available, unused * size / 1024, unused * 100 / available), file = self.collection_file)
         elif name == 'section':
             kind = attrs.get('type', None)
             size = int(attrs.get('size', None))