Rev 97: Show the 'total size' if available. in http://bazaar.launchpad.net/~meliae-dev/meliae/trunk

John Arbash Meinel john at arbash-meinel.com
Sat Oct 17 02:42:07 BST 2009


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

------------------------------------------------------------
revno: 97
revision-id: john at arbash-meinel.com-20091017014149-yo14wvveuqc6vs6e
parent: john at arbash-meinel.com-20091013212654-ed3tsixj3aosu0rc
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: trunk
timestamp: Fri 2009-10-16 20:41:49 -0500
message:
  Show the 'total size' if available.
-------------- next part --------------
=== modified file 'meliae/_loader.pyx'
--- a/meliae/_loader.pyx	2009-10-13 21:18:24 +0000
+++ b/meliae/_loader.pyx	2009-10-17 01:41:49 +0000
@@ -190,6 +190,7 @@
 
     def __repr__(self):
         cdef int i, max_refs
+        cdef double total_size
         if self.name is not None:
             name_str = ', %s' % (self.name,)
         else:
@@ -215,10 +216,27 @@
                 if len(r) > 21:
                     r = r[:18] + "..."
             value_str = ', %s' % (r,)
-        return ('%s(%d, %s%s, %d bytes, %d refs%s%s%s%s)'
+        if self.total_size == 0:
+            total_size_str = ''
+        else:
+            total_size = self.total_size
+            order = 'B'
+            if total_size > 800.0:
+                total_size = total_size / 1024
+                order = 'KiB'
+            if total_size > 800.0:
+                total_size = total_size / 1024
+                order = 'MiB'
+            if total_size > 800.0:
+                total_size = total_size / 1024
+                order = 'GiB'
+            total_size_str = ', %.1f%s' % (total_size, order)
+            
+
+        return ('%s(%d, %s%s, %d bytes, %d refs%s%s%s%s%s)'
                 % (self.__class__.__name__, self.address, self.type_str,
                    name_str, self.size, num_refs, ref_space, ref_str,
-                   referrer_str, value_str))
+                   referrer_str, value_str, total_size_str))
 
     def _intern_from_cache(self, cache):
         self.type_str = cache.setdefault(self.type_str, self.type_str)

=== modified file 'meliae/loader.py'
--- a/meliae/loader.py	2009-10-13 21:13:20 +0000
+++ b/meliae/loader.py	2009-10-17 01:41:49 +0000
@@ -259,6 +259,7 @@
         ## if count > obj.num_refs * 10 and count > break_on:
         ##     import pdb; pdb.set_trace()
         obj.total_size = total_size
+        return obj
 
     def compute_total_size(self):
         """This computes the total bytes referenced from this object."""

=== modified file 'meliae/tests/test__loader.py'
--- a/meliae/tests/test__loader.py	2009-10-13 21:18:24 +0000
+++ b/meliae/tests/test__loader.py	2009-10-17 01:41:49 +0000
@@ -92,3 +92,12 @@
         mem.value = 12345
         self.assertEqual('MemObject(1234, int, 12 bytes'
                          ', 0 refs, 12345)', repr(mem))
+        mem.total_size = 12
+        self.assertEqual('MemObject(1234, int, 12 bytes'
+                         ', 0 refs, 12345, 12.0B)', repr(mem))
+        mem.total_size = 1024
+        self.assertEqual('MemObject(1234, int, 12 bytes'
+                         ', 0 refs, 12345, 1.0KiB)', repr(mem))
+        mem.total_size = int(1024*1024*10.5)
+        self.assertEqual('MemObject(1234, int, 12 bytes'
+                         ', 0 refs, 12345, 10.5MiB)', repr(mem))



More information about the bazaar-commits mailing list