COUNT = 10000 STEP = 100 x = np.linspace(1, COUNT, COUNT / STEP) y = np.empty(COUNT / STEP, dtype=int) i = 0 for contact in site.members._tree.itervalues(): contact.getId() # make sure the object's not a ZODB ghost if not i % STEP: y[i / STEP] = resource.getrusage(resource.RUSAGE_SELF).ru_maxrss / 1000 i += 1 if i >= COUNT: break plt.plot(x, y, 'bo') plt.xlabel('Objects loaded') plt.ylabel('RAM used (KB)') contact_size = (y[-1] - y[0]) / float(COUNT) print '%0.2f KB' % contact_size contact = site.members['david-glick'] contact.getId() contact_pickle_size = contact._p_estimated_size / 1000.0 print '%0.2f KB' % contact_pickle_size print '%0.2f' % (contact_size / contact_pickle_size) from IPython.display import HTML def analyze_dict(o): h = '' h += '' total = 0 size = sys.getsizeof(o) h += '' % size total += size d = vars(o) size = sys.getsizeof(d) h += '' % size total += size for k in sorted(d): v = d[k] if hasattr(v, '_p_jar'): # separate persistent item; don't count its size size = sys.getsizeof(k) else: size = sys.getsizeof(k) + sys.getsizeof(v) total += size h += '' % (k, repr(v), size) h += '' % total h += '
KeyValueSize (Bytes)
[obj]%s
[obj.__dict__]%s
%s%s%s
(TOTAL)%s
' return HTML(h) analyze_dict(contact)