def dump_rpy_heap(file): """Write a full dump of the objects in the heap to the given file (which can be a file, a file name, or a file descritor). Format for each object (each item is one machine word): [addr] [typeindex] [size] [addr1]..[addrn] [-1] where [addr] is the address of the object, [typeindex] and [size] are as get_rpy_type_index() and get_rpy_memory_usage() would return, and [addr1]..[addrn] are addresses of other objects that this object points to. The full dump is a list of such objects, with a marker [0][0][0][-1] inserted after all GC roots, before all non-roots. If the argument is a filename and the 'zlib' module is available, we also write 'typeids.txt' and 'typeids.lst' in the same directory, if they don't already exist. """ if isinstance(file, str): f = open(file, 'wb') gc._dump_rpy_heap(f.fileno()) f.close() try: import zlib, os except ImportError: pass else: filename2 = os.path.join(os.path.dirname(file), 'typeids.txt') if not os.path.exists(filename2): data = zlib.decompress(gc.get_typeids_z()) f = open(filename2, 'w') f.write(data) f.close() filename2 = os.path.join(os.path.dirname(file), 'typeids.lst') if not os.path.exists(filename2): data = ''.join(['%d\n' % n for n in gc.get_typeids_list()]) f = open(filename2, 'w') f.write(data) f.close() else: if isinstance(file, int): fd = file else: if hasattr(file, 'flush'): file.flush() fd = file.fileno() gc._dump_rpy_heap(fd)
def dump_rpy_heap(stream): # pragma: nocover """Write PyPy's gcdump to the specified stream""" if not hasattr(gc, '_dump_rpy_heap'): # not PyPy return with tempfile.NamedTemporaryFile('wb') as fp: gc._dump_rpy_heap(fp.fileno()) try: fpsize = os.stat(fp.name).st_size except OSError: pass else: stream.write("{} size: {}\n".format(fp.name, fpsize)) stat = Stat() stat.summarize(fp.name, stream=None) stat.load_typeids(zlib.decompress(gc.get_typeids_z()).split("\n")) stream.write('\n\n') stat.print_summary(stream)
i = start if stop is None: stop = len(a) while i < stop: j = i + 3 while a[j] != -1: j += 1 yield (i, a[i], a[i+1], a[i+2], a[i+3:j]) i = j + 1 print >> sys.stderr, 'done' if __name__ == '__main__': if len(sys.argv) <= 1: print >> sys.stderr, __doc__ sys.exit(2) stat = Stat() stat.summarize(sys.argv[1]) # if len(sys.argv) > 2: typeid_name = sys.argv[2] else: typeid_name = os.path.join(os.path.dirname(sys.argv[1]), 'typeids.txt') if os.path.isfile(typeid_name): stat.load_typeids(typeid_name) else: import zlib, gc stat.load_typeids(zlib.decompress(gc.get_typeids_z()).split("\n")) # stat.print_summary()
i = start if stop is None: stop = len(a) while i < stop: j = i + 3 while a[j] != -1: j += 1 yield (i, a[i], a[i + 1], a[i + 2], a[i + 3:j]) i = j + 1 print >> sys.stderr, 'done' if __name__ == '__main__': if len(sys.argv) <= 1: print >> sys.stderr, __doc__ sys.exit(2) stat = Stat() stat.summarize(sys.argv[1]) # if len(sys.argv) > 2: typeid_name = sys.argv[2] else: typeid_name = os.path.join(os.path.dirname(sys.argv[1]), 'typeids.txt') if os.path.isfile(typeid_name): stat.load_typeids(typeid_name) else: import zlib, gc stat.load_typeids(zlib.decompress(gc.get_typeids_z()).split("\n")) # stat.print_summary()