def invoke(self, args, from_tty): args = args.split() if args: only_size = int(args[0]) only_cat = args[1] only_str = args[2] else: only_size = None only_cat = None only_str = None print('Used chunks of memory on heap') print('-----------------------------') ms = glibc_arenas.get_ms() for i, u in enumerate(lazily_get_usage_list()): # if not chunk.is_inuse(): # continue # size = chunk.chunksize() # mem = chunk.as_mem() # u = Usage(mem, size) size = u.size if only_size and size != only_size: continue category = categorize(u, None) if only_cat and category.kind != only_cat: continue hd = hexdump_as_bytes(u.start, min(size, 64)) if only_str and only_str not in hd: continue print ('%6i: %s -> %s %8i bytes %20s |%s' % (i, fmt_addr(u.start), fmt_addr(u.start + size), size, category, hd)) print()
def __iter__(self): from heap import iter_usage_with_progress, lazily_get_usage_list if True: # 2-pass, but the expensive first pass may be cached usage_list = lazily_get_usage_list() for u in usage_list: if self.filter_.eval_(u): yield u else: # 1-pass: # This may miss blocks that are only categorized w.r.t. to other # blocks: for u in iter_usage_with_progress(): if self.filter_.eval_(u): yield u
def invoke(self, args, from_tty): total_by_category = {} count_by_category = {} total_size = 0 total_count = 0 try: usage_list = list(lazily_get_usage_list()) for u in usage_list: u.ensure_category() total_size += u.size if u.category in total_by_category: total_by_category[u.category] += u.size else: total_by_category[u.category] = u.size total_count += 1 if u.category in count_by_category: count_by_category[u.category] += 1 else: count_by_category[u.category] = 1 except KeyboardInterrupt: pass # FIXME t = Table(['Domain', 'Kind', 'Detail', 'Count', 'Allocated size']) for category in sorted(total_by_category.keys(), key=total_by_category.get, reverse=True): detail = category.detail if not detail: detail = '' t.add_row([ category.domain, category.kind, detail, fmt_size(count_by_category[category]), fmt_size(total_by_category[category]), ]) t.add_row( ['', '', 'TOTAL', fmt_size(total_count), fmt_size(total_size)]) t.write(sys.stdout) print()
def invoke(self, args, from_tty): total_by_category = {} count_by_category = {} total_size = 0 total_count = 0 try: usage_list = list(lazily_get_usage_list()) for u in usage_list: u.ensure_category() total_size += u.size if u.category in total_by_category: total_by_category[u.category] += u.size else: total_by_category[u.category] = u.size total_count += 1 if u.category in count_by_category: count_by_category[u.category] += 1 else: count_by_category[u.category] = 1 except KeyboardInterrupt: pass # FIXME t = Table(['Domain', 'Kind', 'Detail', 'Count', 'Allocated size']) for category in sorted(total_by_category.keys(), lambda s1, s2: cmp(total_by_category[s2], total_by_category[s1]) ): detail = category.detail if not detail: detail = '' t.add_row([category.domain, category.kind, detail, fmt_size(count_by_category[category]), fmt_size(total_by_category[category]), ]) t.add_row(['', '', 'TOTAL', fmt_size(total_count), fmt_size(total_size)]) t.write(sys.stdout) print