Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_asized_detail(self):
foo = Foo(42)
size1 = asizeof.asized(foo, detail=1)
size2 = asizeof.asized(foo, detail=2)
self.assertEqual(size1.size, size2.size)
def _print_functions(self, obj, name=None, align=8, detail=MAX, code=False, limit=MAX,
opt='', **unused):
if name:
self._printf('%sasizeof functions for %s ... %s', os.linesep, name, opt)
self._printf('%s(): %s', ' basicsize', asizeof.basicsize(obj))
self._printf('%s(): %s', ' itemsize', asizeof.itemsize(obj))
self._printf('%s(): %r', ' leng', asizeof.leng(obj))
self._printf('%s(): %s', ' refs', _repr(asizeof.refs(obj)))
self._printf('%s(): %s', ' flatsize', asizeof.flatsize(obj, align=align)) # , code=code
self._printf('%s(): %s', ' asized', asizeof.asized(obj, align=align, detail=detail, code=code, limit=limit))
##_printf('%s(): %s', '.asized', _asizer.asized(obj, align=align, detail=detail, code=code, limit=limit))
def test_namedtuple(self):
'''Test values are included but namedtuple __dict__ isn't.
'''
from collections import namedtuple
Point = namedtuple('Point', ['x', 'y'])
point = Point(x=11, y=22)
size = asizeof.asized(point, detail=1)
refs = [ref.name for ref in size.refs]
self.assertTrue('__dict__' not in refs, refs)
self.assertTrue('11' in refs, refs)
def test_asized_detail(self):
foo = Foo(42)
size1 = asizeof.asized(foo, detail=1)
size2 = asizeof.asized(foo, detail=2)
self.assertEqual(size1.size, size2.size)
def test_asized_format(self):
'''Test Asized.format(depth=x)
'''
foo = Foo(42)
sized1 = asizeof.asized(foo, detail=1)
sized2 = asizeof.asized(foo, detail=2)
sized1_no = sized1.format('%(name)s', order_by='name')
sized1_d1 = sized1.format('%(name)s', depth=1, order_by='name')
sized1_d2 = sized1.format('%(name)s', depth=2, order_by='name')
sized2_d1 = sized2.format('%(name)s', depth=1, order_by='name')
sized2_d2 = sized2.format('%(name)s', depth=2, order_by='name')
self.assertEqual(sized1_no, "Foo\n __class__\n __dict__")
self.assertEqual(sized1_no, sized1_d1)
self.assertEqual(sized1_no, sized1_d2)
self.assertEqual(sized1_d1, sized2_d1)
self.assertNotEqual(sized2_d1, sized2_d2)
def _compute_sizes(obj, min_size=10000):
"""Return the sizes of the attributes of an object."""
size = asized(obj, detail=2)
for ref in size.refs:
if ref.name == '__dict__':
break
else:
raise Exception('Cannot find __dict__ reference')
return {
item.name.split(':')[0][4:]: item.size
for item in ref.refs
if item.size > min_size
}
def __memory_info(self):
# Get all memory info and get details with 20 depth
size_obj = asizeof.asized(self._node, detail=20)
whole_size = size_obj.size
size_obj = next(r for r in size_obj.refs if r.name == '__dict__')
size_dict = dict()
# Sort in descending order to select most 'heavy' collections
for num, sub_obj in enumerate(sorted(size_obj.refs, key=lambda v: v.size, reverse=True)):
if num > 5:
break
size_dict[sub_obj.name] = dict()
size_dict[sub_obj.name]['size'] = sub_obj.size
# Check if this object (which include __dict__ and __class__) or iterable (dict, list, etc ..)
if len(sub_obj.refs) <= 2 and any(r.name == '__dict__' for r in sub_obj.refs):
sub_obj_ref = next(r for r in sub_obj.refs if r.name == '__dict__')
else:
sub_obj_ref = sub_obj
async def log_data_store(scheduler, state):
"""Count the number of objects and the data store size."""
state['times'].append(time())
for key, value in _iter_data_store(scheduler.data_store_mgr.data):
state['objects'][key].append(
len(value)
)
state['size'][key].append(
asized(value).size
)