Rev 175: ObjManager.summarize() now handles subset summaries in a pretty decent way. in http://bazaar.launchpad.net/~meliae-dev/meliae/trunk

John Arbash Meinel john at arbash-meinel.com
Sat Jul 31 05:23:56 BST 2010


At http://bazaar.launchpad.net/~meliae-dev/meliae/trunk

------------------------------------------------------------
revno: 175
revision-id: john at arbash-meinel.com-20100731042353-kl5zhs13vsqpo6ui
parent: john at arbash-meinel.com-20100729214449-t6giuurb1ukteb0a
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: trunk
timestamp: Fri 2010-07-30 23:23:53 -0500
message:
  ObjManager.summarize() now handles subset summaries in a pretty decent way.
-------------- next part --------------
=== modified file 'CHANGES.txt'
--- a/CHANGES.txt	2010-07-29 15:53:00 +0000
+++ b/CHANGES.txt	2010-07-31 04:23:53 +0000
@@ -24,6 +24,12 @@
   "What objects are accessible from X that aren't accessible from Y?"
   (John Arbash Meinel)
 
+* ``ObjectManager.summarize()`` can now take an object and an exclusion
+  list, and summarize the referenced objects. This can be quite useful
+  when you want to look at just a subset of the graph. The syntax is
+  ``ObjectManager.summarize(obj, [not_address1, not_address2])``.
+  (John Arbash Meinel)
+
 
 Meliae 0.2.1
 ############

=== modified file 'meliae/loader.py'
--- a/meliae/loader.py	2010-07-29 16:08:01 +0000
+++ b/meliae/loader.py	2010-07-31 04:23:53 +0000
@@ -319,9 +319,21 @@
         obj.total_size = sum(c.size for c in obj.iter_recursive_refs())
         return obj
 
-    def summarize(self):
+    def summarize(self, obj=None, excluding=None):
+        """Summarize the objects referenced from this one.
+
+        :param obj: Given obj as the root object, aggregate the count and size
+            of the types of each referenced object.
+            If not supplied, we will walk all objects.
+        :param excluding: A list of addresses to exclude from the aggregate
+        :return: An _ObjSummary() of this subset of the graph
+        """
         summary = _ObjSummary()
-        for obj in self.objs.itervalues():
+        if obj is None:
+            objs = self.objs.itervalues()
+        else:
+            objs = obj.iter_recursive_refs(excluding=excluding)
+        for obj in objs:
             summary._add(obj)
         return summary
 

=== modified file 'meliae/tests/test_loader.py'
--- a/meliae/tests/test_loader.py	2010-07-29 14:40:35 +0000
+++ b/meliae/tests/test_loader.py	2010-07-31 04:23:53 +0000
@@ -391,3 +391,19 @@
         manager = loader.load(_intern_dict_dump, show_prog=False)
         obj = manager.guess_intern_dict()
         self.assertEqual(8, obj.address)
+
+    def test_summarize_refs(self):
+        manager = loader.load(_example_dump, show_prog=False)
+        summary = manager.summarize(manager[2])
+        # Note that the dict itself is not excluded from the summary
+        self.assertEqual(['dict', 'int', 'str', 'tuple'],
+                         sorted(summary.type_summaries.keys()))
+        self.assertEqual(197, summary.total_size)
+
+    def test_summarize_excluding(self):
+        manager = loader.load(_example_dump, show_prog=False)
+        summary = manager.summarize(manager[2], excluding=[4, 5])
+        # No ints when they are explicitly filtered
+        self.assertEqual(['dict', 'str', 'tuple'],
+                         sorted(summary.type_summaries.keys()))
+        self.assertEqual(173, summary.total_size)



More information about the bazaar-commits mailing list