Merge pull request #5714 from alexischr/update_bockbuild
[mono.git] / scripts / mono-heapviz
index 0daa98351a81b9d4af677b939aabf629380637d5..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
 
@@ -127,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')
@@ -156,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
@@ -169,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))